From fc3e0249351f114ba8e10d131d9487d8d9ba3a2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=B5=E3=81=81?= Date: Sun, 24 Sep 2023 08:56:35 +0900 Subject: [PATCH] [python] update circular import MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ふぁ --- .../resources/python/api_doc_example.mustache | 5 ++- .../resources/python/model_anyof.mustache | 5 ++- .../resources/python/model_generic.mustache | 5 ++- .../resources/python/model_oneof.mustache | 5 ++- ...points-models-for-testing-pydantic-v2.yaml | 42 +++++++++---------- 5 files changed, 37 insertions(+), 25 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python/api_doc_example.mustache b/modules/openapi-generator/src/main/resources/python/api_doc_example.mustache index 99855d3ee392..b6fe413d1001 100644 --- a/modules/openapi-generator/src/main/resources/python/api_doc_example.mustache +++ b/modules/openapi-generator/src/main/resources/python/api_doc_example.mustache @@ -34,5 +34,8 @@ from pprint import pprint {{#vendorExtensions.x-py-postponed-example-imports}} {{{.}}} {{/vendorExtensions.x-py-postponed-example-imports}} -{{classname}}.{{#usePydanticV2}}model_rebuild{{/usePydanticV2}}{{^usePydanticV2}}update_forward_refs{{/usePydanticV2}}() +try: + {{classname}}.{{#usePydanticV2}}model_rebuild{{/usePydanticV2}}{{^usePydanticV2}}update_forward_refs{{/usePydanticV2}}() +except Exception: + pass {{/vendorExtensions.x-py-postponed-example-imports.size}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/python/model_anyof.mustache b/modules/openapi-generator/src/main/resources/python/model_anyof.mustache index bf2ac0034b0b..ccf005ba3f55 100644 --- a/modules/openapi-generator/src/main/resources/python/model_anyof.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_anyof.mustache @@ -185,5 +185,8 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} {{#vendorExtensions.x-py-postponed-model-imports}} {{{.}}} {{/vendorExtensions.x-py-postponed-model-imports}} -{{classname}}.{{#usePydanticV2}}model_rebuild{{/usePydanticV2}}{{^usePydanticV2}}update_forward_refs{{/usePydanticV2}}() +try: + {{classname}}.{{#usePydanticV2}}model_rebuild{{/usePydanticV2}}{{^usePydanticV2}}update_forward_refs{{/usePydanticV2}}() +except Exception: + pass {{/vendorExtensions.x-py-postponed-model-imports.size}} diff --git a/modules/openapi-generator/src/main/resources/python/model_generic.mustache b/modules/openapi-generator/src/main/resources/python/model_generic.mustache index af5d4be052b2..f6b10ebeeb31 100644 --- a/modules/openapi-generator/src/main/resources/python/model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_generic.mustache @@ -369,5 +369,8 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} {{#vendorExtensions.x-py-postponed-model-imports}} {{{.}}} {{/vendorExtensions.x-py-postponed-model-imports}} -{{classname}}.{{#usePydanticV2}}model_rebuild{{/usePydanticV2}}{{^usePydanticV2}}update_forward_refs{{/usePydanticV2}}() +try: + {{classname}}.{{#usePydanticV2}}model_rebuild{{/usePydanticV2}}{{^usePydanticV2}}update_forward_refs{{/usePydanticV2}}() +except Exception: + pass {{/vendorExtensions.x-py-postponed-model-imports.size}} diff --git a/modules/openapi-generator/src/main/resources/python/model_oneof.mustache b/modules/openapi-generator/src/main/resources/python/model_oneof.mustache index d8eeb968278f..40dd820edb6b 100644 --- a/modules/openapi-generator/src/main/resources/python/model_oneof.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_oneof.mustache @@ -217,5 +217,8 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} {{#vendorExtensions.x-py-postponed-model-imports}} {{{.}}} {{/vendorExtensions.x-py-postponed-model-imports}} -{{classname}}.{{#usePydanticV2}}model_rebuild{{/usePydanticV2}}{{^usePydanticV2}}update_forward_refs{{/usePydanticV2}}() +try: + {{classname}}.{{#usePydanticV2}}model_rebuild{{/usePydanticV2}}{{^usePydanticV2}}update_forward_refs{{/usePydanticV2}}() +except Exception: + pass {{/vendorExtensions.x-py-postponed-model-imports.size}} diff --git a/modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-pydantic-v2.yaml b/modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-pydantic-v2.yaml index 4fe96df00525..9a509f711008 100644 --- a/modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-pydantic-v2.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-pydantic-v2.yaml @@ -2197,27 +2197,27 @@ components: properties: optionalDict: $ref: "#/components/schemas/DictWithAdditionalProperties" - #Circular-Reference-Model: - # type: object - # properties: - # size: - # type: integer - # nested: - # $ref: '#/components/schemas/FirstRef' - #FirstRef: - # type: object - # properties: - # category: - # type: string - # self_ref: - # $ref: '#/components/schemas/SecondRef' - #SecondRef: - # type: object - # properties: - # category: - # type: string - # circular_ref: - # $ref: '#/components/schemas/Circular-Reference-Model' + Circular-Reference-Model: + type: object + properties: + size: + type: integer + nested: + $ref: '#/components/schemas/FirstRef' + FirstRef: + type: object + properties: + category: + type: string + self_ref: + $ref: '#/components/schemas/SecondRef' + SecondRef: + type: object + properties: + category: + type: string + circular_ref: + $ref: '#/components/schemas/Circular-Reference-Model' InnerDictWithAdditionalProperties: type: object additionalProperties: