From 71d3eb2b44e271c8f04c3e260328689a88d555fe Mon Sep 17 00:00:00 2001 From: Vladimir Gorej Date: Fri, 30 Jun 2023 12:27:29 +0200 Subject: [PATCH] fix(swagger-ui-react): use correct default prop values --- flavors/swagger-ui-react/index.jsx | 41 ++++++++++++++---------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/flavors/swagger-ui-react/index.jsx b/flavors/swagger-ui-react/index.jsx index 0858ec9fe44..ce3be7a9feb 100644 --- a/flavors/swagger-ui-react/index.jsx +++ b/flavors/swagger-ui-react/index.jsx @@ -17,9 +17,9 @@ export default class SwaggerUI extends React.Component { layout: this.props.layout, defaultModelsExpandDepth: this.props.defaultModelsExpandDepth, defaultModelRendering: this.props.defaultModelRendering, - presets: [swaggerUIConstructor.presets.apis,...this.props.presets], - requestInterceptor: this.requestInterceptor, - responseInterceptor: this.responseInterceptor, + presets: [swaggerUIConstructor.presets.apis, ...this.props.presets], + requestInterceptor: this.props.requestInterceptor, + responseInterceptor: this.props.responseInterceptor, onComplete: this.onComplete, docExpansion: this.props.docExpansion, supportedSubmitMethods: this.props.supportedSubmitMethods, @@ -30,11 +30,11 @@ export default class SwaggerUI extends React.Component { displayRequestDuration: this.props.displayRequestDuration, requestSnippetsEnabled: this.props.requestSnippetsEnabled, requestSnippets: this.props.requestSnippets, - showMutatedRequest: typeof this.props.showMutatedRequest === "boolean" ? this.props.showMutatedRequest : true, - deepLinking: typeof this.props.deepLinking === "boolean" ? this.props.deepLinking : false, + showMutatedRequest: this.props.showMutatedRequest, + deepLinking: this.props.deepLinking, showExtensions: this.props.showExtensions, showCommonExtensions: this.props.showCommonExtensions, - filter: ["boolean", "string"].includes(typeof this.props.filter) ? this.props.filter : false, + filter: this.props.filter, persistAuthorization: this.props.persistAuthorization, withCredentials: this.props.withCredentials, oauth2RedirectUrl: this.props.oauth2RedirectUrl @@ -74,20 +74,6 @@ export default class SwaggerUI extends React.Component { } } - requestInterceptor = (req) => { - if (typeof this.props.requestInterceptor === "function") { - return this.props.requestInterceptor(req) - } - return req - } - - responseInterceptor = (res) => { - if (typeof this.props.responseInterceptor === "function") { - return this.props.responseInterceptor(res) - } - return res - } - onComplete = () => { if (typeof this.props.onComplete === "function") { return this.props.onComplete(this.system) @@ -138,18 +124,25 @@ SwaggerUI.propTypes = { } SwaggerUI.defaultProps = { + spec: {}, + url: "", layout: "BaseLayout", + requestInterceptor: req => req, + responseInterceptor: res => res, supportedSubmitMethods: ["get", "put", "post", "delete", "options", "head", "patch", "trace"], queryConfigEnabled: false, + plugins: [], + displayOperationId: false, + showMutatedRequest: true, docExpansion: "list", + defaultModelExpandDepth: 1, defaultModelsExpandDepth: 1, defaultModelRendering: "example", presets: [], deepLinking: false, - displayRequestDuration: false, showExtensions: false, showCommonExtensions: false, - filter: false, + filter: null, requestSnippetsEnabled: false, requestSnippets: { generators: { @@ -169,7 +162,11 @@ SwaggerUI.defaultProps = { defaultExpanded: true, languages: null, // e.g. only show curl bash = ["curl_bash"] }, + tryItOutEnabled: false, + displayRequestDuration: false, + withCredentials: undefined, persistAuthorization: false, + oauth2RedirectUrl: `${window.location.protocol}//${window.location.host}${window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/"))}/oauth2-redirect.html`, } SwaggerUI.presets = swaggerUIConstructor.presets