From b6c703fa7b3d05a52f288f0e7df3d99a9ac2768b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=B5=E3=81=81?= Date: Tue, 25 Jul 2023 23:11:08 +0900 Subject: [PATCH] build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ふぁ --- dist/compatible/schemas/instruction.yaml | 1 - dist/docs/schemas/instruction.yaml | 1 - src/openapi/schemas/instruction.yaml | 2 +- tools/hooks.py | 17 +++++++++++++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/dist/compatible/schemas/instruction.yaml b/dist/compatible/schemas/instruction.yaml index 7d6e0a8..11f755c 100644 --- a/dist/compatible/schemas/instruction.yaml +++ b/dist/compatible/schemas/instruction.yaml @@ -46,7 +46,6 @@ components: content: $ref: ./content.yaml#/components/schemas/ContentUnion entryId: - pattern: ^[a-z\-]+[0-9]+$ type: string sortIndex: pattern: '[0-9]+$' diff --git a/dist/docs/schemas/instruction.yaml b/dist/docs/schemas/instruction.yaml index 7d6e0a8..11f755c 100644 --- a/dist/docs/schemas/instruction.yaml +++ b/dist/docs/schemas/instruction.yaml @@ -46,7 +46,6 @@ components: content: $ref: ./content.yaml#/components/schemas/ContentUnion entryId: - pattern: ^[a-z\-]+[0-9]+$ type: string sortIndex: pattern: '[0-9]+$' diff --git a/src/openapi/schemas/instruction.yaml b/src/openapi/schemas/instruction.yaml index 5531961..7ec2e67 100644 --- a/src/openapi/schemas/instruction.yaml +++ b/src/openapi/schemas/instruction.yaml @@ -162,7 +162,7 @@ components: $ref: "./content.yaml#/components/schemas/ContentUnion" entryId: type: string - pattern: '^[a-z\-]+[0-9]+$' + # pattern: '^[a-z\-]+[0-9]+$' sortIndex: type: string pattern: "[0-9]+$" diff --git a/tools/hooks.py b/tools/hooks.py index 00bbdb8..03effcb 100644 --- a/tools/hooks.py +++ b/tools/hooks.py @@ -109,6 +109,23 @@ class RemoveDiscriminator(SchemasHookBase): return value +class ReplaceLegacyDiscriminator(SchemasHookBase): + def hook(self, value: dict): + if value.get("oneOf") is not None: + value = { + "type": "object", + "example": ",".join( + list(x["$ref"].split("/")[-1] for x in value["oneOf"]) + ), + # "required": [value["discriminator"]["propertyName"]], + "properties": { + f"oneOf_schema_{x}_validator": y + for x, y in enumerate(value["oneOf"]) + }, + } + return value + + # RequestHookBase extends