Skip to content

Commit 8eef1d3

Browse files
author
Mostafa Aghajani
committed
feat(php-laravel): add tests for issue 21334 with API and model definitions
1 parent e247de7 commit 8eef1d3

14 files changed

Lines changed: 405 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
generatorName: php-laravel
2+
outputDir: samples/server/petstore/php-laravel-issue-21334
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/issue21334.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/php-laravel
5+
gitUserId: openapitools
6+
gitRepoId: petstore
7+
additionalProperties:
8+
variableNamingConvention: "off"
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
openapi: 3.0.3
2+
info:
3+
title: Issue 21334 - Abstract PHP Variable Naming Convention
4+
description: ''
5+
version: 1.0.0
6+
paths:
7+
/dummy:
8+
get:
9+
description: ''
10+
operationId: getDummy
11+
parameters:
12+
- name: paramCamelCase
13+
in: query
14+
required: false
15+
schema:
16+
type: string
17+
- name: ParamPascalCase
18+
in: query
19+
required: false
20+
schema:
21+
type: string
22+
- name: param_withRandomCase
23+
in: query
24+
required: false
25+
schema:
26+
type: string
27+
responses:
28+
'200':
29+
description: successful operation
30+
components:
31+
schemas:
32+
SampleModelToTestNamingConvention:
33+
type: object
34+
properties:
35+
propCamelCase:
36+
type: string
37+
default: 'defaultName'
38+
PropPascalCase:
39+
type: string
40+
default: 'DefaultName'
41+
Prop_withRandomCase:
42+
type: string
43+
default: 'defaultName'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/vendor/
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.gitignore
2+
Api/DefaultApiInterface.php
3+
Http/Controllers/DefaultController.php
4+
Model/NoContent200.php
5+
Model/SampleModelToTestNamingConvention.php
6+
README.md
7+
composer.json
8+
phpunit.xml.dist
9+
routes.php
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.14.0-SNAPSHOT
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php declare(strict_types=1);
2+
3+
/**
4+
* Issue 21334 - Abstract PHP Variable Naming Convention
5+
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
6+
* PHP version 8.1
7+
*
8+
* The version of the OpenAPI document: 1.0.0
9+
*
10+
*
11+
* NOTE: This class is auto generated by OpenAPI-Generator
12+
* https://openapi-generator.tech
13+
* Do not edit the class manually.
14+
*
15+
* Source files are located at:
16+
*
17+
* > https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/php-laravel/
18+
*/
19+
20+
21+
namespace OpenAPI\Server\Api;
22+
23+
24+
interface DefaultApiInterface {
25+
26+
27+
/**
28+
* Operation getDummy
29+
* @param null | string $paramCamelCase
30+
* @param null | string $ParamPascalCase
31+
* @param null | string $param_withRandomCase
32+
* @return \OpenAPI\Server\Model\NoContent200
33+
*/
34+
public function getDummy(
35+
?string $paramCamelCase,
36+
?string $ParamPascalCase,
37+
?string $param_withRandomCase,
38+
):
39+
\OpenAPI\Server\Model\NoContent200
40+
;
41+
42+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php declare(strict_types=1);
2+
3+
/**
4+
* Issue 21334 - Abstract PHP Variable Naming Convention
5+
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
6+
* PHP version 8.1
7+
*
8+
* The version of the OpenAPI document: 1.0.0
9+
*
10+
*
11+
* NOTE: This class is auto generated by OpenAPI-Generator
12+
* https://openapi-generator.tech
13+
* Do not edit the class manually.
14+
*
15+
* Source files are located at:
16+
*
17+
* > https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/php-laravel/
18+
*/
19+
20+
21+
namespace OpenAPI\Server\Http\Controllers;
22+
23+
use Crell\Serde\SerdeCommon;
24+
use Illuminate\Routing\Controller;
25+
use Illuminate\Http\JsonResponse;
26+
use Illuminate\Http\Request;
27+
use Illuminate\Support\Facades\Validator;
28+
29+
30+
use OpenAPI\Server\Api\DefaultApiInterface;
31+
32+
class DefaultController extends Controller
33+
{
34+
/**
35+
* Constructor
36+
*/
37+
public function __construct(
38+
private readonly DefaultApiInterface $api,
39+
private readonly SerdeCommon $serde = new SerdeCommon(),
40+
)
41+
{
42+
}
43+
44+
/**
45+
* Operation getDummy
46+
*
47+
* .
48+
*
49+
*/
50+
public function getDummy(Request $request): JsonResponse
51+
{
52+
$validator = Validator::make(
53+
array_merge(
54+
[
55+
56+
],
57+
$request->all(),
58+
),
59+
[
60+
'paramCamelCase' => [
61+
'string',
62+
],
63+
'ParamPascalCase' => [
64+
'string',
65+
],
66+
'param_withRandomCase' => [
67+
'string',
68+
],
69+
],
70+
);
71+
72+
if ($validator->fails()) {
73+
return response()->json(['error' => 'Invalid input'], 400);
74+
}
75+
76+
$paramCamelCase = $request->string('paramCamelCase')->value();
77+
78+
$ParamPascalCase = $request->string('ParamPascalCase')->value();
79+
80+
$param_withRandomCase = $request->string('param_withRandomCase')->value();
81+
82+
try {
83+
$apiResult = $this->api->getDummy($paramCamelCase, $ParamPascalCase, $param_withRandomCase);
84+
} catch (\Exception $exception) {
85+
// This shouldn't happen
86+
report($exception);
87+
return response()->json(['error' => $exception->getMessage()], 500);
88+
}
89+
90+
if ($apiResult instanceof \OpenAPI\Server\Model\NoContent200) {
91+
return response()->json($this->serde->serialize($apiResult, format: 'array'), 200);
92+
}
93+
94+
95+
// This shouldn't happen
96+
return response()->abort(500);
97+
}
98+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php declare(strict_types=1);
2+
3+
/**
4+
* Issue 21334 - Abstract PHP Variable Naming Convention
5+
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
6+
* PHP version 8.1
7+
*
8+
* The version of the OpenAPI document: 1.0.0
9+
*
10+
*
11+
* NOTE: This class is auto generated by OpenAPI-Generator
12+
* https://openapi-generator.tech
13+
* Do not edit the class manually.
14+
*
15+
* Source files are located at:
16+
*
17+
* > https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/php-laravel/
18+
*/
19+
20+
21+
/**
22+
* NoContent200
23+
*/
24+
namespace OpenAPI\Server\Model;
25+
26+
/**
27+
* NoContent200
28+
* @description No content for 200
29+
*/
30+
use Crell\Serde\Renaming\Cases;
31+
use Crell\Serde\Attributes as Serde;
32+
33+
#[Serde\ClassSettings(renameWith: Cases::snake_case)]
34+
class NoContent200
35+
{
36+
/**
37+
*
38+
* dummy property for no-content responses
39+
* @param null | string $dummy
40+
*/
41+
42+
public function __construct(
43+
public ?string $dummy = null,
44+
) {}
45+
}
46+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php declare(strict_types=1);
2+
3+
/**
4+
* Issue 21334 - Abstract PHP Variable Naming Convention
5+
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
6+
* PHP version 8.1
7+
*
8+
* The version of the OpenAPI document: 1.0.0
9+
*
10+
*
11+
* NOTE: This class is auto generated by OpenAPI-Generator
12+
* https://openapi-generator.tech
13+
* Do not edit the class manually.
14+
*
15+
* Source files are located at:
16+
*
17+
* > https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/php-laravel/
18+
*/
19+
20+
21+
/**
22+
* SampleModelToTestNamingConvention
23+
*/
24+
namespace OpenAPI\Server\Model;
25+
26+
/**
27+
* SampleModelToTestNamingConvention
28+
*/
29+
use Crell\Serde\Renaming\Cases;
30+
use Crell\Serde\Attributes as Serde;
31+
32+
#[Serde\ClassSettings(renameWith: Cases::snake_case)]
33+
class SampleModelToTestNamingConvention
34+
{
35+
/**
36+
*
37+
*
38+
* @param string $propCamelCase
39+
*
40+
*
41+
* @param string $PropPascalCase
42+
*
43+
*
44+
* @param string $Prop_withRandomCase
45+
*/
46+
47+
public function __construct(
48+
public string $propCamelCase = 'defaultName',
49+
public string $PropPascalCase = 'DefaultName',
50+
public string $Prop_withRandomCase = 'defaultName',
51+
) {}
52+
}
53+

0 commit comments

Comments
 (0)