Skip to content

Commit

Permalink
Version 1.6 (#216)
Browse files Browse the repository at this point in the history
* Resolves not locating singular table names and other refactors #171

Uses MixerApi/Core to locate models, entities, etc...

* csfix

* Updates SwaggerBake.Schema.created to use ModelDecorator

* cs fix

* Removes EntityDecorator and PropertyDecorator, now uses MixerApi/Core classes.

* set mixerapi/core version

* Support DTOs for XML and JSON request types #204

- Adds support for XML/JSON DTO via SwagDtoRequestBody annotation
- Deprecates SwagDtoForm in favor of SwagDtoRequestBody

* Updates composer and fixes CS issues

- Removes minimum-stability and prefer-stable
- Sets CakePHP version constraint to `~4.0`
- Sets MixerApi/Core to `~1.0`
  • Loading branch information
cnizzardini authored Oct 25, 2020
1 parent 7a0b786 commit cc7a3fd
Show file tree
Hide file tree
Showing 57 changed files with 534 additions and 880 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
"require": {
"php": ">=7.2",
"ext-json": "*",
"cakephp/cakephp": ">=4.0 <4.2",
"cakephp/cakephp": "~4.0",
"symfony/yaml": "^5.0",
"phpdocumentor/reflection-docblock": "^5.1",
"doctrine/annotations": "^1.10",
"thecodingmachine/class-explorer": "^1.1"
"thecodingmachine/class-explorer": "^1.1",
"mixerapi/core": "~1.0"
},
"suggest": {
"friendsofcake/search": "Easy model searching with @SwagSearch",
Expand Down
17 changes: 9 additions & 8 deletions src/Command/ModelCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
use Cake\Console\ConsoleIo;
use Cake\Console\ConsoleOptionParser;
use Cake\Routing\Router;
use ReflectionClass;
use SwaggerBake\Lib\Configuration;
use SwaggerBake\Lib\EntityScanner;
use SwaggerBake\Lib\RouteScanner;
use SwaggerBake\Lib\Model\ModelScanner;
use SwaggerBake\Lib\Route\RouteScanner;
use SwaggerBake\Lib\Utility\DataTypeConversion;
use SwaggerBake\Lib\Utility\ValidateConfiguration;

Expand Down Expand Up @@ -61,10 +62,10 @@ public function execute(Arguments $args, ConsoleIo $io)
}

$routeScanner = new RouteScanner(new Router(), $config);
$entityScanner = new EntityScanner($routeScanner, $config);
$entities = $entityScanner->getEntityDecorators();
$modelScanner = new ModelScanner($routeScanner, $config);
$models = $modelScanner->getModelDecorators();

if (empty($entities)) {
if (empty($models)) {
$io->out();
$io->warning('No models were found that are associated with: ' . $config->getPrefix());
$io->out('Have you added RESTful routes? Do you have models associated with those routes?');
Expand All @@ -74,10 +75,10 @@ public function execute(Arguments $args, ConsoleIo $io)

$header = ['Attribute','Data Type', 'Swagger Type','Default','Primary Key'];

foreach ($entities as $entity) {
$io->out('- ' . $entity->getName());
foreach ($models as $model) {
$io->out('- ' . (new ReflectionClass($model->getModel()->getEntity()))->getShortName());
$output = [$header];
foreach ($entity->getProperties() as $property) {
foreach ($model->getModel()->getProperties() as $property) {
$output[] = [
$property->getName(),
$property->getType(),
Expand Down
2 changes: 1 addition & 1 deletion src/Command/RouteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Cake\Console\ConsoleOptionParser;
use Cake\Routing\Router;
use SwaggerBake\Lib\Configuration;
use SwaggerBake\Lib\RouteScanner;
use SwaggerBake\Lib\Route\RouteScanner;
use SwaggerBake\Lib\Utility\ValidateConfiguration;

/**
Expand Down
11 changes: 11 additions & 0 deletions src/Lib/Annotation/SwagDtoForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,18 @@
* @see https://swagger.io/specification/ search for "Schema Object"
* @see https://swagger.io/docs/specification/data-models/data-types/?sbsearch=Data%20Format search for "data format"
* @see AbstractSchemaProperty
* @deprecated
*/
class SwagDtoForm extends AbstractSchemaProperty
{
/**
* @param array $values Annotation values
*/
public function __construct(array $values)
{
parent::__construct($values);
deprecationWarning(
'This class annotation will be deprecated in a future version, please use SwagDtoRequestBody'
);
}
}
42 changes: 42 additions & 0 deletions src/Lib/Annotation/SwagDtoRequestBody.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);

namespace SwaggerBake\Lib\Annotation;

/**
* Property level annotation for use in your SwagDto classes. Read the comments to see all supported properties.
*
* @Annotation
* @Target({"PROPERTY"})
* @Attributes({
* @Attribute("name", type = "string"),
* @Attribute("type", type = "string"),
* @Attribute("format", type = "string"),
* @Attribute("description", type = "string"),
* @Attribute("readOnly", type = "bool"),
* @Attribute("writeOnly", type = "bool"),
* @Attribute("required", type = "bool"),
* @Attribute("multipleOf", type = "float"),
* @Attribute("maximum", type = "float"),
* @Attribute("exclusiveMaximum", type = "bool"),
* @Attribute("minimum", type = "float"),
* @Attribute("exclusiveMinimum", type = "bool"),
* @Attribute("maxLength", type = "integer"),
* @Attribute("minLength", type = "integer"),
* @Attribute("pattern", type = "string"),
* @Attribute("maxItems", type = "integer"),
* @Attribute("minItems", type = "integer"),
* @Attribute("uniqueItems", type = "bool"),
* @Attribute("maxProperties", type = "integer"),
* @Attribute("minProperties", type = "integer"),
* @Attribute("enum", type = "array"),
* })
*
* Read OpenAPI specification for exact usage of the attributes:
* @see https://swagger.io/specification/ search for "Schema Object"
* @see https://swagger.io/docs/specification/data-models/data-types/?sbsearch=Data%20Format search for "data format"
* @see AbstractSchemaProperty
*/
class SwagDtoRequestBody extends AbstractSchemaProperty
{
}
1 change: 1 addition & 0 deletions src/Lib/AnnotationLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static function load(): void
{
AnnotationRegistry::loadAnnotationClass(SwagAnnotation\SwagDto::class);
AnnotationRegistry::loadAnnotationClass(SwagAnnotation\SwagDtoForm::class);
AnnotationRegistry::loadAnnotationClass(SwagAnnotation\SwagDtoRequestBody::class);
AnnotationRegistry::loadAnnotationClass(SwagAnnotation\SwagDtoQuery::class);
AnnotationRegistry::loadAnnotationClass(SwagAnnotation\SwagEntity::class);
AnnotationRegistry::loadAnnotationClass(SwagAnnotation\SwagEntityAttribute::class);
Expand Down
124 changes: 0 additions & 124 deletions src/Lib/Decorator/EntityDecorator.php

This file was deleted.

110 changes: 0 additions & 110 deletions src/Lib/Decorator/PropertyDecorator.php

This file was deleted.

Loading

0 comments on commit cc7a3fd

Please sign in to comment.