Search for yaml swagger files if check_examples.py is run without
arguments.
This commit is contained in:
parent
7c2ccb1aeb
commit
9896f98e2b
1 changed files with 15 additions and 7 deletions
|
@ -1,6 +1,9 @@
|
||||||
#! /usr/bin/env python
|
#! /usr/bin/env python
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
def import_error(module, package, debian, error):
|
def import_error(module, package, debian, error):
|
||||||
sys.stderr.write((
|
sys.stderr.write((
|
||||||
|
@ -25,8 +28,6 @@ except ImportError as e:
|
||||||
import_error("yaml", "PyYAML", "yaml", e)
|
import_error("yaml", "PyYAML", "yaml", e)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
|
|
||||||
def check_response(filepath, request, code, response):
|
def check_response(filepath, request, code, response):
|
||||||
try:
|
try:
|
||||||
|
@ -56,7 +57,7 @@ def check_swagger_file(filepath):
|
||||||
with open(filepath) as f:
|
with open(filepath) as f:
|
||||||
swagger = yaml.load(f)
|
swagger = yaml.load(f)
|
||||||
|
|
||||||
for path, path_api in swagger['paths'].items():
|
for path, path_api in swagger.get('paths', {}).items():
|
||||||
for method, request_api in path_api.items():
|
for method, request_api in path_api.items():
|
||||||
request = "%s %s" % (method.upper(), path)
|
request = "%s %s" % (method.upper(), path)
|
||||||
try:
|
try:
|
||||||
|
@ -68,7 +69,14 @@ def check_swagger_file(filepath):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
for path in sys.argv[1:]:
|
paths = sys.argv[1:]
|
||||||
|
if not paths:
|
||||||
|
paths = []
|
||||||
|
for (root, dirs, files) in os.walk(os.curdir):
|
||||||
|
for filename in files:
|
||||||
|
if filename.endswith(".yaml"):
|
||||||
|
paths.append(os.path.join(root, filename))
|
||||||
|
for path in paths:
|
||||||
try:
|
try:
|
||||||
check_swagger_file(path)
|
check_swagger_file(path)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue