The Wayback Machine - https://web.archive.org/web/20200706164711/https://github.com/swagger-api/swagger-ui/issues/5981
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mechanism to override host, basePath and scheme for OpenAPI 2.x definitions #5981

Open
char0n opened this issue Apr 30, 2020 · 0 comments
Open

Mechanism to override host, basePath and scheme for OpenAPI 2.x definitions #5981

char0n opened this issue Apr 30, 2020 · 0 comments

Comments

@char0n
Copy link
Member

@char0n char0n commented Apr 30, 2020

Q&A (please complete the following information)

  • Method of installation: [npm, dist assets]
  • Swagger-UI version: [>=3.25.1]
  • Swagger/OpenAPI version: [Swagger 2.0]

Content & configuration

Swagger/OpenAPI definition:
https://petstore.swagger.io/v2/swagger.json

Swagger-UI configuration options:

const UrlMutatorPlugin = (system) => ({
  rootInjects: {
    setScheme: (scheme) => {
      const jsonSpec = system.getState().toJSON().spec.json;
      const schemes = Array.isArray(scheme) ? scheme : [scheme];
      const newJsonSpec = Object.assign({}, jsonSpec, { schemes });

      return system.specActions.updateJsonSpec(newJsonSpec);
    },
    setHost: (host) => {
      const jsonSpec = system.getState().toJSON().spec.json;
      const newJsonSpec = Object.assign({}, jsonSpec, { host });

      return system.specActions.updateJsonSpec(newJsonSpec);
    },
    setBasePath: (basePath) => {
      const jsonSpec = system.getState().toJSON().spec.json;
      const newJsonSpec = Object.assign({}, jsonSpec, { basePath });

      return system.specActions.updateJsonSpec(newJsonSpec);
    }
  }
});

window.ui = SwaggerUI({
  dom_id: '#myDomId',
  plugins: [
    UrlMutatorPlugin,
  ],
  onComplete: () => {
    // this will set appropriate data when swagger-ui ready
    window.ui.setScheme('http');
    window.ui.setHost('www.google.com');
    window.ui.setBasePath('v3');
  }   
})

Gist where UrlMutatorPlugin will be maintained until fully verified that it satisfy the community usecases:

https://gist.github.com/char0n/3b6005c187a4bb771a27705d123af6cd

How can we help?

This issue is not about requesting support, but more about giving one. It consolidates all other issues that have been created around this topics.

Related issues

swagger-api/swagger-js#1095
swagger-api/swagger-js#1027
swagger-api/swagger-js#532
swagger-api/swagger-js#1045
#3042

@char0n char0n changed the title Mechanism to override `path`, `basePath` and `scheme` for OpenAPI 2.x definitions Mechanism to override path, basePath and scheme for OpenAPI 2.x definitions Apr 30, 2020
@char0n char0n self-assigned this Apr 30, 2020
@char0n char0n changed the title Mechanism to override path, basePath and scheme for OpenAPI 2.x definitions Mechanism to override host, basePath and scheme for OpenAPI 2.x definitions Apr 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.