OpenAPITools / OpenAPITools/openapi-generator

[BUG] Ref to another spec file doesn't work

Open
#1,669 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.