in pkg/options/openapi/validate.go [34:75]
func ValidateOptions(opts options.JSONOptions, optSchema *apiextv1beta1.JSONSchemaProps) (*validate.Result, error) {
if optSchema == nil || opts == nil {
return nil, nil
}
// We need to convert to the internal JSONSchemaProps, because that's what
// the conversion library deals with.
intOptSchema := &apiextensions.JSONSchemaProps{}
// TODO(kashomon): Should I make a runtime scheme and use that to convert
// between the types? That seems to be more standard based on looking at
// examples. Ideally, this wouldn't need to happen here -- there would be an
// internal bundle library which used the internal JSON schema type; and then
// conversion would happen at the leaves.
err := apiextv1beta1.Convert_v1beta1_JSONSchemaProps_To_apiextensions_JSONSchemaProps(optSchema, intOptSchema, nil /* conversion scope */)
if err != nil {
return nil, err
}
k8sOpenapiSchema := &kspec.Schema{}
if err := validation.ConvertJSONSchemaProps(intOptSchema, k8sOpenapiSchema); err != nil {
return nil, err
}
openapiSchema := &spec.Schema{}
data, err := k8sOpenapiSchema.MarshalJSON()
if err != nil {
return nil, err
}
openapiSchema.UnmarshalJSON(data)
validator := validate.NewSchemaValidator(openapiSchema, nil, "", strfmt.Default)
// Convert back to map[string]interface{}, since that's what the validation expects.
var conv map[string]interface{} = opts
result := validator.Validate(conv)
if result.AsError() != nil {
return result, result.AsError()
}
return result, nil
}