OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.56k stars 6.52k forks source link

[BUG] [PHP-SYMFONY] Default values for parameter enums are invalid (double quoted string) #8152

Open m-graham opened 3 years ago

m-graham commented 3 years ago

Bug Report Checklist

Description

Default values of parameters that are of type string (enum) are generated with double quotes around the default value. i.e.

What's generated:

/**
     * Operation showPetById
     *
     * Info for a specific pet
     *
     * @param  string $petId  The id of the pet to retrieve (required)
     * @param  string $petType  The type of pet. (optional, default to ''DOG'')
     * @param  integer $responseCode     The HTTP response code to return
     * @param  array   $responseHeaders  Additional HTTP headers to return with the response ()
     *
     * @return OpenAPI\Server\Model\Pet
     *
     */
    public function showPetById($petId, $petType = ''DOG'', &$responseCode, array &$responseHeaders);

What's expected:

/**
     * Operation showPetById
     *
     * Info for a specific pet
     *
     * @param  string $petId  The id of the pet to retrieve (required)
     * @param  string $petType  The type of pet. (optional, default to 'DOG')
     * @param  integer $responseCode     The HTTP response code to return
     * @param  array   $responseHeaders  Additional HTTP headers to return with the response ()
     *
     * @return OpenAPI\Server\Model\Pet
     *
     */
    public function showPetById($petId, $petType = 'DOG', &$responseCode, array &$responseHeaders);
openapi-generator version

I tried with the latest beta build & master.

OpenAPI declaration file content or url
openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  license:
    name: MIT
servers:
  - url: http://petstore.swagger.io/v1
paths:
  /pets/{petId}:
    get:
      summary: Info for a specific pet
      operationId: showPetById
      tags:
        - pets
      parameters:
        - name: petId
          in: path
          required: true
          description: The id of the pet to retrieve
          schema:
            type: string
        - $ref: "#/components/parameters/PetType"
      responses:
        '200':
          description: Expected response to a valid request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Pet"
components:
  schemas:
    Pet:
      type: object
      required:
        - id
        - name
      properties:
        id:
          type: integer

  parameters:
    PetType:
      name: petType
      in: query
      description: The type of pet.
      schema:
        type: string
        default: DOG
        enum:
          - DOG
          - CAT
Generation Details & Steps to Reproduce
  1. Save the spec above as petstore.yaml
  2. In the same directory run the following to see that the spec is valid:
    docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli validate \
    -i /local/petstore.yaml
  3. In the same directory run the following to generate the code:
    docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate \
    -i /local/petstore.yaml \
    -g php-symfony \
    -o /local/petstore
  4. Open petstore/Api/PetsApiInterface.php and you will see that $petType = ''DOG''
Related issues/PRs
Suggest a fix
auto-labeler[bot] commented 3 years ago

👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

m-graham commented 1 year ago

Closing this as I haven't looked at it in years.