1
votes

I was able to successfully create a test API and host in Azure. However when I try to create the proxy client, I receive the following error.

[Fatal]Error generating service model: The operation 'Get' has a body parameter, but did not have a supported MIME type ('application/json') in its Consumes property.
Exception: There was an error during code generation when trying to add a client for the Microsoft Azure API App
Generating client code and adding to project failed

I checked the Swagger file and the Contains node was empty. When I change it to

"consumes": [ "application/json", "application/xml" ]

the proxy creation works. Why did the auto-generated Swagger json not have the Contains property set? I went with the default SwaggerConfig when I created the API app. Am I missing some configuration? Any help will be greatly appreciated.

1
This seems like a bug by Swashbuckle or you didn't have any serializers registered in your configuration. Do you have a project that repos the issue? If yes, can you send me a link to it?Panos
Thanks for your prompt response. Do you need access to the code or the API end point?Raju
Whatever is the minimum to repo the problem. Don't send me anything that's it's real IP of you or your company. Make it simple.Panos
I created a sample project here github.com/raju-rangan/APITest . When I try to create a API Client in the console app, it fails. I have added the generated Swagger json file in the console app. Please let me know if you need anything else. Thank you.Raju
OK, you're doing something weird. You're passing an HttpRequestMessage as input to the Action of your controller. What do you that? It's not necessary. If you need to read the Request within your code, you just do in the Action var request = Request; or just Request.CreateResponse and you're done. That's what is causing the issue as we can't deserialize what that object is and that is causing the issue. The consumes part is a misleading message. I've changed that part and it worked. To see if we can give a better message or why that message is OK to stay.Panos

1 Answers

1
votes

As I found out from the comments, the solution is to to remove the HttpRequestMessage as parameter of the Action. This will enable the API App Client to generate the code OK.

If you need to mock the object, please follow the documented way from here or another example here.