podman
78 строк · 2.2 Кб
1// Copyright 2015 go-swagger maintainers
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package spec
16
17import (
18"encoding/json"
19)
20
21//go:generate curl -L --progress -o ./schemas/v2/schema.json http://swagger.io/v2/schema.json
22//go:generate curl -L --progress -o ./schemas/jsonschema-draft-04.json http://json-schema.org/draft-04/schema
23//go:generate go-bindata -pkg=spec -prefix=./schemas -ignore=.*\.md ./schemas/...
24//go:generate perl -pi -e s,Json,JSON,g bindata.go
25
26const (
27// SwaggerSchemaURL the url for the swagger 2.0 schema to validate specs
28SwaggerSchemaURL = "http://swagger.io/v2/schema.json#"
29// JSONSchemaURL the url for the json schema schema
30JSONSchemaURL = "http://json-schema.org/draft-04/schema#"
31)
32
33// MustLoadJSONSchemaDraft04 panics when Swagger20Schema returns an error
34func MustLoadJSONSchemaDraft04() *Schema {
35d, e := JSONSchemaDraft04()
36if e != nil {
37panic(e)
38}
39return d
40}
41
42// JSONSchemaDraft04 loads the json schema document for json shema draft04
43func JSONSchemaDraft04() (*Schema, error) {
44b, err := Asset("jsonschema-draft-04.json")
45if err != nil {
46return nil, err
47}
48
49schema := new(Schema)
50if err := json.Unmarshal(b, schema); err != nil {
51return nil, err
52}
53return schema, nil
54}
55
56// MustLoadSwagger20Schema panics when Swagger20Schema returns an error
57func MustLoadSwagger20Schema() *Schema {
58d, e := Swagger20Schema()
59if e != nil {
60panic(e)
61}
62return d
63}
64
65// Swagger20Schema loads the swagger 2.0 schema from the embedded assets
66func Swagger20Schema() (*Schema, error) {
67
68b, err := Asset("v2/schema.json")
69if err != nil {
70return nil, err
71}
72
73schema := new(Schema)
74if err := json.Unmarshal(b, schema); err != nil {
75return nil, err
76}
77return schema, nil
78}
79