gazpachoking/jsonref

[feature] inline remote schemas

Opened this issue · 3 comments

Thanks for creating the library! jsonref is able to resolve the recursive references but it's impossible to serialize the resolved schema since it includes circular references as follows:

pprint.pprint(value)

{'components': {'schemas': {'filter': {'properties': {'and': {'items': <Recursion on dict with id=4621593792>,
                                                              'type': 'array'}}},
                            'filterList': {'items': {'properties': {'and': <Recursion on dict with id=4621593216>}},
                                           'type': 'array'}}},
json.dumps(value)

    print(json.dumps(dumps))
  File "/usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
ValueError: Circular reference detected

The json-schema-ref-parser library supports the circular references, the support for the option bundle in jsonref would be great.

@buremba I followed your link, but I was unable to understand what your desired behavior is here. Could you clarify? How should a circular reference be handled when being dumped to json?

Does that 'bundle' option just pull in all remote references, store them in a 'definitions' block, then rewrite the refs to point to the local version of the references? That's not something I'm keen on implementing, although if someone want's to write such a utility function it could be considered for inclusion.
I renamed this issue, since we already support recursive schemas, and can re-serialize them (using the original refs.)

I was about to make a feat. request but I think @gazpachoking you've described it -
it would be great if jsonref could support bundling
but I can see that this would be quite a complex feature to support as subschemas would have to be recursively resolved within their own "namespace"