-
-
Notifications
You must be signed in to change notification settings - Fork 32
How to resolve local references with jsonschema/referencing #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Indeed not even the example on https://openapi-schema-validator.readthedocs.io/en/latest/references.html works.
How should the connection from "#/components/schemas/Name" to "urn:name-schema" be established? |
Guys, if you need WA for the current issue I did the following:
|
seems to work for me, without the replacement of If this is supported by Registry (I haven't really read through their docs well enough to know :)), maybe the example just needs updating? edit: incorrect! see below |
I'm sorry to say, @AlexeyKatanaev the idea you propose is exactly what the docs instruct to do, and what I've already tried to do (see issue description), but unfortunately this simply does not work (and it's not just me, @lawilog also confirmed it). @Cynocracy thanks for the suggestion, but I've now tried I've just now had a brief debugging session. It seems to me that So I'm sorry to say, I'm still completely stuck on how to migrate local references from |
Maybe a little more context to what I wrote helps? I was taking the full apidoc for an openAPI service (saved to schema.json) and doing
I agree that the inclusion of the urn reference in the thing being validated in the docs confused me, and I don't fully understand that bit :)
Huh, now I'm curious how my example worked... looking at it a bit now 🕵️♂️ |
@Cynocracy Thanks for the full code example! I think understand your approach better now, namely validating against the whole schema. My uneducated guess from my short debugging session is that your example should still work even if you omit the Unfortunately, my use case is validating that the given data matches one part precisely, and not just "is valid under any possibilities given in the schema", e.g. in my simplified example I want to validate that the data is a list of uuid, and not a single uuid. So using the whole schema does not work there, I think. |
@wosc Ah yeah, you're correct! It turns out the schema I was using already had $refs evaluated, so the registry was doing a whole lot of nothing. edit: can also confirm that using the YAML with the $refs in it quickly becomes a headache, because my $refs also have $refs and that doesn't seem to be handled correctly, afaict, even with the find replace to urn: |
Alright. I finally figured out how to this (using this for me somewhat cryptic off-hand comment as a starting point). The key point is that in the new API, you have to reference the part of the schema you want to validate against, instead of passing it as "the whole applicable schema" like one did previously. (And you have to assign a URI to the schema as a whole to be able to express this reference.) Thus, the updated/solved example code for the usecase in the issue description looks like this: schema = yaml.safe_load(open('openapi.yaml').read())
resource = referencing.Resource.from_contents(schema, default_specification=DRAFT202012)
registry = referencing.Registry().with_resource(uri='urn:myschema', resource=resource)
openapi_schema_validator.validate(
['{urn:uuid:deadbeef}'],
{'$ref': 'urn:myschema#/components/schemas/something'},
registry=registry) Dear maintainers, I would dearly love either a pointer to where I should have read about this, or for someone knowledgeable to update the library documentation. This has been an exceedingly frustrating exercise. |
Hi @wosc Thanks for your research. That's the exact document the references page is pointing to. I fixed references in the example. I'm happy to hear If you have any other suggestions how to improve the documentation. |
@p1c2u Thanks for looking in. I think my main question is, what should I have been reading to make me think that it could be even remotely possible/sensible to pass a dict that only contains a
|
@wosc thank you for figuring this out! I ran into the same problem last week and this thread was a lifesaver.
Echoing this question, none of the documentation I found suggested that this was a possibility. |
Indeed, this should be included in Migrating from RefResolver section of referencing docs. |
Hi, so I'm sorry for the probably dumb question, but I've been banging my head against this and am getting nowhere.
I have an openapi spec like this
Previously I could do validation like so:
But after the API switch to
referencing
, I'm stumped on how to create aRegistry
that "just" resolves these local pointers. I've tried following the guide in https://openapi-schema-validator.readthedocs.io/en/latest/references.html, like sobut that raises
PointerToNowhere: '/components/schemas/uuid' does not exist within {'type': 'array', 'items': {'$ref': '#/components/schemas/uuid'}}
Thanks for your help!
The text was updated successfully, but these errors were encountered: