func getSchemaAndValidate(c *client.RESTClient, data []byte, group, version string) error { schemaData, err := c.Get(). AbsPath("/swaggerapi", group, version). Do(). Raw() if err != nil { return err } schema, err := validation.NewSwaggerSchemaFromBytes(schemaData) if err != nil { return err } return schema.ValidateBytes(data) }
// OriginSwaggerSchema returns a swagger API doc for an Origin schema under the /oapi prefix. func (f *Factory) OriginSwaggerSchema(client *kclient.RESTClient, version unversioned.GroupVersion) (*swagger.ApiDeclaration, error) { if version.IsEmpty() { return nil, fmt.Errorf("groupVersion cannot be empty") } body, err := client.Get().AbsPath("/").Suffix("swaggerapi", "oapi", version.Version).Do().Raw() if err != nil { return nil, err } var schema swagger.ApiDeclaration err = json.Unmarshal(body, &schema) if err != nil { return nil, fmt.Errorf("got '%s': %v", string(body), err) } return &schema, nil }