karenetheridge / OpenAPI-Modern

Validate HTTP requests and responses against an OpenAPI v3.1 document
https://metacpan.org/release/OpenAPI-Modern/
Other
5 stars 3 forks source link

keep track of the location of all resources in the document, for later validation when use by a $ref #48

Closed karenetheridge closed 10 months ago

karenetheridge commented 1 year ago

We already use callbacks on $ref to track the locations of all operations. We could do this in a more universal way - track the locations of all entities we encounter (using their $defs name), and then we can verify that $refs in the document (not in a json schema, but the openapi part of the doc) are pointing to the right location.

We can do this at runtime, in _resolve_ref, by passing in the name of the entity we expect to be at the other end, and comparing that to our entity index.

We could also do this at initialization time by also tracking the location of all $refs and then resolving the target and comparing against our list of entities. This may not work for $refs to other documents though, as those may not have been loaded yet. This would also incur a startup penalty that may not be worth it.

karenetheridge commented 10 months ago

This was done in 0.045 and 0.051.