Azure / Azure/azure-functions-openapi-extension
Manually post-process the generated structure?
- Dominant language
- C#
- Stars
- 388
- Forks
- 202
- PR merge metrics
- No merged PRs in 30d
Description
**Description**
I have an API that returns a model that in turn contains another model, but from an external package, and one of the properties on that model is of the type `System.Net.HttpStatusCode`.
When my model is referenced as the `Type` in my `OpenApiResponseWithBody`, it correctly renders the enum in the generated output, but because the HttpStatusCode enum contains multiple definitions of the same status code, (for example, `Moved` and `MovedPermanently` both return 301) the array of potential values given in the generated definition contains duplicates.
When the project is deployed to our Azure infrastructure, Azure API Management fails with a `ValidationError: Parsing error(s): JSON is valid against no schemas from 'oneOf'` error, because it expects an enum type to contain unique values.
**To Reproduce**
Add a property of type `System.Net.HttpStatusCode` to a model, and reference that model as the `Type` in a `OpenApiResponseWithBody` attribute, then hit the appropriate Swagger endpoint, which will probably be `http://localhost:7071/api/swagger.json`. Find the model in the list of definitions, and observe that the generated list of values contains duplicates.
**Versions**
- Microsoft.Azure.WebJobs.Extensions.OpenApi v1.3.0
- Newtonsoft.Json v13.0.1
**Additional context**
I've spent time trying to find some kind of middleware or event in which I might be able to modify the output, but it doesn't seem like there exists any method of achieving the desired result. For example, [here](https://blog.dangl.me/archive/remove-duplicate-enum-entries-in-swagger-documents-with-nswag-in-aspnet-core/) you can see the solution implemented in NSwag.
Is there a solution to my problem that I'm not aware of?
Contributor guide
Assessment
This issue has not been assessed yet.