Skip to content

Commit 6d2a7bb

Browse files
izuckencebe
authored andcommitted
Added failing referencing test for referencing common params in referenced path objects.
1 parent 2578a5b commit 6d2a7bb

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

tests/spec/ReferenceTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,44 @@ public function testTransitiveReferenceOverTwoFiles()
457457
'200':
458458
description: 'return a cat'
459459
460+
YAML;
461+
// remove line endings to make string equal on windows
462+
$expected = preg_replace('~\R~', "\n", $expected);
463+
if (PHP_VERSION_ID < 70200) {
464+
// PHP <7.2 returns numeric properties in yaml maps as integer, since 7.2 these are string
465+
// probably related to https://www.php.net/manual/de/migration72.incompatible.php#migration72.incompatible.object-array-casts
466+
$this->assertEquals(str_replace("'200':", "200:", $expected), $yaml, $yaml);
467+
} else {
468+
$this->assertEquals($expected, $yaml, $yaml);
469+
}
470+
}
471+
472+
public function testReferencedCommonParamsInReferencedPath()
473+
{
474+
$openapi = Reader::readFromYamlFile(__DIR__ . '/data/reference/ReferencedCommonParamsInReferencedPath.yml', OpenApi::class, \cebe\openapi\ReferenceContext::RESOLVE_MODE_INLINE);
475+
$yaml = \cebe\openapi\Writer::writeToYaml($openapi);
476+
$expected = <<<YAML
477+
openapi: 3.0.0
478+
info:
479+
title: 'Nested reference with common path params'
480+
version: 1.0.0
481+
paths:
482+
/example:
483+
get:
484+
responses:
485+
'200':
486+
description: 'OK if common params can be references'
487+
parameters:
488+
-
489+
name: test
490+
in: header
491+
description: 'Test parameter to be referenced'
492+
required: true
493+
schema:
494+
enum:
495+
- test
496+
type: string
497+
460498
YAML;
461499
// remove line endings to make string equal on windows
462500
$expected = preg_replace('~\R~', "\n", $expected);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
openapi: 3.0.0
2+
info:
3+
title: Nested reference with common path params
4+
version: 1.0.0
5+
paths:
6+
/example:
7+
$ref: 'paths/ReferencesCommonParams.yml'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: test
2+
in: header
3+
description: Test parameter to be referenced
4+
required: true
5+
schema:
6+
type: string
7+
enum: [ 'test' ]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
- $ref: '../parameters/TestParameter.yml'
3+
4+
get:
5+
responses:
6+
200:
7+
description: OK if common params can be references

0 commit comments

Comments
 (0)