Skip to content

Abstract PHP support of "original" for variableNamingConvention #21336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/samples-php8.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ on:
- samples/server/petstore/php-symfony/SymfonyBundle-php/**
- samples/server/petstore/php-flight/**
- samples/server/petstore/php-laravel/**
- samples/server/petstore/php-laravel-issue-21334/**
pull_request:
paths:
- samples/server/petstore/php-symfony/SymfonyBundle-php/**
- samples/server/petstore/php-flight/**
- samples/server/petstore/php-laravel/**
- samples/server/petstore/php-laravel-issue-21334/**
jobs:
build:
name: Build PHP projects
Expand All @@ -28,6 +30,7 @@ jobs:
- samples/server/petstore/php-symfony/SymfonyBundle-php/
- samples/server/petstore/php-flight/
- samples/server/petstore/php-laravel/
- samples/server/petstore/php-laravel-issue-21334/
steps:
- uses: actions/checkout@v4
- name: Setup PHP with tools
Expand Down
8 changes: 8 additions & 0 deletions bin/configs/php-laravel-issue-21334.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
generatorName: php-laravel
outputDir: samples/server/petstore/php-laravel-issue-21334
inputSpec: modules/openapi-generator/src/test/resources/3_0/issue21334.yaml
templateDir: modules/openapi-generator/src/main/resources/php-laravel
gitUserId: openapitools
gitRepoId: petstore
additionalProperties:
variableNamingConvention: "original"
2 changes: 1 addition & 1 deletion docs/generators/php-dt.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|srcBasePath|The directory to serve as source root.| |null|
|variableNamingConvention|naming convention of variable name, e.g. camelCase.| |snake_case|
|variableNamingConvention|naming convention of variable name, e.g. camelCase.|<dl><dt>**camelCase**</dt><dd>Use camelCase convention</dd><dt>**PascalCase**</dt><dd>Use PascalCase convention</dd><dt>**snake_case**</dt><dd>Use snake_case convention</dd><dt>**original**</dt><dd>Do not change the variable name</dd></dl>|snake_case|

## IMPORT MAPPING

Expand Down
2 changes: 1 addition & 1 deletion docs/generators/php-flight.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|srcBasePath|The directory to serve as source root.| |null|
|variableNamingConvention|naming convention of variable name, e.g. camelCase.| |camelCase|
|variableNamingConvention|naming convention of variable name, e.g. camelCase.|<dl><dt>**camelCase**</dt><dd>Use camelCase convention</dd><dt>**PascalCase**</dt><dd>Use PascalCase convention</dd><dt>**snake_case**</dt><dd>Use snake_case convention</dd><dt>**original**</dt><dd>Do not change the variable name</dd></dl>|camelCase|

## IMPORT MAPPING

Expand Down
2 changes: 1 addition & 1 deletion docs/generators/php-laravel.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|srcBasePath|The directory to serve as source root.| |null|
|variableNamingConvention|naming convention of variable name, e.g. camelCase.| |snake_case|
|variableNamingConvention|naming convention of variable name, e.g. camelCase.|<dl><dt>**camelCase**</dt><dd>Use camelCase convention</dd><dt>**PascalCase**</dt><dd>Use PascalCase convention</dd><dt>**snake_case**</dt><dd>Use snake_case convention</dd><dt>**original**</dt><dd>Do not change the variable name</dd></dl>|snake_case|

## IMPORT MAPPING

Expand Down
2 changes: 1 addition & 1 deletion docs/generators/php-lumen.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|srcBasePath|The directory to serve as source root.| |null|
|variableNamingConvention|naming convention of variable name, e.g. camelCase.| |snake_case|
|variableNamingConvention|naming convention of variable name, e.g. camelCase.|<dl><dt>**camelCase**</dt><dd>Use camelCase convention</dd><dt>**PascalCase**</dt><dd>Use PascalCase convention</dd><dt>**snake_case**</dt><dd>Use snake_case convention</dd><dt>**original**</dt><dd>Do not change the variable name</dd></dl>|snake_case|

## IMPORT MAPPING

Expand Down
2 changes: 1 addition & 1 deletion docs/generators/php-mezzio-ph.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|srcBasePath|The directory to serve as source root.| |null|
|variableNamingConvention|naming convention of variable name, e.g. camelCase.| |snake_case|
|variableNamingConvention|naming convention of variable name, e.g. camelCase.|<dl><dt>**camelCase**</dt><dd>Use camelCase convention</dd><dt>**PascalCase**</dt><dd>Use PascalCase convention</dd><dt>**snake_case**</dt><dd>Use snake_case convention</dd><dt>**original**</dt><dd>Do not change the variable name</dd></dl>|snake_case|

## IMPORT MAPPING

Expand Down
2 changes: 1 addition & 1 deletion docs/generators/php-nextgen.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|srcBasePath|The directory to serve as source root.| |null|
|supportStreaming|Support streaming endpoint| |false|
|variableNamingConvention|naming convention of variable name, e.g. camelCase.| |snake_case|
|variableNamingConvention|naming convention of variable name, e.g. camelCase.|<dl><dt>**camelCase**</dt><dd>Use camelCase convention</dd><dt>**PascalCase**</dt><dd>Use PascalCase convention</dd><dt>**snake_case**</dt><dd>Use snake_case convention</dd><dt>**original**</dt><dd>Do not change the variable name</dd></dl>|snake_case|

## IMPORT MAPPING

Expand Down
2 changes: 1 addition & 1 deletion docs/generators/php-slim4.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|srcBasePath|The directory to serve as source root.| |null|
|variableNamingConvention|naming convention of variable name, e.g. camelCase.| |camelCase|
|variableNamingConvention|naming convention of variable name, e.g. camelCase.|<dl><dt>**camelCase**</dt><dd>Use camelCase convention</dd><dt>**PascalCase**</dt><dd>Use PascalCase convention</dd><dt>**snake_case**</dt><dd>Use snake_case convention</dd><dt>**original**</dt><dd>Do not change the variable name</dd></dl>|camelCase|

## IMPORT MAPPING

Expand Down
2 changes: 1 addition & 1 deletion docs/generators/php-symfony.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|srcBasePath|The directory to serve as source root.| |null|
|variableNamingConvention|naming convention of variable name, e.g. camelCase.| |snake_case|
|variableNamingConvention|naming convention of variable name, e.g. camelCase.|<dl><dt>**camelCase**</dt><dd>Use camelCase convention</dd><dt>**PascalCase**</dt><dd>Use PascalCase convention</dd><dt>**snake_case**</dt><dd>Use snake_case convention</dd><dt>**original**</dt><dd>Do not change the variable name</dd></dl>|snake_case|

## IMPORT MAPPING

Expand Down
2 changes: 1 addition & 1 deletion docs/generators/php.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|srcBasePath|The directory to serve as source root.| |null|
|variableNamingConvention|naming convention of variable name, e.g. camelCase.| |snake_case|
|variableNamingConvention|naming convention of variable name, e.g. camelCase.|<dl><dt>**camelCase**</dt><dd>Use camelCase convention</dd><dt>**PascalCase**</dt><dd>Use PascalCase convention</dd><dt>**snake_case**</dt><dd>Use snake_case convention</dd><dt>**original**</dt><dd>Do not change the variable name</dd></dl>|snake_case|

## IMPORT MAPPING

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ public AbstractPhpCodegen() {
cliOptions.add(new CliOption(CodegenConstants.MODEL_PACKAGE, CodegenConstants.MODEL_PACKAGE_DESC));
cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));
cliOptions.add(new CliOption(VARIABLE_NAMING_CONVENTION, "naming convention of variable name, e.g. camelCase.")
.addEnum("camelCase", "Use camelCase convention")
.addEnum("PascalCase", "Use PascalCase convention")
.addEnum("snake_case", "Use snake_case convention")
.addEnum("original", "Do not change the variable name")
.defaultValue("snake_case"));
cliOptions.add(new CliOption(CodegenConstants.INVOKER_PACKAGE, "The main namespace to use for all classes. e.g. Yay\\Pets"));
cliOptions.add(new CliOption(PACKAGE_NAME, "The main package name for classes. e.g. GeneratedPetstore"));
Expand Down Expand Up @@ -451,6 +455,8 @@ public String toVarName(String name) {
name = camelize(name, LOWERCASE_FIRST_LETTER);
} else if ("PascalCase".equals(variableNamingConvention)) {
name = camelize(name, UPPERCASE_FIRST_CHAR);
} else if ("original".equals(variableNamingConvention)) {
// return the name as it is
} else { // default to snake case
// return the name in underscore style
// PhoneNumber => phone_number
Expand Down
43 changes: 43 additions & 0 deletions modules/openapi-generator/src/test/resources/3_0/issue21334.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
openapi: 3.0.3
info:
title: Issue 21334 - Abstract PHP Variable Naming Convention
description: ''
version: 1.0.0
paths:
/dummy:
get:
description: ''
operationId: getDummy
parameters:
- name: paramCamelCase
in: query
required: false
schema:
type: string
- name: ParamPascalCase
in: query
required: false
schema:
type: string
- name: param_withRandomCase
in: query
required: false
schema:
type: string
responses:
'200':
description: successful operation
components:
schemas:
SampleModelToTestNamingConvention:
type: object
properties:
propCamelCase:
type: string
default: 'defaultName'
PropPascalCase:
type: string
default: 'DefaultName'
Prop_withRandomCase:
type: string
default: 'defaultName'
1 change: 1 addition & 0 deletions samples/server/petstore/php-laravel-issue-21334/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor/
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.gitignore
Api/DefaultApiInterface.php
Http/Controllers/DefaultController.php
Model/NoContent200.php
Model/SampleModelToTestNamingConvention.php
README.md
composer.json
phpunit.xml.dist
routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.14.0-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php declare(strict_types=1);

/**
* Issue 21334 - Abstract PHP Variable Naming Convention
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
* PHP version 8.1
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI-Generator
* https://openapi-generator.tech
* Do not edit the class manually.
*
* Source files are located at:
*
* > https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/php-laravel/
*/


namespace OpenAPI\Server\Api;


interface DefaultApiInterface {


/**
* Operation getDummy
* @param null | string $paramCamelCase
* @param null | string $ParamPascalCase
* @param null | string $param_withRandomCase
* @return \OpenAPI\Server\Model\NoContent200
*/
public function getDummy(
?string $paramCamelCase,
?string $ParamPascalCase,
?string $param_withRandomCase,
):
\OpenAPI\Server\Model\NoContent200
;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php declare(strict_types=1);

/**
* Issue 21334 - Abstract PHP Variable Naming Convention
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
* PHP version 8.1
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI-Generator
* https://openapi-generator.tech
* Do not edit the class manually.
*
* Source files are located at:
*
* > https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/php-laravel/
*/


namespace OpenAPI\Server\Http\Controllers;

use Crell\Serde\SerdeCommon;
use Illuminate\Routing\Controller;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;


use OpenAPI\Server\Api\DefaultApiInterface;

class DefaultController extends Controller
{
/**
* Constructor
*/
public function __construct(
private readonly DefaultApiInterface $api,
private readonly SerdeCommon $serde = new SerdeCommon(),
)
{
}

/**
* Operation getDummy
*
* .
*
*/
public function getDummy(Request $request): JsonResponse
{
$validator = Validator::make(
array_merge(
[

],
$request->all(),
),
[
'paramCamelCase' => [
'string',
],
'ParamPascalCase' => [
'string',
],
'param_withRandomCase' => [
'string',
],
],
);

if ($validator->fails()) {
return response()->json(['error' => 'Invalid input'], 400);
}

$paramCamelCase = $request->string('paramCamelCase')->value();

$ParamPascalCase = $request->string('ParamPascalCase')->value();

$param_withRandomCase = $request->string('param_withRandomCase')->value();

try {
$apiResult = $this->api->getDummy($paramCamelCase, $ParamPascalCase, $param_withRandomCase);
} catch (\Exception $exception) {
// This shouldn't happen
report($exception);
return response()->json(['error' => $exception->getMessage()], 500);
}

if ($apiResult instanceof \OpenAPI\Server\Model\NoContent200) {
return response()->json($this->serde->serialize($apiResult, format: 'array'), 200);
}


// This shouldn't happen
return response()->abort(500);
}
}
Loading
Loading