Ask a Question

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

SOLVED
greglovely
Occasional Contributor

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.

 

greglovely_0-1661267965092.png

greglovely_1-1661268176917.png

greglovely_2-1661268349773.png

greglovely_4-1661268542524.png

greglovely_0-1661269785304.png

 

 

 

 

 

 

 

 

1 REPLY 1
greglovely
Occasional Contributor

Resolved on my own.

cancel
Showing results for 
Search instead for 
Did you mean: