feat(openapi/generator): add the x-omitempty extension#114
feat(openapi/generator): add the x-omitempty extension#114karimassaly wants to merge 1 commit intowI2L:masterfrom
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.
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.
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.