-
-
Notifications
You must be signed in to change notification settings - Fork 954
Add support for x-order extension #1190
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
Add support for x-order extension #1190
Conversation
Fix for oapi-codegen#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 ```
Signed-off-by: Filinto Duran <filinto@diagrid.io>
195105b
to
01e6935
Compare
Signed-off-by: Filinto Duran <filinto@diagrid.io>
@filintod did you see my comment which could make it much simpler for users, avoiding the cruft of having to set I think this would be better approach for this feature. |
@stevenh That is a good suggestion to add, but not sure possible so easily. By the time we get to the point here in the code, we have no knowledge of the struct, and golang parsing of maps is usually not deterministic, one could sort alphabetically though. There is a new yaml module that does a nicer job of preserving order but that would be a bigger change here and would have to be tested/approved. Another option is to add the |
Thanks @filintod had a little look and you're right the information has already been lost :( |
@jamietanna could you take a look on this one please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of tweaks needed - I'll push them up shortly 👍 Thanks for the work on this, and apologies it's taken so long!
Last thing to do is to add an |
As noted in oapi-codegen#428, there are some cases where it can be useful to set the field ordering. This adds support for the `x-order` extension used by other OpenAPI parsers and generators, and ensures that we return keys sorted by that order, if present. This also adds a relevant test case + unit tests to validate functionality. Closes oapi-codegen#428. Co-authored-by: Filinto Duran <filinto@diagrid.io> Signed-off-by: Filinto Duran <filinto@diagrid.io> Co-authored-by: Andrew Rusakow <psihatter@gmail.com> Co-authored-by: Jamie Tanna <jamie@jamietanna.co.uk>
An update on PR #627 to be mergeable
From that PR:
Fix for #458.
Can be used when you need to set the order of fields in the model: