Skip to content

How to build a registry from a simple OpenAPI document dict? #160

Open
@meoyawn

Description

@meoyawn

I'm trying to build a registry

self.registry = Registry().with_resources(
    (f"#/components/schemas/{k}", Resource.from_contents(v, referencing.jsonschema.DRAFT202012)
    for k, v in openapi["components"]["schemas"].items()
)

but then it fails during validation

jsonschema.Draft202012Validator(registry=registry, schema=schema).validate(dict)

with

self = Resource(contents={'oneOf': [{'type': 'object', 'properties': {'status': {'enum': [200]}, 'headers': {'type': 'object'...['mime', 'body']}]}}, 'required': ['status', 'headers', 'body']}]}, _specification=<Specification name='draft2020-12'>)
pointer = '/components/schemas/YtDlInfo'
resolver = Resolver(_base_uri='', _registry=<Registry (25 resources, 5 uncrawled)>)

    def pointer(self, pointer: str, resolver: Resolver[D]) -> Resolved[D]:
        """
        Resolve the given JSON pointer.
    
        Raises:
    
            `exceptions.PointerToNowhere`
    
                if the pointer points to a location not present in the document
    
        """
        if not pointer:
            return Resolved(contents=self.contents, resolver=resolver)
    
        contents = self.contents
        segments: list[int | str] = []
        for segment in unquote(pointer[1:]).split("/"):
            if isinstance(contents, Sequence):
                segment = int(segment)
            else:
                segment = segment.replace("~1", "/").replace("~0", "~")
            try:
>               contents = contents[segment]  # type: ignore[reportUnknownArgumentType]
E               KeyError: 'components'

how do I correctly build a registry from an OpenAPI dict? Docs don't mention this

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions