Azure API App proxy generation error

2019-07-29 09:47发布

问题:

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:

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.