Comments (2)
I encountered the same issue. I think its because the child is not stored as an individual Resource in the Registry, which makes that in-file references are taken to be relative to the main schema, instead of the child schema.
I created a solution that allows referencing by id, instead of filename, and preload all sources in the registry. See pull request #946
Its not exactly solving the issue caused by in-file references in a child, but by converting all reference from reference by filename to reference by $id, the problem is prevented. You could actually use the filename as the id (by defining an $id parameter in each file), but that might be a bit confusing.
As an extension to my solution, all files could be added to the registry with a uri derived from the relative file location from the main source. Currently, all files are registered by the exact filepath provided, so its not attempted to construct the relative path between the main source an all other sources. For some common situations (e.g. all files in the same folder), its relatively simple, but to make a reliable and robust implementation, its required to all paths in some canonical form, and perform all file matching on these canonical names. This Would probably require modifications to package referencing, which is out of scope for me.
from jsonschema-gentypes.
I try to understand better the design choices made in the current implementation of the RefResolver
. If I look at the Resolver
from the referencing
package, it returns a Resolved
object from a call to resolver.lookup
. This contains both the resolved schema, and a new Resolver
that can be used for subsequent lookups in the same context. I have the impression that this is the cause for the failure of looking up relative references from an externally referenced source, as the RefResolver
tries to resolve the relative references relative to the root, instead of relative to the child.
If this is true, one way to solve this, is to implement the same type of logic in the RefResolver
as in the referencing.Resolver
, i.e. return Resolved
objects that include a new resolver from the lookup function. But I suspect that has a major impact on the whole system, as it would not only affect RefResolver
, but also the API
classes.
Or would there be a more localized solution to support relative references from referenced files?
from jsonschema-gentypes.
Related Issues (20)
- Docstring of objects does not end up in generated code HOT 5
- `root_name` does not affect subtypes or docstrings HOT 1
- missing type is not inferred correctly HOT 9
- Proposal: Workaround for mypy's incorrect implementation of NotRequired
- doesn't find any types HOT 2
- RecursionError: maximum recursion depth exceeded HOT 2
- Issues with $ref resolution in multiple schema files
- Ignoring / not generating code for required fields when oneOf HOT 1
- Support for `patternProperties` when there is only one entry HOT 1
- Tests are failing with Python 3.12
- Preserving case when generating $ref classes HOT 5
- Variable name collision with enum case variants
- Can't handle .. paths + ref path resolution properly
- Bug: `python_version` is not read from `generate[*]` in configuration
- Generated code import ordering is random HOT 1
- Geo GHCI test Dashboard
- Geo GHCI int Dashboard
- Invalid Python Code and Type Definitions Generated HOT 5
- `name_mapping` checked against quoted type
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonschema-gentypes.