From 1e21ce51fcb1b5763d4a7909d3b83f82ccd85d46 Mon Sep 17 00:00:00 2001 From: Richard Date: Tue, 6 Jul 2021 15:18:53 +0100 Subject: [PATCH] Some basic validation for OpenAPI I was getting unhelpful OpenAPI errors, this Python script makes it easier to figure out where they come from. --- docs/test_swagger_yaml.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 docs/test_swagger_yaml.py diff --git a/docs/test_swagger_yaml.py b/docs/test_swagger_yaml.py new file mode 100644 index 00000000..d37fcbd7 --- /dev/null +++ b/docs/test_swagger_yaml.py @@ -0,0 +1,15 @@ +import yaml +with open("./build/swagger.yaml", "r") as f: + api = yaml.load(f) + +for path, methods in api["paths"].items(): + for method, properties in methods.items(): + try: + for k in ["responses", "description"]: + current_key = k + _ = properties[k] + for code, r in properties["responses"].items(): + current_key = f"responses/{code}/description" + _ = r["description"] + except KeyError as e: + print(f"❌ {method} {path} has a problem: {e} from {current_key}")