OpenAPITools / OpenAPITools/openapi-generator
[BUG] Using external references in OpenAPI spec
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
If external file references are used in an OpenAPI spec file, an error is thrown by a utility function. Failed to get the schema name: ../../shared/requests/submit.yaml#/components/schemas/SubmitSuccessResponseV1
(This value is particular to my input. In general, it prints the name of the external reference file#/component-name)
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
openapi-generator version
I'm building the tip of master brach at 4b49335
OpenAPI declaration file content or url
I can reproduce the issue with this file: https://github.com/ripple/rippled-api-spec/blob/main/open_api/json_api.yaml
I suspect that any OpenAPI input file that uses $ref in an external file, will see this problem. I'm using OpenAPI v3.1.0
Generation Details
mvn clean package -DSkipTestsjava -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g python -i ../rippled-api-spec/open_api/json_api.yaml -o sample-python-out-jul25-fresh --skip-validate-spec
Here is the observed log from the code-generator:
external-ref.log
Steps to reproduce
Related issues/PRs
couldn't find related issues
Suggest a fix
public static String getSimpleRef(String ref) {
// a reference to an external file
if (ref != NULL && ref.contains(".yaml#/")) {
// strip the filePath portion of the reference, only retain the #/component or #/definition portion
ref = ref.subString(ref.lastIndexOf(".yaml#/") + 5)
}
// ... continue with the rest of the function as-is
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java around line 393 and reproduce with ripple/rippled-api-spec's open_api/json_api.yaml. Run the Maven build and Python generation command from the issue, then inspect how the external $ref is parsed. Done means generation handles the external reference without the reported schema-name error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100