-
Couldn't load subscription status.
- Fork 57
feat(openapi/generator): add the x-omitempty extension #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat(openapi/generator): add the x-omitempty extension #114
Conversation
|
Hi, We observed that go-swagger adds the following struct tag on fields by default : We want to be able to have |
… fields that contains an omitempty in json tag
5883cf3 to
b8071b6
Compare
| type Reference struct { | ||
| Ref string `json:"$ref" yaml:"$ref"` | ||
| Ref string `json:"$ref" yaml:"$ref"` | ||
| Extensions map[string]interface{} `json:"-" yaml:"-"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get the rationale for this field addition.
Extensions should only be present on the Schema struct. It can then be used inline or be references through the spec components.
| Extensions map[string]interface{} `json:"-" yaml:"-"` | ||
| } | ||
|
|
||
| func (s *Schema) MarshalJSON() ([]byte, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I get it right, you're trying to simulate the new omitnil JSON field tag, to avoid marshaling the Extensions field it it's empty ? What the purpose.
omitnil could be used (from go1.24), and for previous versions, it doesn't really matter if we marshal extensions: [].
|
With your current implementation, the new extension is always enabled. For this usecase, I envision the addition of a new The option func could be named |
Contexte to this upgrade
We currently do not have the possibility to decide weither a value should omit empty or not once the openAPI format is transcribed to Golang structures.
I have added a new value to the schema and reference structures called Extensions. This value will be able to handle all extra extensions we would like our components to hold. As of now only the "x-omitempty" is handled as it will search the json tag in a structure and place the value of this extension either to true or false.
But many other extensions could be added later on.