swagger-api / swagger-api/swagger-ui
Mechanism to override host, basePath and scheme for OpenAPI 2.x definitions
@char0n is already working on this.
Since Apr 30, 2020.
- Dominant language
- JavaScript
- Stars
- 29k
- Forks
- 9.3k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 25
Description
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
https://github.com/swagger-api/swagger-js/issues/1095
https://github.com/swagger-api/swagger-js/issues/1027
https://github.com/swagger-api/swagger-js/issues/532
https://github.com/swagger-api/swagger-js/issues/1045
https://github.com/swagger-api/swagger-ui/issues/3042
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.