Skip to content

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

Merged
merged 12 commits into from
Jan 25, 2024

Conversation

filintod
Copy link
Contributor

@filintod filintod commented Aug 9, 2023

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:

    NewPet:
      type: object
      required:
        - name
      properties:
        name:
          type: string
          x-order: 1
        tag:
          type: string
          x-order: 2

psyhatter and others added 3 commits June 14, 2022 12:38
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>
@filintod filintod force-pushed the filinto/x-order-support branch from 195105b to 01e6935 Compare August 9, 2023 18:00
Signed-off-by: Filinto Duran <filinto@diagrid.io>
@filintod filintod changed the title x order support follow up from #627 x-order support follow up from #627 Aug 9, 2023
@filintod filintod changed the title x-order support follow up from #627 Add x-order support follow up from #627 to keep order of fields Aug 11, 2023
@stevenh
Copy link
Contributor

stevenh commented Aug 20, 2023

@filintod did you see my comment which could make it much simpler for users, avoiding the cruft of having to set x-order: <number> on every element, instead having just a single x-ordered: true at the properties level.

I think this would be better approach for this feature.

@filintod
Copy link
Contributor Author

filintod commented Aug 21, 2023

@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 x-order extension automatically at the point we convert from golang struct to openapi format, but that is outside this package in https://github.com/getkin/kin-openapi/.

@stevenh
Copy link
Contributor

stevenh commented Sep 8, 2023

Thanks @filintod had a little look and you're right the information has already been lost :(

@filintod
Copy link
Contributor Author

filintod commented Sep 8, 2023

@jamietanna could you take a look on this one please?

@jamietanna jamietanna self-requested a review September 9, 2023 19:58
@jamietanna jamietanna added this to the v1.15.0 milestone Sep 9, 2023
@jamietanna jamietanna modified the milestones: v1.16.0, v2.1.0 Oct 23, 2023
Copy link
Member

@jamietanna jamietanna left a 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!

@jamietanna
Copy link
Member

Last thing to do is to add an internal/test, which I'll do shortly, then will merge

@jamietanna jamietanna merged commit 3bf5755 into oapi-codegen:master Jan 25, 2024
@jamietanna jamietanna changed the title Add x-order support follow up from #627 to keep order of fields Add support for x-order extension Jan 25, 2024
@jamietanna jamietanna added the enhancement New feature or request label Jan 25, 2024
danicc097 pushed a commit to danicc097/oapi-codegen that referenced this pull request Aug 31, 2024
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy