OpenAPITools / OpenAPITools/openapi-generator
[BUG] Ref to another spec file doesn't work
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
My openapi spec is split into multiple files. In some cases, one of the subfiles will refer to a component from another.
openapi-generator version
3.3.4, not sure on regression
OpenAPI declaration file content or url
allOf:
- $ref: 'common.yaml#/components/schemas/MyRemoteSchema'
- $ref: '#/components/schemas/MyLocalSchema'
Command line used for generation
./openapi-generator-cli.sh generate -i openapi/openapi.yaml -g kotlin-spring -c config.json
OR
/openapi-generator-cli.sh generate -i openapi/openapi.yaml -g spring -c config.json
config.json:
{
"groupId": "com.myco.api",
"artifactId": "my-thing",
"artifactVersion": "0.0.0.1",
"sourceFolder": "src/main/java",
"title": "My Super Cool Thing",
"interfaceOnly": false,
"java8": true,
"async": true,
"reactive": false,
"library": "spring-boot"
}
Steps to reproduce
Run the command given above. The output on the command line will be:
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: common.yaml#/components/schemas/MyObject
[main] WARN o.o.codegen.DefaultCodegen - Error obtaining the datatype from ref:common.yaml#/components/schemas/MyObject. Default to 'object'
Related issues/PRs
Nothing exact
Suggest a fix
It appears like the code in codegen.utils.ModelUtils for getSimpleRef is assuming that the string will always start with either #/components or #/definitions. It is valid yaml to have it be common.yaml#/components. I think that section of code should perhaps check if the reference contains #/components or #/definitions instead.
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 codegen.utils.ModelUtils.getSimpleRef and trace how the generator parses refs such as common.yaml#/components/schemas/MyRemoteSchema. Reproduce with the provided openapi-generator-cli.sh generate command and verify that cross-file schemas resolve without the reported datatype warnings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100