File tree Expand file tree Collapse file tree 3 files changed +47
-0
lines changed
Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,12 @@ OpenAPI Spec Validator is a Python library that validates OpenAPI Specs against
1717
1818## Usage
1919
20+ Command Line Interface:
21+
22+ ``` bash
23+ $ openapi_spec_validator some.yaml
24+ ```
25+
2026Validate spec:
2127
2228``` python
Original file line number Diff line number Diff line change 1+ import logging
2+ import optparse
3+ import os
4+ import sys
5+
6+ from openapi_spec_validator import validate_spec_url
7+ from openapi_spec_validator .exceptions import ValidationError
8+
9+ logger = logging .getLogger (__name__ )
10+ logging .basicConfig (
11+ format = '%(asctime)s %(levelname)s %(name)s %(message)s' ,
12+ level = logging .WARNING
13+ )
14+
15+
16+ def main ():
17+ usage = 'Usage: %prog filename'
18+ parser = optparse .OptionParser (usage )
19+ (options , args ) = parser .parse_args ()
20+ if len (args ) != 1 :
21+ parser .error ('You must provide a filename to validate' )
22+ filename = args [0 ]
23+ filename = os .path .abspath (filename )
24+ try :
25+ validate_spec_url ('file://' + filename )
26+ except ValidationError as e :
27+ print (e )
28+ sys .exit (1 )
29+ except Exception as e :
30+ print (e )
31+ sys .exit (2 )
32+ else :
33+ print ('OK' )
34+
35+ if __name__ == '__main__' :
36+ main ()
Original file line number Diff line number Diff line change @@ -67,6 +67,11 @@ def run_tests(self):
6767 ],
6868 },
6969 include_package_data = True ,
70+ entry_points = {
71+ 'console_scripts' : [
72+ 'openapi-spec-validator = openapi_spec_validator.__main__:main'
73+ ]
74+ },
7075 install_requires = read_requirements ('requirements.txt' ),
7176 tests_require = read_requirements ('requirements_dev.txt' ),
7277 cmdclass = {'test' : PyTest },
You can’t perform that action at this time.
0 commit comments