Skip to content

Commit cdec710

Browse files
committed
Fix #16
1 parent 2948149 commit cdec710

File tree

4 files changed

+172
-12
lines changed

4 files changed

+172
-12
lines changed

composer.lock

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/OpenApiValidation.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,12 @@ private function parseErrors(ValidationError $error, $name = null, $in = null) :
502502
$err['name'] .= mb_strlen($err['name']) ? '.'.$err['missing'] : $err['missing'];
503503
unset($err['missing'],$err['value']);
504504
}
505+
if ('error_'.'$'.'schema' == $err['code']) {
506+
// This is a quickfix as the opis/json-schema wont give any other error message
507+
// There should not be any other reason this error_$schema occurs
508+
$err['code'] = 'error_additional';
509+
unset($err['schema']);
510+
}
505511
$errors[] = $err;
506512
}
507513
return $errors;

tests/RequestBodyTest.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,62 @@ public function testAllOfComposition()
125125
$this->assertSame('body', $json['errors'][0]['in']);
126126
$this->assertSame('body', $json['errors'][1]['in']);
127127
}
128+
129+
public function testAdditionalAttributes()
130+
{
131+
$response = $this->response('post', '/additionalProperties', [
132+
'body' => [
133+
'foo' => [
134+
'bar' => 100,
135+
'additional' => 'test',
136+
],
137+
],
138+
]);
139+
$json = $this->json($response);
140+
$this->assertSame('foo.additional', $json['errors'][0]['name']);
141+
$this->assertSame('error_additional', $json['errors'][0]['code']);
142+
$this->assertSame(400, $response->getStatusCode());
143+
}
144+
public function testHashMapString()
145+
{
146+
$response = $this->response('post', '/additionalProperties/hashmap/string', [
147+
'body' => [
148+
'en' => 'Hello',
149+
'sv' => 'Tjena',
150+
'fi' => 100
151+
],
152+
]);
153+
$json = $this->json($response);
154+
$this->assertSame(400, $response->getStatusCode());
155+
$this->assertSame('fi', $json['errors'][0]['name']);
156+
$this->assertSame('error_type', $json['errors'][0]['code']);
157+
$this->assertSame('integer', $json['errors'][0]['used']);
158+
}
159+
public function testHashMapObject()
160+
{
161+
$response = $this->response('post', '/additionalProperties/hashmap/object', [
162+
'body' => [
163+
'aa' => [
164+
'id' => 10,
165+
'foo' => 'text',
166+
'bar' => 10
167+
],
168+
'bb' => [
169+
'foo' => 10,
170+
'bar' => 'abc'
171+
]
172+
],
173+
]);
174+
$json = $this->json($response);
175+
$this->assertSame(400, $response->getStatusCode());
176+
$this->assertSame('aa.foo', $json['errors'][0]['name']);
177+
$this->assertSame('error_type', $json['errors'][0]['code']);
178+
$this->assertSame('string', $json['errors'][0]['used']);
179+
$this->assertSame('aa.bar', $json['errors'][1]['name']);
180+
$this->assertSame('error_type', $json['errors'][1]['code']);
181+
$this->assertSame('integer', $json['errors'][1]['used']);
182+
$this->assertSame('bb.id', $json['errors'][2]['name']);
183+
$this->assertSame('error_required', $json['errors'][2]['code']);
184+
$this->assertSame('body', $json['errors'][2]['in']);
185+
}
128186
}

tests/testapi.json

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,102 @@
715715
}
716716
}
717717
}
718+
},
719+
"/additionalProperties": {
720+
"post": {
721+
"operationId": "postAdditionalProperties",
722+
"requestBody": {
723+
"content": {
724+
"application/json": {
725+
"schema": {
726+
"type": "object",
727+
"properties": {
728+
"foo": {
729+
"type": "object",
730+
"properties": {
731+
"bar": {
732+
"type": "integer",
733+
"description": "A number"
734+
}
735+
},
736+
"additionalProperties": false
737+
}
738+
}
739+
}
740+
}
741+
}
742+
},
743+
"responses": {
744+
"200": {
745+
"$ref": "#/components/responses/OkResponse"
746+
},
747+
"400": {
748+
"$ref": "#/components/responses/ErrorResponse"
749+
}
750+
}
751+
}
752+
},
753+
"/additionalProperties/hashmap/string": {
754+
"post": {
755+
"operationId": "postAdditionalProperties",
756+
"requestBody": {
757+
"content": {
758+
"application/json": {
759+
"schema": {
760+
"type": "object",
761+
"additionalProperties": {
762+
"type":"string"
763+
}
764+
}
765+
}
766+
}
767+
},
768+
"responses": {
769+
"200": {
770+
"$ref": "#/components/responses/OkResponse"
771+
},
772+
"400": {
773+
"$ref": "#/components/responses/ErrorResponse"
774+
}
775+
}
776+
}
777+
},
778+
"/additionalProperties/hashmap/object": {
779+
"post": {
780+
"operationId": "postAdditionalProperties",
781+
"requestBody": {
782+
"content": {
783+
"application/json": {
784+
"schema": {
785+
"type": "object",
786+
"additionalProperties": {
787+
"type":"object",
788+
"required":["id"],
789+
"properties":{
790+
"id":{
791+
"type":"integer"
792+
},
793+
"foo":{
794+
"type":"integer"
795+
},
796+
"bar":{
797+
"type":"string"
798+
}
799+
}
800+
}
801+
}
802+
}
803+
}
804+
},
805+
"responses": {
806+
"200": {
807+
"$ref": "#/components/responses/OkResponse"
808+
},
809+
"400": {
810+
"$ref": "#/components/responses/ErrorResponse"
811+
}
812+
}
813+
}
718814
}
719815
}
720816
}

0 commit comments

Comments
 (0)