OpenAPITools / OpenAPITools/openapi-generator
[BUG] PHP Symfony if the application/x-www-form-urlencoded content type is used, then all object properties specified in the snake_case in the controller are getting from the request in camelCase
Nobody has claimed this yet.
- 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?
Description
if the application/x-www-form-urlencoded content type is used, then all object properties specified in the sneak_case in the controller are getting from the request in camelCase. This breaks the contract with the frontend and the parameters that were sent according to it in sneak_case are always null .
openapi-generator version
5.0.0 and latest
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: test sneak_case issue
description: |-
test sneak_case issue
version: "1.0"
paths:
/register/:
post:
description: |-
test sneak_case issue
requestBody:
content:
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/RegistrationRequest'
required: true
responses:
200:
description: OK
components:
schemas:
RegistrationRequest:
type: object
required:
- first_name
- last_name
properties:
first_name:
type: string
last_name:
type: string
Generation Details
Generation method:
docker run --rm -v "/$dir:/local" openapitools/openapi-generator-cli:latest generate \
-i local/contract/sneak_issue_test.yaml \
-g php-symfony
public function registerPostAction(Request $request)
{
// Handle authentication
// Read out all input parameter values into variables
$firstName = $request->request->get('firstName');
$lastName = $request->request->get('lastName');
// Use the default value if no value was provided
// Deserialize the input values that needs it
try {
$firstName = $this->deserialize($firstName, 'string', 'string');
$lastName = $this->deserialize($lastName, 'string', 'string');
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
}
// Validate the input values
$asserts = [];
$asserts[] = new Assert\NotNull();
$asserts[] = new Assert\Type("string");
$response = $this->validate($firstName, $asserts);
if ($response instanceof Response) {
return $response;
}
$asserts = [];
$asserts[] = new Assert\NotNull();
$asserts[] = new Assert\Type("string");
$response = $this->validate($lastName, $asserts);
if ($response instanceof Response) {
return $response;
}
try {
$handler = $this->getApiHandler();
// Make the call to the business logic
$responseCode = 204;
$responseHeaders = [];
$result = $handler->registerPost($firstName, $lastName, $responseCode, $responseHeaders);
// Find default response message
$message = '';
// Find a more specific message, if available
switch ($responseCode) {
case 200:
$message = 'OK';
break;
}
return new Response(
'',
$responseCode,
array_merge(
$responseHeaders,
[
'X-OpenAPI-Message' => $message
]
)
);
} catch (Exception $fallthrough) {
return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough));
}
}
Steps to reproduce
- Generate a Symfony controller according to the presented Open Api configuration
Related issues/PRs
Suggest a fix
I know about the variableNamingConvention parameter, but then all the variables in the code and models become in the snake_case. I would like to be able to get parameters from the form in the snake_case to the camelCase variable
example:
// Read out all input parameter values into variables
$firstName = $request->request->get('first_name');
$lastName = $request->request->get('last_name');
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
Start by running the provided OpenAPI declaration through the dockerized php-symfony generator and inspect the generated registerPostAction request reads. Compare the generated parameter names with the snake_case form fields, then verify that the generated controller retrieves first_name and last_name correctly without changing the broader variable naming convention.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, php, symfony
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100