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

Commit 77adb1e

Browse files
authored
Java client, adds responses class + deserializer (#394)
* Removes module-info * Adds responses class with emprt deserialize implmentation * Adds sealed classes for status code and wildcard response deserializers * Adds partial deserialize implementation * Handles returning responses when there is no error * Adds typed response throwing * Adds handling of wildcard responses only * Imrpoves response deserialization handling, adds needed imports, removes unused import * Makes response exceptions sttic * Adds shouldGenerateFile method to all generators * Follows response refs when checking if a response has a body * Adds exception throwing when there is a single response * Generates defaultResponse in responses class * Deserializes default only response * Adds handling of responses default + status and default + wildcard * Samples regenerated * Fixes python files in petstore * Sample regen
1 parent c981617 commit 77adb1e

File tree

203 files changed

+5474
-124
lines changed

Some content is hidden

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

203 files changed

+5474
-124
lines changed

samples/client/3_0_3_unit_test/java/.openapi-generator/FILES

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ src/main/java/org/openapijsonschematools/client/components/schemas/UriTemplateFo
179179
src/main/java/org/openapijsonschematools/client/configurations/ApiConfiguration.java
180180
src/main/java/org/openapijsonschematools/client/configurations/JsonSchemaKeywordFlags.java
181181
src/main/java/org/openapijsonschematools/client/configurations/SchemaConfiguration.java
182+
src/main/java/org/openapijsonschematools/client/exceptions/ApiException.java
182183
src/main/java/org/openapijsonschematools/client/exceptions/BaseException.java
183184
src/main/java/org/openapijsonschematools/client/exceptions/InvalidAdditionalPropertyException.java
184185
src/main/java/org/openapijsonschematools/client/exceptions/InvalidTypeException.java
@@ -191,8 +192,9 @@ src/main/java/org/openapijsonschematools/client/requestbody/GenericRequestBody.j
191192
src/main/java/org/openapijsonschematools/client/requestbody/RequestBodySerializer.java
192193
src/main/java/org/openapijsonschematools/client/requestbody/SerializedRequestBody.java
193194
src/main/java/org/openapijsonschematools/client/response/ApiResponse.java
194-
src/main/java/org/openapijsonschematools/client/response/DeserializedApiResponse.java
195+
src/main/java/org/openapijsonschematools/client/response/DeserializedHttpResponse.java
195196
src/main/java/org/openapijsonschematools/client/response/ResponseDeserializer.java
197+
src/main/java/org/openapijsonschematools/client/response/ResponsesDeserializer.java
196198
src/main/java/org/openapijsonschematools/client/schemas/AnyTypeJsonSchema.java
197199
src/main/java/org/openapijsonschematools/client/schemas/BooleanJsonSchema.java
198200
src/main/java/org/openapijsonschematools/client/schemas/DateJsonSchema.java
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.openapijsonschematools.client.exceptions;
2+
3+
import java.net.http.HttpResponse;
4+
5+
@SuppressWarnings("serial")
6+
public class ApiException extends BaseException {
7+
public HttpResponse<byte[]> response;
8+
9+
public ApiException(String s, HttpResponse<byte[]> response) {
10+
super(s);
11+
this.response = response;
12+
}
13+
}

samples/client/3_0_3_unit_test/java/src/main/java/org/openapijsonschematools/client/exceptions/BaseException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22

33
@SuppressWarnings("serial")
44
public class BaseException extends RuntimeException {
5+
public BaseException(String s) {
6+
super(s);
7+
}
58
}

samples/client/3_0_3_unit_test/java/src/main/java/org/openapijsonschematools/client/exceptions/InvalidAdditionalPropertyException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
@SuppressWarnings("serial")
44
public class InvalidAdditionalPropertyException extends BaseException {
55
public InvalidAdditionalPropertyException(String s) {
6-
super();
6+
super(s);
77
}
88
}

samples/client/3_0_3_unit_test/java/src/main/java/org/openapijsonschematools/client/exceptions/InvalidTypeException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
@SuppressWarnings("serial")
44
public class InvalidTypeException extends BaseException {
55
public InvalidTypeException(String s) {
6-
super();
6+
super(s);
77
}
88
}

samples/client/3_0_3_unit_test/java/src/main/java/org/openapijsonschematools/client/exceptions/UnsetPropertyException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
@SuppressWarnings("serial")
44
public class UnsetPropertyException extends BaseException {
55
public UnsetPropertyException(String s) {
6-
super();
6+
super(s);
77
}
88
}

samples/client/3_0_3_unit_test/java/src/main/java/org/openapijsonschematools/client/exceptions/ValidationException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
@SuppressWarnings("serial")
44
public class ValidationException extends BaseException {
55
public ValidationException(String s) {
6-
super();
6+
super(s);
77
}
88
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.openapijsonschematools.client.response;
2+
3+
import java.net.http.HttpResponse;
4+
5+
public record DeserializedHttpResponse<SealedBodyOutputClass, HeaderOutputClass>(SealedBodyOutputClass body, HeaderOutputClass headers) {
6+
}

samples/client/3_0_3_unit_test/java/src/main/java/org/openapijsonschematools/client/response/ResponseDeserializer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected <T> T deserializeBody(String contentType, byte[] body, JsonSchema<T> s
6363
throw new RuntimeException("Deserialization for contentType="+contentType+" has not yet been implemented.");
6464
}
6565

66-
public ApiResponse<SealedBodyClass, HeaderClass> deserialize(HttpResponse<byte[]> response, SchemaConfiguration configuration) {
66+
public DeserializedHttpResponse<SealedBodyClass, HeaderClass> deserialize(HttpResponse<byte[]> response, SchemaConfiguration configuration) {
6767
Optional<String> contentTypeInfo = response.headers().firstValue("Content-Type");
6868
if (contentTypeInfo.isEmpty()) {
6969
throw new RuntimeException("Invalid response returned, Content-Type header is missing and it must be included");
@@ -78,6 +78,6 @@ public ApiResponse<SealedBodyClass, HeaderClass> deserialize(HttpResponse<byte[]
7878
byte[] bodyBytes = response.body();
7979
SealedBodyClass body = getBody(contentType, bodyBytes, configuration);
8080
HeaderClass headers = getHeaders(response.headers());
81-
return new DeserializedApiResponse<>(response, body, headers);
81+
return new DeserializedHttpResponse<>(body, headers);
8282
}
8383
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.openapijsonschematools.client.response;
2+
3+
import org.openapijsonschematools.client.configurations.SchemaConfiguration;
4+
import java.net.http.HttpResponse;
5+
6+
public interface ResponsesDeserializer<SealedResponseClass> {
7+
SealedResponseClass deserialize(HttpResponse<byte[]> response, SchemaConfiguration configuration);
8+
}

0 commit comments

Comments
 (0)