Last active
November 11, 2022 09:16
-
-
Save v1nc/bc05dc2f77956ac0a91be9c867589031 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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