@@ -37,6 +37,18 @@ type SimpleSchema struct {
3737 Example interface {} `json:"example,omitempty"`
3838}
3939
40+ // Marshaling structure only, always edit along with corresponding
41+ // struct (or compilation will fail).
42+ type simpleSchemaOmitZero struct {
43+ Type string `json:"type,omitempty"`
44+ Nullable bool `json:"nullable,omitzero"`
45+ Format string `json:"format,omitempty"`
46+ Items * Items `json:"items,omitzero"`
47+ CollectionFormat string `json:"collectionFormat,omitempty"`
48+ Default interface {} `json:"default,omitempty"`
49+ Example interface {} `json:"example,omitempty"`
50+ }
51+
4052// CommonValidations describe common JSON-schema validations
4153type CommonValidations struct {
4254 Maximum * float64 `json:"maximum,omitempty"`
@@ -53,6 +65,23 @@ type CommonValidations struct {
5365 Enum []interface {} `json:"enum,omitempty"`
5466}
5567
68+ // Marshaling structure only, always edit along with corresponding
69+ // struct (or compilation will fail).
70+ type commonValidationsOmitZero struct {
71+ Maximum * float64 `json:"maximum,omitempty"`
72+ ExclusiveMaximum bool `json:"exclusiveMaximum,omitzero"`
73+ Minimum * float64 `json:"minimum,omitempty"`
74+ ExclusiveMinimum bool `json:"exclusiveMinimum,omitzero"`
75+ MaxLength * int64 `json:"maxLength,omitempty"`
76+ MinLength * int64 `json:"minLength,omitempty"`
77+ Pattern string `json:"pattern,omitempty"`
78+ MaxItems * int64 `json:"maxItems,omitempty"`
79+ MinItems * int64 `json:"minItems,omitempty"`
80+ UniqueItems bool `json:"uniqueItems,omitzero"`
81+ MultipleOf * float64 `json:"multipleOf,omitempty"`
82+ Enum []interface {} `json:"enum,omitempty"`
83+ }
84+
5685// Items a limited subset of JSON-Schema's items object.
5786// It is used by parameter definitions that are not located in "body".
5887//
@@ -140,37 +169,14 @@ func (i Items) MarshalJSON() ([]byte, error) {
140169}
141170
142171func (i Items ) MarshalNextJSON (opts jsonv2.MarshalOptions , enc * jsonv2.Encoder ) error {
143- type SimpleSchemaOmitZero struct {
144- Type string `json:"type,omitempty"`
145- Nullable bool `json:"nullable,omitzero"`
146- Format string `json:"format,omitempty"`
147- Items * Items `json:"items,omitzero"`
148- CollectionFormat string `json:"collectionFormat,omitempty"`
149- Default interface {} `json:"default,omitempty"`
150- Example interface {} `json:"example,omitempty"`
151- }
152- type CommonValidationsOmitZero struct {
153- Maximum * float64 `json:"maximum,omitempty"`
154- ExclusiveMaximum bool `json:"exclusiveMaximum,omitzero"`
155- Minimum * float64 `json:"minimum,omitempty"`
156- ExclusiveMinimum bool `json:"exclusiveMinimum,omitzero"`
157- MaxLength * int64 `json:"maxLength,omitempty"`
158- MinLength * int64 `json:"minLength,omitempty"`
159- Pattern string `json:"pattern,omitempty"`
160- MaxItems * int64 `json:"maxItems,omitempty"`
161- MinItems * int64 `json:"minItems,omitempty"`
162- UniqueItems bool `json:"uniqueItems,omitzero"`
163- MultipleOf * float64 `json:"multipleOf,omitempty"`
164- Enum []interface {} `json:"enum,omitempty"`
165- }
166172 var x struct {
167- CommonValidationsOmitZero
168- SimpleSchemaOmitZero
169- Ref string `json:"$ref,omitempty"`
173+ CommonValidations commonValidationsOmitZero `json:",inline"`
174+ SimpleSchema simpleSchemaOmitZero `json:",inline"`
175+ Ref string `json:"$ref,omitempty"`
170176 Extensions
171177 }
172- x .CommonValidationsOmitZero = CommonValidationsOmitZero (i .CommonValidations )
173- x .SimpleSchemaOmitZero = SimpleSchemaOmitZero (i .SimpleSchema )
178+ x .CommonValidations = commonValidationsOmitZero (i .CommonValidations )
179+ x .SimpleSchema = simpleSchemaOmitZero (i .SimpleSchema )
174180 x .Ref = i .Refable .Ref .String ()
175181 x .Extensions = i .Extensions
176182 return opts .MarshalNext (enc , x )
0 commit comments