Skip to content

Commit ccbb320

Browse files
committed
Fix
1 parent 7bc40e2 commit ccbb320

File tree

5 files changed

+94
-3
lines changed

5 files changed

+94
-3
lines changed

src/lib/openapi/PropertySchema.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,10 @@ public function getSelfTargetProperty():?PropertySchema
268268
public function isRefPointerToSchema():bool
269269
{
270270
return $this->refPointer &&
271-
((strpos($this->refPointer, self::REFERENCE_PATH) === 0) ||
272-
(str_ends_with($this->uri, '.yml')) || (str_ends_with($this->uri, '.yaml')));
271+
(
272+
(strpos($this->refPointer, self::REFERENCE_PATH) === 0) ||
273+
(str_ends_with($this->uri, '.yml')) || (str_ends_with($this->uri, '.yaml')) || (str_ends_with($this->uri, '.json'))
274+
);
273275
}
274276

275277
public function isRefPointerToSelf():bool
@@ -305,7 +307,7 @@ public function getRefSchemaName():string
305307
$pattern = strpos($this->refPointer, '/properties/') !== false ?
306308
'~^'.self::REFERENCE_PATH.'(?<schemaName>.+)/properties/(?<propName>.+)$~'
307309
: '~^'.self::REFERENCE_PATH.'(?<schemaName>.+)$~';
308-
$separateFilePattern = '/((\.\/)*)(?<schemaName>.+)(\.)(yml|yaml)(.*)/'; # https://github.com/php-openapi/yii2-openapi/issues/74
310+
$separateFilePattern = '/((\.\/)*)(?<schemaName>.+)(\.)(yml|yaml|json)(.*)/'; # https://github.com/php-openapi/yii2-openapi/issues/74
309311
if (!\preg_match($pattern, $this->refPointer, $matches)) {
310312
if (!\preg_match($separateFilePattern, $this->uri, $separateFilePatternMatches)) {
311313
throw new InvalidDefinitionException('Invalid schema reference');
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"title": "Product",
3+
"x-table": "products",
4+
"type": "object",
5+
"required": [
6+
"id",
7+
"vat_rate"
8+
],
9+
"properties": {
10+
"id": {
11+
"type": "integer"
12+
},
13+
"vat_rate": {
14+
"type": "string",
15+
"enum": [
16+
"standard",
17+
"none"
18+
],
19+
"default": "standard"
20+
}
21+
}
22+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"openapi": "3.0.0",
3+
"info": {
4+
"version": "1.0.0",
5+
"title": "\\#87"
6+
},
7+
"paths": {
8+
"/": {
9+
"get": {
10+
"responses": {
11+
"200": {
12+
"description": "The information"
13+
}
14+
}
15+
}
16+
}
17+
},
18+
"components": {
19+
"schemas": {
20+
"Invoice": {
21+
"type": "object",
22+
"required": [
23+
"vat_rate"
24+
],
25+
"properties": {
26+
"id": {
27+
"type": "integer"
28+
},
29+
"vat_rate": {
30+
"$ref": "./Product.json#/properties/vat_rate"
31+
}
32+
}
33+
},
34+
"Product": {
35+
"$ref": "./Product.json"
36+
}
37+
}
38+
}
39+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
return [
4+
'openApiPath' => '@specs/issue_fix/87_implement_for_json_in_is_ref_pointer_to_schema/index.json',
5+
'generateUrls' => false,
6+
'generateModels' => true,
7+
'excludeModels' => [
8+
'Error',
9+
],
10+
'generateControllers' => false,
11+
'generateMigrations' => true,
12+
'generateModelFaker' => true,
13+
];

tests/unit/IssueFixTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,4 +1014,19 @@ public function test22BugRulesRequiredIsGeneratedBeforeDefault()
10141014
]);
10151015
$this->checkFiles($actualFiles, $expectedFiles);
10161016
}
1017+
1018+
// https://github.com/php-openapi/yii2-openapi/issues/87
1019+
public function test87ImplementForJsonInIsrefpointertoschema()
1020+
{
1021+
$testFile = Yii::getAlias("@specs/issue_fix/87_implement_for_json_in_is_ref_pointer_to_schema/index.php");
1022+
$this->runGenerator($testFile);
1023+
$actualFiles = FileHelper::findFiles(Yii::getAlias('@app'), [
1024+
'recursive' => true,
1025+
]);
1026+
$expectedFiles = FileHelper::findFiles(Yii::getAlias("@specs/issue_fix/74_invalid_schema_reference_error/mysql"), [
1027+
'recursive' => true,
1028+
]);
1029+
$this->checkFiles($actualFiles, $expectedFiles);
1030+
$this->runActualMigrations();
1031+
}
10171032
}

0 commit comments

Comments
 (0)