From 779c7cd398297489e22450e8d1367ecf5a513922 Mon Sep 17 00:00:00 2001 From: Sohel Ahmed Mesaniya Date: Mon, 3 Mar 2025 15:59:16 +0530 Subject: [PATCH 1/4] Create PR --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f68df469..4cc1d72a 100644 --- a/README.md +++ b/README.md @@ -779,3 +779,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 7bc40e2e26033e40691bdb7e31d0eb226856a517 Mon Sep 17 00:00:00 2001 From: Sohel Ahmed Mesaniya Date: Mon, 3 Mar 2025 16:01:35 +0530 Subject: [PATCH 2/4] Undo --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 4cc1d72a..f68df469 100644 --- a/README.md +++ b/README.md @@ -779,4 +779,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 ccbb320e0b4422136288f49270ad08be5ec3c6de Mon Sep 17 00:00:00 2001 From: Sohel Ahmed Mesaniya Date: Mon, 3 Mar 2025 17:49:48 +0530 Subject: [PATCH 3/4] Fix --- src/lib/openapi/PropertySchema.php | 8 ++-- .../Product.json | 22 +++++++++++ .../index.json | 39 +++++++++++++++++++ .../index.php | 13 +++++++ tests/unit/IssueFixTest.php | 15 +++++++ 5 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 tests/specs/issue_fix/87_implement_for_json_in_is_ref_pointer_to_schema/Product.json create mode 100644 tests/specs/issue_fix/87_implement_for_json_in_is_ref_pointer_to_schema/index.json create mode 100644 tests/specs/issue_fix/87_implement_for_json_in_is_ref_pointer_to_schema/index.php diff --git a/src/lib/openapi/PropertySchema.php b/src/lib/openapi/PropertySchema.php index eade252e..e75f368b 100644 --- a/src/lib/openapi/PropertySchema.php +++ b/src/lib/openapi/PropertySchema.php @@ -268,8 +268,10 @@ public function getSelfTargetProperty():?PropertySchema public function isRefPointerToSchema():bool { return $this->refPointer && - ((strpos($this->refPointer, self::REFERENCE_PATH) === 0) || - (str_ends_with($this->uri, '.yml')) || (str_ends_with($this->uri, '.yaml'))); + ( + (strpos($this->refPointer, self::REFERENCE_PATH) === 0) || + (str_ends_with($this->uri, '.yml')) || (str_ends_with($this->uri, '.yaml')) || (str_ends_with($this->uri, '.json')) + ); } public function isRefPointerToSelf():bool @@ -305,7 +307,7 @@ public function getRefSchemaName():string $pattern = strpos($this->refPointer, '/properties/') !== false ? '~^'.self::REFERENCE_PATH.'(?.+)/properties/(?.+)$~' : '~^'.self::REFERENCE_PATH.'(?.+)$~'; - $separateFilePattern = '/((\.\/)*)(?.+)(\.)(yml|yaml)(.*)/'; # https://github.com/php-openapi/yii2-openapi/issues/74 + $separateFilePattern = '/((\.\/)*)(?.+)(\.)(yml|yaml|json)(.*)/'; # https://github.com/php-openapi/yii2-openapi/issues/74 if (!\preg_match($pattern, $this->refPointer, $matches)) { if (!\preg_match($separateFilePattern, $this->uri, $separateFilePatternMatches)) { throw new InvalidDefinitionException('Invalid schema reference'); diff --git a/tests/specs/issue_fix/87_implement_for_json_in_is_ref_pointer_to_schema/Product.json b/tests/specs/issue_fix/87_implement_for_json_in_is_ref_pointer_to_schema/Product.json new file mode 100644 index 00000000..91514ab4 --- /dev/null +++ b/tests/specs/issue_fix/87_implement_for_json_in_is_ref_pointer_to_schema/Product.json @@ -0,0 +1,22 @@ +{ + "title": "Product", + "x-table": "products", + "type": "object", + "required": [ + "id", + "vat_rate" + ], + "properties": { + "id": { + "type": "integer" + }, + "vat_rate": { + "type": "string", + "enum": [ + "standard", + "none" + ], + "default": "standard" + } + } +} \ No newline at end of file diff --git a/tests/specs/issue_fix/87_implement_for_json_in_is_ref_pointer_to_schema/index.json b/tests/specs/issue_fix/87_implement_for_json_in_is_ref_pointer_to_schema/index.json new file mode 100644 index 00000000..a879d24c --- /dev/null +++ b/tests/specs/issue_fix/87_implement_for_json_in_is_ref_pointer_to_schema/index.json @@ -0,0 +1,39 @@ +{ + "openapi": "3.0.0", + "info": { + "version": "1.0.0", + "title": "\\#87" + }, + "paths": { + "/": { + "get": { + "responses": { + "200": { + "description": "The information" + } + } + } + } + }, + "components": { + "schemas": { + "Invoice": { + "type": "object", + "required": [ + "vat_rate" + ], + "properties": { + "id": { + "type": "integer" + }, + "vat_rate": { + "$ref": "./Product.json#/properties/vat_rate" + } + } + }, + "Product": { + "$ref": "./Product.json" + } + } + } +} \ No newline at end of file diff --git a/tests/specs/issue_fix/87_implement_for_json_in_is_ref_pointer_to_schema/index.php b/tests/specs/issue_fix/87_implement_for_json_in_is_ref_pointer_to_schema/index.php new file mode 100644 index 00000000..0fd4dc27 --- /dev/null +++ b/tests/specs/issue_fix/87_implement_for_json_in_is_ref_pointer_to_schema/index.php @@ -0,0 +1,13 @@ + '@specs/issue_fix/87_implement_for_json_in_is_ref_pointer_to_schema/index.json', + 'generateUrls' => false, + 'generateModels' => true, + 'excludeModels' => [ + 'Error', + ], + 'generateControllers' => false, + 'generateMigrations' => true, + 'generateModelFaker' => true, +]; diff --git a/tests/unit/IssueFixTest.php b/tests/unit/IssueFixTest.php index ad3ff8fd..8f015934 100644 --- a/tests/unit/IssueFixTest.php +++ b/tests/unit/IssueFixTest.php @@ -1014,4 +1014,19 @@ public function test22BugRulesRequiredIsGeneratedBeforeDefault() ]); $this->checkFiles($actualFiles, $expectedFiles); } + + // https://github.com/php-openapi/yii2-openapi/issues/87 + public function test87ImplementForJsonInIsrefpointertoschema() + { + $testFile = Yii::getAlias("@specs/issue_fix/87_implement_for_json_in_is_ref_pointer_to_schema/index.php"); + $this->runGenerator($testFile); + $actualFiles = FileHelper::findFiles(Yii::getAlias('@app'), [ + 'recursive' => true, + ]); + $expectedFiles = FileHelper::findFiles(Yii::getAlias("@specs/issue_fix/74_invalid_schema_reference_error/mysql"), [ + 'recursive' => true, + ]); + $this->checkFiles($actualFiles, $expectedFiles); + $this->runActualMigrations(); + } } From d88bdd3a78dff231a204ff999081857fe8d708d2 Mon Sep 17 00:00:00 2001 From: Sohel Ahmed Mesaniya Date: Mon, 3 Mar 2025 17:52:55 +0530 Subject: [PATCH 4/4] Add comment --- tests/unit/IssueFixTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/IssueFixTest.php b/tests/unit/IssueFixTest.php index 8f015934..87b5962e 100644 --- a/tests/unit/IssueFixTest.php +++ b/tests/unit/IssueFixTest.php @@ -1023,7 +1023,7 @@ public function test87ImplementForJsonInIsrefpointertoschema() $actualFiles = FileHelper::findFiles(Yii::getAlias('@app'), [ 'recursive' => true, ]); - $expectedFiles = FileHelper::findFiles(Yii::getAlias("@specs/issue_fix/74_invalid_schema_reference_error/mysql"), [ + $expectedFiles = FileHelper::findFiles(Yii::getAlias("@specs/issue_fix/74_invalid_schema_reference_error/mysql"), [ # this is intentional 'recursive' => true, ]); $this->checkFiles($actualFiles, $expectedFiles);