diff --git a/src/Merge/ReferenceNormalizer.php b/src/Merge/ReferenceNormalizer.php index 5ddcfad..9b6301a 100644 --- a/src/Merge/ReferenceNormalizer.php +++ b/src/Merge/ReferenceNormalizer.php @@ -30,27 +30,26 @@ public function normalizeInlineReferences( ): ReferenceResolverResult { $refFileCollection = []; foreach ($openApiDefinition->paths as $path) { + foreach ($path->parameters as $parameterIndex => $parameter) { + /** @var array $allParameters */ + $allParameters = $path->parameters; + if ($parameter instanceof Reference) { + $allParameters[$parameterIndex] = $this->normalizeReference($parameter, $refFileCollection); + } else if ($parameter instanceof Parameter) { + $allParameters[$parameterIndex] = $this->normalizeParameters($parameter, $refFileCollection); + } + + $path->parameters = $allParameters; + } + foreach ($path->getOperations() as $operation) { foreach (($operation->parameters ?? []) as $parameterIndex => $parameter) { if (! $parameter instanceof Parameter) { continue; } - /** @var array $allParameters */ $allParameters = $operation->parameters; - if ($parameter->schema instanceof Reference) { - $allParameters[$parameterIndex]->schema = $this->normalizeReference( - $parameter->schema, - $refFileCollection, - ); - } - - if ($parameter->schema instanceof Schema) { - $allParameters[$parameterIndex]->schema = $this->normalizeProperties( - $parameter->schema, - $refFileCollection, - ); - } + $allParameters[$parameterIndex] = $this->normalizeParameters($parameter, $refFileCollection); $operation->parameters = $allParameters; } @@ -265,4 +264,25 @@ public function normalizeProperty(Reference|Schema $property, array &$refFileCol return $property; } + + /** + * @param array $refFileCollection + */ + public function normalizeParameters(Parameter $parameter,array &$refFileCollection): Parameter + { + if ($parameter->schema instanceof Reference) { + $parameter->schema = $this->normalizeReference( + $parameter->schema, + $refFileCollection, + ); + } + + if ($parameter->schema instanceof Schema) { + $parameter->schema = $this->normalizeProperties( + $parameter->schema, + $refFileCollection, + ); + } + return $parameter; + } } diff --git a/tests/Merge/Fixtures/expected/openapi-normalized.json b/tests/Merge/Fixtures/expected/openapi-normalized.json index 971965f..e909362 100644 --- a/tests/Merge/Fixtures/expected/openapi-normalized.json +++ b/tests/Merge/Fixtures/expected/openapi-normalized.json @@ -3,6 +3,20 @@ "info": {}, "paths": { "\/dummy": {}, + "\/path\/{id}": { + "get": { + "responses": { + "200": { + "description": "OK" + } + } + }, + "parameters": [ + { + "$ref": "#\/components\/schemas\/pathOutsideOperation" + } + ] + }, "\/reference": { "get": { "parameters": [ diff --git a/tests/Merge/Fixtures/openapi-with-reference.json b/tests/Merge/Fixtures/openapi-with-reference.json index 36bc39c..4dd9bc3 100644 --- a/tests/Merge/Fixtures/openapi-with-reference.json +++ b/tests/Merge/Fixtures/openapi-with-reference.json @@ -3,6 +3,20 @@ "info": {}, "paths": { "/dummy": {}, + "/path/{id}": { + "parameters": [ + { + "$ref": "pathOutsideOperation.json#/components/schemas/pathOutsideOperation" + } + ], + "get": { + "responses": { + "200": { + "description": "OK" + } + } + } + }, "/reference": { "get": { "parameters": [ diff --git a/tests/Merge/Fixtures/pathOutsideOperation.json b/tests/Merge/Fixtures/pathOutsideOperation.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/tests/Merge/Fixtures/pathOutsideOperation.json @@ -0,0 +1 @@ +{} diff --git a/tests/Merge/ReferenceNormalizerTest.php b/tests/Merge/ReferenceNormalizerTest.php index bc72af3..85f037f 100644 --- a/tests/Merge/ReferenceNormalizerTest.php +++ b/tests/Merge/ReferenceNormalizerTest.php @@ -48,6 +48,7 @@ public function testReadFileWithResolvedReference(): void $foundRefFiles = $specificationResult->getFoundReferenceFiles(); $expectedRefFiles = [ + __DIR__ . '/Fixtures/pathOutsideOperation.json', __DIR__ . '/Fixtures/requestParam.json', __DIR__ . '/Fixtures/requestParamNullable.json', __DIR__ . '/Fixtures/responseModel.json',