openapi-generator duplicates the endpoint in swagger-ui - java

The openapi-generator-maven-plugin (version 6.3.0) is configured as follows in a Spring-Boot 3 application:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-maven-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/openApi.yaml</inputSpec>
<generatorName>spring</generatorName>
<apiPackage>com.company.api.v1</apiPackage>
<modelPackage>com.company.model.v1</modelPackage>
<supportingFilesToGenerate>ApiUtil.java</supportingFilesToGenerate>
<configOptions>
<delegatePattern>true</delegatePattern>
<useSpringBoot3>true</useSpringBoot3>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
and in the Swagger/OpenAPI Yaml file is only one endpoint configured:
paths:
/table:
get:
summary: get all trains
operationId: trainsList
tags:
- zuege
The issue here is in the Swagger-Ui; the endpoint is duplicated:
When I remove the tag in the yaml then only the first endpoint is visible but actually this is the ugly one with the generated description. When I configure it with <useTags>true</useTags> (cf. config) the two endpoints are still there but both with name zuege.
Any idea how to reduce it to only one endpoint but consider the tag?
When I add a global tag description as follows:
tags:
- name: zuege
description: "Zuege details"
together with <useTags>true</useTags it looks as follows:
So it is still duplicated.

There seems to be an issue with the opeanapi-generator-maven-plugin 6.3.0 because it converts the tag name from the yaml file, e.g.
tags:
- name: zuege
into a slightly deviated annotation tag within the generated code, namely:
#Tag(name = "Zuege", description = "Zuege details")
public interface ZuegeApi {
}
So when you change the tag within the yaml file into the same style (first character is always in upper case), then the issue is gone:

Related

Access Maven property "developers" in application.yml (Spring Boot)

I want to have the developer, which is defined in the pom.xml with the tag to appear in the application.yml after the build process. Somehow it is working with all attributes but developers.
This is in a Spring Boot project, I want the attributes to be filled during the build process.
This is an excerpt of the pom.xml
<description>my description</description>
<developers>
<developer>
<id>12345</id>
<name>John Doe</name>
<email>john#doe.com</email>
</developer>
</developers>
This is in application.yml
info:
description: "#project.description#"
developer: "#project.developers[0].id#"
It works for description, but not for developer. I tried many variations, e.g. ${..}, "#project.developers.0.id". Nothing seems to be working.
If anybody has an idea, I would be very grateful.
You can read the developer id or email address or any values from the pom.xml with this elegant way:
Generate the build-info.properties with the default data plus your additional data
Read values from this file easily with Spring via the BuildProperties.
pom.xml:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
<configuration>
<additionalProperties>
<developer>${project.developers[0].email}</developer>
</additionalProperties>
</configuration>
</execution>
</executions>
</plugin>
This will produce a build-info.properties file under the META-INF directory with the following content:
build.artifact=<artifactId-from-pom>
build.group=<groupId-from-pom>
build.name=<name-from-pom>
build.time=<build-time>
build.version=<version-from-pom>
build.developer=<email-of-the-first-developer-from-pom>
Then you can read values with Spring:
#Configuration
public class OpenApiConfiguration {
#Autowired
private BuildProperties buildProperties;
#Bean
public OpenAPI customOpenAPI()) {
return new OpenAPI().info(new Info()
.title(...)
.version(buildProperties.getVersion())
.contact(new Contact().email(buildProperties.get("developer"))));
}
}
To read:
Spring Boot Maven Plugin
BuildProperties
I hope that this will help you.
Add it on the property and use on pom and property file, example:
<properties>
<team.name>John Doe</team.name>
</properties>
Use on developer data:
<developers>
<developer>
<name>${team.name}</name>
...
And in the application use the property:
description: "#team.name#"

jaxb2-maven-plugin - how to turn off recursive directory traversal when generating xsd from classes

I am using jaxb2-maven-plugin for generating XSD from jaxb annotated classes.
The configuration looks like that
<execution>
<id>rest-api-execution-schemagen</id>
<goals>
<goal>schemagen</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<sources>
<source>src/java/foo/rest/execution/model</source>
</sources>
<outputDirectory>${project.build.directory}/execution-api-xml-schema</outputDirectory>
</configuration>
</execution>
The package foo/rest/execution/model contains many classes, that is why I wish to avoid listing all of them in separate <source> elements. Instead, I specified that I wish to include the whole src/java/foo/rest/execution/model directory, using a single <source> element.
The problem is that there are subpackages:
foo/rest/execution/model/builder
... which contain other classes that are not jaxb annotated and should not be part of the schema.
Unfortunately, the schemagen goal attempts to traverse the foo/rest/execution/model directory recursively and therefore attempts to generate schemas for the classes in the subdirectories.
Is there a way to avoid that?
You can use xjcSourceExcludeFilters to filter the sources defined by source i.e. to exclude packages, files etc.
For example:
<configuration>
<sources>
<source>src/java/foo/rest/execution/model</source>
</sources>
<xjcSourceExcludeFilters>
<filter implementation="org.codehaus.mojo.jaxb2.shared.filters.pattern.PatternFileFilter">
<patterns>
<pattern>src/java/foo/rest/execution/model/builder/*.java</pattern>
</patterns>
</filter>
</xjcSourceExcludeFilters>
...
</configuration>
If the built-in filter support cannot meet your needs then you can provide your own implementation by replacing org.codehaus.mojo.jaxb2.shared.filters.pattern.PatternFileFilter with your own implementation of AbstractFilter.
More details on using this here and more details on defining filters here.

Enunciate reporting - How to Exclude few APIs and include few APIs from a same class

I would like to exclude few API methods in a class from Enunciate documentation.
Is there a way to achieve it using enunciate ?
Thanks in Advance
Enunciate 1.27 has a feature "Facet"(http://docs.codehaus.org/display/ENUNCIATE/Enunciate+API+Facets) which helps in achieving the above.
Requires following changes
1.) pom.xml
Added the plugin
<plugin>
<groupId>org.codehaus.enunciate</groupId>
<artifactId>maven-enunciate-plugin</artifactId>
<version>1.27</version>
<executions>
<execution>
<goals>
<goal>assemble</goal>
</goals>
</execution>
</executions>
</plugin>
2.) In the API Method you want to exclude, add Facet annotation like below
#GET
#Path("/{memberId}")
#Produces(APPLICATION_JSON)
#Facet(name = "external")
3.) Change enunciate xml to refer to 1.27 enunciate xsd
4.) Add Facets tag in your enunciate xml
<facets>
<exclude name ="external"/>
</facets>
Result - Enunciate report excludes selected APIs methods in class "A" and includes the rest.

CXF 2.4.2: No conduit initiator was found for the namespace http://schemas.xmlsoap.org/soap/http

I have a service client generated from wsdl. I am trying to call the remote service and I recieve the conduit initiator error seen below. I have tried numerous solutions without success.
I found solutions (old posts) that recommend using the http-jetty extensions. I do not believe this makes sense for me because the server is not running locally.
I've also found that closest configuration that helps me is an example cxf.xml file that contains:
<bean class="org.apache.cxf.transport.local.LocalTransportFactory"
lazy-init="false">
<property name="transportIds">
<list>
<value>http://cxf.apache.org/transports/local</value>
<value>http://cxf.apache.org/transports/http</value>
<value>http://schemas.xmlsoap.org/soap/http</value>
<value>http://schemas.xmlsoap.org/wsdl/soap/http</value>
</list>
</property>
</bean>
This configuration provides guidance on how to configure a transport factory and bind it to http://schemas.xmlsoap.org/soap/http . When I try this with the HTTPTransportFactory, I receive an exception that it cannot be initialized (no such method error).
Caused by: org.apache.cxf.BusException: No conduit initiator was found for the namespace http://schemas.xmlsoap.org/soap/http.
at org.apache.cxf.transport.ConduitInitiatorManagerImpl.getConduitInitiator(ConduitInitiatorManagerImpl.java:112)
at org.apache.cxf.endpoint.AbstractConduitSelector.getSelectedConduit(AbstractConduitSelector.java:73)
at org.apache.cxf.endpoint.UpfrontConduitSelector.prepare(UpfrontConduitSelector.java:61)
at org.apache.cxf.endpoint.ClientImpl.prepareConduitSelector(ClientImpl.java:708)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:476)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:309)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:261)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:127)
precaution: At this point, I will stop my attempt to upgrade my CXF client to 2.4.2 and fall back to the oldest version that works (2.2 series). This is not ideal.
I would like to move forward with the upgrade. Any suggestions regarding how to configure CXF 2.4.X so that my client-only HTTP SOAP configuration wires correctly would be much appriciated.
Like recommended by the old posts, this is solved by adding cxf-rt-transports-http-jetty into the mix.
This error can be produced by invalid url format on client. For example, if you use http transport, you should define "http://localhost:8080/services/{smth}" url. And if you define "localhost:8080/services/{smth}" without http prefix - you receive such an error.
I was also facing the same issue. Through IntelliJ everything was working fine but maven surefire was throwing up error. And finally found the answer. Here it is:
Basically the cxf libraries each supply a META-INF/cxf/bus-extensions.txt file and the default behavior of the packager is to replace that file, causing it to be incomplete. By configuring the shader to append instead of replace the cxf stuff will behave correctly.
Add this to your build section of your pom in the plugins section:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.4</version>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/cxf/bus-extensions.txt</resource>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
Did you put the cxf-rt-binding-soap-2.4.x.jar into your class path?
Recently I upgraded cxf-rt-ws-security to 3.0.0. From then I started getting org.apache.cxf.BusException: No conduit initiator was found for the namespace http://schemas.xmlsoap.org/soap/http.
at org.apache.cxf.bus.managers.ConduitInitiatorManagerImpl.getConduitInitiator(ConduitInitiatorManagerImpl.java:110).
This issue was resolved after i upgraded the below jars to 3.0.0 in my pom.xml
cxf-rt-frontend-jaxws
cxf-rt-ws-policy
cxf-rt-transports-http
This doesn't apply specifically to the original poster's example URLs listed, but we got this error when the URL was incorrect. I.e., we had a certain string in the URL path listed twice instead of once.
I had a similar situation with this error and for this issue seems to be coming with the older versions of the following jars
cxf-core-2.x.jar
cxf-rt-frontend-jaxrs-2.x.jar
cxf-rt-rs-client-2.x.jar
cxf-rt-transports-http-2.x.jar
When I have switched to the latest releases of these jars (3.2.1, at the time of writing) has resolved the error.
Removing this Dependency from my POM Fixed the error for me
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.1.1</version>
</dependency>

control schema file name created by jaxb schemagen maven plugin (maven-jaxb-schemagen-plugin)

I don't seem to be able to work out how to get control the file name of the XSD file created by maven-jaxb-schemagen-plugin. The documentation is a bit sparse.
<groupId>com.sun.tools.jxc.maven2</groupId>
<artifactId>maven-jaxb-schemagen-plugin</artifactId>
<version>1.2</version>
<configuration>
<project>${project}</project>
<destdir>${project.build.directory}/generated-resources/schemas</destdir>
<srcdir>${project.build.sourceDirectory}/my/jaxb/bean/package</srcdir>
<verbose>true</verbose>
</configuration>
It always seems to create a file called schema1.xsd
You need to add schema elements which describe which file should contain the elements of each namespace you have:
<configuration>
[...]
<schemas>
<schema>
<namespace>http://www.example.invalid/2001/05/27/wibble</namespace>
<file>wibble.xsd</file>
</schema>
</schemas>
<configuration>
Assuming you have set the namespace of you components
#XmlRootElement(name = "wobble", namespace="http://www.example.invalid/2001/05/27/wibble")

Categories

Resources