cebe / php-openapi

Read and write OpenAPI yaml/json files and make the content accessible in PHP objects.
MIT License
466 stars 88 forks source link

validate() returns true with wrong top level elements #84

Open franksl opened 3 years ago

franksl commented 3 years ago

Hi, I tried to run validate like this:

$spec   = cebe\openapi\Reader::readFromJson($jsonstring);
$spec->resolveReferences(new cebe\openapi\ReferenceContext($spec, "/"));
$spec->validate();

on a OpenAPI 3 schema that has, for example the property "AAAAAcomponents" instead of "components", and the call returns true. Is this correct? Thanks, Frank

cebe commented 3 years ago

it is possible to extend the OpenAPI description. So adding properties is generally allowed. Strictly following the spec would mean that you need to prefix additional properties with x-.

cebe commented 3 years ago

validation currently means to check if the existing elements are used correctly. It would be possible to add some kind of strict mode that would also complain about cases like yours.