| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package spec3 |
| 18 |
|
| 19 |
import ( |
| 20 |
"encoding/json" |
| 21 |
|
| 22 |
"k8s.io/kube-openapi/pkg/internal" |
| 23 |
jsonv2 "k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json" |
| 24 |
"k8s.io/kube-openapi/pkg/validation/spec" |
| 25 |
) |
| 26 |
|
| 27 |
|
| 28 |
type OpenAPI struct { |
| 29 |
|
| 30 |
Version string `json:"openapi"` |
| 31 |
|
| 32 |
Info *spec.Info `json:"info"` |
| 33 |
|
| 34 |
Paths *Paths `json:"paths,omitempty"` |
| 35 |
|
| 36 |
Servers []*Server `json:"servers,omitempty"` |
| 37 |
|
| 38 |
Components *Components `json:"components,omitempty"` |
| 39 |
|
| 40 |
SecurityRequirement []map[string][]string `json:"security,omitempty"` |
| 41 |
|
| 42 |
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"` |
| 43 |
} |
| 44 |
|
| 45 |
func (o *OpenAPI) UnmarshalJSON(data []byte) error { |
| 46 |
type OpenAPIWithNoFunctions OpenAPI |
| 47 |
p := (*OpenAPIWithNoFunctions)(o) |
| 48 |
if internal.UseOptimizedJSONUnmarshalingV3 { |
| 49 |
return jsonv2.Unmarshal(data, &p) |
| 50 |
} |
| 51 |
return json.Unmarshal(data, &p) |
| 52 |
} |
| 53 |
|
| 54 |
func (o *OpenAPI) MarshalJSON() ([]byte, error) { |
| 55 |
if internal.UseOptimizedJSONMarshalingV3 { |
| 56 |
return internal.DeterministicMarshal(o) |
| 57 |
} |
| 58 |
type OpenAPIWithNoFunctions OpenAPI |
| 59 |
p := (*OpenAPIWithNoFunctions)(o) |
| 60 |
return json.Marshal(&p) |
| 61 |
} |
| 62 |
|
| 63 |
func (o *OpenAPI) MarshalNextJSON(opts jsonv2.MarshalOptions, enc *jsonv2.Encoder) error { |
| 64 |
type OpenAPIOmitZero struct { |
| 65 |
Version string `json:"openapi"` |
| 66 |
Info *spec.Info `json:"info"` |
| 67 |
Paths *Paths `json:"paths,omitzero"` |
| 68 |
Servers []*Server `json:"servers,omitempty"` |
| 69 |
Components *Components `json:"components,omitzero"` |
| 70 |
SecurityRequirement []map[string][]string `json:"security,omitempty"` |
| 71 |
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitzero"` |
| 72 |
} |
| 73 |
x := (*OpenAPIOmitZero)(o) |
| 74 |
return opts.MarshalNext(enc, x) |
| 75 |
} |