Skip to content

Instantly share code, notes, and snippets.

@svx
Forked from jdkato/swagger.py
Created September 26, 2019 14:35
Show Gist options
  • Save svx/92194ea9ee9b7dda7007d8bb9a2b6b97 to your computer and use it in GitHub Desktop.
Save svx/92194ea9ee9b7dda7007d8bb9a2b6b97 to your computer and use it in GitHub Desktop.

Revisions

  1. @jdkato jdkato revised this gist Sep 23, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion swagger.py
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@


    def lint_keys(data, keys):
    """Recursively the given data.
    """Recursively lint the given data.
    """
    for k, v in data.items():
    if isinstance(v, dict):
  2. @jdkato jdkato revised this gist Sep 19, 2019. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions swagger.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    import subprocess
    import sys

    # pip install PyYAML
    import yaml
    @@ -27,9 +28,9 @@ def lint(spec, sections, keys):

    if __name__ == "__main__":
    lint(
    "petstore.yaml",
    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"],
    )
    )
  3. @jdkato jdkato revised this gist Sep 19, 2019. 1 changed file with 4 additions and 10 deletions.
    14 changes: 4 additions & 10 deletions swagger.py
    Original file line number Diff line number Diff line change
    @@ -13,12 +13,7 @@ def lint_keys(data, 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
    ]))
    print(subprocess.check_output(["vale", "--ext=.md", "--no-exit", v]))


    def lint(spec, sections, keys):
    @@ -27,8 +22,7 @@ def lint(spec, sections, keys):
    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)

    lint_keys(doc[section], keys)


    if __name__ == "__main__":
    @@ -37,5 +31,5 @@ def lint(spec, sections, keys):
    # A list of spec sections to lint:
    sections=["info", "paths"],
    # A list of the keys we want to lint:
    keys=["description", "summary"]
    )
    keys=["description", "summary"],
    )
  4. @jdkato jdkato created this gist Sep 19, 2019.
    41 changes: 41 additions & 0 deletions swagger.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    import subprocess

    # pip install PyYAML
    import yaml


    def lint_keys(data, keys):
    """Recursively 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(
    "petstore.yaml",
    # A list of spec sections to lint:
    sections=["info", "paths"],
    # A list of the keys we want to lint:
    keys=["description", "summary"]
    )