-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port discriminator feature from 4.x branch to master (#91)
Port discriminator feature from 4.x branch to master
- Loading branch information
Showing
54 changed files
with
1,026 additions
and
73 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
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Jane\OpenApi\Generator\Model; | ||
|
||
use Jane\JsonSchema\Generator\Model\ClassGenerator as BaseClassGenerator; | ||
use PhpParser\Node; | ||
use PhpParser\Node\Name; | ||
use PhpParser\Node\Stmt; | ||
|
||
trait ClassGenerator | ||
{ | ||
use BaseClassGenerator { | ||
createModel as baseCreateModel; | ||
} | ||
|
||
/** | ||
* Return a model class. | ||
* | ||
* @param string $name | ||
* @param Node[] $properties | ||
* @param Node[] $methods | ||
* @param bool $hasExtensions | ||
* @param string $extends | ||
* | ||
* @return Stmt\Class_ | ||
*/ | ||
protected function createModel(string $name, $properties, $methods, bool $hasExtensions = false, $extends = null): Stmt\Class_ | ||
{ | ||
$classExtends = null; | ||
if (null !== $extends) { | ||
$classExtends = new Name($extends); | ||
} elseif ($hasExtensions) { | ||
$classExtends = new Name('\ArrayObject'); | ||
} | ||
|
||
return new Stmt\Class_( | ||
new Name($this->getNaming()->getClassName($name)), | ||
[ | ||
'stmts' => array_merge($properties, $methods), | ||
'extends' => $classExtends, | ||
] | ||
); | ||
} | ||
} |
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,44 @@ | ||
<?php | ||
|
||
namespace Jane\OpenApi\Generator; | ||
|
||
use Jane\JsonSchema\Generator\ModelGenerator as BaseModelGenerator; | ||
use Jane\JsonSchema\Guesser\Guess\ClassGuess as BaseClassGuess; | ||
use Jane\JsonSchema\Guesser\Guess\Property; | ||
use Jane\OpenApi\Generator\Model\ClassGenerator; | ||
use Jane\OpenApi\Guesser\Guess\ClassGuess; | ||
use Jane\OpenApi\Guesser\Guess\MultipleClass; | ||
use PhpParser\Node\Stmt; | ||
|
||
class ModelGenerator extends BaseModelGenerator | ||
{ | ||
use ClassGenerator; | ||
|
||
protected function doCreateClassMethods(BaseClassGuess $classGuess, Property $property, string $namespace, bool $required) | ||
{ | ||
$methods = []; | ||
$methods[] = $this->createGetter($property, $namespace, $required); | ||
$methods[] = $this->createSetter($property, $namespace, $required, $classGuess instanceof MultipleClass ? false : true); | ||
|
||
return $methods; | ||
} | ||
|
||
protected function doCreateModel(BaseClassGuess $class, $properties, $methods): Stmt\Class_ | ||
{ | ||
$extends = null; | ||
if ($class instanceof ClassGuess && | ||
$class->getMultipleClass() instanceof MultipleClass) { | ||
$extends = $this->getNaming()->getClassName($class->getMultipleClass()->getName()); | ||
} | ||
|
||
$classModel = $this->createModel( | ||
$class->getName(), | ||
$properties, | ||
$methods, | ||
\count($class->getExtensionsType()) > 0, | ||
$extends | ||
); | ||
|
||
return $classModel; | ||
} | ||
} |
Oops, something went wrong.