Skip to content

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 when a custom modelPackage is set. Also refactors a TypeScript sample to build request options without executing the request.

  • Bug Fixes

    • Use {{modelPackage}} for discriminator-based subclass detection in ObjectSerializer to avoid class resolution errors with custom modelPackage configs.
  • Refactors

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

Written for commit 93c7b0b. Summary will update on new commits.

Copy link

@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?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants