swagger-api / swagger-api/swagger-codegen

[PHP] Bug missing commas in key-value arrays of generated models and parameter of function calls

Open
#12,404 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

The code generated contains arrays like $swaggerTypes as members of Model types but the arrays do not
seem to contain any commas to seperate different key value pairs

Swagger-codegen version
3.0.0-rc1
Swagger declaration file content or url

This is the schema for the User object in the first snippet

"User": {
  "type": "object",
  "description": "User",
  "required": [
    "firstName",
    "email",
    "userGroupId"
  ],
  "properties": {
    "email": {
      "type": "string",
      "description": "Email"
    },
    "firstName": {
      "type": "string",
      "description": "First name"
    },
    "lastName": {
      "type": "string",
      "description": "Last name",
      "nullable": true
    },
    "userGroupId": {
      "type": "string",
      "format": "uuid",
      "description": "User group id"
    }
  }
}
Command line used for generation
java --add-opens=java.base/java.util=ALL-UNNAMED -jar ./swagger-codegen-cli-3.0.0-rc1.jar generate -i http://localhost:8080/api-docs/openapi.json -l php
# I know it's not supposed to be localhost but it should not be related to the spec.
Steps to reproduce
  1. Run the above command
Related issues/PRs
Issue

It generates this invalid code for arrays in PHP:

    /**
      * Array of property to type mappings. Used for (de)serialization
      *
      * @var string[]
      */
    protected static $swaggerTypes = [
        'email' => 'string''first_name' => 'string''last_name' => 'string''user_group_id' => 'string'
    ];

    /**
      * Array of property to format mappings. Used for (de)serialization
      *
      * @var string[]
      */
    protected static $swaggerFormats = [
        'email' => null'first_name' => null'last_name' => null'user_group_id' => 'uuid'
    ];

The commas are missing between key-value pairs.

In some functions for API code, it calls the functions without commas.

    public function getGroupsWithHttpInfo($user_id, $first = null, $max = null)
    {
        $returnType = '\Swagger\Client\Model\InlineResponse20020';
        $request = $this->getGroupsRequest($user_id$first$max); // See the parameters in this line of code.
Suggest a fix/enhancement

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

Reproduce the issue with the provided OpenAPI schema and the generate -l php command, then inspect the templates or entry points that produce PHP model arrays and API function calls. Done means generated PHP includes commas between array pairs and function arguments and is syntactically valid.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.