Closed
Description
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
components:
schemas:
something:
type: array
items:
"$ref": "#/components/schemas/uuid"
uuid:
pattern: "^((\\{urn:uuid:)?([a-f0-9]{8})\\}?)$"
type: string
Previously I could do validation like so:
schema = yaml.safe_load(open('openapi.yaml').read())
resolver = jsonschema.validators.RefResolver.from_schema(schema)
openapi_schema_validator.validate(
['{urn:uuid:deadbeef}'],
schema=schema['components']['schemas']['something'],
resolver=resolver)
But after the API switch to referencing
, I'm stumped on how to create a Registry
that "just" resolves these local pointers. I've tried following the guide in https://openapi-schema-validator.readthedocs.io/en/latest/references.html, like so
schema = yaml.safe_load(open('openapi.yaml').read())
definitions = schema['components']['schemas']
registry = referencing.Registry().with_resources([
(f'urn:{k}-schema', referencing.Resource.from_contents(
v, default_specification=DRAFT202012))
for k, v in definitions.items()
])
openapi_schema_validator.validate(
['{urn:uuid:deadbeef}'],
schema=schema['components']['schemas']['something'],
registry=registry)
but that raises PointerToNowhere: '/components/schemas/uuid' does not exist within {'type': 'array', 'items': {'$ref': '#/components/schemas/uuid'}}
Thanks for your help!
Metadata
Metadata
Assignees
Labels
No labels