Integrate Swagger-UI into project
See original GitHub issueI followed these instructions; probably the best Instructions i’ve seen anywhere pertaining to swagger (and clearest), https://idratherbewriting.com/learnapidoc/pubapis_swagger.html#create-a-swagger-ui-display When i run the nodejs project on my local machine it runs fine; i can go to the ‘/swagger’ route and see the swagger-ui. However when i publish this to the server it can’t find the ‘page’.
Per the instruction above, i am supposed to do the following:
- download the dist folder (https://github.com/swagger-api/swagger-ui)
- copy the contents of the dist folder into your projects (copied all files into the project directory where the project swagger.yaml file existed … ./app/swagger/swagger.yaml)
- modify the content of the index.html file so it points to your swagger.yaml file:
// Build a system const ui = SwaggerUIBundle({ url: "swagger.yaml", // <-- modified this line dom_id: '#swagger-ui', docExpansion: 'none', deepLinking: true, presets: [ SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset ], plugins: [ SwaggerUIBundle.plugins.DownloadUrl ], layout: "StandaloneLayout" })
- in the app.js file include the following code (route to swagger UI) //app.use(‘/swagger’, express.static(‘./api/swagger’)); var path = require(‘path’); app.use(‘/swagger’, express.static(path.join(__dirname + ‘/api/swagger’)));
I’ll probably end up muddling through this on my own but doesn’t kill to post the question. Reading articles online is at times minefield because you find too many ways to do the same thing and it’s also at times difficult to tell what resources (node package) are needed.
I am guessing either step #3 or #4 is wrong or i am missing an node package. The swagger file itself works fine when tested with the swagger editor (is valid). If i figure out the issue i’ll post it.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
You are right. I went ahead and switched the forward slash to a double back slash and published to the server and it works. I’ve been working a good portion of the day testing out all the wrong things. The final solution was:
const ui = SwaggerUIBundle({ url: "swagger.yaml", // <-- modified this line **** dom_id: '#swagger-ui', docExpansion: 'none', deepLinking: true, presets: [ SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset ], plugins: [ SwaggerUIBundle.plugins.DownloadUrl ], layout: "StandaloneLayout" })
Again most of this came from the website mentioned above … just added some to the explanation. Thanks again Shockey for all the help. Helped out a ton.
@brianupskill you’d need to consult a lawyer to discuss the specifics of your use case - we can’t provide that for you here 😄
More generally, here’s a plain-English summary of the Apache 2.0 license: https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)