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

Java generator: adds gradle build tool support #430

Merged
merged 17 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .circleci/parallel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ elif [ "$JOB_ID" = "testJava17ClientSamples" ]; then
echo "Running job $JOB_ID ..."
java -version
mvn -version
gradle --version

cat ./.circleci/testJava17ClientSamples.sh | parallel

else
Expand Down
2 changes: 1 addition & 1 deletion .circleci/testJava17ClientSamples.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(cd samples/client/petstore/java && mvn test)
(cd samples/client/petstore/java && gradle wrapper && gradle test)
(cd samples/client/3_0_3_unit_test/java && mvn test)
(cd samples/client/3_1_0_unit_test/java && mvn test)
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ test-output/
#Java/Android
**/.gradle


# Python
*.pyc
__pycache__
Expand Down
3 changes: 2 additions & 1 deletion bin/generate_samples_configs/java.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ outputDir: samples/client/petstore/java
inputSpec: src/test/resources/3_0/python/petstore_customized.yaml
additionalProperties:
artifactId: petstore
hideGenerationTimestamp: "true"
hideGenerationTimestamp: "true"
buildTool: gradle
1 change: 1 addition & 0 deletions docs/generators/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|artifactDescription|artifact description in generated pom.xml| |OpenAPI Java|
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapi-json-schema-tools/openapi-json-schema-generator|
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|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|
|developerEmail|developer email in generated pom.xml| |[email protected]|
|developerName|developer name in generated pom.xml| |OpenAPI-Generator Contributors|
|developerOrganization|developer organization in generated pom.xml| |OpenAPITools.org|
Expand Down
9 changes: 9 additions & 0 deletions samples/client/3_0_3_unit_test/java/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
build/
.gradle/
.idea/
target/

# gradle wrapper
gradlew
gradlew.bat
gradle/
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.gitignore
README.md
docs/RootServerInfo.md
docs/components/schemas/AdditionalpropertiesAllowsASchemaWhichShouldValidate.md
Expand Down
13 changes: 0 additions & 13 deletions samples/client/3_0_3_unit_test/java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,6 @@ Add this dependency to your project's POM:
</dependency>
```

### Others

At first generate the JAR by executing:

```shell
mvn clean package
```

Then manually install the following JARs:

- `target/unit-test-api-0.0.1.jar`
- `target/lib/*.jar`


## Usage Notes
### Validation, Immutability, and Data Type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ private static String percentEncode(String s) throws NotImplementedException {
.replace("%7E", "~");
// This could be done faster with more hand-crafted code.
} catch (UnsupportedEncodingException wow) {
throw new NotImplementedException(wow.getMessage());
@Nullable String msg = wow.getMessage();
if (msg == null) {
throw new NotImplementedException("UnsupportedEncodingException thrown");
}
throw new NotImplementedException(msg);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected CookieSerializer(Map<String, Parameter> parameters) {

public String serialize(Map<String, ?> inData) throws NotImplementedException {
String result = "";
Map<String, ?> sortedData = new TreeMap<>(inData);
Map<String, @Nullable Object> sortedData = new TreeMap<>(inData);
for (Map.Entry<String, ?> entry: sortedData.entrySet()) {
String mapKey = entry.getKey();
@Nullable Parameter parameter = parameters.get(mapKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void testSerialization() throws ValidationException, NotImplementedExcept
mapPayload.put("R", 100);
mapPayload.put("G", 200);
mapPayload.put("B", 150);
var testCases = List.of(
List<ParamTestCase> testCases = List.of(
new ParamTestCase(
null,
Map.of("color", List.of(""))
Expand Down Expand Up @@ -135,28 +135,43 @@ public void testDeserialization() throws ValidationException, NotImplementedExce
assertNull(deserialized);

header = getHeader(NumberJsonSchema.NumberJsonSchema1.getInstance());
deserialized = header.deserialize(List.of("1"), false, configuration);
var deserializedOne = header.deserialize(List.of("1"), false, configuration);
if (deserializedOne == null) {
throw new RuntimeException("invalid value");
}
@Nullable Object expected = 1L;
Assert.assertEquals(expected, deserialized);
Assert.assertEquals(expected, deserializedOne);

header = getHeader(NumberJsonSchema.NumberJsonSchema1.getInstance());
deserialized = header.deserialize(List.of("3.14"), false, configuration);
var deserialized314 = header.deserialize(List.of("3.14"), false, configuration);
if (deserialized314 == null) {
throw new RuntimeException("invalid value");
}
expected = 3.14d;
Assert.assertEquals(expected, deserialized);
Assert.assertEquals(expected, deserialized314);

header = getHeader(StringJsonSchema.StringJsonSchema1.getInstance());
deserialized = header.deserialize(List.of("blue"), false, configuration);
var deserializedBlue = header.deserialize(List.of("blue"), false, configuration);
if (deserializedBlue == null) {
throw new RuntimeException("invalid value");
}
expected = "blue";
Assert.assertEquals(expected, deserialized);
Assert.assertEquals(expected, deserializedBlue);

header = getHeader(StringJsonSchema.StringJsonSchema1.getInstance());
deserialized = header.deserialize(List.of("hello world"), false, configuration);
var deserializedHelloWorld = header.deserialize(List.of("hello world"), false, configuration);
if (deserializedHelloWorld == null) {
throw new RuntimeException("invalid value");
}
expected = "hello world";
Assert.assertEquals(expected, deserialized);
Assert.assertEquals(expected, deserializedHelloWorld);

header = getHeader(ListJsonSchema.ListJsonSchema1.getInstance());
deserialized = header.deserialize(List.of("blue", "black", "brown"), false, configuration);
var deserializedList = header.deserialize(List.of("blue", "black", "brown"), false, configuration);
if (deserializedList == null) {
throw new RuntimeException("invalid value");
}
expected = List.of("blue", "black", "brown");
Assert.assertEquals(expected, deserialized);
Assert.assertEquals(expected, deserializedList);
}
}
9 changes: 9 additions & 0 deletions samples/client/3_1_0_unit_test/java/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
build/
.gradle/
.idea/
target/

# gradle wrapper
gradlew
gradlew.bat
gradle/
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.gitignore
README.md
docs/RootServerInfo.md
docs/components/schemas/ASchemaGivenForPrefixitems.md
Expand Down
13 changes: 0 additions & 13 deletions samples/client/3_1_0_unit_test/java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,6 @@ Add this dependency to your project's POM:
</dependency>
```

### Others

At first generate the JAR by executing:

```shell
mvn clean package
```

Then manually install the following JARs:

- `target/unit-test-api-0.0.1.jar`
- `target/lib/*.jar`


## Usage Notes
### Validation, Immutability, and Data Type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ private static String percentEncode(String s) throws NotImplementedException {
.replace("%7E", "~");
// This could be done faster with more hand-crafted code.
} catch (UnsupportedEncodingException wow) {
throw new NotImplementedException(wow.getMessage());
@Nullable String msg = wow.getMessage();
if (msg == null) {
throw new NotImplementedException("UnsupportedEncodingException thrown");
}
throw new NotImplementedException(msg);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected CookieSerializer(Map<String, Parameter> parameters) {

public String serialize(Map<String, ?> inData) throws NotImplementedException {
String result = "";
Map<String, ?> sortedData = new TreeMap<>(inData);
Map<String, @Nullable Object> sortedData = new TreeMap<>(inData);
for (Map.Entry<String, ?> entry: sortedData.entrySet()) {
String mapKey = entry.getKey();
@Nullable Parameter parameter = parameters.get(mapKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void testSerialization() throws ValidationException, NotImplementedExcept
mapPayload.put("R", 100);
mapPayload.put("G", 200);
mapPayload.put("B", 150);
var testCases = List.of(
List<ParamTestCase> testCases = List.of(
new ParamTestCase(
null,
Map.of("color", List.of(""))
Expand Down Expand Up @@ -135,28 +135,43 @@ public void testDeserialization() throws ValidationException, NotImplementedExce
assertNull(deserialized);

header = getHeader(NumberJsonSchema.NumberJsonSchema1.getInstance());
deserialized = header.deserialize(List.of("1"), false, configuration);
var deserializedOne = header.deserialize(List.of("1"), false, configuration);
if (deserializedOne == null) {
throw new RuntimeException("invalid value");
}
@Nullable Object expected = 1L;
Assert.assertEquals(expected, deserialized);
Assert.assertEquals(expected, deserializedOne);

header = getHeader(NumberJsonSchema.NumberJsonSchema1.getInstance());
deserialized = header.deserialize(List.of("3.14"), false, configuration);
var deserialized314 = header.deserialize(List.of("3.14"), false, configuration);
if (deserialized314 == null) {
throw new RuntimeException("invalid value");
}
expected = 3.14d;
Assert.assertEquals(expected, deserialized);
Assert.assertEquals(expected, deserialized314);

header = getHeader(StringJsonSchema.StringJsonSchema1.getInstance());
deserialized = header.deserialize(List.of("blue"), false, configuration);
var deserializedBlue = header.deserialize(List.of("blue"), false, configuration);
if (deserializedBlue == null) {
throw new RuntimeException("invalid value");
}
expected = "blue";
Assert.assertEquals(expected, deserialized);
Assert.assertEquals(expected, deserializedBlue);

header = getHeader(StringJsonSchema.StringJsonSchema1.getInstance());
deserialized = header.deserialize(List.of("hello world"), false, configuration);
var deserializedHelloWorld = header.deserialize(List.of("hello world"), false, configuration);
if (deserializedHelloWorld == null) {
throw new RuntimeException("invalid value");
}
expected = "hello world";
Assert.assertEquals(expected, deserialized);
Assert.assertEquals(expected, deserializedHelloWorld);

header = getHeader(ListJsonSchema.ListJsonSchema1.getInstance());
deserialized = header.deserialize(List.of("blue", "black", "brown"), false, configuration);
var deserializedList = header.deserialize(List.of("blue", "black", "brown"), false, configuration);
if (deserializedList == null) {
throw new RuntimeException("invalid value");
}
expected = List.of("blue", "black", "brown");
Assert.assertEquals(expected, deserialized);
Assert.assertEquals(expected, deserializedList);
}
}
9 changes: 9 additions & 0 deletions samples/client/petstore/java/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
build/
.gradle/
.idea/
target/

# gradle wrapper
gradlew
gradlew.bat
gradle/
4 changes: 3 additions & 1 deletion samples/client/petstore/java/.openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.gitignore
README.md
build.gradle.kts
docs/RootServerInfo.md
docs/apis/paths/Anotherfakedummy.md
docs/apis/paths/Commonparamsubdir.md
Expand Down Expand Up @@ -751,7 +753,7 @@ docs/servers/RootServer1.md
docs/servers/RootServer2.md
docs/servers/rootserver0/RootServer0Variables.md
docs/servers/rootserver1/RootServer1Variables.md
pom.xml
settings.gradle.kts
src/main/java/org/openapijsonschematools/client/RootServerInfo.java
src/main/java/org/openapijsonschematools/client/apiclient/ApiClient.java
src/main/java/org/openapijsonschematools/client/apis/paths/Anotherfakedummy.java
Expand Down
42 changes: 12 additions & 30 deletions samples/client/petstore/java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,32 @@ This Java package is automatically generated by the [OpenAPI JSON Schema Generat
## Requirements

1. Java 17
2. Maven
2. Gradle

## Installation

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

```shell
mvn clean install
gradle wrapper
gradlew clean build
```

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

```shell
mvn clean deploy
```

Refer to the [OSSRH Guide](http://central.sonatype.org/pages/ossrh-guide.html) for more information.
Add this dependency to your project's build file:

### Maven users

Add this dependency to your project's POM:

```xml
<dependency>
<groupId>org.openapijsonschematools</groupId>
<artifactId>petstore</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
```
repositories {
mavenCentral() // Needed if the 'petstore' jar has been published to maven centra
mavenLocal() // Needed if the 'petstore' jar has been published to the local maven repo
}

### Others

At first generate the JAR by executing:

```shell
mvn clean package
dependencies {
implementation "org.openapijsonschematools:petstore:1.0.0"
}
```

Then manually install the following JARs:

- `target/petstore-1.0.0.jar`
- `target/lib/*.jar`


## Usage Notes
### Validation, Immutability, and Data Type
Expand Down
Loading