How to fetch an OpenAPI YAML file from a private GitHub repository through token in settings.xml using OpenAPI Generator? - maven

Here is the pom.xml:
<plugin>
<artifactId>openapi-generator-maven-plugin</artifactId>
<executions>
<execution>
<configuration>
<configOptions>
<apiPackage>com.core.client</apiPackage>
<dateLibrary>java8</dateLibrary>
<modelPackage>com.core.client.model</modelPackage>
<packageName>co.core</packageName>
<sourceFolder>restclient</sourceFolder>
<useLombok>true</useLombok>
<useOptional>true</useOptional>
<useTags>true</useTags>
</configOptions>
<generateApiDocumentation>false</generateApiDocumentation>
<generateApiTests>false</generateApiTests>
<generateModelDocumentation>false</generateModelDocumentation>
<generateModelTests>false</generateModelTests>
<generatorName>java</generatorName>
<inputSpec>
GitHub link
</inputSpec>
<library>jersey2</library>
</configuration>
<goals>
<goal>generate</goal>
</goals>
<id>Generate client</id>
</execution>
</executions>
<groupId>org.openapitools</groupId>
<version>6.2.1</version>
</plugin>
I am using 6.2.1 version of the OpenAPI Generator Maven plugin.
I want to pull the <inputSpec> from a private GitHub repo and without giving the password/token in my pom.xml. Is there a way to pick it from settings.xml?

I wouldn't try to do this via the input spec. I think the best way would be to download the file separately, and put it in a defined location. Then, use that location and file name as your input spec.
This post describes how to execute a curl command to download a single file from a private repo.
curl -H 'Authorization: token INSERTACCESSTOKENHERE' -H 'Accept: application/vnd.github.v3.raw' -O -L https://api.github.com/repos/owner/repo/contents/path
The key here is adding the Authorization to the header of the request. The -O flag saves the file in the current location.
You can use the exec-maven-plugin to download your file via a maven command. Here's an example from another stackoverflow post explaining how to use it with a curl command.
Edit:
If you want to use an external properties file in gradle, you can reference it input Stream. for example:
def props = new Properties()
file("setting.yml").withInputStream { props.load(it) }
Now, in your exec-maven-plugin, you can set the header to use the token as follow
<argument>-H 'Authorization: token ${props.getProperty("access.token")}'</argument>

Related

Why does Swagger codegen tool generate different server stubs?

I want to generate jersey 2.0 server stub from a swagger api specification file. When using Swagger online codegen tool to generate server stub, I get a nice jersey server stub containing impl directory with clearly indicated places where I should put my business logic. Everything compiles and runs nicely.
However, when I try to generate jersey 2.0 server stub with swagger-codegen-maven-plugin, I cannot manage to get similar thing. This is the plugin config that I use in my pom.xml file:
<plugin>
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.35</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>src/main/resources/api.yaml</inputSpec>
<language>java</language>
<configOptions>
<sourceFolder>src/gen/java/main</sourceFolder>
<dateLibrary>java11</dateLibrary>
</configOptions>
<library>jersey2</library>
</configuration>
</execution>
</executions>
</plugin>
Server stub I get this way doesn't even use Jersey annotations and is not working out of the box. Generated README.md contains instructions that aren't clear and asks me to use plugins that don't exist on maven repository.
I would like to get a similar server stub as the one I get from the online tool, but the documentation isn't really clear on how to do that.
As it turns out, I needed to specify the language tag to have value jaxrs-jersey, like so:
<language>jaxrs-jersey</language>

How to generate and use a detekt baseline using the maven plugin?

I'm trying to use detekt in a multi-module Maven project using Kotlin with the detekt-maven-plugin.
Following the instructions found here to generate a baseline with the existing issues, I tried running:
mvn detekt:cb -Ddetekt.debug=true
This does not seem to produce the mentioned baseline.xml file however.
Turns out that the baseline filename must be specified when baseline is generated:
mvn detekt:cb -Ddetekt.baseline=baseline.xml
Since the code base already had quite a few issues found by detekt, I also had to use a custom detekt config file and increase the number of allowed issues - otherwise the build would fail and no baseline would be generated at all.
To summarize, the following configuration made it work:
detekt config file:
build:
maxIssues: 1000
Plugin configuration after the baseline was generated:
<plugin>
<groupId>com.github.ozsie</groupId>
<artifactId>detekt-maven-plugin</artifactId>
<version>1.1.1</version>
<configuration>
<baseline>detekt-baseline.xml</baseline>
<config>detekt-config.yml</config>
<buildUponDefaultConfig>true</buildUponDefaultConfig>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
After the baseline was generated, the maxIssuses value in the config file could be lowered to an appropriate value.

understanding goal exec in maven

I'm trying to create a native installer for javafx 8 application using the fxlauncher as explained at http://fxldemo.tornado.no/
In the pom.xml provided with the example, I do not understand what the execution embed-manifest-in-launcher is doing.
Question: Could someone please explain whats happening there?
The first execution is straight forward, it has specified a java class which has main method and provided the arguments.
<execution>
<id>create-manifest</id>
<phase>package</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>fxlauncher.CreateManifest</mainClass>
<arguments>
<argument>${app.url}</argument>
<argument>${app.mainClass}</argument>
<argument>${app.dir}</argument>
</arguments>
</configuration>
</execution>
<!-- Embed app.xml inside fxlauncher.xml so we don't need to reference app.xml
to start the app -->
<execution>
<id>embed-manifest-in-launcher</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>jar</executable>
<workingDirectory>${app.dir}</workingDirectory>
<arguments>
<argument>uf</argument>
<argument>fxlauncher.jar</argument>
<argument>app.xml</argument>
</arguments>
</configuration>
</execution>
The comment just above the execution is already providing a first hint:
Embed app.xml inside fxlauncher.xml so we don't need to reference app.xml to start the app
The executable configuration entry is set to jar, so it will run the jar command.
It will then pass to it the parameters uf, from the jar help command we can see that:
-u update existing archive
-f specify archive file name
Hence, the f option is also expecting a parameter, which is indeed the fxlauncher.jar entry.
As such, the full command which will be executed would be:
jar uf fxlauncher.jar app.xml
Which will update the existing and provided fxlauncher.jar file adding to the app.xml file, as per comment above.
Such execution has a binding to the package phase in a project with packaging jar (the default one, hence no need to specify it), which will be executed after the default bindings to this packaging for this phase (the Maven Jar Plugin, for instance). Hence the build will firstly create/package the jar file, then run these executions to change/update it.

Use maven-exec-plugin to run command line

I want to use maven-exec-plugin to run command line (cmd) for converting a Markdown file to a PDF file using Pandoc.
To do that manually, I've executed these commands:
pandoc ReadMe.md -o ReadMe.html
pandoc ReadMe.html --latex-engine=xelatex -o ReadMe.pdf
I wasn't able to run that in one command, pandoc giving weird error! But this is another problem...
I've added this to my pom file using other sample found on the web but without success.
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>pandoc</id>
<phase>generate-pdf</phase>
<configuration>
<executable>cmd</executable>
<workingDirectory></workingDirectory>
<arguments>
<argument>/C</argument>
<argument>pandoc</argument>
<argument>README.md</argument>
<argument>-o</argument>
<argument>README.html</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I'm not a maven guru and help is appreciate!
The defined phase, <phase>generate-pdf</phase>, is not a maven phase, hence Maven didn't bind the execution to its workflow.
You should bind it to a standard Maven phase, depending on your need. Try <phase>package</phase> for instance, it will be executed nearly at the end of your build.
The id element of a plugin execution is free text, you can type the id you want, it will appear as part of the build output in curved brackets after the plugin and goal name,
i.e. exec-maven-plugin:1.1:exec (pandoc)
The phase element instead must match a well known maven phase in order to attach the plugin/goal execution to it. If the phase is not well known, then Maven will simply ignore that plugin/goal execution (which is also an adopted approach, usually using the de-facto standard none as phase, to disable an inherited plugin execution, but that's a bit advanced for the scope of this question I would say).
For more details on maven phases, look at the official documentation, here.
For a full list of maven phases, here.

Using maven to copy war via ssh

I want to copy war file via ssh. I have the following pom:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>1.0-beta-3</version>
<executions>
<execution>
<id>default-cli</id>
<goals>
<goal>upload-single</goal>
</goals>
<configuration>
<fromFile>${project.build.directory}/${project.build.finalName}.war</fromFile>
<toFile>ROOT.war</toFile>
<url>scpexe://my.server.com</url>
<serverId>my.server.id</serverId>
</configuration>
</execution>
</executions>
</plugin>
When I trying to execute mvn wagon:upload-single, I got the following message:
Embedded error: Error executing command for transfer
Exit code 255 - Permission denied (publickey,gssapi-with-mic,password).
My settings.xml have proper username and password set. Also i can copy file to remote host manually without any propblem via scp.
Please, help me to solve this problem.
It works for me if I change
<toFile>ROOT.war</toFile>
<url>scpexe://my.server.com</url>
to
<toFile>/tmp/ROOT.war</toFile>
<url>scp://my.server.com</url>
You copy your file to the root folder. If you use this:
<toFile>ROOT.war</toFile>
<url>scpexe://my.server.com</url>
Then it is like saying: copy to my.server.com, us this file path: /ROOT.war
It is unlikely you have access to that folder.
Try using for example your home folder:
<toFile>/home/username/ROOT.war</toFile>
<url>scpexe://my.server.com</url>

Resources