Skip to content

Add ability to Include both json and yaml tags to the generated structs #1696

Closed

Description

@MUzairS15

How do we provide a custom template to have json and yaml tags to the generated structs?
I am aware that I can use x-oapi-codegen-extra-tags to add custom tags but it is tedious to add for each schema type.

It is common to encode/decode b/w json and yaml so it would be nice to have ability to add this common tags w/o needing to specify it explicitly.
Originally posted by @MUzairS15 in #1686

Activity

  1. changed the title [-]How do we provide a custom template to have `json` and `yaml` tags to the generated structs?[/-] [+]Add ability to Include both `json` and `yaml` tags to the generated structs[/+] on Jul 11, 2024
  2. yoav-orca commented on Oct 8, 2024

    @yoav-orca

    @jamietanna would you accept a PR for this feature?

  3. jamietanna commented on Oct 8, 2024

    @jamietanna
    Member

    We would, yes! Not sure when we'd get to it (there's a backlog for the next release) but sounds like it'd be reasonable as an opt-in option (via output-options)

  4. added
    enhancement
    on Oct 8, 2024
  5. deitch commented on Oct 14, 2024

    @deitch
    Contributor

    Ah, I have been looking for this. I just spent too long trying to determine why my yaml unmarshal was not generating the expected data, yet no errors. The go structs are generated by oapi-codegen, so they look like:

    type Something struct {
      FooBar *string `json:"fooBar,omitempty"
    }

    My eyes saw it as yaml: so I could not figure out why until I stepped through the unmarshal code (not recommended 😆 ), and found it was looking for "foobar" (lowercase), and I realized.

    I will take a look at it as well.

  6. deitch commented on Oct 14, 2024

    @deitch
    Contributor
  7. deitch commented on Oct 14, 2024

    @deitch
    Contributor

    First attempt #1798 ; review would be appreciated @jamietanna , tell us what is missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions