Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open API code generator Maven plugin uses old Swagger 2 annotations instead of Swagger 3 annotations

I'm using Open API code generator Maven plugin to generate Open API 3.0 from a file. I'm using this plugin in in my pom.xml:

<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.3.0</version>

The plugin generates the API without any issues but instead of using Swagger v3 annotations it uses old Swagger annotations. For example parameters are annotated using @ApiParam, instead @Parameter annotation should be used from io.swagger.v3.oas.annotations package:

default ResponseEntity<Fault> getFault(@ApiParam(value = "",required=true) @PathVariable("jobId") String jobId) {

Because of it the latest Swagger UI isn't showing the documentation correctly. When I create an endpoint using swagger.v3 annotations then Swagger UI is working properly.

According to the official website https://openapi-generator.tech/docs/plugins/ , I should include this dependency:

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

But even with this dependency the plugin still generates sources with the old annotations.

How can I force Open API code generator to use Swagger v3 annotations?

like image 594
Michael Dz Avatar asked Dec 19 '25 09:12

Michael Dz


1 Answers

V3 annotations are not supported at this moment.

You need to override mustache templates.

Check these PRs:
https://github.com/OpenAPITools/openapi-generator/pull/4779
https://github.com/OpenAPITools/openapi-generator/pull/6306

more info:
https://github.com/OpenAPITools/openapi-generator/issues/6108
https://github.com/OpenAPITools/openapi-generator/issues/5803

You can use upgraded templates from PRs above or wait when merged.

like image 95
Shaolin Avatar answered Dec 21 '25 00:12

Shaolin