From 139724df743b20a56c798dc1ed11c2f9df7b238c Mon Sep 17 00:00:00 2001 From: Vishal Ribdiya <33887755+vishalinfyom@users.noreply.github.com> Date: Sat, 16 Mar 2019 15:19:38 +0530 Subject: [PATCH] fix(docs): #380 get comments from table for swagger description (#612) (#532) --- src/Common/GeneratorField.php | 2 ++ src/Generators/ModelGenerator.php | 6 ++++++ src/Generators/Scaffold/ViewGenerator.php | 3 +++ src/Generators/SwaggerGenerator.php | 2 +- src/Utils/TableFieldsGenerator.php | 3 +++ 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Common/GeneratorField.php b/src/Common/GeneratorField.php index ab4a2a75..32a06bd2 100644 --- a/src/Common/GeneratorField.php +++ b/src/Common/GeneratorField.php @@ -12,6 +12,7 @@ class GeneratorField public $htmlInput; public $htmlType; public $fieldType; + public $description; /** @var array */ public $htmlValues; @@ -26,6 +27,7 @@ class GeneratorField public $isFillable = true; public $isPrimary = false; public $inForm = true; + public $isNotNull = false; public $inIndex = true; public function parseDBType($dbInput) diff --git a/src/Generators/ModelGenerator.php b/src/Generators/ModelGenerator.php index ebaee718..5956cae0 100755 --- a/src/Generators/ModelGenerator.php +++ b/src/Generators/ModelGenerator.php @@ -230,9 +230,15 @@ private function fillTimestamps($templateData) private function generateRules() { + $dont_require_fields = config('infyom.laravel_generator.options.hidden_fields', []) + + config('infyom.laravel_generator.options.excluded_fields', []); + $rules = []; foreach ($this->commandData->fields as $field) { + if ($field->isNotNull && empty($field->validations) && !in_array($field->name, $dont_require_fields)) { + $field->validations = 'required'; + } if (!empty($field->validations)) { $rule = "'".$field->name."' => '".$field->validations."'"; $rules[] = $rule; diff --git a/src/Generators/Scaffold/ViewGenerator.php b/src/Generators/Scaffold/ViewGenerator.php index 57dc88ea..f93a70bb 100755 --- a/src/Generators/Scaffold/ViewGenerator.php +++ b/src/Generators/Scaffold/ViewGenerator.php @@ -302,6 +302,9 @@ private function generateFields() $fieldTemplate = HTMLFieldGenerator::generateHTML($field, $this->templateType); if (!empty($fieldTemplate)) { + if ($field->isNotNull) { + $fieldTemplate = str_replace('$FIELD_NAME_TITLE$', '$FIELD_NAME_TITLE$'.($field->isNotNull ? ' *' : ''), $fieldTemplate); + } $fieldTemplate = fill_template_with_field_data( $this->commandData->dynamicVars, $this->commandData->fieldNamesMapping, diff --git a/src/Generators/SwaggerGenerator.php b/src/Generators/SwaggerGenerator.php index 19edf576..4fe50279 100755 --- a/src/Generators/SwaggerGenerator.php +++ b/src/Generators/SwaggerGenerator.php @@ -87,7 +87,7 @@ public static function generateTypes($inputFields) // if (isset($field['description'])) { // $fieldType['description'] = $field['description']; // } else { - $fieldType['description'] = ''; + $fieldType['description'] = (!empty($field->description)) ? $field->description : ''; // } $fieldTypes[] = $fieldType; diff --git a/src/Utils/TableFieldsGenerator.php b/src/Utils/TableFieldsGenerator.php index 006b32b3..823abc6c 100755 --- a/src/Utils/TableFieldsGenerator.php +++ b/src/Utils/TableFieldsGenerator.php @@ -148,6 +148,9 @@ public function prepareFieldsFromTable() $field->inIndex = false; } + $field->isNotNull = (bool) $column->getNotNull(); + $field->description = $column->getComment(); // get comments from table + $this->fields[] = $field; } }