@@ -33,6 +33,13 @@ Installation
33
33
34
34
$ pip install openapi-spec-validator
35
35
36
+ Alternatively you can download the code and install from the repository:
37
+
38
+ .. code-block :: bash
39
+
40
+ $ pip install -e git+https://github.com/p1c2u/openapi-spec-validator.git#egg=openapi_spec_validator
41
+
42
+
36
43
Usage
37
44
#####
38
45
@@ -43,25 +50,25 @@ Straight forward way:
43
50
44
51
.. code :: bash
45
52
46
- $ openapi-spec-validator some .yaml
53
+ $ openapi-spec-validator openapi .yaml
47
54
48
55
pipes way:
49
56
50
57
.. code :: bash
51
58
52
- $ cat some .yaml | openapi-spec-validator -
59
+ $ cat openapi .yaml | openapi-spec-validator -
53
60
54
61
docker way:
55
62
56
63
.. code :: bash
57
64
58
- $ docker run -v path/to/some .yaml:/some .yaml --rm p1c2u/openapi-spec-validator /some .yaml
65
+ $ docker run -v path/to/openapi .yaml:/openapi .yaml --rm p1c2u/openapi-spec-validator /openapi .yaml
59
66
60
67
or more pythonic way:
61
68
62
69
.. code :: bash
63
70
64
- $ python -m openapi_spec_validator some .yaml
71
+ $ python -m openapi_spec_validator openapi .yaml
65
72
66
73
Examples
67
74
********
@@ -70,34 +77,39 @@ Validate spec:
70
77
71
78
.. code :: python
72
79
73
-
74
80
from openapi_spec_validator import validate_spec
81
+ from openapi_spec_validator.readers import read_from_filename
82
+
83
+ spec_dict, spec_url = read_from_filename(' openapi.yaml' )
75
84
85
+ # If no exception is raised by validate_spec(), the spec is valid.
76
86
validate_spec(spec_dict)
77
87
78
- Add `` spec_url `` to validate spec with relative files:
88
+ validate_spec({})
79
89
80
- .. code :: python
90
+ Traceback (most recent call last):
91
+ ...
92
+ OpenAPIValidationError: ' openapi' is a required property
81
93
94
+ Add ``spec_url `` to validate spec with relative files:
82
95
83
- from openapi_spec_validator import validate_spec
96
+ .. code :: python
84
97
85
98
validate_spec(spec_dict, spec_url = ' file:///path/to/spec/openapi.yaml' )
86
99
87
100
You can also validate spec from url:
88
101
89
102
.. code :: python
90
103
91
-
92
104
from openapi_spec_validator import validate_spec_url
93
105
106
+ # If no exception is raised by validate_spec_url(), the spec is valid.
94
107
validate_spec_url(' http://example.com/openapi.json' )
95
108
96
109
If you want to iterate through validation errors:
97
110
98
111
.. code :: python
99
112
100
-
101
113
from openapi_spec_validator import openapi_v3_spec_validator
102
114
103
115
errors_iterator = openapi_v3_spec_validator.iter_errors(spec)
0 commit comments