From 93c7b0b176e009c41a12d12ff0ae693df610d62a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20=C4=8Cern=C3=BD?= Date: Mon, 26 Jan 2026 14:08:48 +0100 Subject: [PATCH 1/2] [php-nextgen] Discriminator class detection uses wrong namespace --- .../php-nextgen/ObjectSerializer.mustache | 2 +- .../infinite-recursion-issue/apis/TestApi.ts | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/php-nextgen/ObjectSerializer.mustache b/modules/openapi-generator/src/main/resources/php-nextgen/ObjectSerializer.mustache index 5f8627566409..aaafb8aefd87 100644 --- a/modules/openapi-generator/src/main/resources/php-nextgen/ObjectSerializer.mustache +++ b/modules/openapi-generator/src/main/resources/php-nextgen/ObjectSerializer.mustache @@ -497,7 +497,7 @@ class ObjectSerializer // If a discriminator is defined and points to a valid subclass, use it. $discriminator = $class::DISCRIMINATOR; if (!empty($discriminator) && isset($data->{$discriminator}) && is_string($data->{$discriminator})) { - $subclass = '\{{invokerPackage}}\Model\\' . $data->{$discriminator}; + $subclass = '\{{modelPackage}}\\' . $data->{$discriminator}; if (is_subclass_of($subclass, $class)) { $class = $subclass; } diff --git a/samples/client/others/typescript-fetch/infinite-recursion-issue/apis/TestApi.ts b/samples/client/others/typescript-fetch/infinite-recursion-issue/apis/TestApi.ts index ba47bcab5145..7b56e685fc57 100644 --- a/samples/client/others/typescript-fetch/infinite-recursion-issue/apis/TestApi.ts +++ b/samples/client/others/typescript-fetch/infinite-recursion-issue/apis/TestApi.ts @@ -28,8 +28,9 @@ import { export class TestApi extends runtime.BaseAPI { /** + * Creates request options for test without sending the request */ - async testRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise>> { + async testRequestOpts(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise { const queryParameters: any = {}; const headerParameters: runtime.HTTPHeaders = {}; @@ -37,12 +38,19 @@ export class TestApi extends runtime.BaseAPI { let urlPath = `/api/v1/test`; - const response = await this.request({ + return { path: urlPath, method: 'GET', headers: headerParameters, query: queryParameters, - }, initOverrides); + }; + } + + /** + */ + async testRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise>> { + const requestConfig = await this.testRequestConfig(initOverrides); + const response = await this.request(requestConfig, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => jsonValue.map(TestBaseDtoFromJSON)); } From 99783e5bc58a828499ef8db00aadeba640e2a754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20=C4=8Cern=C3=BD?= Date: Wed, 18 Mar 2026 11:32:04 +0100 Subject: [PATCH 2/2] [php-nextgen] Discriminator class detection uses wrong namespace - tests --- .../php/PhpNextgenClientCodegenTest.java | 39 +++++++++++++++++++ ...ith-fake-endpoints-models-for-testing.yaml | 19 +++++++++ 2 files changed, 58 insertions(+) diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/php/PhpNextgenClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/php/PhpNextgenClientCodegenTest.java index 68e9dc11ed1f..cc0d0b7d9da5 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/php/PhpNextgenClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/php/PhpNextgenClientCodegenTest.java @@ -119,6 +119,45 @@ public void testEnumUnknownDefaultCaseDeserializationEnabled() throws Exception Assert.assertListNotContains(modelContent, a -> a.equals("\"Invalid value '%s' for 'color', must be one of '%s'\","), ""); } + @Test + public void testDiscriminatorUsesModelPackageNamespace() throws Exception { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + + OpenAPI openAPI = new OpenAPIParser() + .readLocation("src/test/resources/3_0/php-nextgen/petstore-with-fake-endpoints-models-for-testing.yaml", null, new ParseOptions()).getOpenAPI(); + + codegen.setOutputDir(output.getAbsolutePath()); + // Set invokerPackage="MyApp" and modelPackage="Entities" (relative suffix). + // AbstractPhpCodegen.processOpts() will produce final modelPackage = "MyApp\Entities". + // The old bug would have emitted '\MyApp\Model\' (invokerPackage + \Model\). + codegen.additionalProperties().put(CodegenConstants.INVOKER_PACKAGE, "MyApp"); + codegen.additionalProperties().put(CodegenConstants.MODEL_PACKAGE, "Entities"); + + ClientOptInput input = new ClientOptInput() + .openAPI(openAPI) + .config(codegen); + + DefaultGenerator generator = new DefaultGenerator(); + Map files = generator.opts(input).generate().stream() + .collect(Collectors.toMap(File::getName, Function.identity())); + + List objectSerializerContent = Files + .readAllLines(files.get("ObjectSerializer.php").toPath()) + .stream() + .map(String::trim) + .collect(Collectors.toList()); + + // The discriminator subclass lookup must use modelPackage (\MyApp\Entities\), + // NOT invokerPackage + '\Model' (\MyApp\Model\). + Assert.assertListContains(objectSerializerContent, + a -> a.contains("'\\MyApp\\Entities\\\\'"), + "ObjectSerializer discriminator subclass lookup must use modelPackage namespace"); + Assert.assertListNotContains(objectSerializerContent, + a -> a.contains("'\\MyApp\\Model\\\\'"), + "ObjectSerializer discriminator must NOT use invokerPackage\\Model namespace"); + } + @Test public void testEnumUnknownDefaultCaseDeserializationDisabled() throws Exception { File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); diff --git a/modules/openapi-generator/src/test/resources/3_0/php-nextgen/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/openapi-generator/src/test/resources/3_0/php-nextgen/petstore-with-fake-endpoints-models-for-testing.yaml index bc56de575adb..6f5a52aaf851 100644 --- a/modules/openapi-generator/src/test/resources/3_0/php-nextgen/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/php-nextgen/petstore-with-fake-endpoints-models-for-testing.yaml @@ -2291,3 +2291,22 @@ components: description: "Optional array of multiple errors encountered during processing" required: - error + + DiscriminatorBase: + type: object + discriminator: + propertyName: type + required: + - type + properties: + type: + type: string + + DiscriminatorChild: + allOf: + - $ref: '#/components/schemas/DiscriminatorBase' + - type: object + properties: + childProperty: + type: string +