From 77fbce1556b10bdd0485f898fadaac1e1c15dedd Mon Sep 17 00:00:00 2001 From: Gary PEGEOT Date: Thu, 3 Dec 2020 10:42:11 +0000 Subject: [PATCH 1/5] Make "hydra:mapping" item's property nullable --- src/Hydra/JsonSchema/SchemaFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Hydra/JsonSchema/SchemaFactory.php b/src/Hydra/JsonSchema/SchemaFactory.php index 41e68fdd348..a0f36401dd9 100644 --- a/src/Hydra/JsonSchema/SchemaFactory.php +++ b/src/Hydra/JsonSchema/SchemaFactory.php @@ -121,7 +121,7 @@ public function buildSchema(string $className, string $format = 'jsonld', string 'properties' => [ '@type' => ['type' => 'string'], 'variable' => ['type' => 'string'], - 'property' => ['type' => 'string'], + 'property' => ['type' => 'string', 'nullable' => true], 'required' => ['type' => 'boolean'], ], ], From f968cbd2d66e9d8dfc7e77306ca8aae3920ac513 Mon Sep 17 00:00:00 2001 From: Gary PEGEOT Date: Thu, 3 Dec 2020 12:43:59 +0000 Subject: [PATCH 2/5] Switch to anyOf to support null --- src/Hydra/JsonSchema/SchemaFactory.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Hydra/JsonSchema/SchemaFactory.php b/src/Hydra/JsonSchema/SchemaFactory.php index a0f36401dd9..d5a5feb079e 100644 --- a/src/Hydra/JsonSchema/SchemaFactory.php +++ b/src/Hydra/JsonSchema/SchemaFactory.php @@ -121,7 +121,10 @@ public function buildSchema(string $className, string $format = 'jsonld', string 'properties' => [ '@type' => ['type' => 'string'], 'variable' => ['type' => 'string'], - 'property' => ['type' => 'string', 'nullable' => true], + 'property' => [ + 'nullable' => true, + 'anyOf' => [['type' => 'string'], ['type' => 'null']], + ], 'required' => ['type' => 'boolean'], ], ], From 7705980dc040ea34058a60cb6ed917581b2f7bec Mon Sep 17 00:00:00 2001 From: Gary PEGEOT Date: Thu, 3 Dec 2020 13:00:12 +0000 Subject: [PATCH 3/5] Remove anyOf --- src/Hydra/JsonSchema/SchemaFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Hydra/JsonSchema/SchemaFactory.php b/src/Hydra/JsonSchema/SchemaFactory.php index d5a5feb079e..f1df478c407 100644 --- a/src/Hydra/JsonSchema/SchemaFactory.php +++ b/src/Hydra/JsonSchema/SchemaFactory.php @@ -123,7 +123,7 @@ public function buildSchema(string $className, string $format = 'jsonld', string 'variable' => ['type' => 'string'], 'property' => [ 'nullable' => true, - 'anyOf' => [['type' => 'string'], ['type' => 'null']], + 'type' => ['string', 'null'], ], 'required' => ['type' => 'boolean'], ], From a1b21b18ddf3175378b5ff5e824c0ca622baf245 Mon Sep 17 00:00:00 2001 From: Gary PEGEOT Date: Thu, 3 Dec 2020 18:13:18 +0100 Subject: [PATCH 4/5] Fix type definition --- src/Hydra/JsonSchema/SchemaFactory.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Hydra/JsonSchema/SchemaFactory.php b/src/Hydra/JsonSchema/SchemaFactory.php index f1df478c407..83273f1fc87 100644 --- a/src/Hydra/JsonSchema/SchemaFactory.php +++ b/src/Hydra/JsonSchema/SchemaFactory.php @@ -74,6 +74,17 @@ public function buildSchema(string $className, string $format = 'jsonld', string $items = $schema['items']; unset($schema['items']); + switch ($schema->getVersion()) { + case Schema::VERSION_JSON_SCHEMA: + $mappingPropDefinition = ['type' => ['string', 'null']]; + break; + case Schema::VERSION_OPENAPI: + $mappingPropDefinition = ['type' => 'string', 'nullable' => true]; + break; + default: + $mappingPropDefinition = ['type' => 'string']; + } + $schema['type'] = 'object'; $schema['properties'] = [ 'hydra:member' => [ @@ -121,10 +132,7 @@ public function buildSchema(string $className, string $format = 'jsonld', string 'properties' => [ '@type' => ['type' => 'string'], 'variable' => ['type' => 'string'], - 'property' => [ - 'nullable' => true, - 'type' => ['string', 'null'], - ], + 'property' => $mappingPropDefinition, 'required' => ['type' => 'boolean'], ], ], From c08fd5572437c9e7e48f93928e5c8961eabead14 Mon Sep 17 00:00:00 2001 From: Gary PEGEOT Date: Thu, 3 Dec 2020 18:30:15 +0100 Subject: [PATCH 5/5] Rename variable --- src/Hydra/JsonSchema/SchemaFactory.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Hydra/JsonSchema/SchemaFactory.php b/src/Hydra/JsonSchema/SchemaFactory.php index 83273f1fc87..c3f82538df2 100644 --- a/src/Hydra/JsonSchema/SchemaFactory.php +++ b/src/Hydra/JsonSchema/SchemaFactory.php @@ -74,15 +74,15 @@ public function buildSchema(string $className, string $format = 'jsonld', string $items = $schema['items']; unset($schema['items']); + $nullableStringDefinition = ['type' => 'string']; + switch ($schema->getVersion()) { case Schema::VERSION_JSON_SCHEMA: - $mappingPropDefinition = ['type' => ['string', 'null']]; + $nullableStringDefinition = ['type' => ['string', 'null']]; break; case Schema::VERSION_OPENAPI: - $mappingPropDefinition = ['type' => 'string', 'nullable' => true]; + $nullableStringDefinition = ['type' => 'string', 'nullable' => true]; break; - default: - $mappingPropDefinition = ['type' => 'string']; } $schema['type'] = 'object'; @@ -132,7 +132,7 @@ public function buildSchema(string $className, string $format = 'jsonld', string 'properties' => [ '@type' => ['type' => 'string'], 'variable' => ['type' => 'string'], - 'property' => $mappingPropDefinition, + 'property' => $nullableStringDefinition, 'required' => ['type' => 'boolean'], ], ],