Skip to content

Commit

Permalink
Add support for --config to swagger models and swagger routes...
Browse files Browse the repository at this point in the history
swagger models now sorts results alphabetically
  • Loading branch information
cnizzardini committed Jun 30, 2021
1 parent e30b3d6 commit 58c1e14
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/Command/ModelCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Cake\Routing\Router;
use ReflectionClass;
use SwaggerBake\Lib\Configuration;
use SwaggerBake\Lib\Model\ModelDecorator;
use SwaggerBake\Lib\Model\ModelScanner;
use SwaggerBake\Lib\Route\RouteScanner;
use SwaggerBake\Lib\Utility\DataTypeConversion;
Expand All @@ -32,6 +33,9 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption
{
$parser
->setDescription('SwaggerBake Model Checker')
->addOption('config', [
'help' => 'Configuration (defaults to config/swagger_bake). Example: OtherApi.swagger_bake',
])
->addOption('prefix', [
'help' => 'The route prefix (uses value in configuration by default)',
]);
Expand All @@ -48,7 +52,7 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption
*/
public function execute(Arguments $args, ConsoleIo $io)
{
$this->loadConfig();
$this->loadConfig($args->getOption('config') ?? 'swagger_bake');

$io->hr();
$io->out('| SwaggerBake is checking your models...');
Expand All @@ -73,6 +77,10 @@ public function execute(Arguments $args, ConsoleIo $io)
$this->abort();
}

usort($models, function (ModelDecorator $a, ModelDecorator $b) {
return strcasecmp($a->getModel()->getSchema()->name(), $b->getModel()->getSchema()->name());
});

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

foreach ($models as $model) {
Expand Down
5 changes: 4 additions & 1 deletion src/Command/RouteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption
{
$parser
->setDescription('SwaggerBake Route Checker')
->addOption('config', [
'help' => 'Configuration (defaults to config/swagger_bake). Example: OtherApi.swagger_bake',
])
->addOption('prefix', [
'help' => 'The route prefix (uses value in configuration by default)',
]);
Expand All @@ -45,7 +48,7 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption
*/
public function execute(Arguments $args, ConsoleIo $io)
{
$this->loadConfig();
$this->loadConfig($args->getOption('config') ?? 'swagger_bake');

$io->hr();
$io->out('| SwaggerBake is checking your routes...');
Expand Down

0 comments on commit 58c1e14

Please sign in to comment.