...
1# OpenAPI v2 object model [](https://github.com/go-openapi/spec/actions?query=workflow%3A"go+test") [](https://codecov.io/gh/go-openapi/spec)
2
3[](https://slackin.goswagger.io)
4[](https://raw.githubusercontent.com/go-openapi/spec/master/LICENSE)
5[](https://pkg.go.dev/github.com/go-openapi/spec)
6[](https://goreportcard.com/report/github.com/go-openapi/spec)
7
8The object model for OpenAPI specification documents.
9
10### FAQ
11
12* What does this do?
13
14> 1. This package knows how to marshal and unmarshal Swagger API specifications into a golang object model
15> 2. It knows how to resolve $ref and expand them to make a single root document
16
17* How does it play with the rest of the go-openapi packages ?
18
19> 1. This package is at the core of the go-openapi suite of packages and [code generator](https://github.com/go-swagger/go-swagger)
20> 2. There is a [spec loading package](https://github.com/go-openapi/loads) to fetch specs as JSON or YAML from local or remote locations
21> 3. There is a [spec validation package](https://github.com/go-openapi/validate) built on top of it
22> 4. There is a [spec analysis package](https://github.com/go-openapi/analysis) built on top of it, to analyze, flatten, fix and merge spec documents
23
24* Does this library support OpenAPI 3?
25
26> No.
27> This package currently only supports OpenAPI 2.0 (aka Swagger 2.0).
28> There is no plan to make it evolve toward supporting OpenAPI 3.x.
29> This [discussion thread](https://github.com/go-openapi/spec/issues/21) relates the full story.
30>
31> An early attempt to support Swagger 3 may be found at: https://github.com/go-openapi/spec3
32
33* Does the unmarshaling support YAML?
34
35> Not directly. The exposed types know only how to unmarshal from JSON.
36>
37> In order to load a YAML document as a Swagger spec, you need to use the loaders provided by
38> github.com/go-openapi/loads
39>
40> Take a look at the example there: https://pkg.go.dev/github.com/go-openapi/loads#example-Spec
41>
42> See also https://github.com/go-openapi/spec/issues/164
43
44* How can I validate a spec?
45
46> Validation is provided by [the validate package](http://github.com/go-openapi/validate)
47
48* Why do we have an `ID` field for `Schema` which is not part of the swagger spec?
49
50> We found jsonschema compatibility more important: since `id` in jsonschema influences
51> how `$ref` are resolved.
52> This `id` does not conflict with any property named `id`.
53>
54> See also https://github.com/go-openapi/spec/issues/23
View as plain text