Hi everyone!
We’re trying to generate a Java client to interact with the Jira Cloud REST API v3 using OpenAPI generator and the provided OpenAPI specifications.
However, we’re having a bit of trouble and were wondering if anyone else had encountered the same issues?
We are using the java
generator and the resttemplate
library.
Here’s the configuration we use for the OpenAPI generator Maven plugin:
Maven configuration
<!-- OpenAPI generator plugin -->
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-generator-maven-plugin.version}</version>
<executions>
<!-- Jira Rest API v3 -->
<execution>
<id>jira</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/jira/openapi-jira-v3.v3.json</inputSpec>
<!-- Generate a Java client -->
<generatorName>java</generatorName>
<!-- Configure the output -->
<output>${project.build.directory}/generated-sources</output>
<apiPackage>${jira.package}.v3</apiPackage>
<modelPackage>${jira.package}.v3.model</modelPackage>
<invokerPackage>${jira.package}.v3.client</invokerPackage>
<!-- Configure the generated code -->
<generateApis>true</generateApis>
<generateModels>true</generateModels>
<generateSupportingFiles>true</generateSupportingFiles>
<generateModelTests>false</generateModelTests>
<generateApiTests>false</generateApiTests>
<generateModelDocumentation>true</generateModelDocumentation>
<generateApiDocumentation>true</generateApiDocumentation>
<!-- Fix ambiguous imports -->
<importMappings>
<importMapping>Locale=java.util.Locale</importMapping>
</importMappings>
<configOptions>
<!-- Generate code for the RestTemplate -->
<library>resttemplate</library>
<!-- Generate code for Spring Boot 3 -->
<useSpringBoot3>true</useSpringBoot3>
<!-- Use jakarta.* instead of java.* imports -->
<useJakartaEe>true</useJakartaEe>
<!-- Disable documentation annotations -->
<annotationLibrary>none</annotationLibrary>
<!-- Disable OpenAPI documentation -->
<documentationProvider>none</documentationProvider>
<!-- Disable OpenAPI Jackson nullable library -->
<openApiNullable>false</openApiNullable>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
First, we had an issue due to an ambiguous import of Locale
.
We managed to fix this using an import mapping to force the use of java.util.Locale
.
Then, we had an issue with the WorkflowCapabilities
schema.
Indeed, OpenAPI generator seems to get confused and handles the projectTypes
property as both an enum and an array:
Generated code
public class WorkflowCapabilities {
// [...]
private ProjectTypesEnum projectTypes;
// [...]
public WorkflowCapabilities addProjectTypesItem(ProjectTypesEnum projectTypesItem) {
if (this.projectTypes == null) {
this.projectTypes = new ArrayList<>();
}
this.projectTypes.add(projectTypesItem);
return this;
}
// [...]
}
We though this might be a bug in the OpenAPI generator.
However, by checking the OpenAPI specifications, we found that the projectTypes
property of the WorkflowCapabilities
schema was indeed a bit ambiguous.
Indeed, the projectTypes
property is declared as an array
of enum
but also contains an enum
attribute which leads the OpenAPI generator to think this property is both an array and an enum:
OpenAPI specifications
"WorkflowCapabilities": {
"additionalProperties": false,
"properties": {
// [...]
"projectTypes": {
"description": "The types of projects that this capability set is available for.",
"enum": [
"software",
"service_desk",
"product_discovery",
"business",
"unknown"
],
"items": {
"description": "The types of projects that this capability set is available for.",
"enum": [
"software",
"service_desk",
"product_discovery",
"business",
"unknown"
],
"type": "string"
},
"type": "array"
},
// [...]
},
"type": "object"
},
For now, we managed to generate the Java client by manually updating the OpenAPI specifications and removing the enum
attribute of the projectType
property in the WorkflowCapabilities
schema.
However, this is of course not great for maintainability.
We are considering contributing to OpenAPI generator to ignore the enum
attribute if the type of a property is array
or using a different OpenAPI generator library (but we need to use RestTemplate
).
What are your thoughts on the subject?
Do you have other solutions?
Do you think it is a bug in the OpenAPI generator library?
Do you think the OpenAPI specifications for the Jira Cloud REST API v3 should be updated?
Cheers!