Skip to content

Commit 65df3c2

Browse files
gijs-blankengijs.blanken@futureof.financewing328
authored
Rewrite the PHP Laravel generator (#20526)
* remove legacy laravel generator * initial setup of my vision for the laravel generator * update the php laravel samples * update php laravel docs * moved api validation into controller and handle edge cases presented by sample generation * updated samples * added php-laravel to github workflow php8 and removed php7 workflow as it only contained old laravel * preemptive work to support union types as soon as php serde supports them * updated samples * update templates in accordance to samples output * fix pipelines and update samples * correct serde version * fixed phpunit execution and updated samples * added named routes * remove * readd samples --------- Co-authored-by: [email protected] <[email protected]> Co-authored-by: William Cheng <[email protected]>
1 parent c586362 commit 65df3c2

File tree

327 files changed

+7855
-9890
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

327 files changed

+7855
-9890
lines changed

.github/workflows/samples-php7.yaml

Lines changed: 0 additions & 32 deletions
This file was deleted.

.github/workflows/samples-php8.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ on:
55
paths:
66
- samples/server/petstore/php-symfony/SymfonyBundle-php/**
77
- samples/server/petstore/php-flight/**
8+
- samples/server/petstore/php-laravel/**
89
pull_request:
910
paths:
1011
- samples/server/petstore/php-symfony/SymfonyBundle-php/**
1112
- samples/server/petstore/php-flight/**
13+
- samples/server/petstore/php-laravel/**
1214
jobs:
1315
build:
1416
name: Build PHP projects
@@ -25,6 +27,7 @@ jobs:
2527
# servers
2628
- samples/server/petstore/php-symfony/SymfonyBundle-php/
2729
- samples/server/petstore/php-flight/
30+
- samples/server/petstore/php-laravel/
2831
steps:
2932
- uses: actions/checkout@v4
3033
- name: Setup PHP with tools

docs/generators/php-laravel.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ title: Documentation for the php-laravel Generator
1111
| generator type | SERVER | |
1212
| generator language | PHP | |
1313
| generator default templating engine | mustache | |
14-
| helpTxt | Generates a PHP laravel server library. | |
14+
| helpTxt | Generates a php-laravel server. | |
1515

1616
## CONFIG OPTIONS
1717
These options may be applied as additional-properties (cli) or configOptions (plugins). Refer to [configuration docs](https://openapi-generator.tech/docs/configuration) for more details.
@@ -22,6 +22,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
2222
|apiPackage|package for generated api classes| |null|
2323
|artifactUrl|artifact URL in generated pom.xml| |null|
2424
|artifactVersion|The version to use in the composer package version field. e.g. 1.2.3| |null|
25+
|autowire|Should autowire be enabled.| |false|
2526
|composerPackageName|The name to use in the composer package name field. e.g. `vendor/project` (must be lowercase and consist of words separated by `-`, `.` or `_`).| |null|
2627
|developerOrganization|developer organization in generated pom.xml| |null|
2728
|developerOrganizationUrl|developer organization URL in generated pom.xml| |null|
@@ -57,6 +58,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
5758

5859
<ul class="column-ul">
5960
<li>\DateTime</li>
61+
<li>\Illuminate\Http\UploadedFile</li>
6062
<li>\SplFileObject</li>
6163
<li>array</li>
6264
<li>bool</li>
@@ -200,7 +202,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
200202
### Documentation Feature
201203
| Name | Supported | Defined By |
202204
| ---- | --------- | ---------- |
203-
|Readme||ToolingExtension
205+
|Readme||ToolingExtension
204206
|Model|✓|ToolingExtension
205207
|Api|✓|ToolingExtension
206208

@@ -220,7 +222,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
220222
|MultiServer|✗|OAS3
221223
|ParameterizedServer|✗|OAS3
222224
|ParameterStyling|✗|OAS3
223-
|Callbacks||OAS3
225+
|Callbacks||OAS3
224226
|LinkObjects|✗|OAS3
225227

226228
### Parameter Feature
@@ -239,7 +241,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
239241
| ---- | --------- | ---------- |
240242
|Simple|✓|OAS2,OAS3
241243
|Composite|✓|OAS2,OAS3
242-
|Polymorphism||OAS2,OAS3
244+
|Polymorphism||OAS2,OAS3
243245
|Union|✗|OAS3
244246
|allOf|✗|OAS2,OAS3
245247
|anyOf|✗|OAS3
@@ -249,14 +251,14 @@ These options may be applied as additional-properties (cli) or configOptions (pl
249251
### Security Feature
250252
| Name | Supported | Defined By |
251253
| ---- | --------- | ---------- |
252-
|BasicAuth||OAS2,OAS3
253-
|ApiKey||OAS2,OAS3
254+
|BasicAuth||OAS2,OAS3
255+
|ApiKey||OAS2,OAS3
254256
|OpenIDConnect|✗|OAS3
255-
|BearerToken||OAS3
256-
|OAuth2_Implicit||OAS2,OAS3
257-
|OAuth2_Password||OAS2,OAS3
258-
|OAuth2_ClientCredentials||OAS2,OAS3
259-
|OAuth2_AuthorizationCode||OAS2,OAS3
257+
|BearerToken||OAS3
258+
|OAuth2_Implicit||OAS2,OAS3
259+
|OAuth2_Password||OAS2,OAS3
260+
|OAuth2_ClientCredentials||OAS2,OAS3
261+
|OAuth2_AuthorizationCode||OAS2,OAS3
260262
|SignatureAuth|✗|OAS3
261263
|AWSV4Signature|✗|ToolingExtension
262264

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ public String getTypeDeclaration(Schema p) {
373373
} else if (StringUtils.isNotBlank(p.get$ref())) { // model
374374
String type = super.getTypeDeclaration(p);
375375
return (!languageSpecificPrimitives.contains(type))
376-
? "\\" + modelPackage + "\\" + type : type;
376+
? "\\" + modelPackage + "\\" + toModelName(type) : type;
377377
}
378378
return super.getTypeDeclaration(p);
379379
}
@@ -401,6 +401,10 @@ public String getSchemaType(Schema p) {
401401
openAPIType = "UNKNOWN_OPENAPI_TYPE";
402402
}
403403

404+
if ((p.getAnyOf() != null && !p.getAnyOf().isEmpty()) || (p.getOneOf() != null && !p.getOneOf().isEmpty())) {
405+
return openAPIType;
406+
}
407+
404408
if (typeMapping.containsKey(openAPIType)) {
405409
type = typeMapping.get(openAPIType);
406410
if (languageSpecificPrimitives.contains(type)) {
@@ -914,4 +918,28 @@ public boolean isDataTypeString(String dataType) {
914918
public GeneratorLanguage generatorLanguage() {
915919
return GeneratorLanguage.PHP;
916920
}
921+
922+
@Override
923+
public String toOneOfName(List<String> names, Schema composedSchema) {
924+
List<Schema> schemas = ModelUtils.getInterfaces(composedSchema);
925+
926+
List<String> types = new ArrayList<>();
927+
for (Schema s : schemas) {
928+
types.add(getTypeDeclaration(s));
929+
}
930+
931+
return String.join("|", types);
932+
}
933+
934+
@Override
935+
public String toAllOfName(List<String> names, Schema composedSchema) {
936+
List<Schema> schemas = ModelUtils.getInterfaces(composedSchema);
937+
938+
List<String> types = new ArrayList<>();
939+
for (Schema s : schemas) {
940+
types.add(getTypeDeclaration(s));
941+
}
942+
943+
return String.join("&", types);
944+
}
917945
}

0 commit comments

Comments
 (0)