Support for YAML struct tags instead of JSON.
For my use case I'd like the struct tags to be for YAML instead of JSON. I've tried 'applicaion/yaml' in the response type of the API spec had a look at the code and it doesn't seem this project supports that out of the box.
What I get
type Device struct {
Messages *[]Message `json:"messages,omitempty"`
}
What I want
type Device struct {
Messages *[]Message `yaml:"messages,omitempty"`
}
If this isn't already a feature, or on the road map I am happy to fork and give implementing this a crack. Just wanted to get a second pair of eyes to confirm.
For anyone that comes across this and wants a quick fix. sed to the rescue.
sed -i '' "s/json:/yaml:/" api.gen.go
To confirm, is this where you're expecting to produce an application/yaml formatted API response?
@jamietanna yes, produce (with server generation) or consume (with client generation) yaml formatted data.
I would like to see this as well. I don't mind attempting a PR for it, assuming it will get moved through. Based on the comments on GenFieldsFromProperties(), the generation happens in that func, and specifically these lines.
It shouldn't be too hard to add a similar section for yaml, with p.yamlFieldName (which might or might not be identical to p.jsonFieldName. I would have to dig a bit to see where it is set.
Interested?
It shouldn't be too hard to add a similar section for yaml, with p.yamlFieldName (which might or might not be identical to p.jsonFieldName
Actually, I overthought this. By definition, jsonFieldName must be the same as the field name for yaml, as it is the field from the original spec that generated this. So this should be easier than I thought, just adding a few lines there.
@jamietanna want a short PR for it?