Forum Discussion
RonRatovsky
Staff
Generally speaking, swagger-core generates the API definition at runtime (just like another API endpoint). It's a bit unclear from your description how your application works. so:
- If your UI is intended to run alongside the API, you can simply point the UI to the generated definition at runtime. That way it's always up to date and there's no issue.
- If you need the UI to be completely independent from the application, you can use the maven plugin we have to generate the definition at build time and put it wherever you need. More information can be found at https://github.com/swagger-api/swagger-core/tree/master/modules/swagger-maven-plugin.
Kbm99
6 years agoNew Contributor
Thank you for replying RonRatovsky
I would like to point the UI to the generated definition at runtime but i get a "Failed to Load spec". This may be because to access the definition, there must be some authentication and custom header added. I am using a url like this on index.html
window.onload = function() {
// Build a system
const ui = SwaggerUIBundle({
url: "https://localhost:8443/example.swagger.io/api/v1/swagger.json?Platform-TenantId=default&&Authorization=Basic bWlmb3M6cGFzc3dvcmQ=",
dom_id: '#swagger-ui',
validatorUrl : false,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
})
Also the try it out buttons on the swagger ui do not function when i use the path url to the locally saved swagger spec. I think it may be due to the authentication and header to be added on every request inorder to access to the server. How can i resolve this please?
- RonRatovsky6 years agoStaff
This is most likely a CORS issue - please refer to https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/cors.md.
Related Content
- 2 years ago
Recent Discussions
- 4 days ago
- 4 days ago
- 14 days ago
- 31 days ago