How do you control how properties are serialized? #2282
Replies: 1 comment
|
Hi Jamie A Hankins (@jamiehankins) The mapping from dotnet types to OpenAPI is done by Microsoft.AspnetCode.OpenAPI (or the swashbuckle equivalent). This library only handles parsing/object model/serialization of OpenAPI documents. Please ask your question in https://github.com/dotnet/aspnetcore |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
For example, I have an endpoint that takes a Product object. Two of the properties are
SerialNumber(a string) andFormFactor(an enum).My server will consume and emit
snake_case.First, when I generate the document with Microsoft.OpenApi, it generates the enum as an int. I added an attribute to the enum to get it to generate as a string. Then, it generated it in
PascalCase, so I created a subclass ofJsonStringEnumConverterthat specifiedSnakeCaseLower.But the Product object has the property name in
camelCase. If it were just aesthetics, I wouldn't care, but I need the properties to be right since they will be used by clients.When I generate the OpenAPI with Swagger (in YAML), it takes care of this by default. The enum values are snake, the properties are snake, etc. The object names are Pascal, but that doesn't matter.
I would prefer to use the new(ish) first-party OpenAPI support, but a couple of hours in, I realize that just staying with Swagger is a better choice than trying to force Microsoft.OpenApi to do what I need.
There's always the chance that I just missed something simple. Please let me know if that's the case!
All reactions