Skip to content

Commit 519db33

Browse files
committed
Add test that Parameter's content property can only have one key
1 parent 569d776 commit 519db33

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/spec/Parameter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ protected function performValidation()
117117
if (!empty($this->content) && !empty($this->schema)) {
118118
$this->addError('A Parameter Object MUST contain either a schema property, or a content property, but not both.');
119119
}
120+
if(!empty($this->content) && count($this->content)!==1) {
121+
$this->addError('A Parameter Object MUST with Content property must have A SINGLE content type.');
122+
}
120123

121124
$supportedSerializationStyles = [
122125
'path' => ['simple', 'label', 'matrix'],

tests/spec/ParameterTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,28 @@ public function testItValidatesSchemaAndContentCombination()
169169
$this->assertFalse($result);
170170
}
171171

172+
public function testItValidatesContentCanHaveOnlySingleKey()
173+
{
174+
/** @var $parameter Parameter */
175+
$parameter = Reader::readFromYaml(<<<'YAML'
176+
name: token
177+
in: cookie
178+
content:
179+
application/json:
180+
schema:
181+
type: object
182+
application/xml:
183+
schema:
184+
type: object
185+
YAML
186+
, Parameter::class);
187+
188+
$result = $parameter->validate();
189+
$this->assertEquals(['A Parameter Object MUST with Content property must have A SINGLE content type.'], $parameter->getErrors());
190+
$this->assertFalse($result);
191+
}
192+
193+
172194
public function testItValidatesSupportedSerializationStyles()
173195
{
174196
// 1. Prepare test inputs

0 commit comments

Comments
 (0)