- added more guards against panic when continuing on error
- removed more debug printing
- otherwise, no change in functionality
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
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 |
|
|
15 |
package spec |
|
16 |
|
|
17 |
import ( |
|
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 |
|
|
26 |
const ( |
|
27 |
// SwaggerSchemaURL the url for the swagger 2.0 schema to validate specs
|
|
28 |
SwaggerSchemaURL = "http://swagger.io/v2/schema.json#" |
|
29 |
// JSONSchemaURL the url for the json schema schema
|
|
30 |
JSONSchemaURL = "http://json-schema.org/draft-04/schema#" |
|
31 |
)
|
|
32 |
|
|
33 |
// MustLoadJSONSchemaDraft04 panics when Swagger20Schema returns an error
|
|
34 |
func MustLoadJSONSchemaDraft04() *Schema { |
|
35 | 4 |
d, e := JSONSchemaDraft04() |
36 |
if e != nil { |
|
37 |
panic(e) |
|
38 |
}
|
|
39 | 4 |
return d |
40 |
}
|
|
41 |
|
|
42 |
// JSONSchemaDraft04 loads the json schema document for json shema draft04
|
|
43 |
func JSONSchemaDraft04() (*Schema, error) { |
|
44 | 4 |
b, err := Asset("jsonschema-draft-04.json") |
45 |
if err != nil { |
|
46 |
return nil, err |
|
47 |
}
|
|
48 |
|
|
49 | 4 |
schema := new(Schema) |
50 |
if err := json.Unmarshal(b, schema); err != nil { |
|
51 |
return nil, err |
|
52 |
}
|
|
53 | 4 |
return schema, nil |
54 |
}
|
|
55 |
|
|
56 |
// MustLoadSwagger20Schema panics when Swagger20Schema returns an error
|
|
57 |
func MustLoadSwagger20Schema() *Schema { |
|
58 | 4 |
d, e := Swagger20Schema() |
59 |
if e != nil { |
|
60 |
panic(e) |
|
61 |
}
|
|
62 | 4 |
return d |
63 |
}
|
|
64 |
|
|
65 |
// Swagger20Schema loads the swagger 2.0 schema from the embedded assets
|
|
66 |
func Swagger20Schema() (*Schema, error) { |
|
67 |
|
|
68 | 4 |
b, err := Asset("v2/schema.json") |
69 |
if err != nil { |
|
70 |
return nil, err |
|
71 |
}
|
|
72 |
|
|
73 | 4 |
schema := new(Schema) |
74 |
if err := json.Unmarshal(b, schema); err != nil { |
|
75 |
return nil, err |
|
76 |
}
|
|
77 | 4 |
return schema, nil |
78 |
}
|
Read our documentation on viewing source code .