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

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?

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.

Now that version 5.3.1 of the plugin is released, I used the information from https://github.com/OpenAPITools/openapi-generator/pull/9775 and https://github.com/OpenAPITools/openapi-generator/issues/6108 to make it work for me.
I added the three configOptions in the pom.xml:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.3.1</version>
<configuration>
<!-- other config omitted -->
<configOptions>
<oas3>true</oas3>
<useSpringController>true</useSpringController>
<useSpringfox>false</useSpringfox>
</configOptions>
</configuration>
</plugin>
After that, it may be necessary to add another dependency as a workaround, because the plugin adds unused imports into the generated code.
<dependency>
<!-- try to remove this dependency when a new version (5.3.1+) of the openapi-generator plugin is available -->
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.6.3</version>
</dependency>
I am using the springdoc-openapi-ui dependency.
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.3</version>
</dependency>

Related

How to include kotlin.test properly via Maven?

Our team is making first steps into Kotlin and I'm about to to migrate a test. I tried a first example from mockk (https://github.com/mockk/mockk/blob/master/mockk/common/src/test/kotlin/io/mockk/it/InjectMocksTest.kt). For some reason it seems I'm not able to use kotlin.test although I have added it via maven. Do I have to include any other modules? Or do I have to change something else?
(the mockk example uses Gradle so it doesn't help me).
This is what I'd like to use in my Kotlin test file but it which can't be found (at least not the packages I need):
(Restarting Intellij doesn't help, neither running mvn seperately)
This is my maven dependancy (Intellij shows now error):
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version> <!-- kotlin.version == 1.7.0 -->
<scope>test</scope>
</dependency>
The solution was (see hotkey's answer) to add the following maven dependency:
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit5</artifactId>
<version>1.7.0</version>
<scope>test</scope>
</dependency>
You need to add a dependency on one of kotlin-test-junit (for JUnit 4), kotlin-test-junit5 (for JUnit Jupiter), or kotlin-test-testng (for TestNG), depending on what test framework you are using.
The artifact kotlin-test contains only the common code, asserters and other stuff that can be reused across the frameworks.
The kotlin.test annotations like #Test or #BeforeTest are shipped in the test-framework-specific artifacts as typealiases to the actual annotations types of the test frameworks.

Swagger Jersey project, openapi.json is missing "maximum" and "minimum" etc

Jersey project using following Swagger Core:
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2</artifactId>
<version>2.0.2</version>
</dependency>
open and compare "path/openapi.json" and "path/swagger.json", openapi.json is missing information like "maximum" and "minimum". for some reason I have to use openapi.json instead of swagger.json. Please refer to the image below.

Jersey version issue: MessageBodyReader not found for media type=application/xml

While writing a simple Jersey client that was consuming XML data, I came across this exception "MessageBodyReader not found for media type=application/xml". All of my settings, including the jersey-client as maven dependencies was just fine.
The version that I was using was 2.17. Once I degraded the version to 2.15 it started working fine. Can anyone explain what dependencies that needs to be included for version 2.17 to work.
Maven Dependency (works on 2.15 and lower)
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey.version}</version>
</dependency>
Java Code Snippet for consuming the service
Client c = ClientBuilder.newClient();
WebTarget target = null;
target = c.target(Main.BASE_URI_XML);
String customerId = "415D7AB5";
XYZ response = target.path(customerId).request(MediaType.APPLICATION_XML).get(XYZ.class);
Have a look at 27.3. Migrating from Jersey 2.15 to 2.16
27.3.1.1. JAX-B providers separated from the core
From version 2.16 onwards, all JAX-B providers are being bundled in a separate module.
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-jaxb</artifactId>
<version>2.17</version>
</dependency>

Maven dependencies needed for Jersey 2.x (2.6)

I'm trying to migrate from Jersey 1.x (1.2) to 2.x (2.6), I have trouble identifying the exact maven dependencies, jersey documentation is not comprehensive enough, it doesn't mention what maven dependencies are needed for the new version.
Does anyone have comprehensive list of maven dependencies needed for Jersey 2.x (2.6)?
Jersey doc
https://jersey.java.net/documentation/latest/migration.html#mig-1.x
For a servlet environment, the only dependency you need is
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.6</version>
</dependency>
This will pull in all you need. If you are in a servlet 2.5 environment, then you would use this instead
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.6</version>
</dependency>
Further information about 2.5 servlet, can be seen here
Alternatively, you could create a project from a Maven archetype, as seen here
UPDATE
Just as a note, the significance of using Jersey 2.6 is that it is the last version to support Java 6. If this is not a requirement for you, I would recommend using the latest version.

How to include custom type converter using Maven and Grails

I am working on a Grails project that needs to compile with both Grails and Maven. Everything worked great except for my GSON converter I added (using the grails-gson plugin). Now I get the following when I run mvn install.
unable to resolve class grails.plugin.gson.converters.GSON
Anyone know how to overcome this
Plugin has to be added as a dependency in pom.xml too
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>gson</artifactId>
<version>1.1.4</version>
<type>zip</type>
</dependency>
Mavenized grails project refer pom file for all dependencies (including plugin dependencies).

Resources