OpenAPITools / OpenAPITools/openapi-generator

[BUG][php-symfony] phpLegacySupport=false does not seem to generate strongly typed code

Open
#3,926 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Bug Report Checklist
Description

When using the option phpLegacySupport=false, I expect type hinting to be generated in all files, but sadly it isn't. From a quick look at https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java#L346 I deduced that there should be type hinting when legacy support is disabled. Haven't looked very deeply.

openapi-generator version

Latest docker, used this command:

docker run --rm \
  -v ${PWD}:/local openapitools/openapi-generator-cli generate \
  -i /local/doc/swagger.yml \
  -g php-symfony \
  -o /local/src/Swagger
  --additional-properties phpLegacySupport=false
OpenAPI declaration file content or url
swagger: '2.0'
info:
  title: Test
paths:
  /esbm/nesting:
    get:
      tags:
      - esbmodel
      summary: Get nestings
      parameters:
      - in: query
        name: limit
        type: integer
        required: false
      - in: query
        name: q
        type: string
        required: false
      responses:
        '200':
          description: successful operation
          schema:
            type: object
            properties:
              total:
                type: integer
              data:
                type: array
                items:
                  $ref: '#/definitions/Nesting'
      security:
      - esb_auth: []

definitions:
  Nesting:
    type: object
    properties:
      id:
        type: string
        readOnly: true
      _created_at:
        type: string
        format: date-time
      _updated_at:
        type: string
        format: date-time
      name:
        type: string
      job_number:
        type: string
      sequence_number:
        type: integer

##### Command line used for generation

(see above under "openapi-generator version")

##### Steps to reproduce

simply run the command with the given swagger definition. Generates nicely, but no type hinting.

##### Related issues/PRs

none found

##### Suggest a fix

typehint all function arguments and return types. Properly use ex. `?string` when types are nullable. 

Best is to also generate `declare(strict_types=1);` on every file.

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 modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java, especially the phpLegacySupport handling, then reproduce the issue with the Docker generation command and supplied Swagger definition. Done means the php-symfony output uses type hints consistently, handles nullable types appropriately, and includes strict-types declarations if that requested scope is accepted.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, php, symfony
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.