All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.index.mjs Maven / Gradle / Ivy

import React from "react";
import PropTypes from "prop-types";
import SwaggerUIConstructor from "#swagger-ui";
class SwaggerUI extends React.Component {
  constructor(props) {
    super(props);
    this.SwaggerUIComponent = null;
    this.system = null;
  }
  componentDidMount() {
    const ui = SwaggerUIConstructor({
      plugins: this.props.plugins,
      spec: this.props.spec,
      url: this.props.url,
      layout: this.props.layout,
      defaultModelsExpandDepth: this.props.defaultModelsExpandDepth,
      defaultModelRendering: this.props.defaultModelRendering,
      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,
      queryConfigEnabled: this.props.queryConfigEnabled,
      defaultModelExpandDepth: this.props.defaultModelExpandDepth,
      displayOperationId: this.props.displayOperationId,
      tryItOutEnabled: this.props.tryItOutEnabled,
      displayRequestDuration: this.props.displayRequestDuration,
      requestSnippetsEnabled: this.props.requestSnippetsEnabled,
      requestSnippets: this.props.requestSnippets,
      showMutatedRequest: this.props.showMutatedRequest,
      deepLinking: this.props.deepLinking,
      showExtensions: this.props.showExtensions,
      showCommonExtensions: this.props.showCommonExtensions,
      filter: this.props.filter,
      persistAuthorization: this.props.persistAuthorization,
      withCredentials: this.props.withCredentials,
      ...(typeof this.props.oauth2RedirectUrl === "string" ? {
        oauth2RedirectUrl: this.props.oauth2RedirectUrl
      } : {})
    });
    this.system = ui;
    this.SwaggerUIComponent = ui.getComponent("App", "root");
    this.forceUpdate();
  }
  render() {
    return this.SwaggerUIComponent ? /*#__PURE__*/React.createElement(this.SwaggerUIComponent, null) : null;
  }
  componentDidUpdate(prevProps) {
    const prevStateUrl = this.system.specSelectors.url();
    if (this.props.url !== prevStateUrl || this.props.url !== prevProps.url) {
      // flush current content
      this.system.specActions.updateSpec("");
      if (this.props.url) {
        // update the internal URL
        this.system.specActions.updateUrl(this.props.url);
        // trigger remote definition fetch
        this.system.specActions.download(this.props.url);
      }
    }
    const prevStateSpec = this.system.specSelectors.specStr();
    if (this.props.spec && (this.props.spec !== prevStateSpec || this.props.spec !== prevProps.spec)) {
      if (typeof this.props.spec === "object") {
        this.system.specActions.updateSpec(JSON.stringify(this.props.spec));
      } else {
        this.system.specActions.updateSpec(this.props.spec);
      }
    }
  }
  onComplete = () => {
    if (typeof this.props.onComplete === "function") {
      return this.props.onComplete(this.system);
    }
  };
}
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,
  showExtensions: false,
  showCommonExtensions: false,
  filter: null,
  requestSnippetsEnabled: false,
  requestSnippets: {
    generators: {
      "curl_bash": {
        title: "cURL (bash)",
        syntax: "bash"
      },
      "curl_powershell": {
        title: "cURL (PowerShell)",
        syntax: "powershell"
      },
      "curl_cmd": {
        title: "cURL (CMD)",
        syntax: "bash"
      }
    },
    defaultExpanded: true,
    languages: null // e.g. only show curl bash = ["curl_bash"]
  },
  tryItOutEnabled: false,
  displayRequestDuration: false,
  withCredentials: undefined,
  persistAuthorization: false,
  oauth2RedirectUrl: undefined
};
SwaggerUI.System = SwaggerUIConstructor.System;
SwaggerUI.presets = SwaggerUIConstructor.presets;
SwaggerUI.plugins = SwaggerUIConstructor.plugins;
export default SwaggerUI;





© 2015 - 2025 Weber Informatics LLC | Privacy Policy