Skip to content

Commit ebea294

Browse files
committed
added test to ensure a property with name "$ref" is not interpreted as a reference
1 parent a27ffc4 commit ebea294

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/spec/SchemaTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,4 +320,39 @@ public function testRefAdditionalProperties()
320320
$schema = new Schema(['additionalProperties' => new Reference(['$ref' => '#/here'], Schema::class)]);
321321
$this->assertInstanceOf(Reference::class, $schema->additionalProperties);
322322
}
323+
324+
/**
325+
* Ensure that a property named "$ref" is not interpreted as a reference.
326+
* @link https://github.com/OAI/OpenAPI-Specification/issues/2173
327+
*/
328+
public function testPropertyNameRef()
329+
{
330+
$json = <<<'JSON'
331+
{
332+
"components": {
333+
"schemas": {
334+
"person": {
335+
"type": "object",
336+
"properties": {
337+
"name": {
338+
"type": "string"
339+
},
340+
"$ref": {
341+
"type": "string"
342+
}
343+
}
344+
}
345+
}
346+
}
347+
}
348+
JSON;
349+
$openApi = Reader::readFromJson($json);
350+
$this->assertInstanceOf(Schema::class, $person = $openApi->components->schemas['person']);
351+
352+
$this->assertEquals(['name', '$ref'], array_keys($person->properties));
353+
$this->assertInstanceOf(Schema::class, $person->properties['name']);
354+
$this->assertInstanceOf(Schema::class, $person->properties['$ref']);
355+
$this->assertEquals('string', $person->properties['name']->type);
356+
$this->assertEquals('string', $person->properties['$ref']->type);
357+
}
323358
}

0 commit comments

Comments
 (0)