openapi-generator-maven-plugin code gen from http - swagger

Can we pass input yml specification HTTP URL in openapi-generator-maven-plugin?
I wanted to keep the input specification and generated code in sync.

Yes, with openapi-generator-maven-plugin that is possible by simply giving URL including protocol as inputSpec:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.4.0</version>
<executions>
<execution>
...
<configuration>
<inputSpec>https://petstore3.swagger.io/api/v3/openapi.yaml</inputSpec>
...
</configuration>
</execution>
</executions>
</plugin>
Updating plugin version might be necessary.

Related

Strange issue with TomEE 8.0.4 and OpenApi extension (Swagger-UI 1.0.3)

I'm using TomEE microprofile and have defined my rest application path this way:
#ApplicationPath("api")
public class RestConfiguration extends Application {
}
When the application is deployed, tomee log shows the access url to the generated front end resources:
Service URI: http://localhost:8080/api/openapi-ui/
When accesing the url got this message in the swagger-ui web page:
Fetch error undefined /openapi
If I change the application path to empty:
#ApplicationPath("")
Then all works fine and swagger shows all of the service method definitions.
So, what should I do to make it work adding "api" to the ApplicationPath annotation?
Tried with "/api", but doesn't work either.
I made the test here with Tomee-8.0.4, follow the configurations, assumed that you that is using a JAR.
in your pom.xml use the dependency:
<dependency>
<groupId>org.microprofile-ext.openapi-ext</groupId>
<artifactId>openapi-ui</artifactId>
<version>1.1.3</version>
</dependency>
<build>
<finalName>tomee-demo</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomee.maven</groupId>
<artifactId>tomee-maven-plugin</artifactId>
<version>${tomee.version}</version>
<executions>
<execution>
<id>executable-jar</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<context>ROOT</context>
<tomeeClassifier>microprofile</tomeeClassifier>
</configuration>
</plugin>
</plugins>
</build>
in microprofile-config.properties use:
mp.openapi.servers=http://localhost:8080/api
openapi.ui.yamlUrl=/api/openapi
openapi.ui.serverVisibility=visible
and run your project again.
test performed
reference:
https://github.com/microprofile-extensions/openapi-ext/tree/master/openapi-ui

How to download multi files from swagger

I've an issue when try to download file from swagger.
When I compiled a code with config below, I got an error:
Could not find goal 'download' in plugin io.swagger:swagger-codegen-maven-plugin:2.3.1 among available goals generate
I've tried to break to 2 plugins and it compiles successfully, but just one file is downloaded.
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>download</goal>
</goals>
<configuration>
<api>Addresses</api>
<owner>test</owner>
<version>2.13.0</version>
<format>yaml</format>
<token>test</token>
<outputFile>${address-service-swagger.file}</outputFile>
</configuration>
</execution>
<execution>
<id>aec</id>
<phase>generate-sources</phase>
<goals>
<goal>download</goal>
</goals>
<configuration>
<api>Shipper</api>
<owner>test</owner>
<version>2.13.0</version>
<format>yaml</format>
<token>test</token>
<outputFile>${shipper-service-swagger.file}</outputFile>
</configuration>
</execution>
</executions>
</plugin>
By the way, I want to define outputFile is a file in the folder target, and I've tried to change outputFile by the target path, but It compiles fail. Do you have any idea for this case?
Thank you for your helps
As mentioned in the comments, to download API definitions from SwaggerHub you need to use the swaggerhub-maven-plugin, not swagger-codegen-maven-plugin.
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swaggerhub-maven-plugin</artifactId>
...
</plugin>
You are using the wrong plugins and you can do like this
If your swaggerhub api link is like this https://app.swaggerhub.com/apis/massivebet/betting/0.9.0 then you config this and run
mvn clean generate-resources to download as yaml file
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swaggerhub-maven-plugin</artifactId>
<version>1.0.8</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>download</goal>
</goals>
<configuration>
<api>betting</api>
<owner>massivebet</owner>
<version>0.9.0</version>
<host>api.swaggerhub.com</host>
<format>yaml</format>
<token>your token if private apis</token>-->
<outputFile>target/test.yaml</outputFile>
</configuration>
</execution>
</executions>
</plugin>

Spring Boot Maven Plugin

I have two classes with main method and one loads the security configuration and the other does not. In order to create two artifacts - secure and non secure jars, I am doing something like the following :
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>1</id>
<configuration>
<mainClass>a.b.c.Secured</mainClass>
<finalName>secured</finalName>
<classifier>secured</classifier>
</configuration>
</execution>
<execution>
<id>2</id>
<configuration>
<mainClass>a.b.c.NonSecured</mainClass>
<finalName>non-secured</finalName>
<classifier>nonSecured</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
And I am seeing the exception -
java.lang.IllegalStateException: Unable to find a single main class from the following candidates.
Can you please let me know, if there is some thing wrong with the above configuration? I may be able to use maven profiles to create different artifacts. However, I wanted to understand the problem with the above configuration. Any help will be greatly appreciated.
I think both those configurations are active at the same time (otherwise how do you tell maven which one to use?). You could put them both in Maven profiles.

Does -nexclude work when using JiBX as the CXF databining?

I am trying to get CXF (2.7.7) to use JiBX (1.2.5) for databinding. The documentation is a bit sketchy, but there have been reports of success with it. One problem is that CXF does not pass configuration to the JiBX code generator, so if you need to do something that requires customization, such as mapping Joda DateTime to XML Schema date, you need to be able to tell CXF to ignore specific namespaces and then handle those with a separate call to JiBX.
The examples I have seen use the CXF -nexclude flag for this purpose, as in
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>generateSources</id>
<phase>generate-sources</phase>
<goals>
<goal>wsdl2java</goal>
</goals>
<configuration>
<sourceRoot>${generated-sources.dir}/cxf</sourceRoot>
<wsdlRoot>${wsdl.dir}</wsdlRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${wsdl.dir}/GetCounters.wsdl</wsdl>
<dataBinding>jibx</dataBinding>
<extraargs>
<extraarg>-nexclude</extraarg>
<extraarg>http://www.example.com/counters/</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
</execution>
</executions>
</plugin>
I have tried both inline and imported versions of the namespace but the -nexclude flag does not appear to work with JiBX. One option might be to let JiBX do the whole WSDL without invoking the CXF plugin, but apparently this creates problems in the generated service code. An ugly workaround might be to let JiBX regenerate the code for just the classes in this namespace, overwriting the code created by CXF.
Can the -nexclude flag be made to work?
I was having a similar problem while using jaxb. This worked for me:
move the extraargs out of the wsdlOption section and into the defaultOptions section.
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cfx.codegen.version}</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<defaultOptions>
<extraargs>
<extraarg>-nexclude</extraarg>
<extraarg>http://domain.company.org/v1/schema1</extraarg>
<extraarg>-nexclude</extraarg>
<extraarg>http://domain.company.org/v1/schema2</extraarg>
</extraargs>
</defaultOptions>
<wsdlOptions>
<wsdlOption>
<wsdlArtifact>
<groupId>org.company</groupId>
<artifactId>application-contract</artifactId>
<version>${contract.version}</version>
<type>wsdl</type>
</wsdlArtifact>
</wsdlOption>
</wsdlOptions>
<sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>

Maven not honoring excludes

We have this in our pom
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<id>assembly</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<excludes>
<exclude>app/**</exclude>
<exclude>WEB-INF/**</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>assembly-web</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>web</classifier>
<includes>
<include>app/**</include>
<include>WEB-INF/**</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
When I open the xxx-web.jar it looks as expected, but when I look at xxx.jar it includes everything/didn't exclude anything. If I were to add a classified to the 1st plugin (the one with the excludes) then it works properly???
I want this to work in such a way that the xxx.jar has all the class and property files and the xxx-web only has the jsp/css files.
Take a look at 7.1.6 in this maven document. Basically you need to bind to the default goal of "default-jar".
HTH
Take a look at this: Maven and working with legacy app there you will find the complete solution for your problem.
You're telling maven to execute twice with each <execution> command. Try putting the includes and excludes under the same execution.

Resources