encoding.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. Copyright 2021 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package spec3
  14. import (
  15. "encoding/json"
  16. "github.com/go-openapi/swag"
  17. "k8s.io/kube-openapi/pkg/validation/spec"
  18. )
  19. type Encoding struct {
  20. EncodingProps
  21. spec.VendorExtensible
  22. }
  23. // MarshalJSON is a custom marshal function that knows how to encode Encoding as JSON
  24. func (e *Encoding) MarshalJSON() ([]byte, error) {
  25. b1, err := json.Marshal(e.EncodingProps)
  26. if err != nil {
  27. return nil, err
  28. }
  29. b2, err := json.Marshal(e.VendorExtensible)
  30. if err != nil {
  31. return nil, err
  32. }
  33. return swag.ConcatJSON(b1, b2), nil
  34. }
  35. func (e *Encoding) UnmarshalJSON(data []byte) error {
  36. if err := json.Unmarshal(data, &e.EncodingProps); err != nil {
  37. return err
  38. }
  39. if err := json.Unmarshal(data, &e.VendorExtensible); err != nil {
  40. return err
  41. }
  42. return nil
  43. }
  44. type EncodingProps struct {
  45. // Content Type for encoding a specific property
  46. ContentType string `json:"contentType,omitempty"`
  47. // A map allowing additional information to be provided as headers
  48. Headers map[string]*Header `json:"headers,omitempty"`
  49. // Describes how a specific property value will be serialized depending on its type
  50. Style string `json:"style,omitempty"`
  51. // When this is true, property values of type array or object generate separate parameters for each value of the array, or key-value-pair of the map. For other types of properties this property has no effect
  52. Explode string `json:"explode,omitempty"`
  53. // AllowReserved determines whether the parameter value SHOULD allow reserved characters, as defined by RFC3986
  54. AllowReserved bool `json:"allowReserved,omitempty"`
  55. }