question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG][JavaSpring] Not wanted automatic inserted tags if there're ones in OpenAPI definition

See original GitHub issue

11818_swagger-ui_online 11818_swagger-ui_springdoc

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

From the openapi definition (see below) when I open it in the online editor https://editor.swagger.io/ I get the following swagger-ui page. Only the tags present in the definition appear.

When I use the JavaSpring generator with the same openapi definition, the generated java interface contains @Tag annotation on the generated interface deduced from endpoint path, with automatic generated description value.

And the swagger-ui page display it in addition to the one already present in the definition.

I don’t want the generated tag because I define mine directly in the definition. I don’t found an option (in the documentation nor in the api.mustashe) to avoid this generation.

openapi-generator version

v5.4.0

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: API example
  version: "1.0.0"
  description: "OpenAPI definition to illustrate the issue xxx"
tags:
  - name: authentication
    description: "All API concerning authentification."
paths:
  /auth/login:
    get:
      tags:
        - authentication
      summary: API for login
      operationId: authLogin
      security: []
      parameters: []
      responses:
        '200':
          description: "OK"
          content:
            text/html:
              schema:
                type: string
        '401':
          description: "Unauthorized"
          content:
            text/html:
              schema:
                type: string
Generation Details

The genererated interface contains :

@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
@Validated
@Tag(name = "auth", description = "the auth API")
public interface AuthApi {
[...]
    /**
     * GET /auth/login : API for login
     *
     */
    @Operation(
        operationId = "authLogin",
        summary = "API for login",
        tags = { "authentication" },
        [...]
Steps to reproduce

Clear

Related issues/PRs

Clear

Suggest a fix

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
pichlaucommented, Mar 14, 2022

When I use this option, the generated interface name start with the tag name AuthenticationApi instead of the endpoint name AuthApi., ok but that is not what I want. And the automatic annotation @Tag(name="Authentication", description)"the Authentication API" is still generated above the interface declaration, and it is this annotation that causes the wrong tag entry in swagger-ui.

The expected output should be :

@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
@Validated
public interface AuthApi {

=> without any tag annotation on the interface if there are tags in the openapi definition

In the openapi yaml definition the tags are associated only with operations /auth/login, not with the root path of endpoints /auth, so I think we can’t associate to the interface AuthApi the tag present in the definition.

Moreover, an operation can receive several tags. In the definition with the prefix auth, I can definine an operation auth/login with the tag authentication and another operation auth/status without any tag so that the generator should not affect the tag authentication neither to the common root auth nor to the AuthApi interface.

I feel like there should just be a new option disableTagAnnotation (default to false for backward compatibility) to not generate the @tag annotation on interfaces.

0reactions
jkoortscommented, Dec 2, 2022

You need to fork this openapi-generator application from github. Change the code and compile your own binaries and use that.

On Fri, 2 Dec 2022, 11:50 anitha2010, @.***> wrote:

Fork, then remove:

@tag https://github.com/tag(name = “{{{baseName}}}”, description = {{#tagDescription}}“{{{.}}}”{{/tagDescription}}{{^tagDescription}}“the {{{baseName}}} API”{{/tagDescription}})

from api.mustache

@jkoorts https://github.com/jkoorts Do you add any custom file to remove the code from api.mustache because i dont see any file"api.mustache" in my project

— Reply to this email directly, view it on GitHub https://github.com/OpenAPITools/openapi-generator/issues/11818#issuecomment-1335001729, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACPLRZJUQJER6BWLLCXYPUTWLHA7ZANCNFSM5QDOVLHA . You are receiving this because you were mentioned.Message ID: @.***>

Read more comments on GitHub >

github_iconTop Results From Across the Web

Grouping Operations With Tags - Swagger
You can assign a list of tags to each API operation. Tagged operations may be handled differently by tools and libraries. For example,...
Read more >
Using OpenAPI and Swagger UI - Quarkus
Roughly 15 minutes. An IDE. JDK 11+ installed with JAVA_HOME configured appropriately. Apache Maven 3.8.6. Optionally the Quarkus CLI if you want to...
Read more >
Adding tags to an API - IBM
You can include tags in API definition. Such tags are added to the OpenAPI definition of the API but are not used by...
Read more >
OpenAPI Specification v3.0.3 | Introduction, Definitions, & More
The order of the tags can be used to reflect on their order by the parsing tools. Not all tags that are used...
Read more >
F.A.Q - Springdoc-openapi
How can I define multiple OpenAPI definitions in one Spring Boot project? ... OAS 3 was released in July 2017, and there was...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found