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

Commit d362b65

Browse files
committed
Adds needed supporting java files
1 parent a052241 commit d362b65

File tree

9 files changed

+151
-1
lines changed

9 files changed

+151
-1
lines changed

samples/client/petstore/java/.openapi-generator/FILES

+6
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,9 @@ src/main/java/org/openapijsonschematools/client/exceptions/InvalidAdditionalProp
488488
src/main/java/org/openapijsonschematools/client/exceptions/InvalidTypeException.java
489489
src/main/java/org/openapijsonschematools/client/exceptions/UnsetPropertyException.java
490490
src/main/java/org/openapijsonschematools/client/exceptions/ValidationException.java
491+
src/main/java/org/openapijsonschematools/client/mediatype/Encoding.java
492+
src/main/java/org/openapijsonschematools/client/mediatype/MediaType.java
493+
src/main/java/org/openapijsonschematools/client/parameter/ParameterStyle.java
491494
src/main/java/org/openapijsonschematools/client/paths/anotherfakedummy/patch/responses/response200/content/applicationjson/Schema.java
492495
src/main/java/org/openapijsonschematools/client/paths/commonparamsubdir/delete/HeaderParameters.java
493496
src/main/java/org/openapijsonschematools/client/paths/commonparamsubdir/delete/PathParameters.java
@@ -716,6 +719,9 @@ src/main/java/org/openapijsonschematools/client/paths/userusername/get/responses
716719
src/main/java/org/openapijsonschematools/client/paths/userusername/get/responses/response200/content/applicationxml/Schema.java
717720
src/main/java/org/openapijsonschematools/client/paths/userusername/put/PathParameters.java
718721
src/main/java/org/openapijsonschematools/client/paths/userusername/put/requestbody/content/applicationjson/Schema.java
722+
src/main/java/org/openapijsonschematools/client/requestbody/RequestBody.java
723+
src/main/java/org/openapijsonschematools/client/requestbody/RequestBodySerializer.java
724+
src/main/java/org/openapijsonschematools/client/requestbody/SerializedRequestBody.java
719725
src/main/java/org/openapijsonschematools/client/schemas/AnyTypeJsonSchema.java
720726
src/main/java/org/openapijsonschematools/client/schemas/BooleanJsonSchema.java
721727
src/main/java/org/openapijsonschematools/client/schemas/DateJsonSchema.java
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.openapijsonschematools.client.mediatype;
2+
3+
import org.checkerframework.checker.nullness.qual.Nullable;
4+
package org.openapijsonschematools.client.parameter.ParameterStyle;
5+
6+
import java.util.Map;
7+
8+
public class Encoding {
9+
public final String contentType;
10+
public final @Nullable Map<String, String> headers; // todo change value to HeaderParameter
11+
public final @Nullable ParameterStyle style;
12+
public final boolean explode;
13+
public final boolean allowReserved;
14+
15+
public Encoding(String contentType) {
16+
this.contentType = contentType;
17+
headers = null;
18+
style = null;
19+
explode = false;
20+
allowReserved = false;
21+
}
22+
public Encoding(String contentType, @Nullable Map<String, String> headers) {
23+
this.contentType = contentType;
24+
this.headers = headers;
25+
style = null;
26+
explode = false;
27+
allowReserved = false;
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.openapijsonschematools.client.mediatype;
2+
3+
import package org.openapijsonschematools.client.schemas.validation.JsonSchema;
4+
import org.checkerframework.checker.nullness.qual.Nullable;
5+
6+
import java.util.Map;
7+
8+
public class MediaType<T extends JsonSchema> {
9+
/*
10+
* Used to store request and response body schema information
11+
* encoding:
12+
* A map between a property name and its encoding information.
13+
* The key, being the property name, MUST exist in the schema as a property.
14+
* The encoding object SHALL only apply to requestBody objects when the media type is
15+
* multipart or application/x-www-form-urlencoded.
16+
*/
17+
public final Class<T> schema;
18+
public final @Nullable Map<String, Encoding> encoding;
19+
20+
public MediaTypeWithoutEncoding(Class<T> schema, @Nullable Map<String, Encoding> encoding) {
21+
this.schema = schema;
22+
this.encoding = encoding;
23+
}
24+
25+
public MediaTypeWithoutEncoding(Class<T> schema) {
26+
this.schema = schema;
27+
this.encoding = null;
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.openapijsonschematools.client.parameter;
2+
3+
public enum ParameterStyle {
4+
MATRIX,
5+
LABEL,
6+
FORM,
7+
SIMPLE,
8+
SPACE_DELIMITED,
9+
PIPE_DELIMITED,
10+
DEEP_OBJECT
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.openapijsonschematools.client.requestbody;
2+
3+
public interface RequestBody<SealedSchemaOutputClass> {
4+
String contentType();
5+
SealedSchemaOutputClass schema();
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.openapijsonschematools.client.requestbody;
2+
3+
import org.openapijsonschematools.client.mediatype.MediaType;
4+
5+
import java.util.Map;
6+
7+
public abstract class RequestBodySerializer<T extends RequestBody> {
8+
/*
9+
* Describes a single request body
10+
* content: content_type to MediaType schema info
11+
* each implementing class must implement RequestBody makeForApplicationJson(SealedOutput)
12+
* each the returned RequestBody must have a protected constructor to insure that
13+
* it is created by makeForApplicationJson
14+
* or make one enum for each content type, then implement make(SpecificContentType, SealedOutput)
15+
* requires one enum per contentType
16+
* abstract T make(String contentType, @Nullable Object body)
17+
* logic: MediaType<?> get(ContentTypeEnum contentType)
18+
* .makeRequestBody(SealedOutput)
19+
*/
20+
public final Map<String, MediaType<?>> content;
21+
public final boolean required;
22+
23+
public RequestBodySerializer(Map<String, MediaType<?>> content, boolean required) {
24+
this.content = content;
25+
this.required = required;
26+
}
27+
28+
public abstract SerializedRequestBody serialize(T requestBody);
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.openapijsonschematools.client.requestbody;
2+
3+
import java.net.http.HttpRequest;
4+
5+
public class SerializedRequestBody {
6+
public final String contentType;
7+
public final HttpRequest.BodyPublisher bodyPublisher;
8+
9+
protected RequestBody(String contentType, HttpRequest.BodyPublisher bodyPublisher) {
10+
this.contentType = contentType;
11+
this.bodyPublisher = bodyPublisher;
12+
}
13+
}

src/main/java/org/openapijsonschematools/codegen/generators/JavaClientGenerator.java

+27
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,33 @@ public void processOpts() {
733733
"src/main/java/packagename/configurations/ApiConfiguration.hbs",
734734
packagePath() + File.separatorChar + "configurations",
735735
"ApiConfiguration.java"));
736+
// requestbody
737+
supportingFiles.add(new SupportingFile(
738+
"src/main/java/packagename/requestbody/RequestBody.hbs",
739+
packagePath() + File.separatorChar + "requestbody",
740+
"RequestBody.java"));
741+
supportingFiles.add(new SupportingFile(
742+
"src/main/java/packagename/requestbody/RequestBodySerializer.hbs",
743+
packagePath() + File.separatorChar + "requestbody",
744+
"RequestBodySerializer.java"));
745+
supportingFiles.add(new SupportingFile(
746+
"src/main/java/packagename/requestbody/SerializedRequestBody.hbs",
747+
packagePath() + File.separatorChar + "requestbody",
748+
"SerializedRequestBody.java"));
749+
// mediatype
750+
supportingFiles.add(new SupportingFile(
751+
"src/main/java/packagename/mediatype/MediaType.hbs",
752+
packagePath() + File.separatorChar + "mediatype",
753+
"MediaType.java"));
754+
supportingFiles.add(new SupportingFile(
755+
"src/main/java/packagename/mediatype/Encoding.hbs",
756+
packagePath() + File.separatorChar + "mediatype",
757+
"Encoding.java"));
758+
// parameter
759+
supportingFiles.add(new SupportingFile(
760+
"src/main/java/packagename/parameter/ParameterStyle.hbs",
761+
packagePath() + File.separatorChar + "parameter",
762+
"ParameterStyle.java"));
736763

737764
HashMap<String, String> schemaTemplates = new HashMap<>();
738765
schemaTemplates.put("src/main/java/packagename/components/schemas/Schema.hbs", ".java");

src/main/resources/java/src/main/java/packagename/requestbody/RequestBodySerializer.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {{{packageName}}}.mediatype.MediaType;
44

55
import java.util.Map;
66

7-
public abstract class RequestBodySerializer<T> {
7+
public abstract class RequestBodySerializer<T extends RequestBody> {
88
/*
99
* Describes a single request body
1010
* content: content_type to MediaType schema info

0 commit comments

Comments
 (0)