How to solve failed to load API definition?
See original GitHub issueI am trying to configure the swagger.json but every time it is giving the below error.
Fetch errorFailed to fetch C:\Project\test\swagger.json
Fetch errorPossible cross-origin (CORS) issue? The URL origin (file://) does not match the page (http://127.0.0.1:5000). Check the server returns the correct 'Access-Control-Allow-*' headers.
When i clicked on “Invalid” button {"schemaValidationMessages":[{"level":"error","message":"Can't read from file c:/Project\test\\swagger.json"}]}
this error is coming .
SWAGGER_URL = '/swagger'
API_URL = 'C:\Project\test\swagger.json'
SWAGGERUI_BLUEPRINT = get_swaggerui_blueprint(
SWAGGER_URL,
API_URL,
config={
'app_name': "Seans-Python-Flask-REST-Boilerplate"
}
)
app.register_blueprint(SWAGGERUI_BLUEPRINT, url_prefix=SWAGGER_URL)
Let me know what i am doing wrong.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Swashbuckle/Swagger + ASP.Net Core: "Failed to load API ...
This helped me find the answer. The problem was a public helper method in a controller. Changed it to protected - swagger file...
Read more >WebApi Core / Swagger: "failed to load API definition" error
I was working with some ASP.NET WebApi code and needed to test something using the Swagger UI. Usually, it's just a matter of...
Read more >Failed to load Swagger API definition for a Newly Published ...
I just pushed a .NET Core 6.0 WebAPI to Azure AppService. When I access the location I receive the following error issued when...
Read more >Resolved:Failed to load API definition (undefined /swagger/v1 ...
Please make sure all controller methods are attributed with proper HTTP attributes Example- HttpGET or HttpPost etc. Missing this attribute ...
Read more >Swagger Failed to load API definition In ASP.NET Core API
The solution is that you have to change the default route configuration at the controller level when you have created more than one...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You could do something like this modified example, if using flask to serve the file:
This assumes that
swagger.json
is in current working directory, so adjust accordingly.Hi,
the API_URL should be a endpoint (resource) at your server (e.g. /docs/swagger.json), not a file on the system. In other words you’ll need to manually serve this file somehow at a given resource.