Added OpenAPI validation from apispec

This commit is contained in:
Richard 2021-07-19 11:50:50 +01:00
parent 6a7c305468
commit 077d6fdc4b
3 changed files with 471 additions and 231 deletions

View file

@ -258,7 +258,16 @@ def generate_openapi():
'Use .yml or .yaml for YAML (which is the default'
)
)
parser.add_argument(
"--validate",
action="store_true",
help="Validate the API spec, returning an error code if it does not pass."
)
args = parser.parse_args()
if args.validate:
import apispec.utils
if apispec.utils.validate_spec(labthing.spec):
print("OpenAPI specification validated OK.")
fname = args.output
if fname.endswith(".json"):
import json
@ -268,7 +277,6 @@ def generate_openapi():
with open(fname, 'w') as fd:
fd.write(labthing.spec.to_yaml())
# Start the app if the module is run directly
if __name__ == "__main__":
ofm_serve()