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.
Provide payload as below
resource=${#Project#RESOURCE} &client_id=${#Project#CLIENT_ID} &client_secret=${#Project#CLIENT_SECRET} &grant_type=client_crendentials
You can define property file as show below, and create a file for each enrionment.
dev.properties
RESOURCE=<dev-resource> CLIENT_ID=<dev-client-id> CLIENT_SECRET=<dev-client-secret>
And import the above file at project level, refer below documentation
https://www.soapui.org/scripting-properties/working-with-properties.html
So, you can similarly, use properties for END POINTS / other varying values per environment into property file and use them in the project as mentioned in the payload content.
Now all you need is single project, common test cases. No separate test suites / test cases per environment any more, just use appropriate property file, import them into project before running the tests.
If you are running the tests command line, even properties can be directly loaded runtime without even modifying the existing values in the project.