go-openapi / spec

openapi specification object model
Apache License 2.0
389 stars 98 forks source link

YAML declarations in SchemaProps struct #164

Closed alexartwww closed 8 months ago

alexartwww commented 1 year ago

This code won't work because type SchemaProps struct does not have yaml declarations, why?

schema := new(spec.Schema)
errYamlUnmarshal := yaml.Unmarshal(yamlBytes, schema)
if errYamlUnmarshal != nil {
    return errYamlUnmarshal
}

I'm working with example https://pkg.go.dev/github.com/go-openapi/validate#example-AgainstSchema And cannot load yaml file.

fredbi commented 9 months ago

The Spec object does not unmarshal YAML natively, only JSON. In order to load a YAML document into a swagger spec, you need to use the loaders provided by github.com/go-openapi/loads

Please take a look at the example there: https://pkg.go.dev/github.com/go-openapi/loads#example-Spec