Skip to content

Commit 5882787

Browse files
committed
Fix this issue and add test
1 parent 1df4af0 commit 5882787

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

src/spec/OpenApi.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace cebe\openapi\spec;
99

10-
use cebe\openapi\exceptions\TypeErrorException;
1110
use cebe\openapi\SpecBaseObject;
1211

1312
/**
@@ -79,11 +78,11 @@ public function performValidation()
7978
$this->addError('Unsupported openapi version: ' . $this->openapi);
8079
}
8180

82-
$providedFields = array_keys(json_decode(json_encode($this->getSerializableData()), true)); # TODO this getSerializableData() can be eliminated if
81+
$providedFields = array_keys($this->getRawSpecData());
8382
$allowedFields = array_keys($this->attributes());
8483
foreach ($providedFields as $field) {
8584
if (!in_array($field, $allowedFields)) {
86-
$this->addError('Invalid top level fields: ' . $field);
85+
$this->addError('Invalid top level field: "' . $field . '". More information can be obtained at https://spec.openapis.org/oas/v3.0.3.html#fixed-fields');
8786
}
8887
}
8988
}

tests/spec/OpenApiTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public function testSpecs($openApiFile)
236236
public function testInvalidTopLevelField()
237237
{
238238
$openapi = new OpenApi([
239-
'AAcomponents' => [
239+
'AAAAAcomponents' => [
240240
'User' => [
241241
'type' => 'object',
242242
'properties' => [
@@ -247,12 +247,12 @@ public function testInvalidTopLevelField()
247247
]
248248
]
249249
]);
250-
$isValid = $openapi->validate();
251-
// $this->assertTrue($openapi->validate());
250+
$this->assertFalse($openapi->validate());
252251
$this->assertEquals([
253252
'OpenApi is missing required property: openapi',
254253
'OpenApi is missing required property: info',
255254
'OpenApi is missing required property: paths',
255+
'Invalid top level field: "AAAAAcomponents". More information can be obtained at https://spec.openapis.org/oas/v3.0.3.html#fixed-fields',
256256
], $openapi->getErrors());
257257

258258
// // check default value of servers

0 commit comments

Comments
 (0)