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

691
Pipfile.lock generated

File diff suppressed because it is too large Load diff

View file

@ -258,7 +258,16 @@ def generate_openapi():
'Use .yml or .yaml for YAML (which is the default' '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() 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 fname = args.output
if fname.endswith(".json"): if fname.endswith(".json"):
import json import json
@ -268,7 +277,6 @@ def generate_openapi():
with open(fname, 'w') as fd: with open(fname, 'w') as fd:
fd.write(labthing.spec.to_yaml()) fd.write(labthing.spec.to_yaml())
# Start the app if the module is run directly # Start the app if the module is run directly
if __name__ == "__main__": if __name__ == "__main__":
ofm_serve() ofm_serve()

View file

@ -44,6 +44,7 @@ setup(
# set up the project for development, you use those specific packages, rather than # set up the project for development, you use those specific packages, rather than
# the looser specifications given here. # the looser specifications given here.
install_requires=[ install_requires=[
"apispec[validation]", # We need the extra to validate the spec
"Flask ~= 1.0", "Flask ~= 1.0",
"Pillow ~= 7.2.0", "Pillow ~= 7.2.0",
"numpy ~= 1.20", "numpy ~= 1.20",