How do you control how properties are serialized? #2282
Unanswered
jamiehankins
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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 ofJsonStringEnumConverter
that 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!
Beta Was this translation helpful? Give feedback.
All reactions