You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Getting PointerToNowhere when migrating from RefResolver to referencing #1312
I have been trying my best to migrate from RefResolver to the newer referencing lib but with no avail, and I even requested for help in the openapi-schema-validator repository: python-openapi/openapi-schema-validator#203 as I'm using jsonschema together with the openapi-schema-validator library.
I will report the issue I opened there, hoping that someone from your team can better assist me. Thank you for the help.
Dear team,
I've been trying my best to migrate my schema validation from RefResolver to the newer referencing library, but with no avail.
I would really appreciate some help or tips to point me in the right direction.
What is working for me, with RefResolver, is the following code:
defvalidate_schema(
instance: dict[str, Any],
schema: dict[str, Any],
*,
path: str,
method: str,
response: str,
content: str="application/json",
) ->None:
try:
_methods=schema["paths"][path]
exceptKeyError: # pragma: no cover (should never happen)msg=f"Path {path} not found in schema"raiseValueError(msg) fromNonetry:
_responses=_methods[method]
exceptKeyError: # pragma: no cover (should never happen)msg=f"Method {method} not found in schema"raiseValueError(msg) fromNonetry:
_content=_responses["responses"][response]["content"]
exceptKeyError: # pragma: no cover (should never happen)msg=f"Response {response} not found in schema"raiseValueError(msg) fromNonetry:
_schema=_content[content]["schema"]
exceptKeyError: # pragma: no cover (should never happen)msg=f"Content {content} not found in schema"raiseValueError(msg) fromNoneopenapi_schema_validator.validate(
instance,
_schema,
cls=OAS30Validator,
resolver=RefResolver.from_schema(schema), # TODO: migrate to referencing lib
)
I then tried to migrate to the referencing lib as mentioned here:
But with no success, as all I get are errors like: jsonschema.exceptions._WrappedReferencingError: PointerToNowhere: '/components/schemas/Foo' does not exist within {'$ref': '#/components/schemas/Foo'}
I will try to find some time to look there, but {'$ref': '#/components/schemas/Foo'} is never correct. That pointer means "in this document is a key called components, and in it is a subkey called schemas, and.. etc.
But that's clearly wrong, as that document has one and only one key in it, it's $ref.
Activity
Julian commentedon Oct 28, 2024
I will try to find some time to look there, but
{'$ref': '#/components/schemas/Foo'}is never correct. That pointer means "in this document is a key calledcomponents, and in it is a subkey calledschemas, and.. etc.But that's clearly wrong, as that document has one and only one key in it, it's
$ref.