Reputation: 868
Fetch error undefined swagger/v1/swagger.json .Net Core 3.1 API
I have tried almost everything, Can anyone help me to get this fix.
Thanks in advance!
Upvotes: 6
Views: 10481
Reputation: 645
Can have few reasons for the issue
Upvotes: 0
Reputation: 1693
Following the instruction on swagger on microsoft there is a line that says: navigate to: https://localhost:/swagger/v1/swagger.json
If you have errors they will show up when you do so, and with an indication which error it is
Upvotes: 0
Reputation: 27026
Check all of the above, because it could be any of these.
But make sure to also check, that the route is unique. In my case
[Route("api")]
[ApiController]
public class MyApiForFooAbcCalcController : ControllerBase
{
// ...
}
the route "api" was already defined in a 2nd controller class of the project, which caused the conflict. Although the methods in both classes all had different names (and attributes for HttpGet, HttpPost, ...), the conflict was there and caused the runtime error. Note that it compiles without any error.
To resolve, add a more specific route for each class, e.g.:
[Route("api/forFooAbcCalc")]
and in the other one something like
[Route("api/forFooXYZCalc")]
which will then compile and run again!
Upvotes: 1
Reputation: 916
Swagger may throw this error when there are more than one endpoints with the same routing URL. Just give a try by resolving the action route URLs across all controllers and make each URL unique.
Upvotes: 1
Reputation: 21
Look in the Output console as suggested by Carlos Javier Bazan. In my case it was an error in the controller: Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorException: Ambiguous HTTP method for action - WebsiteR3.Controllers.WHhandlerController.UpdPaymentStatus
Upvotes: 1
Reputation: 21
If there is a HttpPost then you need to make sure you give it a name.
[HttpPost(nameof(UpdateContactDetails))]
and not just
[HttpPost]
Upvotes: 1
Reputation: 323
when your controller has a problem usually shows that error, check the code of your controller, in my case I forgot to put the [HttpDelete("{id}")] in a method and that's why I gave that error. in the debugging console it should show you the error, just look for it because it is quite text.
Upvotes: 1
Reputation: 2017
You should add symbol /
just before swagger
:
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "IRIEO.API");
});
Upvotes: 1