Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/lib/openapi/PropertySchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,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
Expand Down Expand Up @@ -310,7 +312,7 @@ public function getRefSchemaName():string
$pattern = strpos($this->refPointer, '/properties/') !== false ?
'~^'.self::REFERENCE_PATH.'(?<schemaName>.+)/properties/(?<propName>.+)$~'
: '~^'.self::REFERENCE_PATH.'(?<schemaName>.+)$~';
$separateFilePattern = '/((\.\/)*)(?<schemaName>.+)(\.)(yml|yaml)(.*)/'; # https://github.com/php-openapi/yii2-openapi/issues/74
$separateFilePattern = '/((\.\/)*)(?<schemaName>.+)(\.)(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');
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

return [
'openApiPath' => '@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,
];
15 changes: 15 additions & 0 deletions tests/unit/IssueFixTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1029,4 +1029,19 @@ public function test23ConsiderOpenapiExtensionXNoRelationAlsoInOtherPertinentPla
$this->checkFiles($actualFiles, $expectedFiles);
$this->runActualMigrations();
}

// 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"), [ # this is intentional
'recursive' => true,
]);
$this->checkFiles($actualFiles, $expectedFiles);
$this->runActualMigrations();
}
}