First of - very useful library/tool - thanks for making it!
I have a set of OpenAPI files (from these 3GPP specification) which I want to use.
In these files, many $ref
s point to components from local files.
For example:
'400':
$ref: 'TS29571_CommonData.yaml#/components/responses/400'
or
dnais:
type: array
items:
$ref: 'TS29571_CommonData.yaml#/components/schemas/Dnai'
minItems: 1
I see that the generator supports remote references but it does not support local files. It won't be too hard to search-and-replace these references - assuming the files are hosted somewhere, or you want to make the effort to host them yourself, which is not always the case... so maybe it would be good to support such local references.
I've look into the code and it seems a few changes are required.
In this library, in get_ref_body
(fastapi_code_generator/parser.py, in line 40) - need to add another case to identify references to a file. I manually tested the following code:
RE_FILE_REF: Pattern[str] = re.compile(r"^.*\.ya?ml#") # at the top
elif RE_FILE_REF.match(ref):
# a new case - get ref body from local file
filename, path = ref.rsplit('#/', 1)
ref_body = openapi_model_parser._get_ref_body(filename)
return get_model_by_path(ref_body, path.split('/'))
I thought this might be enough, and it does work if your cwd
is where the files are located. Otherwise, _get_ref_body_from_remote
fails because of the way it is currently implemented.
I tried to understand what would be the right approach from here but I am not sure - I couldn't find (yet) a reference to the original file available in parsing another - with the original file name, the $ref-ed file could either be in cwd
or relative to the original file.
I sort of got the project to run locally on my machine but I run into issues. I am not sure how quickly I can get everything to run (tests etc).
I'd be happy to help and I will try to setup my computer for development...
Thanks!
Tomer
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too