OpenAPITools / OpenAPITools/openapi-generator

[BUG] [JAVA] [OKHTTP-GSON] Annotations added at invalid location since 7.13.0 regression

Open
#21,358 0 comments 2 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?
  • 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

The openapi.yaml specification I used for 7.12.0 did not produce any compilation errors, whereas updating to 7.13.0 without any other change results in the following compile-time exception inside each of the fooApi.java:
no annotations are allowed in the type of a class literal.

The exception occurs inside each getXXValidateBeforeCall on the following line:
Method method = this.getClass().getMethod("getXXWithHttpInfo", @jakarta.annotation.Nonnull String.class, @jakarta.annotation.Nonnull String.class);

The error is caused by the @jakarta.annotation.Nonnull annotation on the type String.class. This annotation is probably applied in our case since we have a path parameter set with required: true

openapi-generator version

Since 7.13.0. This is a regression.

OpenAPI declaration file content or url
  /foo/{bar}:
    get:
      tags:
      - baz
      operationId: getXX
      parameters:
      - name: bar
        in: path
        required: true
        schema:
          type: string

-->

Generation Details

https://gist.github.com/Viserius/f1ecdd2e1d63669886aa5ee8a62c474c

Steps to reproduce

Should be evident from generation details and spec.
Have a path parameter of type string set to required: true.

Related issues/PRs

None that I know of

Suggest a fix

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 by reproducing the Java client generation from the linked generation details and the shown OpenAPI path parameter. Inspect the generated fooApi.java methods around getXXValidateBeforeCall and compare output from 7.12.0 and 7.13.0. Done means the generated client no longer places @jakarta.annotation.Nonnull on String.class and compiles successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
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.