Generating a REST client for Jira Cloud

36 comments

jon martin solaas January 27, 2023
Use openapi-generator to avoid this. Worked for me at least. Used Java 8 to build. Didn't need any of the tweaks above to have my minimal hello-world app working. Could be needed for real-world usage though.

java -jar openapi-generator-cli.jar generate -i https://developer.atlassian.com/cloud/jira/platform/swagger-v3.v3.json -g java -o ./jira-client
jon martin solaas January 27, 2023
Following up on my own post ... seems to be an issue with date/time, offset seems to be unexpected:

Caused by: java.time.format.DateTimeParseException: Text '2022-09-25T23:29:18.487+0200' could not be parsed, unparsed text found at index 26
jon martin solaas January 27, 2023

Yet a follow-up: DateTime formatting hack:

In JSON.java look for 

if (date.endsWith("+0000"))

and edit it so that it looks like

String date = in.nextString();
//if (date.endsWith("+0000")) {
if (date.contains("+")) {
date = date.substring(0, date.length()-5) + "Z";
}
return OffsetDateTime.parse(date, formatter);

(OffsetDateTimeTypeAdapter.read method)

Happy hacking ... :0)

Like Steffen Opel _Utoolity_ likes this
Ben Kelley
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 29, 2023

Hi @jon martin solaas. Thanks for the comment about openapi-generator. We made a few fixes to the spec since this article was originally published, so hopefully none of the hacks are needed any more!

Thanks for the tip on date/time formatting.

Like Jon Martin Solaas likes this
Gaetano Manzo November 4, 2024
I am trying to use Open API generator to generate the java 11 client for Jira Cloud.
 
I am using the dedicated maven plugin in order to generate it (v. 7.9.0).
Using this  as documentation, and formulating the maven plugin like this:

 <plugin>
   <groupId>org.openapitools</groupId>
   <artifactId>openapi-generator-maven-plugin</artifactId>
   <version>7.9.0</version>
   <executions>
      <execution>
         <goals>
            <goal>generate</goal>
        </goals>
      <configuration>
          <inputSpec>${project.basedir}/src/main/resources/jira-api.json</inputSpec>
          <output>${project.build.directory}/generated-sources/jira-cloud-generated-client</output>
        <generatorName>java</generatorName>
          <apiPackage>${project.groupId}.api</apiPackage>
          <modelPackage>${project.groupId}.model</modelPackage>
          <invokerPackage>${project.groupId}.invoker</invokerPackage>
          <generateApiTests>false</generateApiTests>
          <generateModelTests>false</generateModelTests>
          <generateApiDocumentation>false</generateApiDocumentation>
          <generateModelDocumentation>false</generateModelDocumentation>
      </configuration>
    </execution>
  </executions>
</plugin>

The generated code returns me an error in the ApprovalConfiguration.java class, specifically: 

ApprovalConfiguration.java:313:35
java: incompatible types: cannot infer type arguments for java.util.ArrayList<>
    reason: no instance(s) of type variable(s) E exist so that java.util.ArrayList<E> conforms
to jira_test.model.ApprovalConfiguration.ExcludeEnum

Is this an error due to some anomaly in the documentation structure or a problem related to Open API generator?

I was looking for the ''incriminating'' enum.

I noticed that this part is present in the JSON:

"exclude":{
"description":"A list of roles that should be excluded as possible approvers.",
"enum":["assignee","reporter"],
"items":{
"description":"A list of roles that should be excluded as possible approvers.",
"enum":["assignee","reporter"],
"nullable":true,
"type":"string"
},
"nullable":true,
"type":"array"
}

Could it be that the problem is related to the fact that it is an enum, of type string, which can accept multiple values (array)?

Waiting your feedback,
Thank you
Jon Martin Solaas
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 4, 2024

@Gaetano Manzo What happens if you build with java 8?

Gaetano Manzo November 4, 2024

Hi @Jon Martin Solaas , 

same result trying to generate the client with Java 8.

Ben Kelley
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 5, 2024

Hi @Gaetano Manzo 

I had a quick look at this. I don't have openapi-generator configured, but I did build with the latest swagger-codegen (3.0.63). It expresses this as:

public enum ExcludeEnum {
ASSIGNEE("assignee"),
REPORTER("reporter");
// ...
}

and in ApprovalConfiguration it has a list of the enums:

 

private List<ExcludeEnum> exclude = null;

So I think the spec is correct.

Jon Martin Solaas
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 6, 2024

openapi-generator is just a jar file you can download. i tried now with swagger-codegen, after removing the enum-stuff described in the article, and it does not compile.

First error is

incompatible types: java.lang.Class<io.swagger.client.model.MandatoryFieldValue> cannot be converted to java.lang.Class<? extends io.swagger.client.model.Fields>

in JSON.java line 73 (and 74)

Do I need to dig out and old java 7 jdk to build it?

<properties>
<java.version>1.7</java.version>

What is the exact swagger-codegen command line and modifications needed for the spec file? I followed the instructions in the article, maybe they're a bit outdated now?

Ben Kelley
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 6, 2024

The instructions here are definitely outdated! A lot has changed in 4 years, including improvements to consumability of our spec. See one of my early comments on this article, linking to a new article. There should be no need to make any edits to the spec any more.

I was building using swagger-codegen-maven-plugin 3.0.63 (which calls swagger-codegen 3.0.63) using Java 17 using the "jersey1" library option, although I recommend using "resttemplate" now (as the Jersey 1 client is quite outdated).

It might be easier to ask a new question in the developer community, like at https://community.developer.atlassian.com/c/jira/jira-cloud/ (Feel free to @ mention me.)

 

Like Jon Martin Solaas likes this
Gaetano Manzo November 8, 2024

Hi @Ben Kelley ,

I confirm that with swagger-codegen-maven-plugin everything was built correctly. Only thing I had to insert a dependency in pom for javax.annotations (but nothing special). At this point I assume there is something wrong with openapi-generator. I thank you for the feedback.

Like Jon Martin Solaas likes this

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events