Add ability to Include both `json` and `yaml` tags to the generated structs
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 https://github.com/oapi-codegen/oapi-codegen/discussions/1686
@jamietanna would you accept a PR for this feature?
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:
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.
Simple test when just json is defined vs json and yaml: https://go.dev/play/p/mBu34KwpW9O
First attempt https://github.com/oapi-codegen/oapi-codegen/pull/1798 ; review would be appreciated @jamietanna , tell us what is missing.