OpenAPITools / OpenAPITools/openapi-generator
[BUG] [PHP-SYMFONY] Default values for parameter enums are invalid (double quoted string)
Open
Nobody has claimed this yet.
Issue: Bug
Server: PHP
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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''
Related issues/PRs
Suggest a fix
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the provided petstore.yaml and the php-symfony generation command, then inspect the generator or template responsible for Api/PetsApiInterface.php. Done means the generated string-enum default is written as 'DOG' rather than ''DOG'', while the documented reproduction remains valid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, php, symfony
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100