datamodel-code-generator
datamodel-code-generator copied to clipboard
Relative paths in url '$ref's are added to local file path instead of the url.
Describe the bug If file A refers to file B via url, and file B refers to file C using a relative path, datamodel-codegen searches local file system (from A) for file C instead of adding the relative path to the url of file B.
To Reproduce
I cloned https://github.com/ga4gh-beacon/beacon-v2/tree/main and tried converting the json schema file (file A in the description above) https://github.com/ga4gh-beacon/beacon-v2/blob/main/models/json/beacon-v2-default-model/analyses/defaultSchema.json to pydantic.
this file refers to file B using url like this:
"$ref": "https://raw.githubusercontent.com/ga4gh-beacon/beacon-v2/main/framework/json/common/beaconCommonComponents.json#/definitions/Info"
File B refers to file C using relative path like this:
"$ref": "./ontologyTerm.json",
File C is available at https://raw.githubusercontent.com/ga4gh-beacon/beacon-v2/main/framework/json/common/ontologyTerm.json
but instead of finding this (by adding it to the url of file B), I get error
FileNotFoundError: [Errno 2] No such file or directory: '/Users/sondre/beacon-v2-main/models/json/beacon-v2-default-model/analyses/ontologyTerm.json'
i.e. the relative path is added to the path of file A.
Used commandline:
$ datamodel-codegen --input defaultSchema.json
Expected behavior I think it should add the relative path to the file containing the relative path
Version:
- Python version: 3.10.0
- datamodel-code-generator version: 0.25.8
Additional context I forked and made a workaround, but i figured i should still let you know