[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
- Save the spec above as petstore.yaml
- 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
- 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
- Open petstore/Api/PetsApiInterface.php and you will see that $petType = ''DOG''