swagger-api / swagger-api/swagger-codegen

[php-symfony] Generated Controller uses an undefined property

Open
#8,337 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

Controller does not have container property which is being accessed in the code.
https://github.com/swagger-api/swagger-codegen/pull/6842 introduced access to container property of the BaseController. At this point Controller did not have container property anymore since the inheritance from the Base Symfony Controller was removed in https://github.com/swagger-api/swagger-codegen/pull/6615. These changes were incompatible and now any generated php-symfony code will fail should any exception be thrown down the stack and caught by the Controller.
Example of an invalid Controller: https://github.com/swagger-api/swagger-codegen/blob/master/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/Controller.php#L149

Swagger-codegen version

2.3.0, 2.3.1, master

Swagger declaration file content or url

Any swagger file, example: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml

Command line used for generation

java -jar swagger-codegen-cli.jar generate -i /api/swagger.yml -l php-symfony -o /src

Steps to reproduce

Any generated php-symfony code is invalid now and will fail should any exception be thrown.

  1. Generate any php-symfony code from any swagger configuration
  2. Throw an exception anywhere during the business logic execution.
Related issues/PRs

Issue introduced in: https://github.com/swagger-api/swagger-codegen/pull/6842
Related PR (removal of BaseController inheritance): https://github.com/swagger-api/swagger-codegen/pull/6615

Suggest a fix/enhancement

Fixed in https://github.com/swagger-api/swagger-codegen/pull/8338

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 the generated sample at samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/Controller.php around line 149, then trace it back to the php-symfony generator template. Reproduce generation with the petstore.yaml example and verify that exception handling no longer accesses an undefined container property; PR 8338 is identified as the fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, symfony
Domain
backend, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
15/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.