Skip to content

Commit

Permalink
fix class
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Jan 29, 2025
1 parent 7db6607 commit 5df895a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/Parser/TypeSchema/BCLayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
13 changes: 10 additions & 3 deletions tests/Parser/TypeSchema/test_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"type": "reference",
"target": "Location"
}
}
},
"x-psx-class": "PSX\\Schema\\Tests\\Parser\\Popo\\Author"
},
"Location": {
"description": "Location of the person",
Expand All @@ -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",
Expand Down Expand Up @@ -133,6 +136,10 @@
"payload": {
"type": "any"
}
},
"x-psx-class": "PSX\\Schema\\Tests\\Parser\\Popo\\News",
"x-psx-mapping": {
"g-recaptcha-response": "captcha"
}
}
},
Expand Down
1 change: 1 addition & 0 deletions tests/Parser/TypeSchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
13 changes: 11 additions & 2 deletions tests/SchemaTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

use PHPUnit\Framework\TestCase;
use PSX\Schema\Generator\TypeSchema;
use PSX\Schema\SchemaInterface;
use PSX\Schema\SchemaManager;

/**
Expand All @@ -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();

Expand All @@ -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());
}
}
}

0 comments on commit 5df895a

Please sign in to comment.