operation.go 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. // Operation describes a single API operation on a path, more at https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#operationObject
  20. //
  21. // Note that this struct is actually a thin wrapper around OperationProps to make it referable and extensible
  22. type Operation struct {
  23. OperationProps
  24. spec.VendorExtensible
  25. }
  26. // MarshalJSON is a custom marshal function that knows how to encode Operation as JSON
  27. func (o *Operation) MarshalJSON() ([]byte, error) {
  28. b1, err := json.Marshal(o.OperationProps)
  29. if err != nil {
  30. return nil, err
  31. }
  32. b2, err := json.Marshal(o.VendorExtensible)
  33. if err != nil {
  34. return nil, err
  35. }
  36. return swag.ConcatJSON(b1, b2), nil
  37. }
  38. // UnmarshalJSON hydrates this items instance with the data from JSON
  39. func (o *Operation) UnmarshalJSON(data []byte) error {
  40. if err := json.Unmarshal(data, &o.OperationProps); err != nil {
  41. return err
  42. }
  43. return json.Unmarshal(data, &o.VendorExtensible)
  44. }
  45. // OperationProps describes a single API operation on a path, more at https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#operationObject
  46. type OperationProps struct {
  47. // Tags holds a list of tags for API documentation control
  48. Tags []string `json:"tags,omitempty"`
  49. // Summary holds a short summary of what the operation does
  50. Summary string `json:"summary,omitempty"`
  51. // Description holds a verbose explanation of the operation behavior
  52. Description string `json:"description,omitempty"`
  53. // ExternalDocs holds additional external documentation for this operation
  54. ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"`
  55. // OperationId holds a unique string used to identify the operation
  56. OperationId string `json:"operationId,omitempty"`
  57. // Parameters a list of parameters that are applicable for this operation
  58. Parameters []*Parameter `json:"parameters,omitempty"`
  59. // RequestBody holds the request body applicable for this operation
  60. RequestBody *RequestBody `json:"requestBody,omitempty"`
  61. // Responses holds the list of possible responses as they are returned from executing this operation
  62. Responses *Responses `json:"responses,omitempty"`
  63. // Deprecated declares this operation to be deprecated
  64. Deprecated bool `json:"deprecated,omitempty"`
  65. // SecurityRequirement holds a declaration of which security mechanisms can be used for this operation
  66. SecurityRequirement []*SecurityRequirement `json:"security,omitempty"`
  67. // Servers contains an alternative server array to service this operation
  68. Servers []*Server `json:"servers,omitempty"`
  69. }