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][Java][Spring] Multiple "tags" parameters in @Operation annotation

See original GitHub issue

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

The OpenAPI generator generates invalid Java SpringBoot code if multiple tags are used in the OpenAPI definition. The generated @Operation annotation contains all the tags multiple times, depending on how many tags are present.

Here is an example:

    @Operation(
        operationId = "dummyoperation",
        tags = { "tag1", "tag2" },
        tags = { "tag1", "tag2" }, // <- this is the invalid duplicate
        responses = {
            @ApiResponse(responseCode = "200", description = "successful operation")
        }
    )

This is generated with the latest stable version 5.4.0. We are using spring-boot generator. This is an example project, which demonstrates the error: maven-openapi-generator-poc.zip

OpenAPI declaration file
openapi: 3.0.1
info:
  description: Proof of error
  title: Proof of error
  version: 0.0.1
servers:
- url: http://localhost:8090/api/v1
- url: https://localhost:8090/api/v1
paths:
  /dummy:
    post:
      operationId: dummyoperation
      responses:
        "200":
          content: {}
          description: successful operation
      tags:
        - tag1
        - tag2
Maven project description
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>maven-openapi-generator-poc</artifactId>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.3</version>
        <relativePath/>
    </parent>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>io.swagger.core.v3</groupId>
            <artifactId>swagger-annotations</artifactId>
            <version>2.1.12</version>
        </dependency>
        <dependency>
            <groupId>org.openapitools</groupId>
            <artifactId>jackson-databind-nullable</artifactId>
            <version>0.2.2</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-yaml</artifactId>
            <version>2.13.1</version>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>2.0.1.Final</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>5.4.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>src/main/resources/openapi.yaml</inputSpec>
                            <generatorName>spring</generatorName>
                            <configOptions>
                                <interfaceOnly>false</interfaceOnly>
                                <basePackage>org.example.base</basePackage>
                                <configPackage>org.example.config</configPackage>
                            </configOptions>
                            <library>spring-boot</library>
                            <output>${project.build.directory}/generated-sources</output>
                            <apiPackage>org.example.api</apiPackage>
                            <modelPackage>org.example.model</modelPackage>
                            <invokerPackage>org.example.invoke</invokerPackage>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>
Generation Details
  • Maven SpringBoot project
Steps to reproduce

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
wing328commented, Feb 10, 2022

@apr4 can you please try the latest master? We just merged a PR related to multiple “tags” for the spring generator.

0reactions
GregDThomascommented, Sep 15, 2022

A workaround is to download the template in the PR at https://github.com/OpenAPITools/openapi-generator/pull/13434 and place a copy locally in a folder called JavaSpring, and specify it when generating code as described at https://openapi-generator.tech/docs/templating/

e.g. -t (wherever)\templates\JavaSpring

Hopefully the PR will be accepted and in a release soon 🤞

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to annotate to require individual elements of requestBody ...
oas.annotations.parameters.RequestBody from the Swagger library, you'll still need to use the org.springframework.web.bind.annotation.
Read more >
Operation (swagger-annotations 2.0.0-rc3 API)
The annotation may be used to define a resource method as an OpenAPI Operation, and/or to define additional properties for the Operation.
Read more >
Setting Example and Description with Swagger - Baeldung
Learn how to use Swagger annotations to make documentation more ... We'll add descriptions to the methods, parameters, and response codes.
Read more >
Chapter 6. Aspect Oriented Programming with Spring
Many AOP frameworks, including Spring, model an advice as an interceptor, ... type of the actual arguments passed have annotations of the given...
Read more >
Annotations — FOSHttpCacheBundle Documentation
See Invalidation for more information. @InvalidateRoute ¶. Like InvalidatePath annotations, you can use PHP attributes instead if you are using PHP 8 Invalidate ......
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