Skip to content

Maven Plugin: "jaxrs-spec" generator doesn't allow to specify the "annotationLibrary" --> Stubs wont compile #14543

@ziomill

Description

@ziomill

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 Generator generates java classes that won't compile when the spec file includes NXX response codes. For example:

openapi: 3.0.3
...
...
      responses:
        '5XX':
          description: INTERNAL SERVER ERROR
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OrdersCheckoutSagaApiErrorResponse'
...
...

The Generator uses the dependency:

<dependency>
    <groupId>io.swagger.parser.v3</groupId>
    <artifactId>swagger-parser</artifactId>
</dependency>

generating the import:

import io.swagger.annotations.*;

into the generated stub:

import it.millsoft.orders.checkout.saga.api.interfaces.rest.model.CheckoutRequest;
import it.millsoft.orders.checkout.saga.api.interfaces.rest.model.OrdersCheckoutSagaApiErrorResponse;

import javax.ws.rs.*;
import javax.ws.rs.core.Response;

import io.swagger.annotations.*;

import java.io.InputStream;
import java.util.Map;
import java.util.List;
import javax.validation.constraints.*;
import javax.validation.Valid;

@Path("/order/checkout")
@Api(description = "the OrdersCheckoutSagaRest API")
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen", date = "2023-01-27T17:44:44.287439+01:00[Europe/Rome]")
public class OrdersCheckoutSagaRestApi {

    @POST
    @Consumes({ "application/json" })
    @Produces({ "application/json" })
    @ApiOperation(value = "Start new checkout order Saga", notes = "", response = String.class, tags={ "OrdersCheckoutSagaRest" })
    @ApiResponses(value = { 
        @ApiResponse(code = 200, message = "OK - The ID of the Order that has been created", response = String.class),
        @ApiResponse(code = 5XX, message = "INTERNAL SERVER ERROR", response = OrdersCheckoutSagaApiErrorResponse.class) // THIS DOESN''T COMPILE!!!!
    })
    public Response checkout(@Valid @NotNull CheckoutRequest checkoutRequest) {
        return Response.ok().entity("magic!").build();
    }
}

The @apiresponse annotation only supports the code field as Integer, resulting in not being compatible with the "NXX" format.

openapi-generator version

Using the maven plugin:

<plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>6.2.1</version>
</plugin>
OpenAPI declaration file content or url
Generation Details
<plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>6.2.1</version>
                <executions>
                    <execution>
                        <id>execution-openapi-server</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${basedir}/src/main/resources/static/openapi/server/v0/orders_checkout_saga_api___openapi_interfaces__v0.yaml</inputSpec>
                            <output>${basedir}</output> <!-- Needed in order to generated classes in the artifcat -->
                            <generatorName>jaxrs-spec</generatorName>
                            <generateSupportingFiles>false</generateSupportingFiles>
                            <configOptions>
                                <library>quarkus</library>
                                <sourceFolder>src/main/java</sourceFolder>
                                <basePackage>it.mycompany.orders.checkout.saga.api.interfaces.rest</basePackage>
                                <apiPackage>it.mycompany.orders.checkout.saga.api.interfaces.rest.endpoints</apiPackage>
                                <modelPackage>it.mycompany.orders.checkout.saga.api.interfaces.rest.model</modelPackage>
                                <useBeanValidation>true</useBeanValidation>
                                <performBeanValidation>false</performBeanValidation>
                                <serializableModel>true</serializableModel>
                                <useTags>true</useTags>
                                <additionalModelTypeAnnotations>@lombok.Data @lombok.Builder @lombok.NoArgsConstructor @lombok.AllArgsConstructor</additionalModelTypeAnnotations>-->
                                <useSwaggerAnnotations>true</useSwaggerAnnotations>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
Steps to reproduce

Try to generate server stubs by using the open API generator maven plugin with the provided configuration

Suggest a fix

The jaxrs-spec generator should support the "annotation library" configuration, like the "spring" generator, giving the chance to use the "swagger 2" annotations

The plugin should switch to the new swagger dependencies version, which supports the NXX response code format through the annotation io.swagger.v3.oas.annotations.responses.ApiResponse.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions