OpenAPISchema fetches the open api schema using a rest client and parses the proto.
()
| 419 | |
| 420 | // OpenAPISchema fetches the open api schema using a rest client and parses the proto. |
| 421 | func (d *DiscoveryClient) OpenAPISchema() (*openapi_v2.Document, error) { |
| 422 | data, err := d.restClient.Get().AbsPath("/openapi/v2").SetHeader("Accept", mimePb).Do().Raw() |
| 423 | if err != nil { |
| 424 | if errors.IsForbidden(err) || errors.IsNotFound(err) || errors.IsNotAcceptable(err) { |
| 425 | // single endpoint not found/registered in old server, try to fetch old endpoint |
| 426 | // TODO: remove this when kubectl/client-go don't work with 1.9 server |
| 427 | data, err = d.restClient.Get().AbsPath("/swagger-2.0.0.pb-v1").Do().Raw() |
| 428 | if err != nil { |
| 429 | return nil, err |
| 430 | } |
| 431 | } else { |
| 432 | return nil, err |
| 433 | } |
| 434 | } |
| 435 | document := &openapi_v2.Document{} |
| 436 | err = proto.Unmarshal(data, document) |
| 437 | if err != nil { |
| 438 | return nil, err |
| 439 | } |
| 440 | return document, nil |
| 441 | } |
| 442 | |
| 443 | // withRetries retries the given recovery function in case the groups supported by the server change after ServerGroup() returns. |
| 444 | func withRetries(maxRetries int, f func() ([]*metav1.APIGroup, []*metav1.APIResourceList, error)) ([]*metav1.APIGroup, []*metav1.APIResourceList, error) { |