Skip to content

Commit ed38aa2

Browse files
DorthuGitHub Enterprise
authored andcommitted
Merge pull request #3 from jsager/readme-and-yaml
new: movie OpenAPI spec into this repository, modify readme
2 parents 7f696ca + 2375cba commit ed38aa2

File tree

3 files changed

+10345
-278
lines changed

3 files changed

+10345
-278
lines changed

openapi-linter.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/local/bin/python3
2+
#
3+
# OpenAPI Spec Linter
4+
#
5+
# Usage:
6+
# ./openapi-linter.py openapi.yaml
7+
#
8+
# Scans the provided openapi 3 spec file and outputs and errors found. The
9+
# provided file is expected to be a yaml representation of the openapi spec,
10+
# and formatting/errors are provided by the openapi_v3_spec_validator package
11+
12+
import os
13+
import sys
14+
import yaml
15+
16+
from jsonschema.exceptions import RefResolutionError
17+
from openapi_spec_validator import openapi_v3_spec_validator
18+
19+
20+
target = sys.argv[1]
21+
pretty = len(sys.argv) > 2 and sys.argv[2] == 'pretty'
22+
23+
error_symbol = '❌ ' if pretty else '!!!'
24+
ok_symbol = '✅ ' if pretty else ''
25+
26+
if not os.path.isfile(target):
27+
print("File not found: {}".format(target))
28+
sys.exit(2)
29+
30+
with open(target) as f:
31+
spec = yaml.load(f.read())
32+
33+
has_errors=False
34+
errors = openapi_v3_spec_validator.iter_errors(spec)
35+
36+
try:
37+
for e in errors:
38+
has_errors=True
39+
print("{} {path}: {message}".format(error_symbol, path='.'.join(e.path), message=e.message))
40+
except RefResolutionError as e:
41+
print("{} {}".format(error_symbol, e))
42+
has_errors=True
43+
44+
45+
if has_errors:
46+
sys.exit(1)
47+
48+
print("{} OK".format(ok_symbol))

0 commit comments

Comments
 (0)