-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
php-laravel, enum models, nullable and default values (#12480)
* + support for enum models & separating mustache templates for enums and generics + extract property 'type' and 'default value' from a #ref to an enum model + support for `PascalCase` naming convention for PHP generators + use a default value for known basic types when they are not nullable + use 'null' as default value for nullable types when they do not specify the default value + use defined constant path as enum default value when found * + sample output update * + change model fields to be public and acessible from outside * + sample output update Co-authored-by: Mostafa Aghajani <[email protected]>
- Loading branch information
Showing
54 changed files
with
427 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 9 additions & 13 deletions
22
modules/openapi-generator/src/main/resources/php-laravel/model.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,17 @@ | ||
<?php | ||
{{#models}}{{#model}}/** | ||
{{#models}} | ||
{{#model}} | ||
/** | ||
* {{classname}} | ||
*/ | ||
namespace {{modelPackage}}; | ||
|
||
/** | ||
* {{classname}} | ||
{{#description}} | ||
* @description {{{.}}} | ||
{{/description}} | ||
*/ | ||
class {{classname}} { | ||
{{#vars}} | ||
/** @var {{{dataType}}} ${{name}} {{description}}*/ | ||
{{#deprecated}} | ||
/** @deprecated */ | ||
{{/deprecated}} | ||
private ${{name}}; | ||
|
||
{{/vars}} | ||
} | ||
{{/model}}{{/models}} | ||
{{#isEnum}}{{>model_enum}}{{/isEnum}}{{^isEnum}}{{>model_generic}}{{/isEnum}} | ||
{{/model}} | ||
{{/models}} |
28 changes: 28 additions & 0 deletions
28
modules/openapi-generator/src/main/resources/php-laravel/model_enum.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class {{classname}} | ||
{ | ||
/** | ||
* Possible values of this enum | ||
*/ | ||
{{#allowableValues}} | ||
{{#enumVars}} | ||
const {{{name}}} = {{{value}}}; | ||
|
||
{{/enumVars}} | ||
{{/allowableValues}} | ||
/** | ||
* Gets allowable values of the enum | ||
* @return string[] | ||
*/ | ||
public static function getAllowableEnumValues() | ||
{ | ||
return [ | ||
{{#allowableValues}} | ||
{{#enumVars}} | ||
self::{{{name}}}{{^-last}}, | ||
{{/-last}} | ||
{{/enumVars}} | ||
{{/allowableValues}} | ||
|
||
]; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
modules/openapi-generator/src/main/resources/php-laravel/model_generic.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class {{classname}} { | ||
{{#vars}} | ||
/** @var {{{dataType}}}{{#isNullable}}|null{{/isNullable}} ${{name}} {{description}}*/ | ||
{{#deprecated}} | ||
/** @deprecated */ | ||
{{/deprecated}} | ||
public ${{name}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}{{#isNullable}} = null{{/isNullable}}{{/defaultValue}}; | ||
|
||
{{/vars}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,6 @@ | |
class ArrayOfNumberOnly { | ||
|
||
/** @var float[] $arrayNumber */ | ||
private $arrayNumber; | ||
public $arrayNumber = []; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,6 @@ | |
class CatAllOf { | ||
|
||
/** @var bool $declawed */ | ||
private $declawed; | ||
public $declawed = false; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,6 @@ | |
class Client { | ||
|
||
/** @var string $client */ | ||
private $client; | ||
public $client = ""; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,6 @@ | |
class DeprecatedObject { | ||
|
||
/** @var string $name */ | ||
private $name; | ||
public $name = ""; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.