[d24f17c] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
---|
| 4 | exports.__esModule = true;
|
---|
| 5 | exports.default = void 0;
|
---|
| 6 | var _react = _interopRequireDefault(require("react"));
|
---|
| 7 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
---|
| 8 | var _swaggerUi = _interopRequireDefault(require("#swagger-ui"));
|
---|
| 9 | class SwaggerUI extends _react.default.Component {
|
---|
| 10 | constructor(props) {
|
---|
| 11 | super(props);
|
---|
| 12 | this.SwaggerUIComponent = null;
|
---|
| 13 | this.system = null;
|
---|
| 14 | }
|
---|
| 15 | componentDidMount() {
|
---|
| 16 | const ui = (0, _swaggerUi.default)({
|
---|
| 17 | plugins: this.props.plugins,
|
---|
| 18 | spec: this.props.spec,
|
---|
| 19 | url: this.props.url,
|
---|
| 20 | layout: this.props.layout,
|
---|
| 21 | defaultModelsExpandDepth: this.props.defaultModelsExpandDepth,
|
---|
| 22 | defaultModelRendering: this.props.defaultModelRendering,
|
---|
| 23 | presets: [_swaggerUi.default.presets.apis, ...this.props.presets],
|
---|
| 24 | requestInterceptor: this.props.requestInterceptor,
|
---|
| 25 | responseInterceptor: this.props.responseInterceptor,
|
---|
| 26 | onComplete: this.onComplete,
|
---|
| 27 | docExpansion: this.props.docExpansion,
|
---|
| 28 | supportedSubmitMethods: this.props.supportedSubmitMethods,
|
---|
| 29 | queryConfigEnabled: this.props.queryConfigEnabled,
|
---|
| 30 | defaultModelExpandDepth: this.props.defaultModelExpandDepth,
|
---|
| 31 | displayOperationId: this.props.displayOperationId,
|
---|
| 32 | tryItOutEnabled: this.props.tryItOutEnabled,
|
---|
| 33 | displayRequestDuration: this.props.displayRequestDuration,
|
---|
| 34 | requestSnippetsEnabled: this.props.requestSnippetsEnabled,
|
---|
| 35 | requestSnippets: this.props.requestSnippets,
|
---|
| 36 | showMutatedRequest: this.props.showMutatedRequest,
|
---|
| 37 | deepLinking: this.props.deepLinking,
|
---|
| 38 | showExtensions: this.props.showExtensions,
|
---|
| 39 | showCommonExtensions: this.props.showCommonExtensions,
|
---|
| 40 | filter: this.props.filter,
|
---|
| 41 | persistAuthorization: this.props.persistAuthorization,
|
---|
| 42 | withCredentials: this.props.withCredentials,
|
---|
| 43 | ...(typeof this.props.oauth2RedirectUrl === "string" ? {
|
---|
| 44 | oauth2RedirectUrl: this.props.oauth2RedirectUrl
|
---|
| 45 | } : {})
|
---|
| 46 | });
|
---|
| 47 | this.system = ui;
|
---|
| 48 | this.SwaggerUIComponent = ui.getComponent("App", "root");
|
---|
| 49 | this.forceUpdate();
|
---|
| 50 | }
|
---|
| 51 | render() {
|
---|
| 52 | return this.SwaggerUIComponent ? /*#__PURE__*/_react.default.createElement(this.SwaggerUIComponent, null) : null;
|
---|
| 53 | }
|
---|
| 54 | componentDidUpdate(prevProps) {
|
---|
| 55 | const prevStateUrl = this.system.specSelectors.url();
|
---|
| 56 | if (this.props.url !== prevStateUrl || this.props.url !== prevProps.url) {
|
---|
| 57 | // flush current content
|
---|
| 58 | this.system.specActions.updateSpec("");
|
---|
| 59 | if (this.props.url) {
|
---|
| 60 | // update the internal URL
|
---|
| 61 | this.system.specActions.updateUrl(this.props.url);
|
---|
| 62 | // trigger remote definition fetch
|
---|
| 63 | this.system.specActions.download(this.props.url);
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 | const prevStateSpec = this.system.specSelectors.specStr();
|
---|
| 67 | if (this.props.spec && (this.props.spec !== prevStateSpec || this.props.spec !== prevProps.spec)) {
|
---|
| 68 | if (typeof this.props.spec === "object") {
|
---|
| 69 | this.system.specActions.updateSpec(JSON.stringify(this.props.spec));
|
---|
| 70 | } else {
|
---|
| 71 | this.system.specActions.updateSpec(this.props.spec);
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 | onComplete = () => {
|
---|
| 76 | if (typeof this.props.onComplete === "function") {
|
---|
| 77 | return this.props.onComplete(this.system);
|
---|
| 78 | }
|
---|
| 79 | };
|
---|
| 80 | }
|
---|
| 81 | SwaggerUI.defaultProps = {
|
---|
| 82 | spec: "",
|
---|
| 83 | url: "",
|
---|
| 84 | layout: "BaseLayout",
|
---|
| 85 | requestInterceptor: req => req,
|
---|
| 86 | responseInterceptor: res => res,
|
---|
| 87 | supportedSubmitMethods: ["get", "put", "post", "delete", "options", "head", "patch", "trace"],
|
---|
| 88 | queryConfigEnabled: false,
|
---|
| 89 | plugins: [],
|
---|
| 90 | displayOperationId: false,
|
---|
| 91 | showMutatedRequest: true,
|
---|
| 92 | docExpansion: "list",
|
---|
| 93 | defaultModelExpandDepth: 1,
|
---|
| 94 | defaultModelsExpandDepth: 1,
|
---|
| 95 | defaultModelRendering: "example",
|
---|
| 96 | presets: [],
|
---|
| 97 | deepLinking: false,
|
---|
| 98 | showExtensions: false,
|
---|
| 99 | showCommonExtensions: false,
|
---|
| 100 | filter: null,
|
---|
| 101 | requestSnippetsEnabled: false,
|
---|
| 102 | requestSnippets: {
|
---|
| 103 | generators: {
|
---|
| 104 | "curl_bash": {
|
---|
| 105 | title: "cURL (bash)",
|
---|
| 106 | syntax: "bash"
|
---|
| 107 | },
|
---|
| 108 | "curl_powershell": {
|
---|
| 109 | title: "cURL (PowerShell)",
|
---|
| 110 | syntax: "powershell"
|
---|
| 111 | },
|
---|
| 112 | "curl_cmd": {
|
---|
| 113 | title: "cURL (CMD)",
|
---|
| 114 | syntax: "bash"
|
---|
| 115 | }
|
---|
| 116 | },
|
---|
| 117 | defaultExpanded: true,
|
---|
| 118 | languages: null // e.g. only show curl bash = ["curl_bash"]
|
---|
| 119 | },
|
---|
| 120 | tryItOutEnabled: false,
|
---|
| 121 | displayRequestDuration: false,
|
---|
| 122 | withCredentials: undefined,
|
---|
| 123 | persistAuthorization: false,
|
---|
| 124 | oauth2RedirectUrl: undefined
|
---|
| 125 | };
|
---|
| 126 | SwaggerUI.System = _swaggerUi.default.System;
|
---|
| 127 | SwaggerUI.presets = _swaggerUi.default.presets;
|
---|
| 128 | SwaggerUI.plugins = _swaggerUi.default.plugins;
|
---|
| 129 | var _default = exports.default = SwaggerUI;
|
---|
| 130 |
|
---|