Failed to load API definition error in Swagger for ASP.NET Core
There are various reasons cause the swagger to fail to load the API definition and you will get the error shared in the below screenshot. Below are the possible reasons,
- Swagger misconfiguration
- Controller methods without HTTP verbs (HttpGet, HttpPost etc.)
- Same class name etc…
Solution:
The Swagger can be launched by adding the ‘/swagger’ after your API URL which doesn’t show the error details causing the Swagger to fail to load.
http://localhost:{PortNo}/swagger/index.html
If you navigate to ‘swagger/v1/swagger.json’ page you will see error details which helpful in addressing the issues.
http://localhost:{PortNo}/swagger/v{VersionNo}/swagger.json
Note: v1 is the version of your API. Change the version according to your API version.
Once all the issues are addressed then you can launch the Swagger URL to view the API definitions.
Leave a comment