From 3a166277ad09fcdb1cc1618384c99d32a4aaf136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Thu, 15 Feb 2018 08:00:23 +0100 Subject: [PATCH 1/2] Enhancement: Assert that referenced schema in oneOf is resolved --- .../HasOneOf/{ => Direct}/normalized.json | 0 .../HasOneOf/{ => Direct}/original.json | 0 .../Schema/HasOneOf/{ => Direct}/schema.json | 0 .../HasOneOf/HasReference/normalized.json | 11 +++++++ .../HasOneOf/HasReference/original.json | 11 +++++++ .../Schema/HasOneOf/HasReference/schema.json | 30 +++++++++++++++++++ 6 files changed, 52 insertions(+) rename test/Fixture/SchemaNormalizer/NormalizeNormalizes/Data/IsArray/Schema/HasOneOf/{ => Direct}/normalized.json (100%) rename test/Fixture/SchemaNormalizer/NormalizeNormalizes/Data/IsArray/Schema/HasOneOf/{ => Direct}/original.json (100%) rename test/Fixture/SchemaNormalizer/NormalizeNormalizes/Data/IsArray/Schema/HasOneOf/{ => Direct}/schema.json (100%) create mode 100644 test/Fixture/SchemaNormalizer/NormalizeNormalizes/Data/IsArray/Schema/HasOneOf/HasReference/normalized.json create mode 100644 test/Fixture/SchemaNormalizer/NormalizeNormalizes/Data/IsArray/Schema/HasOneOf/HasReference/original.json create mode 100644 test/Fixture/SchemaNormalizer/NormalizeNormalizes/Data/IsArray/Schema/HasOneOf/HasReference/schema.json diff --git a/test/Fixture/SchemaNormalizer/NormalizeNormalizes/Data/IsArray/Schema/HasOneOf/normalized.json b/test/Fixture/SchemaNormalizer/NormalizeNormalizes/Data/IsArray/Schema/HasOneOf/Direct/normalized.json similarity index 100% rename from test/Fixture/SchemaNormalizer/NormalizeNormalizes/Data/IsArray/Schema/HasOneOf/normalized.json rename to test/Fixture/SchemaNormalizer/NormalizeNormalizes/Data/IsArray/Schema/HasOneOf/Direct/normalized.json diff --git a/test/Fixture/SchemaNormalizer/NormalizeNormalizes/Data/IsArray/Schema/HasOneOf/original.json b/test/Fixture/SchemaNormalizer/NormalizeNormalizes/Data/IsArray/Schema/HasOneOf/Direct/original.json similarity index 100% rename from test/Fixture/SchemaNormalizer/NormalizeNormalizes/Data/IsArray/Schema/HasOneOf/original.json rename to test/Fixture/SchemaNormalizer/NormalizeNormalizes/Data/IsArray/Schema/HasOneOf/Direct/original.json diff --git a/test/Fixture/SchemaNormalizer/NormalizeNormalizes/Data/IsArray/Schema/HasOneOf/schema.json b/test/Fixture/SchemaNormalizer/NormalizeNormalizes/Data/IsArray/Schema/HasOneOf/Direct/schema.json similarity index 100% rename from test/Fixture/SchemaNormalizer/NormalizeNormalizes/Data/IsArray/Schema/HasOneOf/schema.json rename to test/Fixture/SchemaNormalizer/NormalizeNormalizes/Data/IsArray/Schema/HasOneOf/Direct/schema.json diff --git a/test/Fixture/SchemaNormalizer/NormalizeNormalizes/Data/IsArray/Schema/HasOneOf/HasReference/normalized.json b/test/Fixture/SchemaNormalizer/NormalizeNormalizes/Data/IsArray/Schema/HasOneOf/HasReference/normalized.json new file mode 100644 index 00000000..6b71f6b8 --- /dev/null +++ b/test/Fixture/SchemaNormalizer/NormalizeNormalizes/Data/IsArray/Schema/HasOneOf/HasReference/normalized.json @@ -0,0 +1,11 @@ +[ + { + "type": "Website", + "url": "https://localheinz.com" + }, + "https://github.com/localheinz", + { + "type": "Twitter", + "url": "https://twitter.com/localheinz" + } +] diff --git a/test/Fixture/SchemaNormalizer/NormalizeNormalizes/Data/IsArray/Schema/HasOneOf/HasReference/original.json b/test/Fixture/SchemaNormalizer/NormalizeNormalizes/Data/IsArray/Schema/HasOneOf/HasReference/original.json new file mode 100644 index 00000000..42fbbb2f --- /dev/null +++ b/test/Fixture/SchemaNormalizer/NormalizeNormalizes/Data/IsArray/Schema/HasOneOf/HasReference/original.json @@ -0,0 +1,11 @@ +[ + { + "url": "https://localheinz.com", + "type": "Website" + }, + "https://github.com/localheinz", + { + "url": "https://twitter.com/localheinz", + "type": "Twitter" + } +] diff --git a/test/Fixture/SchemaNormalizer/NormalizeNormalizes/Data/IsArray/Schema/HasOneOf/HasReference/schema.json b/test/Fixture/SchemaNormalizer/NormalizeNormalizes/Data/IsArray/Schema/HasOneOf/HasReference/schema.json new file mode 100644 index 00000000..1184076e --- /dev/null +++ b/test/Fixture/SchemaNormalizer/NormalizeNormalizes/Data/IsArray/Schema/HasOneOf/HasReference/schema.json @@ -0,0 +1,30 @@ +{ + "type": "array", + "items": { + "oneOf": [ + { + "$ref": "#/definitions/url-object" + }, + { + "$ref": "#/definitions/url-string" + } + ] + }, + "definitions": { + "url-object": { + "type": "object", + "additionalProperties": false, + "properties": { + "type": { + "type": "string" + }, + "url": { + "type": "string" + } + } + }, + "url-string": { + "type": "string" + } + } +} From c91a39ba802781455abdb7d8227708b455d8f572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Thu, 15 Feb 2018 08:13:02 +0100 Subject: [PATCH 2/2] Fix: Resolve referenced schema in oneOf combination if it matches --- src/SchemaNormalizer.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/SchemaNormalizer.php b/src/SchemaNormalizer.php index 65f54483..8e24168b 100644 --- a/src/SchemaNormalizer.php +++ b/src/SchemaNormalizer.php @@ -239,7 +239,10 @@ private function resolveSchema($data, \stdClass $schema): \stdClass if (\property_exists($schema, 'oneOf') && \is_array($schema->oneOf)) { foreach ($schema->oneOf as $oneOfSchema) { if ($this->schemaValidator->isValid($data, $oneOfSchema)) { - return $oneOfSchema; + return $this->resolveSchema( + $data, + $oneOfSchema + ); } } }