Forum Discussion

greglovely's avatar
greglovely
Occasional Contributor
2 years ago
Solved

Swashbuckle requests swagger.json as 'text/html' content type on server, not 'application/json'

When I run my web api project from VS2022 on my desktop, I get the results that I expect (screen print 1).

When I inspect the request for swagger.json, I see the headers (screen print 2).  They show that the swagger.json file was requested as ‘application/json’.

 

When I run the web api on the server from the browser, I get the results indicating that the file couldn’t be rendered (screen print 3).

When I inspect the request for swagger.json, I see the headers (screen print 4).  They show that the swagger.json file was requested as ‘text/html’.  Obviously, if it is reading the json file as text it will be unable to render it correctly.
How can I get Swagger to request the swagger.json as 'application/json'?  Since the swagger.json is generated at runtime, the only control I have is in my .Net Core web api project.  As you can see in screen print 5, the swagger.json does contain a correct version.