Last active
September 26, 2019 14:35
-
-
Save jdkato/40211d9276845b2dad10fe2ba7987fc3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import subprocess | |
import sys | |
# pip install PyYAML | |
import yaml | |
def lint_keys(data, keys): | |
"""Recursively lint the given data. | |
""" | |
for k, v in data.items(): | |
if isinstance(v, dict): | |
lint_keys(v, keys) | |
elif k in keys: | |
# NOTE: We use `--ext=.md` since the Petstore example | |
# uses Markdown formatting in its descriptions. | |
print(subprocess.check_output(["vale", "--ext=.md", "--no-exit", v])) | |
def lint(spec, sections, keys): | |
"""A lint a given OpenAPI specification file. | |
""" | |
with open(spec, "r") as s: | |
doc = yaml.load(s) | |
for section in [s for s in doc if s in sections]: | |
lint_keys(doc[section], keys) | |
if __name__ == "__main__": | |
lint( | |
sys.argv[1], | |
# A list of spec sections to lint: | |
sections=["info", "paths"], | |
# A list of the keys we want to lint: | |
keys=["description", "summary"], | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment