groupversion.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. Copyright 2017 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 openapi
  14. import (
  15. "context"
  16. "k8s.io/kube-openapi/pkg/handler3"
  17. )
  18. const ContentTypeOpenAPIV3PB = "application/com.github.proto-openapi.spec.v3@v1.0+protobuf"
  19. type GroupVersion interface {
  20. Schema(contentType string) ([]byte, error)
  21. }
  22. type groupversion struct {
  23. client *client
  24. item handler3.OpenAPIV3DiscoveryGroupVersion
  25. }
  26. func newGroupVersion(client *client, item handler3.OpenAPIV3DiscoveryGroupVersion) *groupversion {
  27. return &groupversion{client: client, item: item}
  28. }
  29. func (g *groupversion) Schema(contentType string) ([]byte, error) {
  30. return g.client.restClient.Get().
  31. RequestURI(g.item.ServerRelativeURL).
  32. SetHeader("Accept", contentType).
  33. Do(context.TODO()).
  34. Raw()
  35. }