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
How to build a registry from a simple OpenAPI document dict? #160
I haven't looked at this carefully but two things:
Support specifically for the OpenAPI spec is/was planned for but not implemented yet, so it's possible the answer here depends on finishing that work
You're tagging the resources with JSON Schema 2020-12, so you're getting behavior for JSON Schema 2020-12, where what you have isn't going to work
The reason it won't work is that #/components/schemas/{k} means "look for a components/schemas/k key in this subschema" for each subschema you're looping over -- and that is (probably) incorrect -- you want# to be the parent OpenAPI spec document, as that's presumably the one with the components/schemas sub-properties. So maybe try only adding the parent document and then using $refs to yourSpecDocument#/components/schemas/foo, but whether that works exactly correctly or not depends on any differences in OpenAPI.
For anyone who is looking for a solution, this worked for me.
fromreferencingimportRegistry, Resourcefromreferencing.jsonschemaimportDRAFT202012fromjsonschemaimportDraft202012Validatorregistry=Registry()
# Dump all openapi components as is (don't edit #/components/schemas/Xyz style refs).parent_schema= {"components": spec['components']}
schema=Resource(contents=parent_schema, specification=DRAFT202012)
registry=registry.with_resource(uri="parent", resource=schema)
# Now validate using:Draft202012Validator(
schema={"$ref": "parent#/components/schemas/Xyz"},
instance={},
registry=registry
)
# You can name 'parent' anything, probaly filename or url for your spec file if you are cross-referencing.
Activity
Julian commentedon Aug 6, 2024
I haven't looked at this carefully but two things:
#/components/schemas/{k}means "look for a components/schemas/k key in this subschema" for each subschema you're looping over -- and that is (probably) incorrect -- you want#to be the parent OpenAPI spec document, as that's presumably the one with thecomponents/schemassub-properties. So maybe try only adding the parent document and then using$refs toyourSpecDocument#/components/schemas/foo, but whether that works exactly correctly or not depends on any differences in OpenAPI.rafalkrupinski commentedon Sep 1, 2024
Support for OpenAPI would be greatly appreciated.
nitg16 commentedon Feb 22, 2025
For anyone who is looking for a solution, this worked for me.