Skip to content

Commit f8303c5

Browse files
committed
Implement this issue for all child class of SpecBaseObject - WIP - Only failing test is ReaderTest::testReadYamlWithAnchors
1 parent daed418 commit f8303c5

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/SpecBaseObject.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,12 @@ public function validate(): bool
234234
}
235235
$this->_recursingValidate = true;
236236
$valid = true;
237-
foreach ($this->_properties as $v) {
237+
$allowedFields = array_keys($this->attributes());
238+
foreach ($this->_properties as $k => $v) {
239+
if ($allowedFields && !in_array($k, $allowedFields, true) && substr($k, 0, 2) !== 'x-' ) {
240+
$valid = false;
241+
$this->addError('Invalid field: "' . $k . '"');
242+
}
238243
if ($v instanceof SpecObjectInterface) {
239244
if (!$v->validate()) {
240245
$valid = false;

src/spec/OpenApi.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,6 @@ public function performValidation()
7878
$this->addError('Unsupported openapi version: ' . $this->openapi);
7979
}
8080

81-
$providedFields = array_keys($this->getRawSpecData());
82-
$allowedFields = array_keys($this->attributes());
83-
foreach ($providedFields as $field) {
84-
if (!in_array($field, $allowedFields, true)) {
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');
86-
}
87-
}
81+
8882
}
8983
}

0 commit comments

Comments
 (0)