Skip to content

Handle leading underscores in property names #1822

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 2 commits into from
Nov 4, 2024

Conversation

tobio
Copy link
Contributor

@tobio tobio commented Nov 4, 2024

I'm working with a spec that has something like:

      properties:
        _version:
          type: string
        version:
          type: int

Now surely there's some better naming they could have used whilst designing the response, but that's not in my control. As it is, oapi-codegen generates a duplicate Version field for both of these properties.

This PR updates the name prefix to add an Underscore prefix in this case, de-duplicating the field names.

@tobio tobio requested a review from a team as a code owner November 4, 2024 11:19
@jamietanna jamietanna added the bug Something isn't working label Nov 4, 2024
@jamietanna
Copy link
Member

Thanks for the fix, @tobio! Mind running make generate, and committing the changes?

@tobio
Copy link
Contributor Author

tobio commented Nov 4, 2024

I should read the docs better :) Done. I'll take a look at adding a BWC option for this tomorrow if that makes sense?

@jamietanna
Copy link
Member

NP! For these ones, we generally don't try and make them backwards-compatible, so I'm happy merging as-is 😀

@jamietanna jamietanna merged commit 18c9887 into oapi-codegen:main Nov 4, 2024
18 checks passed
@tobio tobio deleted the underscore-prefix branch November 4, 2024 19:51
mdjarv pushed a commit to mdjarv/oapi-codegen that referenced this pull request Nov 12, 2024
…gen#1822)

Similar to other changes we've made to make our generated field names
more predictable - and in many cases, valid Go names - we should tweak
how a leading underscore is used in a field name.

This avoids cases with a spec such as:

```yaml
      properties:
        _version:
          type: string
        version:
          type: int
```

Which would previously generate duplicate field names, `Version` and
`Version`.

Instead, we now produce `_Version` and `Version`.

Co-authored-by: Jamie Tanna <jamie.tanna@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 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