From 9ab9a38074f82bee779fc0cb27a700c72dc4b78e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Bonhomme?= Date: Wed, 10 Jan 2024 15:06:09 +0100 Subject: [PATCH 1/2] fix: [openapi31] Fixes #146 when anyOf is used in schemas. --- sphinxcontrib/openapi/openapi31.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinxcontrib/openapi/openapi31.py b/sphinxcontrib/openapi/openapi31.py index 1c943fa..2af22c8 100644 --- a/sphinxcontrib/openapi/openapi31.py +++ b/sphinxcontrib/openapi/openapi31.py @@ -302,7 +302,7 @@ def _get_type_from_schema(schema): dtype = schema["type"] else: dtype = set() - for t in schema["anyOf"]: + for t in schema.get("anyOf", []): if "format" in t.keys(): dtype.add(t["format"]) else: From 3ba79afcbaa2583b2e6e6e7b0919dc21bae6b615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Bonhomme?= Date: Tue, 16 Jan 2024 14:17:39 +0100 Subject: [PATCH 2/2] Added reproducer for issue #147. --- tests/testspecs/v3.1/issue-147.yml | 68 ++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 tests/testspecs/v3.1/issue-147.yml diff --git a/tests/testspecs/v3.1/issue-147.yml b/tests/testspecs/v3.1/issue-147.yml new file mode 100644 index 0000000..b2d7295 --- /dev/null +++ b/tests/testspecs/v3.1/issue-147.yml @@ -0,0 +1,68 @@ +--- +openapi: "3.1.0" +info: + title: "Reproducer for issue #147" +components: + schemas: + HTTPValidationError: + properties: + detail: + items: + $ref: '#/components/schemas/ValidationError' + title: Detail + type: array + title: HTTPValidationError + type: object + ValidationError: + properties: + loc: + items: + anyOf: + - type: string + - type: integer + title: Location + type: array + msg: + title: Message + type: string + type: + title: Error Type + type: string + required: + - loc + - msg + - type + title: ValidationError + type: object +paths: + /TimeStampTokens/: + get: + operationId: read_tsts_TimeStampTokens__get + parameters: + - in: query + name: skip + required: false + schema: + default: 0 + title: Skip + type: integer + - in: query + name: limit + required: false + schema: + default: 100 + title: Limit + type: integer + responses: + '200': + content: + application/json: + schema: {} + description: Successful Response + '422': + content: + application/json: + schema: + $ref: '#/components/schemas/HTTPValidationError' + description: Validation Error + summary: Read Tsts