Skip to content

Commit

Permalink
Merge pull request #1 from enobrev/fix-patternProperties_as_properties
Browse files Browse the repository at this point in the history
Converts schema of patternProperties using the convertProperties method
  • Loading branch information
BenMorel committed Dec 10, 2020
2 parents c38bad1 + 9eef1e7 commit d94d7f2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Converter/SchemaConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ private static function convertSchema(object $schema, Options $options) : object

if (isset($schema->{'x-patternProperties'}) && is_object($schema->{'x-patternProperties'}) && $options->supportPatternProperties) {
$schema = self::convertPatternProperties($schema, $options->patternPropertiesHandler);

if (isset($schema->patternProperties) && is_object($schema->patternProperties)) {
$schema->patternProperties = self::convertProperties($schema->patternProperties, $options);
}
}

foreach ($notSupported as $prop) {
Expand Down
35 changes: 35 additions & 0 deletions tests/PatternPropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -522,4 +522,39 @@ public function testAdditionalPropertiesNotModifiedIfSetToTrue() : void

self::assertEquals($expected, $result);
}

public function testHandlingPatternPropertiesWithNullableTypes() : void
{
$schema = json_decode(<<<'JSON'
{
"type": "object",
"x-patternProperties": {
"^[a-z]*$": {
"type": "string",
"nullable": true
}
}
}
JSON
);

$expected = json_decode(<<<'JSON'
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"patternProperties": {
"^[a-z]*$": {
"type": ["string", "null"]
}
}
}
JSON
);

$result = Convert::openapiSchemaToJsonSchema($schema, [
'supportPatternProperties' => true
]);

self::assertEquals($expected, $result);
}
}

0 comments on commit d94d7f2

Please sign in to comment.