diff --git a/src/ApiGenerator.php b/src/ApiGenerator.php index e9b9e39..e12995a 100644 --- a/src/ApiGenerator.php +++ b/src/ApiGenerator.php @@ -28,6 +28,7 @@ public function handle() try { $this->actionIndex($ramlFile); } catch (\Exception $e) { + $this->info($e->getMessage()); $this->error($e->getTraceAsString()); } } diff --git a/src/controllers/BaseCommand.php b/src/controllers/BaseCommand.php index 13d2c9c..8849d82 100644 --- a/src/controllers/BaseCommand.php +++ b/src/controllers/BaseCommand.php @@ -88,8 +88,22 @@ public function actionIndex(string $file) */ private function validate() { + // required yaml fields will be thrown as exceptions if (empty($this->data[ApiInterface::OPEN_API_KEY])) { - throw new SchemaException('There must be ' . ApiInterface::OPEN_API_KEY . ' document root field'); + throw new SchemaException('There must be ' . ApiInterface::OPEN_API_KEY . ', ' . ApiInterface::API_SERVERS . ' document root fields'); + } + + $schemas = $this->data[ApiInterface::API_COMPONENTS][ApiInterface::API_SCHEMAS]; + if (empty($schemas[CustomsInterface::CUSTOM_TYPES_ID]) + || empty($schemas[CustomsInterface::CUSTOM_TYPES_TYPE]) + || empty($schemas[CustomsInterface::CUSTOM_RELATIONSHIPS_DATA_ITEM])) { + throw new SchemaException('At least these types must be declared: ' . CustomsInterface::CUSTOM_TYPES_ID + . ', ' . CustomsInterface::CUSTOM_TYPES_TYPE . ', ' . CustomsInterface::CUSTOM_RELATIONSHIPS_DATA_ITEM + . ' as components -> schemas descendants'); + } + + if (empty($this->data[ApiInterface::API_INFO])) { + $this->warn(ApiInterface::API_INFO . ': field would be convenient to show users what this API is about'); } } @@ -104,7 +118,7 @@ private function generateOpenApi() $this->migrationsDir = DirsInterface::MIGRATIONS_DIR; foreach ($this->data[ApiInterface::API_SERVERS] as $server) { - $vars = $server[ApiInterface::API_VARS]; + $vars = $server[ApiInterface::API_VARS]; $this->version = $vars[ApiInterface::API_BASE_PATH][ApiInterface::API_DEFAULT]; if (env('APP_ENV') === 'dev') { // for test env based on .env diff --git a/src/types/ApiInterface.php b/src/types/ApiInterface.php index 1bd0682..cd5dba3 100644 --- a/src/types/ApiInterface.php +++ b/src/types/ApiInterface.php @@ -6,6 +6,7 @@ interface ApiInterface { public const OPEN_API_KEY = 'openapi'; public const API_SERVERS = 'servers'; + public const API_INFO = 'info'; public const API_VARS = 'variables'; public const API_BASE_PATH = 'basePath'; diff --git a/src/types/CustomsInterface.php b/src/types/CustomsInterface.php index b945c0e..c2770d7 100644 --- a/src/types/CustomsInterface.php +++ b/src/types/CustomsInterface.php @@ -1,15 +1,18 @@