Skip to content

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
@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 <[email protected]>
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