New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Option to generate a struct without sorting fields #458
Comments
+100 - great job with oapi-codegen, but we are very irritated to see all the fields from our nicely designed structures appear in alphabetical order... the underlying https://github.com/getkin/kin-openapi/ seems to be the problem, parsing it into a map where the ordering is lost. |
@deepmap-marcinr Is there a way to fix / work around this? |
Fix for deepmap#458. Can be used when you need to set the order of fields in the model: ```yaml NewPet: type: object required: - name properties: name: type: string x-order: 1 tag: type: string x-order: 2 ```
Fix for deepmap#458. Can be used when you need to set the order of fields in the model: ```yaml NewPet: type: object required: - name properties: name: type: string x-order: 1 tag: type: string x-order: 2 ```
Often this problem is solved by the |
Fix for deepmap#458. Can be used when you need to set the order of fields in the model: ```yaml NewPet: type: object required: - name properties: name: type: string x-order: 1 tag: type: string x-order: 2 ```
I have check dependecy for parsing openapi specification - github.com/getkin/kin-openapi Look like it is a behaviour of "github.com/invopop/yaml" unmarshalling mechanism. What suggestions how to fix it without writing a new yaml parser? |
https://github.com/getkin/kin-openapi did use https://github.com/ghodss/yaml but they switched to https://github.com/invopop/yaml for some reason. |
Well, it's somewhere inside convertToJSONableObject in invopop/yaml because go-yaml/yaml keeps the ordering when YAML is converted to map. |
https://github.com/goccy/go-yaml |
The problem is relevant for me too. Are there any solutions? |
This also frustrates me the most about the oapi codegen. Are there any workarounds for this? |
👀 #1190 should be merged today |
Closed by 3bf5755 (incorrectly attributed commit) |
I want to generate a struct without sorting fields, in the order listed in the OpenAPI doc.
I wrote my OpenAPI component schema so that the fields that are important to the user are at the top
And I want to return JSON fields on my server response in the same order.
However, for now, generated fields are sorted in increasing order.
So I want an option to generate a struct without sorting field.
openapi.yml
Current
What I want
The text was updated successfully, but these errors were encountered: