You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add ability to Include both json and yaml tags to the generated structs #1696
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
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
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)
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:
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.
Activity
[-]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[/+]yoav-orca commentedon Oct 8, 2024
@jamietanna would you accept a PR for this feature?
jamietanna commentedon Oct 8, 2024
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)deitch commentedon Oct 14, 2024
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:
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.
deitch commentedon Oct 14, 2024
Simple test when just json is defined vs json and yaml: https://go.dev/play/p/mBu34KwpW9O
deitch commentedon Oct 14, 2024
First attempt #1798 ; review would be appreciated @jamietanna , tell us what is missing.
feat(output-options): add `yaml-tags` option (oapi-codegen#1798)