From 2e86a4da2e45da24b2102ed8f472cd0f70662faf Mon Sep 17 00:00:00 2001 From: izucken Date: Mon, 1 Mar 2021 07:34:36 +0300 Subject: [PATCH 1/3] Updated vendor (mermade/openapi3-examples) openapi test paths to pass tests. --- tests/spec/OpenApiTest.php | 72 +++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/tests/spec/OpenApiTest.php b/tests/spec/OpenApiTest.php index bf321f1b..16275980 100644 --- a/tests/spec/OpenApiTest.php +++ b/tests/spec/OpenApiTest.php @@ -103,43 +103,43 @@ public function specProvider() // examples from https://github.com/Mermade/openapi3-examples $mermadeExamples = [ - __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/externalPathItemRef.yaml', - __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/deprecated.yaml', - __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/swagger2openapi/openapi.json', - __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/gluecon/example1_from_._Different_parameters.md.yaml', - __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/gluecon/example1_from_._Fixed_file.md.yaml', - __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/gluecon/example1_from_._Different_parameters.md.yaml', - __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/gluecon/example1_from_._Fixed_file.md.yaml', - __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/gluecon/example1_from_._Fixed_multipart.md.yaml', - __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/gluecon/example1_from_._Improved_examples.md.yaml', - __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/gluecon/example1_from_._Improved_pathdescriptions.md.yaml', - __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/gluecon/example1_from_._Improved_securityschemes.md.yaml', - __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/gluecon/example1_from_._Improved_serverseverywhere.md.yaml', - __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/gluecon/example1_from_._New_callbacks.md.yaml', - __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/gluecon/example1_from_._New_links.md.yaml', - __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/gluecon/example2_from_._Different_parameters.md.yaml', - __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/gluecon/example2_from_._Different_requestbody.md.yaml', - __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/gluecon/example2_from_._Different_servers.md.yaml', - __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/gluecon/example2_from_._Fixed_multipart.md.yaml', - __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/gluecon/example2_from_._Improved_securityschemes.md.yaml', - __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/gluecon/example2_from_._New_callbacks.md.yaml', - __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/gluecon/example2_from_._New_links.md.yaml', - __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/gluecon/example3_from_._Different_parameters.md.yaml', - __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/gluecon/example3_from_._Different_servers.md.yaml', - __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/gluecon/example4_from_._Different_parameters.md.yaml', - __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/gluecon/example5_from_._Different_parameters.md.yaml', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/externalPathItemRef.yaml', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/deprecated.yaml', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/swagger2openapi/openapi.json', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/gluecon/example1_from_._Different_parameters.md.yaml', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/gluecon/example1_from_._Fixed_file.md.yaml', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/gluecon/example1_from_._Different_parameters.md.yaml', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/gluecon/example1_from_._Fixed_file.md.yaml', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/gluecon/example1_from_._Fixed_multipart.md.yaml', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/gluecon/example1_from_._Improved_examples.md.yaml', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/gluecon/example1_from_._Improved_pathdescriptions.md.yaml', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/gluecon/example1_from_._Improved_securityschemes.md.yaml', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/gluecon/example1_from_._Improved_serverseverywhere.md.yaml', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/gluecon/example1_from_._New_callbacks.md.yaml', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/gluecon/example1_from_._New_links.md.yaml', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/gluecon/example2_from_._Different_parameters.md.yaml', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/gluecon/example2_from_._Different_requestbody.md.yaml', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/gluecon/example2_from_._Different_servers.md.yaml', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/gluecon/example2_from_._Fixed_multipart.md.yaml', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/gluecon/example2_from_._Improved_securityschemes.md.yaml', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/gluecon/example2_from_._New_callbacks.md.yaml', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/gluecon/example2_from_._New_links.md.yaml', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/gluecon/example3_from_._Different_parameters.md.yaml', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/gluecon/example3_from_._Different_servers.md.yaml', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/gluecon/example4_from_._Different_parameters.md.yaml', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/gluecon/example5_from_._Different_parameters.md.yaml', // TODO symfony/yaml can not read this file!? -// __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/OAI/api-with-examples.yaml', - __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/OAI/petstore-expanded.yaml', - __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/OAI/petstore.yaml', - __DIR__ . '/../../vendor/mermade/openapi3-examples/pass/OAI/uber.yaml', - - __DIR__ . '/../../vendor/mermade/openapi3-examples/malicious/rapid7-html.json', - __DIR__ . '/../../vendor/mermade/openapi3-examples/malicious/rapid7-java.json', - __DIR__ . '/../../vendor/mermade/openapi3-examples/malicious/rapid7-js.json', - __DIR__ . '/../../vendor/mermade/openapi3-examples/malicious/rapid7-php.json', - __DIR__ . '/../../vendor/mermade/openapi3-examples/malicious/rapid7-ruby.json', -// __DIR__ . '/../../vendor/mermade/openapi3-examples/malicious/yamlbomb.yaml', +// __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/OAI/api-with-examples.yaml', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/OAI/petstore-expanded.yaml', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/OAI/petstore.yaml', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/pass/OAI/uber.yaml', + + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/malicious/rapid7-html.json', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/malicious/rapid7-java.json', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/malicious/rapid7-js.json', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/malicious/rapid7-php.json', + __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/malicious/rapid7-ruby.json', +// __DIR__ . '/../../vendor/mermade/openapi3-examples/3.0/malicious/yamlbomb.yaml', ]; // examples from https://github.com/APIs-guru/openapi-directory/tree/openapi3.0.0/APIs From 5cd5dfa67214240efc5c190dc0c3780faa6e927b Mon Sep 17 00:00:00 2001 From: izucken Date: Mon, 1 Mar 2021 07:38:21 +0300 Subject: [PATCH 2/3] Added failing referencing test for referencing common params in referenced path objects. --- tests/spec/ReferenceTest.php | 38 +++++++++++++++++++ ...ReferencedCommonParamsInReferencedPath.yml | 7 ++++ .../reference/parameters/TestParameter.yml | 7 ++++ .../paths/ReferencesCommonParams.yml | 7 ++++ 4 files changed, 59 insertions(+) create mode 100644 tests/spec/data/reference/ReferencedCommonParamsInReferencedPath.yml create mode 100644 tests/spec/data/reference/parameters/TestParameter.yml create mode 100644 tests/spec/data/reference/paths/ReferencesCommonParams.yml diff --git a/tests/spec/ReferenceTest.php b/tests/spec/ReferenceTest.php index 40307fd2..6156fc06 100644 --- a/tests/spec/ReferenceTest.php +++ b/tests/spec/ReferenceTest.php @@ -446,6 +446,44 @@ public function testTransitiveReferenceOverTwoFiles() '200': description: 'return a cat' +YAML; + // remove line endings to make string equal on windows + $expected = preg_replace('~\R~', "\n", $expected); + if (PHP_VERSION_ID < 70200) { + // PHP <7.2 returns numeric properties in yaml maps as integer, since 7.2 these are string + // probably related to https://www.php.net/manual/de/migration72.incompatible.php#migration72.incompatible.object-array-casts + $this->assertEquals(str_replace("'200':", "200:", $expected), $yaml, $yaml); + } else { + $this->assertEquals($expected, $yaml, $yaml); + } + } + + public function testReferencedCommonParamsInReferencedPath() + { + $openapi = Reader::readFromYamlFile(__DIR__ . '/data/reference/ReferencedCommonParamsInReferencedPath.yml', OpenApi::class, \cebe\openapi\ReferenceContext::RESOLVE_MODE_INLINE); + $yaml = \cebe\openapi\Writer::writeToYaml($openapi); + $expected = << Date: Mon, 1 Mar 2021 07:44:46 +0300 Subject: [PATCH 3/3] Fixed path references resolution fail tied to a dynamic prop modification - dynamic attribute array references were not resolving, producing an E_NOTICE. --- src/spec/PathItem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spec/PathItem.php b/src/spec/PathItem.php index f93e43fc..db6b105e 100644 --- a/src/spec/PathItem.php +++ b/src/spec/PathItem.php @@ -180,7 +180,7 @@ public function resolveReferences(ReferenceContext $context = null) foreach ($this->$attribute as $k => $item) { if ($item instanceof Reference) { $referencedObject = $item->resolve(); - $this->$attribute[$k] = $referencedObject; + $this->$attribute = [$k => $referencedObject] + $this->$attribute; if (!$referencedObject instanceof Reference && $referencedObject !== null) { $referencedObject->resolveReferences(); }