swagger-api / swagger-api/swagger-codegen

[PHP] Wrong arrays of objects code generation

Open
#9,549 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

php-symfony for server generates wrong type hinting for setter method when array of object required. This could be found in samples provided by codegen: https://github.com/swagger-api/swagger-codegen/blob/master/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php#L230

public function setTags(Tag $tags = null) // << should be an array
{
    $this->tags = $tags;
    return $this;
}
Swagger-codegen version

Both master and 3.0.0.

Swagger declaration file content or url
Pet: 
    id: Pet
    description: "A pet is a person's best friend"
    required: 
      - id
      - name
    properties: 
      id: 
        type: integer
        format: int64
      tags: 
        type: array
        items: 
          $ref: Tag

Tag: 
   id: Tag
   properties: 
     name: 
       type: string
     id: 
       type: integer
       format: int64

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 samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php and the Pet/Tag schema shown in the issue. Trace the PHP Symfony generator template that produces setTags; done means the generated setter correctly represents an array of Tag objects, with the sample or relevant generator test regenerated to verify the result.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.