-
Notifications
You must be signed in to change notification settings - Fork 15
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
Self referencing schemas results in SystemStackError
#291
Comments
Hi. Thanks for the report. In general, and also related to #285, I would like to change from "dereference everything" to "dereference everything outside JSON Schema schemas" and let json_schemer handle $refs inside JSON Schemas (local and across files) correctly via it's |
This should be fixed on main. I was able to reproduce this with this test: 9c2aaaa |
Oh this is cool! Really like the dynamic ref resolver approach! This looks like it will solve a lot of problems. I did give it a whirl and ran into some issues. The Openapi spec we've inherited takes a modular approach with specifying routes by using paths:
/companies:
$ref: paths/companies.yml And that YAML file will have something like get:
responses:
'200':
content:
application/json:
schema:
$ref: ../components/schemas/CompanyPaged.yml
'400':
$ref: ../components/responses/400.yml
'403':
$ref: ../components/responses/403.yml What I think is happening is that those My understanding is that the above setup as valid for an Openapi spec - or at least that's what I've been told; I may be wrong on that. Not sure if it's possible to dereference things in the Openapi part, and only use the ref resolver when dealing with the JSON schemas via Still poking around to see if I can get it into a format that |
Hi Michael, I am afraid that the 2.2 release with the RefResolver is far from done now. I am also looking into |
When providing
openapi_first
a spec containing a schema likeit hits a
stack level too deep (SystemStackError)
error.I have a general idea of what is happening.
openapi_first
is successfully loading the schema, but in doing so it creates self referencing hashes as it de-$ref
erences everything. So it basically ends up doing something like this:This schema gets passed off to
json_schemer
to build a newJSONSchemer::Schema
which works until something is executed on it. For example:This happens because
openapi_first
de-references everything to keep the entire schema local. It doesn't know that'#/component/schemas/BoomRef'
is self referencing, so it de-references that and basically picks itself up from thefile_cache
and creates a self referencing hash. This causes an error when trying to any recursive work on it; in the example above,json_schemer
attempts adeep_stringify_keys
that runs forever until the stack error hits.There are a few ways to do self referencing schemas like this in Openapi. One way is like
but during dereferencing
openapi_first
sees that'#'
and tries to load it from a file, which results in an error.Another way is
which seems to work, but requires changes to the schema.
It would be nice if
openapi_first
could handle that first schema. I think what we could do is compareobject_id
s during the de-referencing process, and if we encounter a schema whoseobject_id
matches theobject_id
of the thing it is attempting to make a$ref
to, we simply swap that value out with a'#'
.Additionally, it would be nice if
openapi_first
could handle the second schema example. I think what we could do here is modifyDereferencer
slightly so that when it encounters a bare'#'
it skips trying to resolve it and instead just uses that as the$ref
value.Do you have any thoughts on this? I think I have a pretty good idea of how it works, so I could try submitting a PR to accommodate those if you find either solution acceptable.
The text was updated successfully, but these errors were encountered: