OpenAPITools / OpenAPITools/openapi-generator

[BUG] PHP Generator omits Namespace of Models in $allOf

Open
#9,061 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

The PHP Generator seems to omit the class namespace for components referenced within allOf, leading to a class not found error during deserialization. I created a repository showing the generated code https://github.com/rcky/openapi-generator-all-of .

Fatal error: Uncaught Error: Class 'TestDto' not found in .../openapi-generator-all-of/lib/ObjectSerializer.php:366
openapi-generator version

Tested with 4.3.1, 5.0.0, 5.0.1

OpenAPI declaration file content or url

openapi.yml

openapi: '3.0.1'
info:
  title: Test allOf PHP
  version: '1.0'
paths:
  /test:
    get:
      tags: [ Test ]
      responses:
        default:
          description: Say hi
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CompoundDto'
components:
  schemas:
    CompoundDto:
      title: CompoundDto
      type: object
      properties:
        testProperty:
          description: Property using allOf
          allOf:
            - $ref: '#/components/schemas/TestDto'
    TestDto:
      title: TestDto
      type: object
      properties:
        name:
          type: string
Generation Details

Generated it using the docker image. generate -i /local/openapi/openapi.yml -g php -o /local. Find more details in the corresponding docker-compose.yml

Steps to reproduce

One can already see it in the corresponding model definitions. If someone wants to test the corresponding code:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with openapi.yml and the generated lib/ObjectSerializer.php, then reproduce the failure using docker-compose.yml and tryout.php. Compare the allOf TestDto reference in the generated model definitions with the deserialization error at ObjectSerializer.php:366; done means the generated PHP code resolves the model namespace and tryout.php completes without a class-not-found error.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.