OpenAPITools / OpenAPITools/openapi-generator

[BUG][Java] Disabling `useInlineModelResolver` does not affect oneOf model name generation

Open
#20,665 0 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

Bug Report Checklist
  • 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

I have disabled inline schema resolving, by using useInlineModelResolver config option. And given the below specification (considering that the two models are not related, I don't need to have an interface/class generated, especially for response.):

responses:
  Unauthorized:
    description: Unauthorized
    content:
      application/json:
        schema:
          oneOf:
            - $ref: "#/components/schemas/InvalidCredentialsError"
            - $ref: "#/components/schemas/ExpiredTokenError"

The model name is still used in the @Schema annotation and causes compile time errors (seems disabling is not connected with name resolution):

@ApiResponse(responseCode = "401", description = "Unauthorized", content = {
    @Content(mediaType = "application/json",
    schema = @Schema(implementation = GetEchoById401Response.class)),
})

Expected:

@ApiResponse(responseCode = "401", description = "Unauthorized", content = {
    @Content(mediaType = "application/json",
    schema = @Schema(oneOf = {InvalidCredentialsError.class, ExpiredTokenError.class})),
})

Checked these issues which were somewhat related, but not fully: #2058, https://github.com/OpenAPITools/openapi-generator/issues/12838 and this PR: https://github.com/OpenAPITools/openapi-generator/pull/13056

openapi-generator version

7.11

OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix

JavaSpring/api.mustache#L174 - updating the template to support oneOf and other properties?

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 with the supplied oneOf specification and the useInlineModelResolver option, then inspect JavaSpring/api.mustache around line 174 and the code that resolves model names. Reproduce the generated @ApiResponse and compare it with the expected oneOf annotation; done means disabling inline resolution no longer produces the unresolved GetEchoById401Response model name.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.