Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit 9e824ae

Browse files
authored
Adds gradle build tool support for java generator (#430)
* Adds buildTool cli option for java * Updates buildTool info * Adds gradle files in petsote sample * Adds gitignore * Moves common files to same place in java * Fixes gradle checker framework settings * Excludes gradle wrapper * Fixes buuild and settings filenames for gradle buildTool * Fixes gitignoring of gradle wrapper files * Updates java version constraint in gradle settings file, petstore uses gradle in ci * Reverts root gitignore * Fixes java generator tests * Fixes AuthorTemplateTest * Fixes all getGnerator invocations * Docs regen * Updates buildTool ordering for docs * Samples regen
1 parent 8771aee commit 9e824ae

File tree

41 files changed

+377
-375
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+377
-375
lines changed

Diff for: .circleci/parallel.sh

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ elif [ "$JOB_ID" = "testJava17ClientSamples" ]; then
2929
echo "Running job $JOB_ID ..."
3030
java -version
3131
mvn -version
32+
gradle --version
33+
3234
cat ./.circleci/testJava17ClientSamples.sh | parallel
3335

3436
else

Diff for: .circleci/testJava17ClientSamples.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
(cd samples/client/petstore/java && mvn test)
1+
(cd samples/client/petstore/java && gradle wrapper && gradle test)
22
(cd samples/client/3_0_3_unit_test/java && mvn test)
33
(cd samples/client/3_1_0_unit_test/java && mvn test)

Diff for: .gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ test-output/
4949
#Java/Android
5050
**/.gradle
5151

52-
5352
# Python
5453
*.pyc
5554
__pycache__

Diff for: bin/generate_samples_configs/java.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ outputDir: samples/client/petstore/java
33
inputSpec: src/test/resources/3_0/python/petstore_customized.yaml
44
additionalProperties:
55
artifactId: petstore
6-
hideGenerationTimestamp: "true"
6+
hideGenerationTimestamp: "true"
7+
buildTool: gradle

Diff for: docs/generators/java.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
2323
|artifactDescription|artifact description in generated pom.xml| |OpenAPI Java|
2424
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapi-json-schema-tools/openapi-json-schema-generator|
2525
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
26+
|buildTool|the build automation tool used in generated code|<dl><dt>**maven**</dt><dd>Use maven</dd><dt>**gradle**</dt><dd>Use gradle</dd></dl>|maven|
2627
|developerEmail|developer email in generated pom.xml| |[email protected]|
2728
|developerName|developer name in generated pom.xml| |OpenAPI-Generator Contributors|
2829
|developerOrganization|developer organization in generated pom.xml| |OpenAPITools.org|

Diff for: samples/client/3_0_3_unit_test/java/.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
build/
2+
.gradle/
3+
.idea/
4+
target/
5+
6+
# gradle wrapper
7+
gradlew
8+
gradlew.bat
9+
gradle/

Diff for: samples/client/3_0_3_unit_test/java/.openapi-generator/FILES

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.gitignore
12
README.md
23
docs/RootServerInfo.md
34
docs/components/schemas/AdditionalpropertiesAllowsASchemaWhichShouldValidate.md

Diff for: samples/client/3_0_3_unit_test/java/README.md

-13
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,6 @@ Add this dependency to your project's POM:
4141
</dependency>
4242
```
4343

44-
### Others
45-
46-
At first generate the JAR by executing:
47-
48-
```shell
49-
mvn clean package
50-
```
51-
52-
Then manually install the following JARs:
53-
54-
- `target/unit-test-api-0.0.1.jar`
55-
- `target/lib/*.jar`
56-
5744

5845
## Usage Notes
5946
### Validation, Immutability, and Data Type

Diff for: samples/client/3_0_3_unit_test/java/src/main/java/org/openapijsonschematools/client/header/Rfc6570Serializer.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ private static String percentEncode(String s) throws NotImplementedException {
2727
.replace("%7E", "~");
2828
// This could be done faster with more hand-crafted code.
2929
} catch (UnsupportedEncodingException wow) {
30-
throw new NotImplementedException(wow.getMessage());
30+
@Nullable String msg = wow.getMessage();
31+
if (msg == null) {
32+
throw new NotImplementedException("UnsupportedEncodingException thrown");
33+
}
34+
throw new NotImplementedException(msg);
3135
}
3236
}
3337

Diff for: samples/client/3_0_3_unit_test/java/src/main/java/org/openapijsonschematools/client/parameter/CookieSerializer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ protected CookieSerializer(Map<String, Parameter> parameters) {
1616

1717
public String serialize(Map<String, ?> inData) throws NotImplementedException {
1818
String result = "";
19-
Map<String, ?> sortedData = new TreeMap<>(inData);
19+
Map<String, @Nullable Object> sortedData = new TreeMap<>(inData);
2020
for (Map.Entry<String, ?> entry: sortedData.entrySet()) {
2121
String mapKey = entry.getKey();
2222
@Nullable Parameter parameter = parameters.get(mapKey);

Diff for: samples/client/3_0_3_unit_test/java/src/test/java/org/openapijsonschematools/client/header/SchemaHeaderTest.java

+26-11
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void testSerialization() throws ValidationException, NotImplementedExcept
3434
mapPayload.put("R", 100);
3535
mapPayload.put("G", 200);
3636
mapPayload.put("B", 150);
37-
var testCases = List.of(
37+
List<ParamTestCase> testCases = List.of(
3838
new ParamTestCase(
3939
null,
4040
Map.of("color", List.of(""))
@@ -135,28 +135,43 @@ public void testDeserialization() throws ValidationException, NotImplementedExce
135135
assertNull(deserialized);
136136

137137
header = getHeader(NumberJsonSchema.NumberJsonSchema1.getInstance());
138-
deserialized = header.deserialize(List.of("1"), false, configuration);
138+
var deserializedOne = header.deserialize(List.of("1"), false, configuration);
139+
if (deserializedOne == null) {
140+
throw new RuntimeException("invalid value");
141+
}
139142
@Nullable Object expected = 1L;
140-
Assert.assertEquals(expected, deserialized);
143+
Assert.assertEquals(expected, deserializedOne);
141144

142145
header = getHeader(NumberJsonSchema.NumberJsonSchema1.getInstance());
143-
deserialized = header.deserialize(List.of("3.14"), false, configuration);
146+
var deserialized314 = header.deserialize(List.of("3.14"), false, configuration);
147+
if (deserialized314 == null) {
148+
throw new RuntimeException("invalid value");
149+
}
144150
expected = 3.14d;
145-
Assert.assertEquals(expected, deserialized);
151+
Assert.assertEquals(expected, deserialized314);
146152

147153
header = getHeader(StringJsonSchema.StringJsonSchema1.getInstance());
148-
deserialized = header.deserialize(List.of("blue"), false, configuration);
154+
var deserializedBlue = header.deserialize(List.of("blue"), false, configuration);
155+
if (deserializedBlue == null) {
156+
throw new RuntimeException("invalid value");
157+
}
149158
expected = "blue";
150-
Assert.assertEquals(expected, deserialized);
159+
Assert.assertEquals(expected, deserializedBlue);
151160

152161
header = getHeader(StringJsonSchema.StringJsonSchema1.getInstance());
153-
deserialized = header.deserialize(List.of("hello world"), false, configuration);
162+
var deserializedHelloWorld = header.deserialize(List.of("hello world"), false, configuration);
163+
if (deserializedHelloWorld == null) {
164+
throw new RuntimeException("invalid value");
165+
}
154166
expected = "hello world";
155-
Assert.assertEquals(expected, deserialized);
167+
Assert.assertEquals(expected, deserializedHelloWorld);
156168

157169
header = getHeader(ListJsonSchema.ListJsonSchema1.getInstance());
158-
deserialized = header.deserialize(List.of("blue", "black", "brown"), false, configuration);
170+
var deserializedList = header.deserialize(List.of("blue", "black", "brown"), false, configuration);
171+
if (deserializedList == null) {
172+
throw new RuntimeException("invalid value");
173+
}
159174
expected = List.of("blue", "black", "brown");
160-
Assert.assertEquals(expected, deserialized);
175+
Assert.assertEquals(expected, deserializedList);
161176
}
162177
}

Diff for: samples/client/3_1_0_unit_test/java/.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
build/
2+
.gradle/
3+
.idea/
4+
target/
5+
6+
# gradle wrapper
7+
gradlew
8+
gradlew.bat
9+
gradle/

Diff for: samples/client/3_1_0_unit_test/java/.openapi-generator/FILES

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.gitignore
12
README.md
23
docs/RootServerInfo.md
34
docs/components/schemas/ASchemaGivenForPrefixitems.md

Diff for: samples/client/3_1_0_unit_test/java/README.md

-13
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,6 @@ Add this dependency to your project's POM:
4141
</dependency>
4242
```
4343

44-
### Others
45-
46-
At first generate the JAR by executing:
47-
48-
```shell
49-
mvn clean package
50-
```
51-
52-
Then manually install the following JARs:
53-
54-
- `target/unit-test-api-0.0.1.jar`
55-
- `target/lib/*.jar`
56-
5744

5845
## Usage Notes
5946
### Validation, Immutability, and Data Type

Diff for: samples/client/3_1_0_unit_test/java/src/main/java/org/openapijsonschematools/client/header/Rfc6570Serializer.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ private static String percentEncode(String s) throws NotImplementedException {
2727
.replace("%7E", "~");
2828
// This could be done faster with more hand-crafted code.
2929
} catch (UnsupportedEncodingException wow) {
30-
throw new NotImplementedException(wow.getMessage());
30+
@Nullable String msg = wow.getMessage();
31+
if (msg == null) {
32+
throw new NotImplementedException("UnsupportedEncodingException thrown");
33+
}
34+
throw new NotImplementedException(msg);
3135
}
3236
}
3337

Diff for: samples/client/3_1_0_unit_test/java/src/main/java/org/openapijsonschematools/client/parameter/CookieSerializer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ protected CookieSerializer(Map<String, Parameter> parameters) {
1616

1717
public String serialize(Map<String, ?> inData) throws NotImplementedException {
1818
String result = "";
19-
Map<String, ?> sortedData = new TreeMap<>(inData);
19+
Map<String, @Nullable Object> sortedData = new TreeMap<>(inData);
2020
for (Map.Entry<String, ?> entry: sortedData.entrySet()) {
2121
String mapKey = entry.getKey();
2222
@Nullable Parameter parameter = parameters.get(mapKey);

Diff for: samples/client/3_1_0_unit_test/java/src/test/java/org/openapijsonschematools/client/header/SchemaHeaderTest.java

+26-11
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void testSerialization() throws ValidationException, NotImplementedExcept
3434
mapPayload.put("R", 100);
3535
mapPayload.put("G", 200);
3636
mapPayload.put("B", 150);
37-
var testCases = List.of(
37+
List<ParamTestCase> testCases = List.of(
3838
new ParamTestCase(
3939
null,
4040
Map.of("color", List.of(""))
@@ -135,28 +135,43 @@ public void testDeserialization() throws ValidationException, NotImplementedExce
135135
assertNull(deserialized);
136136

137137
header = getHeader(NumberJsonSchema.NumberJsonSchema1.getInstance());
138-
deserialized = header.deserialize(List.of("1"), false, configuration);
138+
var deserializedOne = header.deserialize(List.of("1"), false, configuration);
139+
if (deserializedOne == null) {
140+
throw new RuntimeException("invalid value");
141+
}
139142
@Nullable Object expected = 1L;
140-
Assert.assertEquals(expected, deserialized);
143+
Assert.assertEquals(expected, deserializedOne);
141144

142145
header = getHeader(NumberJsonSchema.NumberJsonSchema1.getInstance());
143-
deserialized = header.deserialize(List.of("3.14"), false, configuration);
146+
var deserialized314 = header.deserialize(List.of("3.14"), false, configuration);
147+
if (deserialized314 == null) {
148+
throw new RuntimeException("invalid value");
149+
}
144150
expected = 3.14d;
145-
Assert.assertEquals(expected, deserialized);
151+
Assert.assertEquals(expected, deserialized314);
146152

147153
header = getHeader(StringJsonSchema.StringJsonSchema1.getInstance());
148-
deserialized = header.deserialize(List.of("blue"), false, configuration);
154+
var deserializedBlue = header.deserialize(List.of("blue"), false, configuration);
155+
if (deserializedBlue == null) {
156+
throw new RuntimeException("invalid value");
157+
}
149158
expected = "blue";
150-
Assert.assertEquals(expected, deserialized);
159+
Assert.assertEquals(expected, deserializedBlue);
151160

152161
header = getHeader(StringJsonSchema.StringJsonSchema1.getInstance());
153-
deserialized = header.deserialize(List.of("hello world"), false, configuration);
162+
var deserializedHelloWorld = header.deserialize(List.of("hello world"), false, configuration);
163+
if (deserializedHelloWorld == null) {
164+
throw new RuntimeException("invalid value");
165+
}
154166
expected = "hello world";
155-
Assert.assertEquals(expected, deserialized);
167+
Assert.assertEquals(expected, deserializedHelloWorld);
156168

157169
header = getHeader(ListJsonSchema.ListJsonSchema1.getInstance());
158-
deserialized = header.deserialize(List.of("blue", "black", "brown"), false, configuration);
170+
var deserializedList = header.deserialize(List.of("blue", "black", "brown"), false, configuration);
171+
if (deserializedList == null) {
172+
throw new RuntimeException("invalid value");
173+
}
159174
expected = List.of("blue", "black", "brown");
160-
Assert.assertEquals(expected, deserialized);
175+
Assert.assertEquals(expected, deserializedList);
161176
}
162177
}

Diff for: samples/client/petstore/java/.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
build/
2+
.gradle/
3+
.idea/
4+
target/
5+
6+
# gradle wrapper
7+
gradlew
8+
gradlew.bat
9+
gradle/

Diff for: samples/client/petstore/java/.openapi-generator/FILES

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
.gitignore
12
README.md
3+
build.gradle.kts
24
docs/RootServerInfo.md
35
docs/apis/paths/Anotherfakedummy.md
46
docs/apis/paths/Commonparamsubdir.md
@@ -751,7 +753,7 @@ docs/servers/RootServer1.md
751753
docs/servers/RootServer2.md
752754
docs/servers/rootserver0/RootServer0Variables.md
753755
docs/servers/rootserver1/RootServer1Variables.md
754-
pom.xml
756+
settings.gradle.kts
755757
src/main/java/org/openapijsonschematools/client/RootServerInfo.java
756758
src/main/java/org/openapijsonschematools/client/apiclient/ApiClient.java
757759
src/main/java/org/openapijsonschematools/client/apis/paths/Anotherfakedummy.java

Diff for: samples/client/petstore/java/README.md

+12-30
Original file line numberDiff line numberDiff line change
@@ -10,50 +10,32 @@ This Java package is automatically generated by the [OpenAPI JSON Schema Generat
1010
## Requirements
1111

1212
1. Java 17
13-
2. Maven
13+
2. Gradle
1414

1515
## Installation
1616

1717
To install the API client library to your local Maven repository, simply execute:
1818

1919
```shell
20-
mvn clean install
20+
gradle wrapper
21+
gradlew clean build
2122
```
2223

23-
To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:
24+
### Gradle users
2425

25-
```shell
26-
mvn clean deploy
27-
```
28-
29-
Refer to the [OSSRH Guide](http://central.sonatype.org/pages/ossrh-guide.html) for more information.
26+
Add this dependency to your project's build file:
3027

31-
### Maven users
32-
33-
Add this dependency to your project's POM:
34-
35-
```xml
36-
<dependency>
37-
<groupId>org.openapijsonschematools</groupId>
38-
<artifactId>petstore</artifactId>
39-
<version>1.0.0</version>
40-
<scope>compile</scope>
41-
</dependency>
4228
```
29+
repositories {
30+
mavenCentral() // Needed if the 'petstore' jar has been published to maven centra
31+
mavenLocal() // Needed if the 'petstore' jar has been published to the local maven repo
32+
}
4333
44-
### Others
45-
46-
At first generate the JAR by executing:
47-
48-
```shell
49-
mvn clean package
34+
dependencies {
35+
implementation "org.openapijsonschematools:petstore:1.0.0"
36+
}
5037
```
5138

52-
Then manually install the following JARs:
53-
54-
- `target/petstore-1.0.0.jar`
55-
- `target/lib/*.jar`
56-
5739

5840
## Usage Notes
5941
### Validation, Immutability, and Data Type

0 commit comments

Comments
 (0)