security_requirement.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. // SecurityRequirementProps describes the required security schemes to execute an operation, more at https://swagger.io/specification/#security-requirement-object
  20. //
  21. // Note that this struct is actually a thin wrapper around SecurityRequirementProps to make it referable and extensible
  22. type SecurityRequirement struct {
  23. SecurityRequirementProps
  24. spec.VendorExtensible
  25. }
  26. // MarshalJSON is a custom marshal function that knows how to encode SecurityRequirement as JSON
  27. func (s *SecurityRequirement) MarshalJSON() ([]byte, error) {
  28. b1, err := json.Marshal(s.SecurityRequirementProps)
  29. if err != nil {
  30. return nil, err
  31. }
  32. b2, err := json.Marshal(s.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 (s *SecurityRequirement) UnmarshalJSON(data []byte) error {
  40. if err := json.Unmarshal(data, &s.SecurityRequirementProps); err != nil {
  41. return err
  42. }
  43. return json.Unmarshal(data, &s.VendorExtensible)
  44. }
  45. // SecurityRequirementProps describes the required security schemes to execute an operation, more at https://swagger.io/specification/#security-requirement-object
  46. type SecurityRequirementProps map[string][]string