Skip to content

[php-nextgen] Discriminator class detection uses wrong namespace#22811

Closed
lukascernydis wants to merge 2 commits intoOpenAPITools:masterfrom
lukascernydis:master
Closed

[php-nextgen] Discriminator class detection uses wrong namespace#22811
lukascernydis wants to merge 2 commits intoOpenAPITools:masterfrom
lukascernydis:master

Conversation

@lukascernydis
Copy link
Contributor

@lukascernydis lukascernydis commented Jan 26, 2026

When using discriminator - for example:

    ChangeVO:
      type: object
      properties:
        changeType:
          $ref: '#/components/schemas/ChangeTypeEnum'
      discriminator:
        propertyName: changeType
        mapping:
          ChangeNewVO: '#/components/schemas/ChangeNewVO'

then the object serializer is trying to find matching class ChangeNewVO.

ObjectSerializer class inside generated package was using hard-coded namespace {{invokerPackage}}\Model instead of proper {{modelPackage}}.

Error is happening only when non-standard modelPackage config option is set.

@jebentier @dkarlovi @mandrean @jfastnacht @ybelenko @renepardon


Summary by cubic

Fix discriminator subclass resolution in PHP NextGen to use the configured {{modelPackage}}, so polymorphic models resolve correctly with custom model packages. Adds tests to lock this behavior and refactors a TypeScript sample to build request options without sending the request.

  • Bug Fixes

    • Use {{modelPackage}} for discriminator-based subclass detection in ObjectSerializer (not {{invokerPackage}}\Model).
    • Add test to assert subclass lookup uses the model package namespace.
  • Refactors

    • In TestApi.ts, add testRequestOpts() returning runtime.RequestOpts.
    • Update testRaw() to use the request options builder before sending the request.

Written for commit 99783e5. Summary will update on new commits.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

$discriminator = $class::DISCRIMINATOR;
if (!empty($discriminator) && isset($data->{$discriminator}) && is_string($data->{$discriminator})) {
$subclass = '\{{invokerPackage}}\Model\\' . $data->{$discriminator};
$subclass = '\{{modelPackage}}\\' . $data->{$discriminator};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the PR

what about adding a test schema in modules/openapi-generator/src/test/resources/3_0/php-nextgen/petstore-with-fake-endpoints-models-for-testing.yaml to cover this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, sorry for the late reply. My poor brain forgot about it completly. Tests commited.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files


Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

@wing328
Copy link
Member

wing328 commented Mar 19, 2026

update: merged via #23287

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants