Skip to content

Instantly share code, notes, and snippets.

@v1nc
Last active November 11, 2022 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save v1nc/bc05dc2f77956ac0a91be9c867589031 to your computer and use it in GitHub Desktop.
Save v1nc/bc05dc2f77956ac0a91be9c867589031 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from pathlib import Path
from openapi3 import OpenAPI
import yaml
# colors for printing
GREEN = '\033[92m'
RED = '\033[91m'
END_COLOR = '\033[0m'
# iterate over all API files
pathlist = Path('openapi-in-the-wild').glob('*.json')
for path in pathlist:
# load API file
with open(path) as f:
# load as yaml
try:
spec = yaml.safe_load(f.read())
parsed_spec = OpenAPI(spec, validate=True)
errors = parsed_spec.errors()
# get filename for printing
filename = str(path).split('/')[1]
if errors:
# print error
print(f'{RED}error{END_COLOR}: {filename}.')
else:
print(f'{GREEN}valid{END_COLOR}: {filename}')
except Exception as e:
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment