Skip to content

Rewrite the PHP Laravel generator #20526

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
merged 16 commits into from
Feb 17, 2025
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
32 changes: 0 additions & 32 deletions .github/workflows/samples-php7.yaml

This file was deleted.

3 changes: 3 additions & 0 deletions .github/workflows/samples-php8.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ on:
paths:
- samples/server/petstore/php-symfony/SymfonyBundle-php/**
- samples/server/petstore/php-flight/**
- samples/server/petstore/php-laravel/**
pull_request:
paths:
- samples/server/petstore/php-symfony/SymfonyBundle-php/**
- samples/server/petstore/php-flight/**
- samples/server/petstore/php-laravel/**
jobs:
build:
name: Build PHP projects
Expand All @@ -25,6 +27,7 @@ jobs:
# servers
- samples/server/petstore/php-symfony/SymfonyBundle-php/
- samples/server/petstore/php-flight/
- samples/server/petstore/php-laravel/
steps:
- uses: actions/checkout@v4
- name: Setup PHP with tools
Expand Down
24 changes: 13 additions & 11 deletions docs/generators/php-laravel.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ title: Documentation for the php-laravel Generator
| generator type | SERVER | |
| generator language | PHP | |
| generator default templating engine | mustache | |
| helpTxt | Generates a PHP laravel server library. | |
| helpTxt | Generates a php-laravel server. | |

## CONFIG OPTIONS
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.
Expand All @@ -22,6 +22,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|apiPackage|package for generated api classes| |null|
|artifactUrl|artifact URL in generated pom.xml| |null|
|artifactVersion|The version to use in the composer package version field. e.g. 1.2.3| |null|
|autowire|Should autowire be enabled.| |false|
|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|
|developerOrganization|developer organization in generated pom.xml| |null|
|developerOrganizationUrl|developer organization URL in generated pom.xml| |null|
Expand Down Expand Up @@ -57,6 +58,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl

<ul class="column-ul">
<li>\DateTime</li>
<li>\Illuminate\Http\UploadedFile</li>
<li>\SplFileObject</li>
<li>array</li>
<li>bool</li>
Expand Down Expand Up @@ -200,7 +202,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
### Documentation Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Readme||ToolingExtension
|Readme||ToolingExtension
|Model|✓|ToolingExtension
|Api|✓|ToolingExtension

Expand All @@ -220,7 +222,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|MultiServer|✗|OAS3
|ParameterizedServer|✗|OAS3
|ParameterStyling|✗|OAS3
|Callbacks||OAS3
|Callbacks||OAS3
|LinkObjects|✗|OAS3

### Parameter Feature
Expand All @@ -239,7 +241,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
| ---- | --------- | ---------- |
|Simple|✓|OAS2,OAS3
|Composite|✓|OAS2,OAS3
|Polymorphism||OAS2,OAS3
|Polymorphism||OAS2,OAS3
|Union|✗|OAS3
|allOf|✗|OAS2,OAS3
|anyOf|✗|OAS3
Expand All @@ -249,14 +251,14 @@ These options may be applied as additional-properties (cli) or configOptions (pl
### Security Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|BasicAuth||OAS2,OAS3
|ApiKey||OAS2,OAS3
|BasicAuth||OAS2,OAS3
|ApiKey||OAS2,OAS3
|OpenIDConnect|✗|OAS3
|BearerToken||OAS3
|OAuth2_Implicit||OAS2,OAS3
|OAuth2_Password||OAS2,OAS3
|OAuth2_ClientCredentials||OAS2,OAS3
|OAuth2_AuthorizationCode||OAS2,OAS3
|BearerToken||OAS3
|OAuth2_Implicit||OAS2,OAS3
|OAuth2_Password||OAS2,OAS3
|OAuth2_ClientCredentials||OAS2,OAS3
|OAuth2_AuthorizationCode||OAS2,OAS3
|SignatureAuth|✗|OAS3
|AWSV4Signature|✗|ToolingExtension

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public String getTypeDeclaration(Schema p) {
} else if (StringUtils.isNotBlank(p.get$ref())) { // model
String type = super.getTypeDeclaration(p);
return (!languageSpecificPrimitives.contains(type))
? "\\" + modelPackage + "\\" + type : type;
? "\\" + modelPackage + "\\" + toModelName(type) : type;
}
return super.getTypeDeclaration(p);
}
Expand Down Expand Up @@ -401,6 +401,10 @@ public String getSchemaType(Schema p) {
openAPIType = "UNKNOWN_OPENAPI_TYPE";
}

if ((p.getAnyOf() != null && !p.getAnyOf().isEmpty()) || (p.getOneOf() != null && !p.getOneOf().isEmpty())) {
return openAPIType;
}

if (typeMapping.containsKey(openAPIType)) {
type = typeMapping.get(openAPIType);
if (languageSpecificPrimitives.contains(type)) {
Expand Down Expand Up @@ -909,4 +913,28 @@ public boolean isDataTypeString(String dataType) {
public GeneratorLanguage generatorLanguage() {
return GeneratorLanguage.PHP;
}

@Override
public String toOneOfName(List<String> names, Schema composedSchema) {
List<Schema> schemas = ModelUtils.getInterfaces(composedSchema);

List<String> types = new ArrayList<>();
for (Schema s : schemas) {
types.add(getTypeDeclaration(s));
}

return String.join("|", types);
}

@Override
public String toAllOfName(List<String> names, Schema composedSchema) {
List<Schema> schemas = ModelUtils.getInterfaces(composedSchema);

List<String> types = new ArrayList<>();
for (Schema s : schemas) {
types.add(getTypeDeclaration(s));
}

return String.join("&", types);
}
}
Loading
Loading