From f7c2b5b58f75f20bf50721ecc785465ad3e215c5 Mon Sep 17 00:00:00 2001 From: Sohel Ahmed Mesaniya Date: Tue, 28 May 2024 14:18:53 +0530 Subject: [PATCH 1/4] Initial commit to create PR --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index df87e47a..86e77ce8 100644 --- a/README.md +++ b/README.md @@ -564,3 +564,4 @@ Professional support, consulting as well as software development services are av https://www.cebe.cc/en/contact Development of this library is sponsored by [cebe.:cloud: "Your Professional Deployment Platform"](https://cebe.cloud). + From f41f0fa4eade6896fa25a0a546454ae4b111118d Mon Sep 17 00:00:00 2001 From: Sohel Ahmed Mesaniya Date: Tue, 28 May 2024 14:22:03 +0530 Subject: [PATCH 2/4] Undo initial commit --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 86e77ce8..df87e47a 100644 --- a/README.md +++ b/README.md @@ -564,4 +564,3 @@ Professional support, consulting as well as software development services are av https://www.cebe.cc/en/contact Development of this library is sponsored by [cebe.:cloud: "Your Professional Deployment Platform"](https://cebe.cloud). - From 51875cb57d7fc8905c5acf7af892759968f4ce05 Mon Sep 17 00:00:00 2001 From: Sohel Ahmed Mesaniya Date: Tue, 28 May 2024 14:34:20 +0530 Subject: [PATCH 3/4] Add docs for https://github.com/cebe/yii2-openapi/issues/173 --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index b04e500f..711b2a1c 100644 --- a/README.md +++ b/README.md @@ -182,6 +182,8 @@ Such values are not allowed: - `int null default null after low_price` (null and default will be handled by `nullable` and `default` keys respectively) - MEDIUMINT(10) UNSIGNED ZEROFILL NULL DEFAULT '7' COMMENT 'comment' AFTER `seti`, ADD INDEX `t` (`w`) +If `enum` and `x-db-type` both are provided then for database column schema (migrations), only `x-db-type` will be considered ignoring `enum`. + ### `x-indexes` Specify table indexes @@ -446,6 +448,8 @@ It works on all 3 DB: MySQL, MariaDb and PgSQL. Note: Changes in enum values are not very simple. For Mysql and Mariadb, migrations will be generated but in many cases custom modification in it are required. For Pgsql migrations for change in enum values will not be generated. It should be handled manually. +It will be ignored for database column schema (migrations) if `x-db-type` is provided. + ## Handling of `numeric` (#numeric, #MariaDb) precision-default = 10 From 949a32faaf719f1ac9e3fed0fc58905578a68cfa Mon Sep 17 00:00:00 2001 From: Sohel Ahmed Mesaniya Date: Tue, 28 May 2024 17:09:43 +0530 Subject: [PATCH 4/4] Fix https://github.com/cebe/yii2-openapi/issues/175 --- src/lib/openapi/ResponseSchema.php | 3 + .../index.php | 14 ++ .../index.yaml | 113 ++++++++++++++ .../pgsql/config/urls.rest.php | 10 ++ .../pgsql/controllers/AccountController.php | 20 +++ .../controllers/base/AccountController.php | 32 ++++ .../m200000_000000_create_table_accounts.php | 21 +++ .../m200000_000001_create_table_contacts.php | 24 +++ ...00_000002_create_table_payment_methods.php | 22 +++ .../pgsql/models/Account.php | 10 ++ .../pgsql/models/AccountFaker.php | 42 +++++ .../pgsql/models/BaseModelFaker.php | 144 ++++++++++++++++++ .../pgsql/models/Contact.php | 10 ++ .../pgsql/models/ContactFaker.php | 52 +++++++ .../pgsql/models/PaymentMethod.php | 10 ++ .../pgsql/models/PaymentMethodFaker.php | 40 +++++ .../pgsql/models/base/Account.php | 29 ++++ .../pgsql/models/base/Contact.php | 39 +++++ .../pgsql/models/base/PaymentMethod.php | 28 ++++ tests/unit/IssueFixTest.php | 15 ++ 20 files changed, 678 insertions(+) create mode 100644 tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/index.php create mode 100644 tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/index.yaml create mode 100644 tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/config/urls.rest.php create mode 100644 tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/controllers/AccountController.php create mode 100644 tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/controllers/base/AccountController.php create mode 100644 tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/migrations_pgsql_db/m200000_000000_create_table_accounts.php create mode 100644 tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/migrations_pgsql_db/m200000_000001_create_table_contacts.php create mode 100644 tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/migrations_pgsql_db/m200000_000002_create_table_payment_methods.php create mode 100644 tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/Account.php create mode 100644 tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/AccountFaker.php create mode 100644 tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/BaseModelFaker.php create mode 100644 tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/Contact.php create mode 100644 tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/ContactFaker.php create mode 100644 tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/PaymentMethod.php create mode 100644 tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/PaymentMethodFaker.php create mode 100644 tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/base/Account.php create mode 100644 tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/base/Contact.php create mode 100644 tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/base/PaymentMethod.php diff --git a/src/lib/openapi/ResponseSchema.php b/src/lib/openapi/ResponseSchema.php index f64bd8de..a0274449 100644 --- a/src/lib/openapi/ResponseSchema.php +++ b/src/lib/openapi/ResponseSchema.php @@ -49,6 +49,9 @@ protected static function schemaNameByRef($schemaOrReference): ?string // if($schemaOrReference instanceof Reference){ // $schemaOrReference->resolve(); // } + if (!$schemaOrReference instanceof Reference) { # https://github.com/cebe/yii2-openapi/issues/175 + return null; + } $ref = $schemaOrReference->getJsonReference()->getJsonPointer()->getPointer(); $name = strpos($ref, '/components/schemas/') === 0 ? substr($ref, 20) : null; return str_replace(JunctionSchemas::PREFIX, '', $name); diff --git a/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/index.php b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/index.php new file mode 100644 index 00000000..3ccbc836 --- /dev/null +++ b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/index.php @@ -0,0 +1,14 @@ + '@specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/index.yaml', + 'generateUrls' => true, + 'generateModels' => true, + 'excludeModels' => [ + 'Error', + ], + 'generateControllers' => true, + 'generateMigrations' => true, + 'generateModelFaker' => true, // `generateModels` must be `true` in orde to use `generateModelFaker` as `true` +]; + diff --git a/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/index.yaml b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/index.yaml new file mode 100644 index 00000000..429b59ad --- /dev/null +++ b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/index.yaml @@ -0,0 +1,113 @@ + +openapi: 3.0.3 + +info: + title: 'Proxy-Service' + version: 1.0.0 + +components: + + responses: + + AccountExpanded: + description: 'Returns one account by ID with additional information.' + content: + application/vnd.api+json: + schema: + type: object + required: + - status + - Account + properties: + status: + type: string + enum: + - valid + - invalid + Account: + allOf: + - $ref: '#/components/schemas/Account' + - type: object + properties: + invoiceContact: + $ref: "#/components/schemas/Contact" + paymentMethod: + $ref: "#/components/schemas/PaymentMethod" + errors: + type: object + description: only exists if status = invalid + + schemas: + + Account: + description: Account + type: object + required: + - id + - name + properties: + id: + type: integer + readOnly: true + name: + description: account name + type: string + maxLength: 128 + paymentMethodName: + type: string + + Contact: + description: Contact + type: object + required: + - id + - account + properties: + id: + type: integer + readOnly: true + account: + $ref: '#/components/schemas/Account' + active: + type: boolean + default: false + nickname: + type: string + + PaymentMethod: + type: object + description: PaymentMethod + x-indexes: + - 'unique:name' + required: + - id + - name + properties: + id: + type: integer + readOnly: true + name: + type: string + example: Bank transfer within 14 days + maxLength: 150 + x-faker: false + +paths: + + '/account/{id}': + parameters: + - name: Id + in: path + description: ID of Account + required: true + schema: + type: integer + + get: + operationId: getAccount + summary: Account information + responses: + '200': + $ref: '#/components/responses/AccountExpanded' + '404': + description: Account with id = "\" was not found. diff --git a/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/config/urls.rest.php b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/config/urls.rest.php new file mode 100644 index 00000000..d448d409 --- /dev/null +++ b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/config/urls.rest.php @@ -0,0 +1,10 @@ +' => 'account/view', + 'account/' => 'account/options', +]; diff --git a/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/controllers/AccountController.php b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/controllers/AccountController.php new file mode 100644 index 00000000..b4044b8f --- /dev/null +++ b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/controllers/AccountController.php @@ -0,0 +1,20 @@ + [ + 'class' => \yii\rest\OptionsAction::class, + ], + ]; + } + + /** + * Checks the privilege of the current user. + * + * This method checks whether the current user has the privilege + * to run the specified action against the specified data model. + * If the user does not have access, a [[ForbiddenHttpException]] should be thrown. + * + * @param string $action the ID of the action to be executed + * @param object $model the model to be accessed. If null, it means no specific model is being accessed. + * @param array $params additional parameters + * @throws \yii\web\ForbiddenHttpException if the user does not have access + */ + abstract public function checkAccess($action, $model = null, $params = []); + + abstract public function actionView($id); + +} diff --git a/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/migrations_pgsql_db/m200000_000000_create_table_accounts.php b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/migrations_pgsql_db/m200000_000000_create_table_accounts.php new file mode 100644 index 00000000..1606f2fc --- /dev/null +++ b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/migrations_pgsql_db/m200000_000000_create_table_accounts.php @@ -0,0 +1,21 @@ +createTable('{{%accounts}}', [ + 'id' => $this->primaryKey(), + 'name' => $this->string(128)->notNull(), + 'paymentMethodName' => $this->text()->null(), + ]); + } + + public function down() + { + $this->dropTable('{{%accounts}}'); + } +} diff --git a/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/migrations_pgsql_db/m200000_000001_create_table_contacts.php b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/migrations_pgsql_db/m200000_000001_create_table_contacts.php new file mode 100644 index 00000000..5fcda9dc --- /dev/null +++ b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/migrations_pgsql_db/m200000_000001_create_table_contacts.php @@ -0,0 +1,24 @@ +createTable('{{%contacts}}', [ + 'id' => $this->primaryKey(), + 'account_id' => $this->integer()->notNull(), + 'active' => $this->boolean()->null()->defaultValue(false), + 'nickname' => $this->text()->null(), + ]); + $this->addForeignKey('fk_contacts_account_id_accounts_id', '{{%contacts}}', 'account_id', '{{%accounts}}', 'id'); + } + + public function down() + { + $this->dropForeignKey('fk_contacts_account_id_accounts_id', '{{%contacts}}'); + $this->dropTable('{{%contacts}}'); + } +} diff --git a/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/migrations_pgsql_db/m200000_000002_create_table_payment_methods.php b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/migrations_pgsql_db/m200000_000002_create_table_payment_methods.php new file mode 100644 index 00000000..b6be74a0 --- /dev/null +++ b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/migrations_pgsql_db/m200000_000002_create_table_payment_methods.php @@ -0,0 +1,22 @@ +createTable('{{%payment_methods}}', [ + 'id' => $this->primaryKey(), + 'name' => $this->string(150)->notNull(), + ]); + $this->createIndex('payment_methods_name_key', '{{%payment_methods}}', 'name', true); + } + + public function down() + { + $this->dropIndex('payment_methods_name_key', '{{%payment_methods}}'); + $this->dropTable('{{%payment_methods}}'); + } +} diff --git a/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/Account.php b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/Account.php new file mode 100644 index 00000000..2d25d7fc --- /dev/null +++ b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/Account.php @@ -0,0 +1,10 @@ +generateModels(['author_id' => 1]); + * $model = (new PostFaker())->generateModels(function($model, $faker, $uniqueFaker) { + * $model->scenario = 'create'; + * $model->author_id = 1; + * return $model; + * }); + **/ + public function generateModel($attributes = []) + { + $faker = $this->faker; + $uniqueFaker = $this->uniqueFaker; + $model = new Account(); + //$model->id = $uniqueFaker->numberBetween(0, 1000000); + $model->name = substr($faker->text(128), 0, 128); + $model->paymentMethodName = $faker->sentence; + if (!is_callable($attributes)) { + $model->setAttributes($attributes, false); + } else { + $model = $attributes($model, $faker, $uniqueFaker); + } + return $model; + } +} diff --git a/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/BaseModelFaker.php b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/BaseModelFaker.php new file mode 100644 index 00000000..c367fbb4 --- /dev/null +++ b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/BaseModelFaker.php @@ -0,0 +1,144 @@ +faker = FakerFactory::create(str_replace('-', '_', \Yii::$app->language)); + $this->uniqueFaker = new UniqueGenerator($this->faker); + } + + abstract public function generateModel($attributes = []); + + public function getFaker():Generator + { + return $this->faker; + } + + public function getUniqueFaker():UniqueGenerator + { + return $this->uniqueFaker; + } + + public function setFaker(Generator $faker):void + { + $this->faker = $faker; + } + + public function setUniqueFaker(UniqueGenerator $faker):void + { + $this->uniqueFaker = $faker; + } + + /** + * Generate and return model + * @param array|callable $attributes + * @param UniqueGenerator|null $uniqueFaker + * @return \yii\db\ActiveRecord + * @example MyFaker::makeOne(['user_id' => 1, 'title' => 'foo']); + * @example MyFaker::makeOne( function($model, $faker) { + * $model->scenario = 'create'; + * $model->setAttributes(['user_id' => 1, 'title' => $faker->sentence]); + * return $model; + * }); + */ + public static function makeOne($attributes = [], ?UniqueGenerator $uniqueFaker = null) + { + $fakeBuilder = new static(); + if ($uniqueFaker !== null) { + $fakeBuilder->setUniqueFaker($uniqueFaker); + } + $model = $fakeBuilder->generateModel($attributes); + return $model; + } + + /** + * Generate, save and return model + * @param array|callable $attributes + * @param UniqueGenerator|null $uniqueFaker + * @return \yii\db\ActiveRecord + * @example MyFaker::saveOne(['user_id' => 1, 'title' => 'foo']); + * @example MyFaker::saveOne( function($model, $faker) { + * $model->scenario = 'create'; + * $model->setAttributes(['user_id' => 1, 'title' => $faker->sentence]); + * return $model; + * }); + */ + public static function saveOne($attributes = [], ?UniqueGenerator $uniqueFaker = null) + { + $model = static::makeOne($attributes, $uniqueFaker); + $model->save(); + return $model; + } + + /** + * Generate and return multiple models + * @param int $number + * @param array|callable $commonAttributes + * @return \yii\db\ActiveRecord[]|array + * @example TaskFaker::make(5, ['project_id'=>1, 'user_id' => 2]); + * @example TaskFaker::make(5, function($model, $faker, $uniqueFaker) { + * $model->setAttributes(['name' => $uniqueFaker->username, 'state'=>$faker->boolean(20)]); + * return $model; + * }); + */ + public static function make(int $number, $commonAttributes = [], ?UniqueGenerator $uniqueFaker = null):array + { + if ($number < 1) { + return []; + } + $fakeBuilder = new static(); + if ($uniqueFaker !== null) { + $fakeBuilder->setUniqueFaker($uniqueFaker); + } + return array_map(function () use ($commonAttributes, $fakeBuilder) { + $model = $fakeBuilder->generateModel($commonAttributes); + return $model; + }, range(0, $number -1)); + } + + /** + * Generate, save and return multiple models + * @param int $number + * @param array|callable $commonAttributes + * @return \yii\db\ActiveRecord[]|array + * @example TaskFaker::save(5, ['project_id'=>1, 'user_id' => 2]); + * @example TaskFaker::save(5, function($model, $faker, $uniqueFaker) { + * $model->setAttributes(['name' => $uniqueFaker->username, 'state'=>$faker->boolean(20)]); + * return $model; + * }); + */ + public static function save(int $number, $commonAttributes = [], ?UniqueGenerator $uniqueFaker = null):array + { + if ($number < 1) { + return []; + } + $fakeBuilder = new static(); + if ($uniqueFaker !== null) { + $fakeBuilder->setUniqueFaker($uniqueFaker); + } + return array_map(function () use ($commonAttributes, $fakeBuilder) { + $model = $fakeBuilder->generateModel($commonAttributes); + $model->save(); + return $model; + }, range(0, $number -1)); + } +} diff --git a/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/Contact.php b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/Contact.php new file mode 100644 index 00000000..8447fdaf --- /dev/null +++ b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/Contact.php @@ -0,0 +1,10 @@ +generateModels(['author_id' => 1]); + * $model = (new PostFaker())->generateModels(function($model, $faker, $uniqueFaker) { + * $model->scenario = 'create'; + * $model->author_id = 1; + * return $model; + * }); + **/ + public function generateModel($attributes = []) + { + $faker = $this->faker; + $uniqueFaker = $this->uniqueFaker; + $model = new Contact(); + //$model->id = $uniqueFaker->numberBetween(0, 1000000); + $model->account_id = $faker->randomElement(\app\models\Account::find()->select("id")->column()); + $model->active = $faker->boolean; + $model->nickname = $faker->sentence; + if (!is_callable($attributes)) { + $model->setAttributes($attributes, false); + } else { + $model = $attributes($model, $faker, $uniqueFaker); + } + return $model; + } + + public static function dependentOn() + { + return [ + // just model class names + 'Account', + + ]; + } +} diff --git a/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/PaymentMethod.php b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/PaymentMethod.php new file mode 100644 index 00000000..dec326f2 --- /dev/null +++ b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/PaymentMethod.php @@ -0,0 +1,10 @@ +generateModels(['author_id' => 1]); + * $model = (new PostFaker())->generateModels(function($model, $faker, $uniqueFaker) { + * $model->scenario = 'create'; + * $model->author_id = 1; + * return $model; + * }); + **/ + public function generateModel($attributes = []) + { + $faker = $this->faker; + $uniqueFaker = $this->uniqueFaker; + $model = new PaymentMethod(); + //$model->id = $uniqueFaker->numberBetween(0, 1000000); + if (!is_callable($attributes)) { + $model->setAttributes($attributes, false); + } else { + $model = $attributes($model, $faker, $uniqueFaker); + } + return $model; + } +} diff --git a/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/base/Account.php b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/base/Account.php new file mode 100644 index 00000000..f3dae5db --- /dev/null +++ b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/base/Account.php @@ -0,0 +1,29 @@ + [['name', 'paymentMethodName'], 'trim'], + 'required' => [['name'], 'required'], + 'name_string' => [['name'], 'string', 'max' => 128], + 'paymentMethodName_string' => [['paymentMethodName'], 'string'], + ]; + } +} diff --git a/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/base/Contact.php b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/base/Contact.php new file mode 100644 index 00000000..21a2e7f1 --- /dev/null +++ b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/base/Contact.php @@ -0,0 +1,39 @@ + [['nickname'], 'trim'], + 'required' => [['account_id'], 'required'], + 'account_id_integer' => [['account_id'], 'integer'], + 'account_id_exist' => [['account_id'], 'exist', 'targetRelation' => 'Account'], + 'active_boolean' => [['active'], 'boolean'], + 'active_default' => [['active'], 'default', 'value' => false], + 'nickname_string' => [['nickname'], 'string'], + ]; + } + + public function getAccount() + { + return $this->hasOne(\app\models\Account::class, ['id' => 'account_id']); + } +} diff --git a/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/base/PaymentMethod.php b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/base/PaymentMethod.php new file mode 100644 index 00000000..79e8c05b --- /dev/null +++ b/tests/specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql/models/base/PaymentMethod.php @@ -0,0 +1,28 @@ + [['name'], 'trim'], + 'required' => [['name'], 'required'], + 'name_unique' => [['name'], 'unique'], + 'name_string' => [['name'], 'string', 'max' => 150], + ]; + } +} diff --git a/tests/unit/IssueFixTest.php b/tests/unit/IssueFixTest.php index c38a57ff..04a31c2d 100644 --- a/tests/unit/IssueFixTest.php +++ b/tests/unit/IssueFixTest.php @@ -300,4 +300,19 @@ public function test163GeneratorCrashWhenUsingReferenceInsideAnObject() ]); $this->checkFiles($actualFiles, $expectedFiles); } + + // #175 https://github.com/cebe/yii2-openapi/issues/175 + // Bug: allOf with multiple $refs + public function test175BugAllOfWithMultipleDollarRefs() + { + $testFile = Yii::getAlias("@specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/index.php"); + $this->runGenerator($testFile, 'pgsql'); + $actualFiles = FileHelper::findFiles(Yii::getAlias('@app'), [ + 'recursive' => true, + ]); + $expectedFiles = FileHelper::findFiles(Yii::getAlias("@specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/pgsql"), [ + 'recursive' => true, + ]); + $this->checkFiles($actualFiles, $expectedFiles); + } }