external_documentation.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. "k8s.io/kube-openapi/pkg/validation/spec"
  17. "github.com/go-openapi/swag"
  18. )
  19. type ExternalDocumentation struct {
  20. ExternalDocumentationProps
  21. spec.VendorExtensible
  22. }
  23. type ExternalDocumentationProps struct {
  24. // Description is a short description of the target documentation. CommonMark syntax MAY be used for rich text representation.
  25. Description string `json:"description,omitempty"`
  26. // URL is the URL for the target documentation.
  27. URL string `json:"url"`
  28. }
  29. // MarshalJSON is a custom marshal function that knows how to encode Responses as JSON
  30. func (e *ExternalDocumentation) MarshalJSON() ([]byte, error) {
  31. b1, err := json.Marshal(e.ExternalDocumentationProps)
  32. if err != nil {
  33. return nil, err
  34. }
  35. b2, err := json.Marshal(e.VendorExtensible)
  36. if err != nil {
  37. return nil, err
  38. }
  39. return swag.ConcatJSON(b1, b2), nil
  40. }
  41. func (e *ExternalDocumentation) UnmarshalJSON(data []byte) error {
  42. if err := json.Unmarshal(data, &e.ExternalDocumentationProps); err != nil {
  43. return err
  44. }
  45. if err := json.Unmarshal(data, &e.VendorExtensible); err != nil {
  46. return err
  47. }
  48. return nil
  49. }