diff --git a/src/Parser/TypeSchema/BCLayer.php b/src/Parser/TypeSchema/BCLayer.php index f176c542..512eea03 100644 --- a/src/Parser/TypeSchema/BCLayer.php +++ b/src/Parser/TypeSchema/BCLayer.php @@ -52,6 +52,10 @@ public static function transformDefinition(\stdClass $data): \stdClass $data->type = 'struct'; } + if (isset($data->{'x-psx-mapping'}) && $data->{'x-psx-mapping'} instanceof \stdClass) { + $data->{'x-psx-mapping'} = (array) $data->{'x-psx-mapping'}; + } + if (!isset($data->type)) { if (isset($data->additionalProperties) || isset($data->schema)) { $data->type = 'map'; diff --git a/tests/Parser/TypeSchema/test_schema.json b/tests/Parser/TypeSchema/test_schema.json index 7b6ec964..b603b821 100644 --- a/tests/Parser/TypeSchema/test_schema.json +++ b/tests/Parser/TypeSchema/test_schema.json @@ -30,7 +30,8 @@ "type": "reference", "target": "Location" } - } + }, + "x-psx-class": "PSX\\Schema\\Tests\\Parser\\Popo\\Author" }, "Location": { "description": "Location of the person", @@ -42,13 +43,15 @@ "long": { "type": "number" } - } + }, + "x-psx-class": "PSX\\Schema\\Tests\\Parser\\Popo\\Location" }, "Meta": { "type": "object", "additionalProperties": { "type": "string" - } + }, + "x-psx-class": "PSX\\Schema\\Tests\\Parser\\Popo\\Meta" }, "News": { "description": "An general news entry", @@ -133,6 +136,10 @@ "payload": { "type": "any" } + }, + "x-psx-class": "PSX\\Schema\\Tests\\Parser\\Popo\\News", + "x-psx-mapping": { + "g-recaptcha-response": "captcha" } } }, diff --git a/tests/Parser/TypeSchemaTest.php b/tests/Parser/TypeSchemaTest.php index 74dc3fd8..b316f00c 100644 --- a/tests/Parser/TypeSchemaTest.php +++ b/tests/Parser/TypeSchemaTest.php @@ -47,6 +47,7 @@ public function testParse() $schema = $parser->parse(__DIR__ . '/TypeSchema/test_schema.json'); $this->assertSchema($this->getSchema(), $schema); + $this->assertSchemaAttributes($this->getSchema(), $schema); } public function testParseTypeSchema() diff --git a/tests/SchemaTestCase.php b/tests/SchemaTestCase.php index 1313e9a6..e9754a60 100644 --- a/tests/SchemaTestCase.php +++ b/tests/SchemaTestCase.php @@ -22,6 +22,7 @@ use PHPUnit\Framework\TestCase; use PSX\Schema\Generator\TypeSchema; +use PSX\Schema\SchemaInterface; use PSX\Schema\SchemaManager; /** @@ -40,12 +41,12 @@ protected function setUp(): void $this->schemaManager = new SchemaManager(); } - protected function getSchema() + protected function getSchema(): SchemaInterface { return $this->schemaManager->getSchema(TestSchema::class); } - protected function assertSchema($leftSchema, $rightSchema) + protected function assertSchema(SchemaInterface $leftSchema, SchemaInterface $rightSchema): void { $generator = new TypeSchema(); @@ -54,4 +55,12 @@ protected function assertSchema($leftSchema, $rightSchema) $this->assertJsonStringEqualsJsonString($expect, $actual); } + + protected function assertSchemaAttributes(SchemaInterface $leftSchema, SchemaInterface $rightSchema): void + { + foreach ($leftSchema->getDefinitions()->getTypes() as $typeName => $leftType) { + $rightType = $rightSchema->getDefinitions()->getType($typeName); + $this->assertSame($leftType->getAttributes(), $rightType->getAttributes()); + } + } }