swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

PHP Generator does not generate comma's between string array values

Open Klyner007 opened this issue 8 years ago • 10 comments

Description

When generating a project, the generated models contain array properties which are not formatted right. Between multiple array values there should be a comma but it is not there.

Swagger-codegen version

3.0.0 SNAPSHOT

Klyner007 avatar Jun 22 '18 13:06 Klyner007

Hello @Klyner007 , can you please check an example of your output? Also if it's possible for you to share the spec you used it would be helpful too.

HugoMario avatar Jun 28 '18 08:06 HugoMario

An example of what the generator generated, is the following:

/**
  * Array of property to type mappings. Used for (de)serialization
  *
  * @var string[]
  */
protected static $swaggerTypes = [
    'uri' => 'string',
	'versions' => '\Swagger\Client\Model\Version[]'
];

I think this is default code which is not in the yml file I imported.

Klyner007 avatar Jun 29 '18 12:06 Klyner007

I can reproduce this bug on https://editor.swagger.io and latest release 3.6.3

Spec:

openapi: 3.0.0
info:
  title: vzaar
  description: Swagger document for generating vzaar's SDKs
  version: "2.0"
servers:
  - url: https://vzaar.com/api/v2
paths:
  /videos:
    get:
      summary: Returns a list of videos.
      description: Get videos in account with optional filter and sorting
      responses:
        '200':
          description: A JSON array of videos
          content:
            application/json:
              schema: 
                $ref: '#/components/schemas/Video'
components:
  schemas:
      Video:
        type: object
        properties:
          id:
            type: integer
            example: 123
          title:
            type: string
            example: "My Video"
          description:
            type: string
            example: "Video Description"

lib/model/Video.php:67 is an example where the array has been generated without comma separators:

protected static $swaggerTypes = [
    'id' => 'int''title' => 'string''description' => 'string'
];

In short, component references are broken and when you try to use the client you get a PHP syntax error.

lumivient avatar Jul 11 '18 09:07 lumivient

hey @Klyner007 @richjenks

i think this was fixed for recent codegen 3.0.0-SNAPSHOT but this version is still not used for editor. however can you please check and let me knnow if it still present? thanks!

HugoMario avatar Aug 08 '18 02:08 HugoMario

@HugoMario half fixed~

3.0.0-SNAPSHOT/swagger-codegen-cli-3.0.0-20180710.190537-87.jar

 protected static $swaggerTypes = [
        'id' => 'int',
        'title' => 'string',
        'description' => 'string'
    ];

but still busted here..

  protected static $attributeMap = [
        'id' => 'id''title' => 'title''description' => 'description'
    ];

hampsterx avatar Oct 03 '18 01:10 hampsterx

Hi, Any news here?

I have similar problem in version 3.0.3. It's not generate commas properly in method parameters: java -jar swagger-codegen-cli-3.0.3.jar generate -i https://developer.allegro.pl/swagger.yaml -o . -l php --type-mappings BigDecimal=integer

generated code:

    /**
     * Operation changePublicationStatusUsingPUT
*
     * Modify multiple offers publication at once.
*
* @param  \GreenCell\AllegroRestApiClient\Model\PublicationChangeCommandDto $body publicationChangeCommandDto (required)
* @param  string $commandId commandId (required)
*
     * @throws \GreenCell\AllegroRestApiClient\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \GreenCell\AllegroRestApiClient\Model\GeneralReport
     */
    public function changePublicationStatusUsingPUT($body$commandId)
    {
        list($response) = $this->changePublicationStatusUsingPUTWithHttpInfo($body$commandId);
        return $response;
    }

Do you know anything about this problem? How now can I modify templates for php? - I don't see any directory with templates in 3.x version.

bnowak avatar Dec 10 '18 09:12 bnowak

@bnowak (Solution may only apply to Spring/SpringBoot). It's not great, but it looks like this problem was introduced after 3.0.0. Try reverting version back from 3.0.3 to 3.0.0 and see if this is fixed for you.

joneiros avatar Jan 16 '19 15:01 joneiros

@hampsterx , can you please check again? i checked this for 3.0.4 and it's fixed. going to close it but let me know if the issue is still present and i'll work on it.

HugoMario avatar Jan 23 '19 10:01 HugoMario

@HugoMario are you sure it's fixed? I'm running swaggerapi/swagger-codegen-cli-v3:3.0.4 Docker container and just got this exact issue. Generated code:

public function method($body$arg1, $arg2, $arg3)

EDIT: just updated my container, it's fixed in 3.0.5

zefj avatar Feb 19 '19 17:02 zefj

it works in 3.0.5
thanks :smile:

bnowak avatar Feb 26 '19 08:02 bnowak