How to use OAS file (from swaggerhub) instead of spec present in src/main/resources "<InputSpec>" tag in Open API Generator Maven Plugin - openapi-generator-maven-plugin

This is my pom. Here, in the "inputSpec" tag I want to pass the url that returns the OAS yaml file of my project from our company swaggerhub, instead of pointing it to the spec file on src/main/resource. Issue is inorder to access the spec file through that url, it requires me to pass the bearer token. Is there a way to do that (provide the token on the pom somewhere or something like that) ? Has anyone faced similar situation?
<plugins>
<plugin>``
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.1.1</version>
<executions>
<execution>
<id>generate-sources-client</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/test.yaml</inputSpec>
<generatorName>java</generatorName>
<generateApiDocumentation>false</generateApiDocumentation>
<generateApis>true</generateApis>
<generateModels>true</generateModels>
<generateSupportingFiles>true</generateSupportingFiles>
<library>resttemplate</library>
<configOptions>
<java8>true</java8>
<dateLibrary>java8</dateLibrary>
</configOptions>
<library>resttemplate</library>
<output>${project.basedir}</output>
<apiPackage>com.test.api</apiPackage>
<modelPackage>com.test.model</modelPackage>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Related

Is it possible to generate multiple HTML reports with different configuration after the same execution? jmeter-maven-plugin

I'm using jmeter's maven plugin and I would like to generate two different HTML reports from the same execution log. Is it even possible to do this using this plugin?
This is my pom.xml and I'm not sure how to create a second report with a different output folder and title for example.
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>${jmeter.plugin.version}</version>
<executions>
<execution>
<id>configuration</id>
<goals>
<goal>configure</goal>
</goals>
</execution>
<execution>
<id>tests</id>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
<execution>
<id>check-results</id>
<goals>
<goal>results</goal>
</goals>
</execution>
</executions>
<configuration>
<propertiesUser>
<thread.number>${thread.number}</thread.number>
<rampup>${rampup}</rampup>
<jmeter.reportgenerator.report_title>CA Dashboard</jmeter.reportgenerator.report_title>
</propertiesUser>
<ignoreResultFailures>true</ignoreResultFailures>
<generateReports>true</generateReports>
</configuration>
</plugin>
</plugins>
</build>
Currently no, the report generation happens at the same time the test is run.
When the following issues have been fixed it may be an option:
https://github.com/jmeter-maven-plugin/jmeter-maven-plugin/issues/328
https://github.com/jmeter-maven-plugin/jmeter-maven-plugin/issues/391
https://github.com/jmeter-maven-plugin/jmeter-maven-plugin/issues/316

Maven Swagger swagger-codegen-plugin only generate model and controller

I'm using maven-codegen-plugin just to generate from my yml file the interface for the controller and model files. This is a java spring-boot proyect.
The pluging Configuration:
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.4.10</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/api.yml</inputSpec>
<output>${project.build.directory}/generated-sources/swagger</output>
<language>spring</language>
<configOptions>
<java8>true</java8>
<interfaceOnly>true</interfaceOnly>
<dateLibrary>java</dateLibrary>
</configOptions>
<modelPackage>${project.groupId}.blabla.model</modelPackage>
<apiPackage>${project.groupId}.blabla.controller</apiPackage>
</configuration>
</execution>
</executions>
</plugin>
The point is that within my target/generated-sources directory/swagger is generating a lot of files that I don't need such as:
.swagger-codegen/Version
.swagger-codegen-ignore
pom-xml
README.md
The files that I just needs are the files generated within src/main/java.... basically Model and controller packages.
How i can configure the plugging not to generate such files?
Thank you in advance
You should add the following code:
<configuration>
<skipOverwrite>true</skipOverwrite>
</configuration>
To avoid the pom.xml and readme.md to be overwritten
and the rest of the files under .gitIgnore

Mockserver maven plugin: init mockserver expectations from file

I'm using Mockserver maven plugin to mock some requests for integration tests.
My pom.xml looks like:
...
<plugin>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-maven-plugin</artifactId>
<version>5.5.1</version>
<configuration>
<serverPort>1080</serverPort>
<logLevel>DEBUG</logLevel>
<initializationClass>com.mycompany.ExampleInitializationClass</initializationClass>
</configuration>
<executions>
<execution>
<id>run-mockserver</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-mockserver</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
...
Problem here is that I have to provide expectations using a class (com.mycompany.ExampleInitializationClass) and I want to provide expectations using a JSON file like described here:
http://www.mock-server.com/mock_server/initializing_expectations.html
I didn't find any way in the plugin configuration to initialize the Mockserver with the property:
-Dmockserver.initializationJsonPath
Is there any way to achieve that? Thanks in advance.
You just have to define initializationJson property specifying path to JSON file with expectations:
<plugin>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-maven-plugin</artifactId>
<version>5.5.1</version>
<configuration>
<serverPort>1080</serverPort>
<logLevel>DEBUG</logLevel>
<initializationJson>expectations.json</initializationJson>
</configuration>
<executions>
...
</executions>
</plugin>
The catch here is that the file path is relative to testClasspath directory (e.g. ${project.basedir}/target/test-classes/), so you have to copy the expectation file there. You may use e.g. maven-antrun-plugin for this (as below) or
maven-resources-plugin.
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<copy file="your/expectations.json" todir="${project.basedir}/target/test-classes/"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>

maven-replacer-plugin to replace tokens in build and not source

I am trying to use the maven-replacer-plugin to replace tokens in my web.xml when it is built in the WAR file but not in the source, which would remove the tokens for subsequent builds and show the file as changed relative to the version control repository.
Currently, I am only able to change the file in the source, which does not meet my requirement:
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.2</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<file>${project.basedir}/src/main/webapp/WEB-INF/web.xml</file>
<replacements>
<replacement>
<token>##sec.level##</token>
<value>local</value>
</replacement>
</replacements>
</configuration>
</plugin>
Question: How can I run the replacer to only change the file in the WAR package while leaving the source unchanged for subsequent builds?
You can use the exploded goal of the maven-war-plugin to get to a temporary folder (like whatever created under target actually) the exploded version of what would later on be part of the final war file, then execute the replacer plugin on this file (a safe copy, not in conflict with other plugins consuming the file).
This approach is actually also documented by the official replacer plugin doc
That is, having a similar configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<useCache>true</useCache>
</configuration>
<executions>
<execution>
<id>prepare-war</id>
<phase>prepare-package</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.2</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<file>${project.build.directory}/${project.build.finalName}/WEB-INF/web.xml</file>
<token>##sec.level##</token>
<value>local</value>
</configuration>
</plugin>
Note: the replacer documentation also suggests to use the useCache option which should prevent the plugin to override what the exploded goal previously created. However, the option doesn't really suit this purpose.
Similarly, the following approach would instead work according to my tests:
Use the exploded goal of the maven-war-plugin to create a temporary copy of the future war file in a <war_name>-tmp directory under target: that's not an issue, whatever is under target is supposed to be discarded via a clean command anyway
Configure the replacer plugin to replace that copy of the web.xml file
Configure the default war goal using its webXml option to point to that web.xml file for its final war file
The following would apply the approach described above:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<!-- explode the future war content for pre-package processing -->
<id>prepare-war</id>
<phase>prepare-package</phase>
<goals>
<goal>exploded</goal>
</goals>
<configuration>
<webappDirectory>${project.build.directory}/${project.build.finalName}-tmp</webappDirectory>
</configuration>
</execution>
<execution>
<!-- use the same execution id to further configure the default binding and execution -->
<id>default-war</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
<configuration>
<!-- during the package phase, use the processed web.xml file -->
<webXml>${project.build.directory}/${project.build.finalName}-tmp/WEB-INF/web.xml</webXml>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.2</version>
<executions>
<execution>
<!-- apply pre-package processing on web resources -->
<id>process-web-resources</id>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<file>${project.build.directory}/${project.build.finalName}-tmp/WEB-INF/web.xml</file>
<token>##test##</token>
<value>local</value>
</configuration>
</plugin>

how to define an additional source directory in maven-apt-plugin

We have some of our JPA entities generated in target/java directory during maven goal "generate". But not all of them are generated, as some of them are in our src/main/java directory. Is there any way to configure the plugin to specify more than one source directory?
I have tried with <additionalSourceRoots>target/java<additionalSourceRoots> but it does not work. I halve also tried to add target/java but then this is the only directory that is processed to the other JPA entities that are in the main code that are not generated are not processed.
I know I could try a workaround trying to copy the generated sources to another directory and putting there the other entities as well, but I am wondering if there is a "clean" solution for this.
EDITED
After Andrey answer I have tried this as well, but still does not work. maven-apt-plugin cannot see the classes generated classes located in target/java. I have tried with <additionalSourceRoots> with different syntax without any luck.. :(
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>maven-apt-plugin</artifactId>
<version>1.0.2</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<additionalSourceRoots>
<additionalSourceRoot>target/java</additionalSourceRoot>
</additionalSourceRoots>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
Thanks
Maven build helper pligin will do the job.
Then just add more source roots in maven-apt-plugin with "additionalSourceRoots" parameter.
Our problem was that we had some classes in directory1 and directory2 that was used by the classes in directory3. The classes in directory3 was the classes with JPA annotations. We also found that it is important to put the directory with JPA annotated classes as the last directory, otherwise there was no classes generated by the apt plugin.
Surprisingly enough I tried to add additional sourceDirectory tags and it worked for me:
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>maven-apt-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>process</goal>
</goals>
<configuration>
<sourceDirectory>__directory1__</sourceDirectory>
<sourceDirectory>__directory2__</sourceDirectory>
<sourceDirectory>__directory3__</sourceDirectory>
<outputDirectory>target/generated-sources</outputDirectory>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>

Resources