Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #8152
Closed
Open
Issue created Dec 10, 2020 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

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

Created by: m-graham

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
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
  1. 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
  1. Open petstore/Api/PetsApiInterface.php and you will see that $petType = ''DOG''
Related issues/PRs
Suggest a fix
Assignee
Assign to
Time tracking