swagger-api / swagger-api/swagger-ui
How to inject Swagger UI Configuring into index.html in Express Application
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 29k
- Forks
- 9.3k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 25
Description
Q&A (please complete the following information)
- OS: macOS running docker container containing a Linux distro an Express application)
- Browser: Chrome (not a browser issue, but using Node v8.11.1)
- Version: 67.0.3396.99
- Method of installation: npm 5.6.0 (using swagger-ui-dist)
- Swagger-UI version: 3.17.6
- Swagger/OpenAPI version: OpenAPI 3.0
Content & configuration
const pathToSwaggerUi = require('swagger-ui-dist').absolutePath();
const SwaggerUIBundle = require('swagger-ui-dist').SwaggerUIBundle;
const SwaggerUIStandalonePreset = require('swagger-ui-dist').SwaggerUIStandalonePreset;
const ui = SwaggerUIBundle({
url: '/openapi/submissions',
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIStandalonePreset
],
layout: 'StandaloneLayout'
});
const SwaggerRouter = express.Router();
SwaggerRouter.use(express.static(pathToSwaggerUi));
Swagger/OpenAPI definition:
Using a standard definition file, but due to security, I cannot paste the file or examples based on our file's structure. The issue is not related to the definition file.
Swagger-UI configuration options:
const ui = SwaggerUIBundle({
url: '/openapi/submissions',
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIStandalonePreset
],
layout: 'StandaloneLayout'
});
Screenshots
How can we help?
I'm using swagger-ui-dist in an Express application, and I can't seem to figure out how to pass my Swagger UI configuration to the static asset HTML served using this package. Clearly there's no document object in Node. The documentation is vague by advising to configure the Swagger app like above, but it does not explain how to inject into the static HTML file.
Is the only way to do this to edit the index.html file within node_modules? That seems odd to me if that is the case.
Thank you to everyone for your help!
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.
Research direction
Start by reviewing the swagger-ui-dist static index.html, the shown SwaggerUIBundle configuration, and the Express static-serving setup. Compare these with the existing documentation to identify what is missing about passing configuration to the served HTML; done means the supported setup is clearly documented or the limitation is explicitly explained.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- express, javascript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100