Compare commits

...

10 Commits

Author SHA1 Message Date
William Cheng
a596d5aec0 update jackson databind to newer version (#12053) 2022-04-05 18:09:23 +08:00
Katsuyuki Omuro
efc1a66ebc [Ruby] Fix incorrectly capitalized identifier in apis template (#12045) 2022-04-05 17:50:44 +08:00
William Cheng
5cef7e613a add response headers to api exception (#12042) 2022-04-05 17:24:41 +08:00
William Cheng
4e16146638 more checks in validateJsonObject (#12041) 2022-04-05 17:24:22 +08:00
William Cheng
cd41bc824b [java] Add jersey3 support to the Java client (#12046)
* add jersey3 client support

* update code to support jersey3

* test jersey3 in ci

* update doc

* update sbt, gradle build files
2022-04-05 17:23:37 +08:00
William Cheng
74259724dc add a link to zozo tech blog post 2022-04-05 15:24:28 +08:00
William Cheng
3d8414fa6c update ts samples 2022-04-05 11:40:34 +08:00
javier-garcia-meteologica
e8e1f6b500 feat(typescript-fetch): use ReponseError (#10477) (#10478) 2022-04-04 20:31:47 +02:00
William Cheng
1b570243b6 update local-spec/gradle.properties to snapshot version 2022-04-04 12:24:53 +08:00
William Cheng
2d4a01aa70 Revert "Prepare 6.0.0 beta release (#12039)"
This reverts commit 914b539eea.
2022-04-04 12:17:12 +08:00
1266 changed files with 44541 additions and 856 deletions

View File

@@ -841,6 +841,7 @@ Here are some companies/projects (alphabetical order) using OpenAPI Generator in
- 2022-01-02 - [Towards a secure API client generator for IoT devices](https://arxiv.org/abs/2201.00270) by Anders Aaen Springborg, Martin Kaldahl Andersen, Kaare Holland Hattel, Michele Albano
- 2022-02-02 - [Use OpenApi generator to share your models between Flutter and your backend](https://www.youtube.com/watch?v=kPW7ccu9Yvk) by [Guillaume Bernos](https://feb2022.fluttervikings.com/speakers/guillaume_bernos) at [Flutter Vikings Conference 2022 (Hybrid)](https://feb2022.fluttervikings.com/)
- 2022-03-15 - [OpenAPI Specでハイフン区切りのEnum値をOpenAPI Generatorで出力すると、ハイフン区切りのまま出力される](https://qiita.com/yuji38kwmt/items/824d74d4889055ab37d8) by [yuji38kwmt](https://qiita.com/yuji38kwmt)
- 2022-04-01 - [OpenAPI Generatorのコード生成とSpring Frameworkのカスタムデータバインディングを共存させる](https://techblog.zozo.com/entry/coexistence-of-openapi-and-spring) in [ZOZO Tech Blog](https://techblog.zozo.com/)
## [6 - About Us](#table-of-contents)

View File

@@ -0,0 +1,13 @@
generatorName: java
outputDir: samples/client/petstore/java/jersey3
library: jersey3
inputSpec: modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
templateDir: modules/openapi-generator/src/main/resources/Java
additionalProperties:
artifactId: petstore-jersey3
hideGenerationTimestamp: true
serverPort: "8082"
dateLibrary: java8
useOneOfDiscriminatorLookup: true
disallowAdditionalPropertiesIfNotPresent: false
gradleProperties: "\n# JVM arguments\norg.gradle.jvmargs=-Xmx2024m -XX:MaxPermSize=512m\n# set timeout\norg.gradle.daemon.idletimeout=3600000\n# show all warnings\norg.gradle.warning.mode=all"

View File

@@ -52,7 +52,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|implicitHeadersRegex|Skip header parameters that matches given regex in the generated API methods using @ApiImplicitParams annotation. Note: this parameter is ignored when implicitHeaders=true| |null|
|invokerPackage|root package for generated code| |org.openapitools.client|
|legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C#have this enabled by default).|<dl><dt>**true**</dt><dd>The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.</dd><dt>**false**</dt><dd>The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.</dd></dl>|true|
|library|library template (sub-template) to use|<dl><dt>**jersey1**</dt><dd>HTTP client: Jersey client 1.19.x. JSON processing: Jackson 2.9.x. Enable gzip request encoding using '-DuseGzipFeature=true'. IMPORTANT NOTE: jersey 1.x is no longer actively maintained so please upgrade to 'jersey2' or other HTTP libraries instead.</dd><dt>**jersey2**</dt><dd>HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.9.x</dd><dt>**feign**</dt><dd>HTTP client: OpenFeign 10.x. JSON processing: Jackson 2.9.x.</dd><dt>**okhttp-gson**</dt><dd>[DEFAULT] HTTP client: OkHttp 3.x. JSON processing: Gson 2.8.x. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.</dd><dt>**retrofit2**</dt><dd>HTTP client: OkHttp 3.x. JSON processing: Gson 2.x (Retrofit 2.3.0). Enable the RxJava adapter using '-DuseRxJava[2/3]=true'. (RxJava 1.x or 2.x or 3.x)</dd><dt>**resttemplate**</dt><dd>HTTP client: Spring RestTemplate 4.x. JSON processing: Jackson 2.9.x</dd><dt>**webclient**</dt><dd>HTTP client: Spring WebClient 5.x. JSON processing: Jackson 2.9.x</dd><dt>**resteasy**</dt><dd>HTTP client: Resteasy client 3.x. JSON processing: Jackson 2.9.x</dd><dt>**vertx**</dt><dd>HTTP client: VertX client 3.x. JSON processing: Jackson 2.9.x</dd><dt>**google-api-client**</dt><dd>HTTP client: Google API client 1.x. JSON processing: Jackson 2.9.x</dd><dt>**rest-assured**</dt><dd>HTTP client: rest-assured : 4.x. JSON processing: Gson 2.x or Jackson 2.10.x. Only for Java 8</dd><dt>**native**</dt><dd>HTTP client: Java native HttpClient. JSON processing: Jackson 2.9.x. Only for Java11+</dd><dt>**microprofile**</dt><dd>HTTP client: Microprofile client 1.x. JSON processing: JSON-B</dd><dt>**apache-httpclient**</dt><dd>HTTP client: Apache httpclient 4.x</dd></dl>|okhttp-gson|
|library|library template (sub-template) to use|<dl><dt>**jersey1**</dt><dd>HTTP client: Jersey client 1.19.x. JSON processing: Jackson 2.9.x. Enable gzip request encoding using '-DuseGzipFeature=true'. IMPORTANT NOTE: jersey 1.x is no longer actively maintained so please upgrade to 'jersey3' or other HTTP libraries instead.</dd><dt>**jersey2**</dt><dd>HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.9.x</dd><dt>**jersey3**</dt><dd>HTTP client: Jersey client 3.x. JSON processing: Jackson 2.x</dd><dt>**feign**</dt><dd>HTTP client: OpenFeign 10.x. JSON processing: Jackson 2.9.x.</dd><dt>**okhttp-gson**</dt><dd>[DEFAULT] HTTP client: OkHttp 3.x. JSON processing: Gson 2.8.x. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.</dd><dt>**retrofit2**</dt><dd>HTTP client: OkHttp 3.x. JSON processing: Gson 2.x (Retrofit 2.3.0). Enable the RxJava adapter using '-DuseRxJava[2/3]=true'. (RxJava 1.x or 2.x or 3.x)</dd><dt>**resttemplate**</dt><dd>HTTP client: Spring RestTemplate 4.x. JSON processing: Jackson 2.9.x</dd><dt>**webclient**</dt><dd>HTTP client: Spring WebClient 5.x. JSON processing: Jackson 2.9.x</dd><dt>**resteasy**</dt><dd>HTTP client: Resteasy client 3.x. JSON processing: Jackson 2.9.x</dd><dt>**vertx**</dt><dd>HTTP client: VertX client 3.x. JSON processing: Jackson 2.9.x</dd><dt>**google-api-client**</dt><dd>HTTP client: Google API client 1.x. JSON processing: Jackson 2.9.x</dd><dt>**rest-assured**</dt><dd>HTTP client: rest-assured : 4.x. JSON processing: Gson 2.x or Jackson 2.10.x. Only for Java 8</dd><dt>**native**</dt><dd>HTTP client: Java native HttpClient. JSON processing: Jackson 2.9.x. Only for Java11+</dd><dt>**microprofile**</dt><dd>HTTP client: Microprofile client 1.x. JSON processing: JSON-B</dd><dt>**apache-httpclient**</dt><dd>HTTP client: Apache httpclient 4.x</dd></dl>|okhttp-gson|
|licenseName|The name of the license| |Unlicense|
|licenseUrl|The URL of the license| |http://unlicense.org|
|microprofileFramework|Framework for microprofile. Possible values &quot;kumuluzee&quot;| |null|
@@ -78,7 +78,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|useAbstractionForFiles|Use alternative types instead of java.io.File to allow passing bytes without a file on disk. Available on resttemplate, webclient, libraries| |false|
|useBeanValidation|Use BeanValidation API annotations| |false|
|useGzipFeature|Send gzip-encoded requests| |false|
|useOneOfDiscriminatorLookup|Use the discriminator's mapping in oneOf to speed up the model lookup. IMPORTANT: Validation (e.g. one and only one match in oneOf's schemas) will be skipped. Only jersey2, native, okhttp-gson support this option.| |false|
|useOneOfDiscriminatorLookup|Use the discriminator's mapping in oneOf to speed up the model lookup. IMPORTANT: Validation (e.g. one and only one match in oneOf's schemas) will be skipped. Only jersey2, jersey3, native, okhttp-gson support this option.| |false|
|usePlayWS|Use Play! Async HTTP client (Play WS API)| |false|
|useReflectionEqualsHashCode|Use org.apache.commons.lang3.builder for equals and hashCode in the models. WARNING: This will fail under a security manager, unless the appropriate permissions are set up correctly and also there's potential performance impact.| |false|
|useRuntimeException|Use RuntimeException instead of Exception| |false|

View File

@@ -4,7 +4,7 @@
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-project</artifactId>
<!-- RELEASE_VERSION -->
<version>6.0.0-beta</version>
<version>6.0.0-SNAPSHOT</version>
<!-- /RELEASE_VERSION -->
<relativePath>../..</relativePath>
</parent>

View File

@@ -6,7 +6,7 @@
<artifactId>openapi-generator-project</artifactId>
<groupId>org.openapitools</groupId>
<!-- RELEASE_VERSION -->
<version>6.0.0-beta</version>
<version>6.0.0-SNAPSHOT</version>
<!-- /RELEASE_VERSION -->
<relativePath>../..</relativePath>
</parent>

View File

@@ -1,5 +1,5 @@
# RELEASE_VERSION
openApiGeneratorVersion=6.0.0-beta
openApiGeneratorVersion=6.0.0-SNAPSHOT
# /RELEASE_VERSION
# BEGIN placeholders

View File

@@ -4,7 +4,7 @@
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-project</artifactId>
<!-- RELEASE_VERSION -->
<version>6.0.0-beta</version>
<version>6.0.0-SNAPSHOT</version>
<!-- /RELEASE_VERSION -->
<relativePath>../..</relativePath>
</parent>

View File

@@ -1,3 +1,3 @@
# RELEASE_VERSION
openApiGeneratorVersion=6.0.0-beta
openApiGeneratorVersion=6.0.0-SNAPSHOT
# /RELEASE_VERSION

View File

@@ -13,7 +13,7 @@
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<!-- RELEASE_VERSION -->
<version>6.0.0-beta</version>
<version>6.0.0-SNAPSHOT</version>
<!-- /RELEASE_VERSION -->
<executions>
<execution>

View File

@@ -15,7 +15,7 @@
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<!-- RELEASE_VERSION -->
<version>6.0.0-beta</version>
<version>6.0.0-SNAPSHOT</version>
<!-- /RELEASE_VERSION -->
<executions>
<execution>

View File

@@ -19,7 +19,7 @@
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<!-- RELEASE_VERSION -->
<version>6.0.0-beta</version>
<version>6.0.0-SNAPSHOT</version>
<!-- /RELEASE_VERSION -->
<dependencies>
<dependency>

View File

@@ -13,7 +13,7 @@
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<!-- RELEASE_VERSION -->
<version>6.0.0-beta</version>
<version>6.0.0-SNAPSHOT</version>
<!-- /RELEASE_VERSION -->
<executions>
<execution>

View File

@@ -13,7 +13,7 @@
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<!-- RELEASE_VERSION -->
<version>6.0.0-beta</version>
<version>6.0.0-SNAPSHOT</version>
<!-- /RELEASE_VERSION -->
<executions>
<execution>

View File

@@ -20,7 +20,7 @@
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<!-- RELEASE_VERSION -->
<version>6.0.0-beta</version>
<version>6.0.0-SNAPSHOT</version>
<!-- /RELEASE_VERSION -->
<executions>
<execution>

View File

@@ -5,7 +5,7 @@
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-project</artifactId>
<!-- RELEASE_VERSION -->
<version>6.0.0-beta</version>
<version>6.0.0-SNAPSHOT</version>
<!-- /RELEASE_VERSION -->
<relativePath>../..</relativePath>
</parent>

View File

@@ -4,7 +4,7 @@
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-project</artifactId>
<!-- RELEASE_VERSION -->
<version>6.0.0-beta</version>
<version>6.0.0-SNAPSHOT</version>
<!-- /RELEASE_VERSION -->
<relativePath>../..</relativePath>
</parent>

View File

@@ -4,7 +4,7 @@
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-project</artifactId>
<!-- RELEASE_VERSION -->
<version>6.0.0-beta</version>
<version>6.0.0-SNAPSHOT</version>
<!-- /RELEASE_VERSION -->
<relativePath>../..</relativePath>
</parent>

View File

@@ -76,6 +76,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
public static final String GOOGLE_API_CLIENT = "google-api-client";
public static final String JERSEY1 = "jersey1";
public static final String JERSEY2 = "jersey2";
public static final String JERSEY3 = "jersey3";
public static final String NATIVE = "native";
public static final String OKHTTP_GSON = "okhttp-gson";
public static final String RESTEASY = "resteasy";
@@ -162,10 +163,11 @@ public class JavaClientCodegen extends AbstractJavaCodegen
cliOptions.add(CliOption.newString(GRADLE_PROPERTIES, "Append additional Gradle properties to the gradle.properties file"));
cliOptions.add(CliOption.newString(ERROR_OBJECT_TYPE, "Error Object type. (This option is for okhttp-gson-next-gen only)"));
cliOptions.add(CliOption.newString(CONFIG_KEY, "Config key in @RegisterRestClient. Default to none. Only `microprofile` supports this option."));
cliOptions.add(CliOption.newBoolean(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP, CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP_DESC + " Only jersey2, native, okhttp-gson support this option."));
cliOptions.add(CliOption.newBoolean(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP, CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP_DESC + " Only jersey2, jersey3, native, okhttp-gson support this option."));
supportedLibraries.put(JERSEY1, "HTTP client: Jersey client 1.19.x. JSON processing: Jackson 2.9.x. Enable gzip request encoding using '-DuseGzipFeature=true'. IMPORTANT NOTE: jersey 1.x is no longer actively maintained so please upgrade to 'jersey2' or other HTTP libraries instead.");
supportedLibraries.put(JERSEY1, "HTTP client: Jersey client 1.19.x. JSON processing: Jackson 2.9.x. Enable gzip request encoding using '-DuseGzipFeature=true'. IMPORTANT NOTE: jersey 1.x is no longer actively maintained so please upgrade to 'jersey3' or other HTTP libraries instead.");
supportedLibraries.put(JERSEY2, "HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.9.x");
supportedLibraries.put(JERSEY3, "HTTP client: Jersey client 3.x. JSON processing: Jackson 2.x");
supportedLibraries.put(FEIGN, "HTTP client: OpenFeign 10.x. JSON processing: Jackson 2.9.x.");
supportedLibraries.put(OKHTTP_GSON, "[DEFAULT] HTTP client: OkHttp 3.x. JSON processing: Gson 2.8.x. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.");
supportedLibraries.put(RETROFIT_2, "HTTP client: OkHttp 3.x. JSON processing: Gson 2.x (Retrofit 2.3.0). Enable the RxJava adapter using '-DuseRxJava[2/3]=true'. (RxJava 1.x or 2.x or 3.x)");
@@ -369,7 +371,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
}
// helper for client library that allow to parse/format java.time.OffsetDateTime or org.threeten.bp.OffsetDateTime
if (additionalProperties.containsKey("jsr310") && (isLibrary(WEBCLIENT) || isLibrary(VERTX) || isLibrary(RESTTEMPLATE) || isLibrary(RESTEASY) || isLibrary(MICROPROFILE) || isLibrary(JERSEY1) || isLibrary(JERSEY2) || isLibrary(APACHE))) {
if (additionalProperties.containsKey("jsr310") && (isLibrary(WEBCLIENT) || isLibrary(VERTX) || isLibrary(RESTTEMPLATE) || isLibrary(RESTEASY) || isLibrary(MICROPROFILE) || isLibrary(JERSEY1) || isLibrary(JERSEY2) || isLibrary(JERSEY3) || isLibrary(APACHE))) {
supportingFiles.add(new SupportingFile("JavaTimeFormatter.mustache", invokerFolder, "JavaTimeFormatter.java"));
}
@@ -478,6 +480,23 @@ public class JavaClientCodegen extends AbstractJavaCodegen
// one by one for each library.
supportsAdditionalPropertiesWithComposedSchema = true;
} else if (JERSEY3.equals(getLibrary())) {
additionalProperties.put("jersey3", true);
supportingFiles.add(new SupportingFile("JSON.mustache", invokerFolder, "JSON.java"));
supportingFiles.add(new SupportingFile("ApiResponse.mustache", invokerFolder, "ApiResponse.java"));
if (ProcessUtils.hasHttpSignatureMethods(openAPI)) {
supportingFiles.add(new SupportingFile("auth/HttpSignatureAuth.mustache", authFolder, "HttpSignatureAuth.java"));
}
supportingFiles.add(new SupportingFile("AbstractOpenApiSchema.mustache", modelsFolder, "AbstractOpenApiSchema.java"));
forceSerializationLibrary(SERIALIZATION_LIBRARY_JACKSON);
// Composed schemas can have the 'additionalProperties' keyword, as specified in JSON schema.
// In principle, this should be enabled by default for all code generators. However due to limitations
// in other code generators, support needs to be enabled on a case-by-case basis.
// The flag below should be set for all Java libraries, but the templates need to be ported
// one by one for each library.
supportsAdditionalPropertiesWithComposedSchema = true;
} else if (NATIVE.equals(getLibrary())) {
supportingFiles.add(new SupportingFile("ApiResponse.mustache", invokerFolder, "ApiResponse.java"));
supportingFiles.add(new SupportingFile("JSON.mustache", invokerFolder, "JSON.java"));
@@ -892,7 +911,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
CodegenModel cm = mo.getModel();
cm.getVendorExtensions().putIfAbsent("x-implements", new ArrayList<String>());
if (JERSEY2.equals(getLibrary()) || NATIVE.equals(getLibrary()) || OKHTTP_GSON.equals(getLibrary())) {
if (JERSEY2.equals(getLibrary()) || JERSEY3.equals(getLibrary()) || NATIVE.equals(getLibrary()) || OKHTTP_GSON.equals(getLibrary())) {
cm.getVendorExtensions().put("x-implements", new ArrayList<String>());
if (cm.oneOf != null && !cm.oneOf.isEmpty() && cm.oneOf.contains("ModelNull")) {

View File

@@ -100,13 +100,13 @@ if(hasProperty('target') && target == 'android') {
ext {
swagger_annotations_version = "1.6.5"
jackson_version = "2.13.2"
jackson_databind_version = "2.13.2"
jackson_databind_version = "2.13.2.2"
{{#openApiNullable}}
jackson_databind_nullable_version = "0.2.2"
{{/openApiNullable}}
jakarta_annotation_version = "1.3.5"
jersey_version = "2.35"
junit_version = "4.13.2"
junit_version = "5.8.2"
{{#hasOAuthMethods}}
scribejava_apis_version = "8.3.1"
{{/hasOAuthMethods}}
@@ -140,7 +140,12 @@ dependencies {
implementation "org.tomitribe:tomitribe-http-signatures:$tomitribe_http_signatures_version"
{{/hasHttpSignatureMethods}}
implementation "jakarta.annotation:jakarta.annotation-api:$jakarta_annotation_version"
testImplementation "junit:junit:$junit_version"
testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_version"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit_version"
}
test {
useJUnitPlatform()
}
javadoc {

View File

@@ -18,11 +18,11 @@ lazy val root = (project in file(".")).
"org.glassfish.jersey.connectors" % "jersey-apache-connector" % "2.35",
"com.fasterxml.jackson.core" % "jackson-core" % "2.13.2" % "compile",
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.13.2" % "compile",
"com.fasterxml.jackson.core" % "jackson-databind" % "2.13.2" % "compile",
"com.fasterxml.jackson.core" % "jackson-databind" % "2.13.2.2" % "compile",
{{#joda}}
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % "2.13.0" % "compile",
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % "2.13.2" % "compile",
{{/joda}}
"com.fasterxml.jackson.datatype" % "jackson-datatype-jsr310" % "2.13.0" % "compile",
"com.fasterxml.jackson.datatype" % "jackson-datatype-jsr310" % "2.13.2" % "compile",
{{#openApiNullable}}
"org.openapitools" % "jackson-databind-nullable" % "0.2.2" % "compile",
{{/openApiNullable}}
@@ -33,7 +33,6 @@ lazy val root = (project in file(".")).
"org.tomitribe" % "tomitribe-http-signatures" % "1.7" % "compile",
{{/hasHttpSignatureMethods}}
"jakarta.annotation" % "jakarta.annotation-api" % "1.3.5" % "compile",
"junit" % "junit" % "4.13.2" % "test",
"com.novocode" % "junit-interface" % "0.10" % "test"
"org.junit.jupiter" % "junit-jupiter-api" % "5.8.2" % "test"
)
)

View File

@@ -383,7 +383,7 @@
<swagger-annotations-version>1.6.5</swagger-annotations-version>
<jersey-version>2.35</jersey-version>
<jackson-version>2.13.2</jackson-version>
<jackson-databind-version>2.13.2</jackson-databind-version>
<jackson-databind-version>2.13.2.2</jackson-databind-version>
<jackson-databind-nullable-version>0.2.2</jackson-databind-nullable-version>
<jakarta-annotation-version>1.3.5</jakarta-annotation-version>
{{#useBeanValidation}}

View File

@@ -0,0 +1,138 @@
{{>licenseInfo}}
package {{modelPackage}};
import {{invokerPackage}}.ApiException;
import java.util.Objects;
import java.lang.reflect.Type;
import java.util.Map;
import jakarta.ws.rs.core.GenericType;
import com.fasterxml.jackson.annotation.JsonValue;
/**
* Abstract class for oneOf,anyOf schemas defined in OpenAPI spec
*/
{{>additionalModelTypeAnnotations}}{{>generatedAnnotation}}
public abstract class AbstractOpenApiSchema {
// store the actual instance of the schema/object
private Object instance;
// is nullable
private Boolean isNullable;
// schema type (e.g. oneOf, anyOf)
private final String schemaType;
public AbstractOpenApiSchema(String schemaType, Boolean isNullable) {
this.schemaType = schemaType;
this.isNullable = isNullable;
}
/**
* Get the list of oneOf/anyOf composed schemas allowed to be stored in this object
*
* @return an instance of the actual schema/object
*/
public abstract Map<String, GenericType> getSchemas();
/**
* Get the actual instance
*
* @return an instance of the actual schema/object
*/
@JsonValue
public Object getActualInstance() {return instance;}
/**
* Set the actual instance
*
* @param instance the actual instance of the schema/object
*/
public void setActualInstance(Object instance) {this.instance = instance;}
/**
* Get the instant recursively when the schemas defined in oneOf/anyof happen to be oneOf/anyOf schema as well
*
* @return an instance of the actual schema/object
*/
public Object getActualInstanceRecursively() {
return getActualInstanceRecursively(this);
}
private Object getActualInstanceRecursively(AbstractOpenApiSchema object) {
if (object.getActualInstance() == null) {
return null;
} else if (object.getActualInstance() instanceof AbstractOpenApiSchema) {
return getActualInstanceRecursively((AbstractOpenApiSchema)object.getActualInstance());
} else {
return object.getActualInstance();
}
}
/**
* Get the schema type (e.g. anyOf, oneOf)
*
* @return the schema type
*/
public String getSchemaType() {
return schemaType;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class ").append(getClass()).append(" {\n");
sb.append(" instance: ").append(toIndentedString(instance)).append("\n");
sb.append(" isNullable: ").append(toIndentedString(isNullable)).append("\n");
sb.append(" schemaType: ").append(toIndentedString(schemaType)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AbstractOpenApiSchema a = (AbstractOpenApiSchema) o;
return Objects.equals(this.instance, a.instance) &&
Objects.equals(this.isNullable, a.isNullable) &&
Objects.equals(this.schemaType, a.schemaType);
}
@Override
public int hashCode() {
return Objects.hash(instance, isNullable, schemaType);
}
/**
* Is nullable
*
* @return true if it's nullable
*/
public Boolean isNullable() {
if (Boolean.TRUE.equals(isNullable)) {
return Boolean.TRUE;
} else {
return Boolean.FALSE;
}
}
{{>libraries/jersey2/additional_properties}}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,73 @@
{{>licenseInfo}}
package {{invokerPackage}};
import java.util.List;
import java.util.Map;
{{#caseInsensitiveResponseHeaders}}
import java.util.Map.Entry;
import java.util.TreeMap;
{{/caseInsensitiveResponseHeaders}}
/**
* API response returned by API call.
*
* @param <T> The type of data that is deserialized from response body
*/
public class ApiResponse<T> {
private final int statusCode;
private final Map<String, List<String>> headers;
private final T data;
/**
* @param statusCode The status code of HTTP response
* @param headers The headers of HTTP response
*/
public ApiResponse(int statusCode, Map<String, List<String>> headers) {
this(statusCode, headers, null);
}
/**
* @param statusCode The status code of HTTP response
* @param headers The headers of HTTP response
* @param data The object deserialized from response bod
*/
public ApiResponse(int statusCode, Map<String, List<String>> headers, T data) {
this.statusCode = statusCode;
{{#caseInsensitiveResponseHeaders}}
Map<String, List<String>> responseHeaders = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
for(Entry<String, List<String>> entry : headers.entrySet()){
responseHeaders.put(entry.getKey().toLowerCase(), entry.getValue());
}
{{/caseInsensitiveResponseHeaders}}
this.headers = {{#caseInsensitiveResponseHeaders}}responseHeaders{{/caseInsensitiveResponseHeaders}}{{^caseInsensitiveResponseHeaders}}headers{{/caseInsensitiveResponseHeaders}};
this.data = data;
}
/**
* Get the status code
*
* @return status code
*/
public int getStatusCode() {
return statusCode;
}
/**
* Get the headers
*
* @return map of headers
*/
public Map<String, List<String>> getHeaders() {
return headers;
}
/**
* Get the data
*
* @return data
*/
public T getData() {
return data;
}
}

View File

@@ -0,0 +1,261 @@
package {{invokerPackage}};
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.json.JsonMapper;
{{#openApiNullable}}
import org.openapitools.jackson.nullable.JsonNullableModule;
{{/openApiNullable}}
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
{{#joda}}
import com.fasterxml.jackson.datatype.joda.JodaModule;
{{/joda}}
{{#models.0}}
import {{modelPackage}}.*;
{{/models.0}}
import java.text.DateFormat;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import jakarta.ws.rs.core.GenericType;
import jakarta.ws.rs.ext.ContextResolver;
{{>generatedAnnotation}}
public class JSON implements ContextResolver<ObjectMapper> {
private ObjectMapper mapper;
public JSON() {
mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
JsonMapper.builder().configure(MapperFeature.ALLOW_COERCION_OF_SCALARS, false);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
mapper.configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, true);
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
mapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
mapper.setDateFormat(new RFC3339DateFormat());
mapper.registerModule(new JavaTimeModule());
{{#joda}}
mapper.registerModule(new JodaModule());
{{/joda}}
{{#openApiNullable}}
JsonNullableModule jnm = new JsonNullableModule();
mapper.registerModule(jnm);
{{/openApiNullable}}
}
/**
* Set the date format for JSON (de)serialization with Date properties.
* @param dateFormat Date format
*/
public void setDateFormat(DateFormat dateFormat) {
mapper.setDateFormat(dateFormat);
}
@Override
public ObjectMapper getContext(Class<?> type) {
return mapper;
}
/**
* Get the object mapper
*
* @return object mapper
*/
public ObjectMapper getMapper() { return mapper; }
/**
* Returns the target model class that should be used to deserialize the input data.
* The discriminator mappings are used to determine the target model class.
*
* @param node The input data.
* @param modelClass The class that contains the discriminator mappings.
*/
public static Class<?> getClassForElement(JsonNode node, Class<?> modelClass) {
ClassDiscriminatorMapping cdm = modelDiscriminators.get(modelClass);
if (cdm != null) {
return cdm.getClassForElement(node, new HashSet<Class<?>>());
}
return null;
}
/**
* Helper class to register the discriminator mappings.
*/
private static class ClassDiscriminatorMapping {
// The model class name.
Class<?> modelClass;
// The name of the discriminator property.
String discriminatorName;
// The discriminator mappings for a model class.
Map<String, Class<?>> discriminatorMappings;
// Constructs a new class discriminator.
ClassDiscriminatorMapping(Class<?> cls, String propertyName, Map<String, Class<?>> mappings) {
modelClass = cls;
discriminatorName = propertyName;
discriminatorMappings = new HashMap<String, Class<?>>();
if (mappings != null) {
discriminatorMappings.putAll(mappings);
}
}
// Return the name of the discriminator property for this model class.
String getDiscriminatorPropertyName() {
return discriminatorName;
}
// Return the discriminator value or null if the discriminator is not
// present in the payload.
String getDiscriminatorValue(JsonNode node) {
// Determine the value of the discriminator property in the input data.
if (discriminatorName != null) {
// Get the value of the discriminator property, if present in the input payload.
node = node.get(discriminatorName);
if (node != null && node.isValueNode()) {
String discrValue = node.asText();
if (discrValue != null) {
return discrValue;
}
}
}
return null;
}
/**
* Returns the target model class that should be used to deserialize the input data.
* This function can be invoked for anyOf/oneOf composed models with discriminator mappings.
* The discriminator mappings are used to determine the target model class.
*
* @param node The input data.
* @param visitedClasses The set of classes that have already been visited.
*/
Class<?> getClassForElement(JsonNode node, Set<Class<?>> visitedClasses) {
if (visitedClasses.contains(modelClass)) {
// Class has already been visited.
return null;
}
// Determine the value of the discriminator property in the input data.
String discrValue = getDiscriminatorValue(node);
if (discrValue == null) {
return null;
}
Class<?> cls = discriminatorMappings.get(discrValue);
// It may not be sufficient to return this cls directly because that target class
// may itself be a composed schema, possibly with its own discriminator.
visitedClasses.add(modelClass);
for (Class<?> childClass : discriminatorMappings.values()) {
ClassDiscriminatorMapping childCdm = modelDiscriminators.get(childClass);
if (childCdm == null) {
continue;
}
if (!discriminatorName.equals(childCdm.discriminatorName)) {
discrValue = getDiscriminatorValue(node);
if (discrValue == null) {
continue;
}
}
if (childCdm != null) {
// Recursively traverse the discriminator mappings.
Class<?> childDiscr = childCdm.getClassForElement(node, visitedClasses);
if (childDiscr != null) {
return childDiscr;
}
}
}
return cls;
}
}
/**
* Returns true if inst is an instance of modelClass in the OpenAPI model hierarchy.
*
* The Java class hierarchy is not implemented the same way as the OpenAPI model hierarchy,
* so it's not possible to use the instanceof keyword.
*
* @param modelClass A OpenAPI model class.
* @param inst The instance object.
*/
public static boolean isInstanceOf(Class<?> modelClass, Object inst, Set<Class<?>> visitedClasses) {
if (modelClass.isInstance(inst)) {
// This handles the 'allOf' use case with single parent inheritance.
return true;
}
if (visitedClasses.contains(modelClass)) {
// This is to prevent infinite recursion when the composed schemas have
// a circular dependency.
return false;
}
visitedClasses.add(modelClass);
// Traverse the oneOf/anyOf composed schemas.
Map<String, GenericType> descendants = modelDescendants.get(modelClass);
if (descendants != null) {
for (GenericType childType : descendants.values()) {
if (isInstanceOf(childType.getRawType(), inst, visitedClasses)) {
return true;
}
}
}
return false;
}
/**
* A map of discriminators for all model classes.
*/
private static Map<Class<?>, ClassDiscriminatorMapping> modelDiscriminators = new HashMap<Class<?>, ClassDiscriminatorMapping>();
/**
* A map of oneOf/anyOf descendants for each model class.
*/
private static Map<Class<?>, Map<String, GenericType>> modelDescendants = new HashMap<Class<?>, Map<String, GenericType>>();
/**
* Register a model class discriminator.
*
* @param modelClass the model class
* @param discriminatorPropertyName the name of the discriminator property
* @param mappings a map with the discriminator mappings.
*/
public static void registerDiscriminator(Class<?> modelClass, String discriminatorPropertyName, Map<String, Class<?>> mappings) {
ClassDiscriminatorMapping m = new ClassDiscriminatorMapping(modelClass, discriminatorPropertyName, mappings);
modelDiscriminators.put(modelClass, m);
}
/**
* Register the oneOf/anyOf descendants of the modelClass.
*
* @param modelClass the model class
* @param descendants a map of oneOf/anyOf descendants.
*/
public static void registerDescendants(Class<?> modelClass, Map<String, GenericType> descendants) {
modelDescendants.put(modelClass, descendants);
}
private static JSON json;
static
{
json = new JSON();
}
/**
* Get the default JSON instance.
*
* @return the default JSON instance
*/
public static JSON getDefault() {
return json;
}
/**
* Set the default JSON instance.
*
* @param json JSON instance to be used
*/
public static void setDefault(JSON json) {
JSON.json = json;
}
}

View File

@@ -0,0 +1,39 @@
{{#additionalPropertiesType}}
/**
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*/
private Map<String, {{{.}}}> additionalProperties;
/**
* Set the additional (undeclared) property with the specified name and value.
* If the property does not already exist, create it otherwise replace it.
*/
@JsonAnySetter
public {{classname}} putAdditionalProperty(String key, {{{.}}} value) {
if (this.additionalProperties == null) {
this.additionalProperties = new HashMap<String, {{{.}}}>();
}
this.additionalProperties.put(key, value);
return this;
}
/**
* Return the additional (undeclared) property.
*/
@JsonAnyGetter
public Map<String, {{{.}}}> getAdditionalProperties() {
return additionalProperties;
}
/**
* Return the additional (undeclared) property with the specified name.
*/
public {{{.}}} getAdditionalProperty(String key) {
if (this.additionalProperties == null) {
return null;
}
return this.additionalProperties.get(key);
}
{{/additionalPropertiesType}}

View File

@@ -0,0 +1,202 @@
import jakarta.ws.rs.core.GenericType;
import jakarta.ws.rs.core.Response;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import {{invokerPackage}}.JSON;
{{>additionalModelTypeAnnotations}}{{>generatedAnnotation}}{{>xmlAnnotation}}
@JsonDeserialize(using={{classname}}.{{classname}}Deserializer.class)
@JsonSerialize(using = {{classname}}.{{classname}}Serializer.class)
public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-implements}}, {{{.}}}{{/vendorExtensions.x-implements}} {
private static final Logger log = Logger.getLogger({{classname}}.class.getName());
public static class {{classname}}Serializer extends StdSerializer<{{classname}}> {
public {{classname}}Serializer(Class<{{classname}}> t) {
super(t);
}
public {{classname}}Serializer() {
this(null);
}
@Override
public void serialize({{classname}} value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
jgen.writeObject(value.getActualInstance());
}
}
public static class {{classname}}Deserializer extends StdDeserializer<{{classname}}> {
public {{classname}}Deserializer() {
this({{classname}}.class);
}
public {{classname}}Deserializer(Class<?> vc) {
super(vc);
}
@Override
public {{classname}} deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
JsonNode tree = jp.readValueAsTree();
Object deserialized = null;
{{#discriminator}}
Class<?> cls = JSON.getClassForElement(tree, {{classname}}.class);
if (cls != null) {
// When the OAS schema includes a discriminator, use the discriminator value to
// discriminate the anyOf schemas.
// Get the discriminator mapping value to get the class.
deserialized = tree.traverse(jp.getCodec()).readValueAs(cls);
{{classname}} ret = new {{classname}}();
ret.setActualInstance(deserialized);
return ret;
}
{{/discriminator}}
{{#anyOf}}
// deserialize {{{.}}}
try {
deserialized = tree.traverse(jp.getCodec()).readValueAs({{{.}}}.class);
{{classname}} ret = new {{classname}}();
ret.setActualInstance(deserialized);
return ret;
} catch (Exception e) {
// deserialization failed, continue, log to help debugging
log.log(Level.FINER, "Input data does not match '{{classname}}'", e);
}
{{/anyOf}}
throw new IOException(String.format("Failed deserialization for {{classname}}: no match found"));
}
/**
* Handle deserialization of the 'null' value.
*/
@Override
public {{classname}} getNullValue(DeserializationContext ctxt) throws JsonMappingException {
{{#isNullable}}
return null;
{{/isNullable}}
{{^isNullable}}
throw new JsonMappingException(ctxt.getParser(), "{{classname}} cannot be null");
{{/isNullable}}
}
}
// store a list of schema names defined in anyOf
public static final Map<String, GenericType> schemas = new HashMap<String, GenericType>();
public {{classname}}() {
super("anyOf", {{#isNullable}}Boolean.TRUE{{/isNullable}}{{^isNullable}}Boolean.FALSE{{/isNullable}});
}
{{> libraries/jersey2/additional_properties }}
{{#additionalPropertiesType}}
/**
* Return true if this {{name}} object is equal to o.
*/
@Override
public boolean equals(Object o) {
return super.equals(o) && Objects.equals(this.additionalProperties, (({{classname}})o).additionalProperties);
}
@Override
public int hashCode() {
return Objects.hash(getActualInstance(), isNullable(), getSchemaType(), additionalProperties);
}
{{/additionalPropertiesType}}
{{#anyOf}}
public {{classname}}({{{.}}} o) {
super("anyOf", {{#isNullable}}Boolean.TRUE{{/isNullable}}{{^isNullable}}Boolean.FALSE{{/isNullable}});
setActualInstance(o);
}
{{/anyOf}}
static {
{{#anyOf}}
schemas.put("{{{.}}}", new GenericType<{{{.}}}>() {
});
{{/anyOf}}
JSON.registerDescendants({{classname}}.class, Collections.unmodifiableMap(schemas));
{{#discriminator}}
// Initialize and register the discriminator mappings.
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
{{#mappedModels}}
mappings.put("{{mappingName}}", {{modelName}}.class);
{{/mappedModels}}
mappings.put("{{name}}", {{classname}}.class);
JSON.registerDiscriminator({{classname}}.class, "{{propertyBaseName}}", mappings);
{{/discriminator}}
}
@Override
public Map<String, GenericType> getSchemas() {
return {{classname}}.schemas;
}
/**
* Set the instance that matches the anyOf child schema, check
* the instance parameter is valid against the anyOf child schemas:
* {{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}
*
* It could be an instance of the 'anyOf' schemas.
* The anyOf child schemas may themselves be a composed schema (allOf, anyOf, anyOf).
*/
@Override
public void setActualInstance(Object instance) {
{{#isNullable}}
if (instance == null) {
super.setActualInstance(instance);
return;
}
{{/isNullable}}
{{#anyOf}}
if (JSON.isInstanceOf({{{.}}}.class, instance, new HashSet<Class<?>>())) {
super.setActualInstance(instance);
return;
}
{{/anyOf}}
throw new RuntimeException("Invalid instance type. Must be {{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}");
}
/**
* Get the actual instance, which can be the following:
* {{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}
*
* @return The actual instance ({{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}})
*/
@Override
public Object getActualInstance() {
return super.getActualInstance();
}
{{#anyOf}}
/**
* Get the actual instance of `{{{.}}}`. If the actual instance is not `{{{.}}}`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `{{{.}}}`
* @throws ClassCastException if the instance is not `{{{.}}}`
*/
public {{{.}}} get{{{.}}}() throws ClassCastException {
return ({{{.}}})super.getActualInstance();
}
{{/anyOf}}
}

View File

@@ -0,0 +1,262 @@
package {{package}};
import {{invokerPackage}}.ApiException;
import {{invokerPackage}}.ApiClient;
import {{invokerPackage}}.ApiResponse;
import {{invokerPackage}}.Configuration;
import {{invokerPackage}}.Pair;
import jakarta.ws.rs.core.GenericType;
{{#imports}}import {{import}};
{{/imports}}
{{^fullJavaUtil}}
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
{{/fullJavaUtil}}
{{>generatedAnnotation}}
{{#operations}}
public class {{classname}} {
private ApiClient apiClient;
public {{classname}}() {
this(Configuration.getDefaultApiClient());
}
public {{classname}}(ApiClient apiClient) {
this.apiClient = apiClient;
}
/**
* Get the API client
*
* @return API client
*/
public ApiClient getApiClient() {
return apiClient;
}
/**
* Set the API client
*
* @param apiClient an instance of API client
*/
public void setApiClient(ApiClient apiClient) {
this.apiClient = apiClient;
}
{{#operation}}
{{^vendorExtensions.x-group-parameters}}
/**
* {{summary}}
* {{notes}}
{{#allParams}}
* @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}
{{/allParams}}
{{#returnType}}
* @return {{.}}
{{/returnType}}
* @throws ApiException if fails to make API call
{{#responses.0}}
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
{{#responses}}
<tr><td> {{code}} </td><td> {{message}} </td><td> {{#headers}} * {{baseName}} - {{description}} <br> {{/headers}}{{^headers.0}} - {{/headers.0}} </td></tr>
{{/responses}}
</table>
{{/responses.0}}
{{#isDeprecated}}
* @deprecated
{{/isDeprecated}}
{{#externalDocs}}
* {{description}}
* @see <a href="{{url}}">{{summary}} Documentation</a>
{{/externalDocs}}
*/
{{#isDeprecated}}
@Deprecated
{{/isDeprecated}}
public {{#returnType}}{{{.}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}) throws ApiException {
{{#returnType}}return {{/returnType}}{{operationId}}WithHttpInfo({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}){{#returnType}}.getData(){{/returnType}};
}
{{/vendorExtensions.x-group-parameters}}
{{^vendorExtensions.x-group-parameters}}
/**
* {{summary}}
* {{notes}}
{{#allParams}}
* @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}
{{/allParams}}
* @return ApiResponse&lt;{{returnType}}{{^returnType}}Void{{/returnType}}&gt;
* @throws ApiException if fails to make API call
{{#responses.0}}
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
{{#responses}}
<tr><td> {{code}} </td><td> {{message}} </td><td> {{#headers}} * {{baseName}} - {{description}} <br> {{/headers}}{{^headers.0}} - {{/headers.0}} </td></tr>
{{/responses}}
</table>
{{/responses.0}}
{{#isDeprecated}}
* @deprecated
{{/isDeprecated}}
{{#externalDocs}}
* {{description}}
* @see <a href="{{url}}">{{summary}} Documentation</a>
{{/externalDocs}}
*/
{{#isDeprecated}}
@Deprecated
{{/isDeprecated}}
public{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}private{{/vendorExtensions.x-group-parameters}} ApiResponse<{{{returnType}}}{{^returnType}}Void{{/returnType}}> {{operationId}}WithHttpInfo({{#allParams}}{{{dataType}}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}) throws ApiException {
Object localVarPostBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
{{#allParams}}{{#required}}
// verify the required parameter '{{paramName}}' is set
if ({{paramName}} == null) {
throw new ApiException(400, "Missing the required parameter '{{paramName}}' when calling {{operationId}}");
}
{{/required}}{{/allParams}}
// create path and map variables
String localVarPath = "{{{path}}}"{{#pathParams}}
.replaceAll("\\{" + "{{baseName}}" + "\\}", apiClient.escapeString({{{paramName}}}.toString())){{/pathParams}};
// query params
{{javaUtilPrefix}}List<Pair> localVarQueryParams = new {{javaUtilPrefix}}ArrayList<Pair>();
{{javaUtilPrefix}}Map<String, String> localVarHeaderParams = new {{javaUtilPrefix}}HashMap<String, String>();
{{javaUtilPrefix}}Map<String, String> localVarCookieParams = new {{javaUtilPrefix}}HashMap<String, String>();
{{javaUtilPrefix}}Map<String, Object> localVarFormParams = new {{javaUtilPrefix}}HashMap<String, Object>();
{{#queryParams}}
localVarQueryParams.addAll(apiClient.parameterToPairs("{{{collectionFormat}}}", "{{baseName}}", {{paramName}}));
{{/queryParams}}
{{#headerParams}}if ({{paramName}} != null)
localVarHeaderParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));
{{/headerParams}}
{{#cookieParams}}if ({{paramName}} != null)
localVarCookieParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));
{{/cookieParams}}
{{#formParams}}if ({{paramName}} != null)
localVarFormParams.put("{{baseName}}", {{paramName}});
{{/formParams}}
final String[] localVarAccepts = {
{{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}}
};
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
final String[] localVarContentTypes = {
{{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}}
};
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
String[] localVarAuthNames = new String[] { {{#authMethods}}"{{name}}"{{^-last}}, {{/-last}}{{/authMethods}} };
{{#returnType}}
GenericType<{{{returnType}}}> localVarReturnType = new GenericType<{{{returnType}}}>() {};
{{/returnType}}
return apiClient.invokeAPI("{{classname}}.{{operationId}}", localVarPath, "{{httpMethod}}", localVarQueryParams, localVarPostBody,
localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAccept, localVarContentType,
localVarAuthNames, {{#returnType}}localVarReturnType{{/returnType}}{{^returnType}}null{{/returnType}}, {{#bodyParam}}{{#isNullable}}true{{/isNullable}}{{^isNullable}}false{{/isNullable}}{{/bodyParam}}{{^bodyParam}}false{{/bodyParam}});
}
{{#vendorExtensions.x-group-parameters}}
public class API{{operationId}}Request {
{{#allParams}}
private {{#isRequired}}final {{/isRequired}}{{{dataType}}} {{paramName}};
{{/allParams}}
private API{{operationId}}Request({{#pathParams}}{{{dataType}}} {{paramName}}{{^-last}}, {{/-last}}{{/pathParams}}) {
{{#pathParams}}
this.{{paramName}} = {{paramName}};
{{/pathParams}}
}
{{#allParams}}
{{^isPathParam}}
/**
* Set {{paramName}}
* @param {{paramName}} {{description}} ({{^required}}optional{{^isContainer}}{{#defaultValue}}, default to {{.}}{{/defaultValue}}{{/isContainer}}{{/required}}{{#required}}required{{/required}})
* @return API{{operationId}}Request
*/
public API{{operationId}}Request {{paramName}}({{{dataType}}} {{paramName}}) {
this.{{paramName}} = {{paramName}};
return this;
}
{{/isPathParam}}
{{/allParams}}
/**
* Execute {{operationId}} request
{{#returnType}}* @return {{.}}{{/returnType}}
* @throws ApiException if fails to make API call
{{#responses.0}}
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
{{#responses}}
<tr><td> {{code}} </td><td> {{message}} </td><td> {{#headers}} * {{baseName}} - {{description}} <br> {{/headers}}{{^headers.0}} - {{/headers.0}} </td></tr>
{{/responses}}
</table>
{{/responses.0}}
{{#isDeprecated}}* @deprecated{{/isDeprecated}}
*/
{{#isDeprecated}}@Deprecated{{/isDeprecated}}
public {{{returnType}}}{{^returnType}}void{{/returnType}} execute() throws ApiException {
{{#returnType}}return {{/returnType}}this.executeWithHttpInfo().getData();
}
/**
* Execute {{operationId}} request with HTTP info returned
* @return ApiResponse&lt;{{returnType}}{{^returnType}}Void{{/returnType}}&gt;
* @throws ApiException if fails to make API call
{{#responses.0}}
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
{{#responses}}
<tr><td> {{code}} </td><td> {{message}} </td><td> {{#headers}} * {{baseName}} - {{description}} <br> {{/headers}}{{^headers.0}} - {{/headers.0}} </td></tr>
{{/responses}}
</table>
{{/responses.0}}
{{#isDeprecated}}
* @deprecated{{/isDeprecated}}
*/
{{#isDeprecated}}
@Deprecated
{{/isDeprecated}}
public ApiResponse<{{{returnType}}}{{^returnType}}Void{{/returnType}}> executeWithHttpInfo() throws ApiException {
return {{operationId}}WithHttpInfo({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}});
}
}
/**
* {{summary}}
* {{notes}}{{#pathParams}}
* @param {{paramName}} {{description}} (required){{/pathParams}}
* @return {{operationId}}Request
* @throws ApiException if fails to make API call
{{#isDeprecated}}* @deprecated{{/isDeprecated}}
{{#externalDocs}}* {{description}}
* @see <a href="{{url}}">{{summary}} Documentation</a>{{/externalDocs}}
*/
{{#isDeprecated}}
@Deprecated
{{/isDeprecated}}
public API{{operationId}}Request {{operationId}}({{#pathParams}}{{{dataType}}} {{paramName}}{{^-last}}, {{/-last}}{{/pathParams}}) throws ApiException {
return new API{{operationId}}Request({{#pathParams}}{{paramName}}{{^-last}}, {{/-last}}{{/pathParams}});
}
{{/vendorExtensions.x-group-parameters}}
{{/operation}}
}
{{/operations}}

View File

@@ -0,0 +1,99 @@
{{>licenseInfo}}
package {{invokerPackage}};
import java.util.Map;
import java.util.List;
{{#caseInsensitiveResponseHeaders}}
import java.util.Map.Entry;
import java.util.TreeMap;
{{/caseInsensitiveResponseHeaders}}
/**
* API Exception
*/
{{>generatedAnnotation}}
public class ApiException extends{{#useRuntimeException}} RuntimeException {{/useRuntimeException}}{{^useRuntimeException}} Exception {{/useRuntimeException}}{
private int code = 0;
private Map<String, List<String>> responseHeaders = null;
private String responseBody = null;
public ApiException() {}
public ApiException(Throwable throwable) {
super(throwable);
}
public ApiException(String message) {
super(message);
}
public ApiException(String message, Throwable throwable, int code, Map<String, List<String>> responseHeaders, String responseBody) {
super(message, throwable);
this.code = code;
{{#caseInsensitiveResponseHeaders}}
Map<String, List<String>> headers = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
for(Entry<String, List<String>> entry : responseHeaders.entrySet()){
headers.put(entry.getKey().toLowerCase(), entry.getValue());
}
{{/caseInsensitiveResponseHeaders}}
this.responseHeaders = {{#caseInsensitiveResponseHeaders}}headers{{/caseInsensitiveResponseHeaders}}{{^caseInsensitiveResponseHeaders}}responseHeaders{{/caseInsensitiveResponseHeaders}};
this.responseBody = responseBody;
}
public ApiException(String message, int code, Map<String, List<String>> responseHeaders, String responseBody) {
this(message, (Throwable) null, code, responseHeaders, responseBody);
}
public ApiException(String message, Throwable throwable, int code, Map<String, List<String>> responseHeaders) {
this(message, throwable, code, responseHeaders, null);
}
public ApiException(int code, Map<String, List<String>> responseHeaders, String responseBody) {
this((String) null, (Throwable) null, code, responseHeaders, responseBody);
}
public ApiException(int code, String message) {
super(message);
this.code = code;
}
public ApiException(int code, String message, Map<String, List<String>> responseHeaders, String responseBody) {
this(code, message);
{{#caseInsensitiveResponseHeaders}}
Map<String, List<String>> headers = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
for(Entry<String, List<String>> entry : responseHeaders.entrySet()){
headers.put(entry.getKey().toLowerCase(), entry.getValue());
}
{{/caseInsensitiveResponseHeaders}}
this.responseHeaders = {{#caseInsensitiveResponseHeaders}}headers{{/caseInsensitiveResponseHeaders}}{{^caseInsensitiveResponseHeaders}}responseHeaders{{/caseInsensitiveResponseHeaders}};
this.responseBody = responseBody;
}
/**
* Get the HTTP status code.
*
* @return HTTP status code
*/
public int getCode() {
return code;
}
/**
* Get the HTTP response headers.
*
* @return A map of list of string
*/
public Map<String, List<String>> getResponseHeaders() {
return responseHeaders;
}
/**
* Get the HTTP response body.
*
* @return Response body in the form of string
*/
public String getResponseBody() {
return responseBody;
}
}

View File

@@ -0,0 +1,124 @@
# {{classname}}{{#description}}
{{.}}{{/description}}
All URIs are relative to *{{basePath}}*
| Method | HTTP request | Description |
|------------- | ------------- | -------------|
{{#operations}}{{#operation}}| [**{{operationId}}**]({{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{path}} | {{summary}} |
{{/operation}}{{/operations}}
{{#operations}}
{{#operation}}
## {{operationId}}
{{^vendorExtensions.x-group-parameters}}
> {{#returnType}}{{.}} {{/returnType}}{{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}})
{{/vendorExtensions.x-group-parameters}}
{{#vendorExtensions.x-group-parameters}}
> {{#returnType}}{{.}} {{/returnType}}{{operationId}}({{#pathParams}}{{paramName}}{{^-last}}, {{/-last}}{{/pathParams}}){{#allParams}}{{^isPathParam}}.{{paramName}}({{paramName}}){{/isPathParam}}{{/allParams}}.execute();
{{/vendorExtensions.x-group-parameters}}
{{summary}}{{#notes}}
{{{unescapedNotes}}}{{/notes}}
### Example
```java
{{#vendorExtensions.x-java-import}}
import {{.}};
{{/vendorExtensions.x-java-import}}
// Import classes:
import {{{invokerPackage}}}.ApiClient;
import {{{invokerPackage}}}.ApiException;
import {{{invokerPackage}}}.Configuration;{{#hasAuthMethods}}
import {{{invokerPackage}}}.auth.*;{{/hasAuthMethods}}
import {{{invokerPackage}}}.model.*;
import {{{package}}}.{{{classname}}};
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("{{{basePath}}}");
{{#hasAuthMethods}}
{{#authMethods}}{{#isBasic}}{{#isBasicBasic}}
// Configure HTTP basic authorization: {{{name}}}
HttpBasicAuth {{{name}}} = (HttpBasicAuth) defaultClient.getAuthentication("{{{name}}}");
{{{name}}}.setUsername("YOUR USERNAME");
{{{name}}}.setPassword("YOUR PASSWORD");{{/isBasicBasic}}{{#isBasicBearer}}
// Configure HTTP bearer authorization: {{{name}}}
HttpBearerAuth {{{name}}} = (HttpBearerAuth) defaultClient.getAuthentication("{{{name}}}");
{{{name}}}.setBearerToken("BEARER TOKEN");{{/isBasicBearer}}{{/isBasic}}{{#isApiKey}}
// Configure API key authorization: {{{name}}}
ApiKeyAuth {{{name}}} = (ApiKeyAuth) defaultClient.getAuthentication("{{{name}}}");
{{{name}}}.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//{{{name}}}.setApiKeyPrefix("Token");{{/isApiKey}}{{#isOAuth}}
// Configure OAuth2 access token for authorization: {{{name}}}
OAuth {{{name}}} = (OAuth) defaultClient.getAuthentication("{{{name}}}");
{{{name}}}.setAccessToken("YOUR ACCESS TOKEN");{{/isOAuth}}
{{/authMethods}}
{{/hasAuthMethods}}
{{{classname}}} apiInstance = new {{{classname}}}(defaultClient);
{{#allParams}}
{{{dataType}}} {{{paramName}}} = {{{example}}}; // {{{dataType}}} | {{{description}}}
{{/allParams}}
try {
{{^vendorExtensions.x-group-parameters}}
{{#returnType}}{{{.}}} result = {{/returnType}}apiInstance.{{{operationId}}}({{#allParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}});
{{/vendorExtensions.x-group-parameters}}
{{#vendorExtensions.x-group-parameters}}
{{#returnType}}{{{.}}} result = {{/returnType}}api.{{operationId}}({{#pathParams}}{{paramName}}{{^-last}}, {{/-last}}{{/pathParams}}){{#allParams}}{{^isPathParam}}
.{{paramName}}({{paramName}}){{/isPathParam}}{{/allParams}}
.execute();
{{/vendorExtensions.x-group-parameters}}
{{#returnType}}
System.out.println(result);
{{/returnType}}
} catch (ApiException e) {
System.err.println("Exception when calling {{{classname}}}#{{{operationId}}}");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
```
### Parameters
{{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#allParams}}{{#-last}}
| Name | Type | Description | Notes |
|------------- | ------------- | ------------- | -------------|{{/-last}}{{/allParams}}
{{#allParams}}| **{{paramName}}** | {{#isContainer}}{{#isArray}}{{#items}}{{#isModel}}{{^isFile}}[{{/isFile}}{{/isModel}}**List&lt;{{dataType}}&gt;**{{#isModel}}{{^isFile}}]({{^baseType}}{{dataType}}{{/baseType}}{{baseType}}.md){{/isFile}}{{/isModel}}{{/items}}{{/isArray}}{{#isMap}}{{#items}}{{#isModel}}{{^isFile}}[{{/isFile}}{{/isModel}}**Map&lt;String,{{dataType}}&gt;**{{#isModel}}{{^isFile}}]({{^baseType}}{{dataType}}{{/baseType}}{{baseType}}.md){{/isFile}}{{/isModel}}{{/items}}{{/isMap}}{{/isContainer}}{{^isContainer}}{{#isModel}}{{^isFile}}[{{/isFile}}{{/isModel}}**{{dataType}}**{{#isModel}}{{^isFile}}]({{^baseType}}{{dataType}}{{/baseType}}{{baseType}}.md){{/isFile}}{{/isModel}}{{/isContainer}}| {{description}} |{{^required}} [optional]{{/required}}{{^isContainer}}{{#defaultValue}} [default to {{.}}]{{/defaultValue}}{{/isContainer}}{{#allowableValues}} [enum: {{#values}}{{{.}}}{{^-last}}, {{/-last}}{{/values}}]{{/allowableValues}} |
{{/allParams}}
### Return type
{{#returnType}}{{#returnTypeIsPrimitive}}**{{returnType}}**{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}[**{{returnType}}**]({{returnBaseType}}.md){{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}null (empty response body){{/returnType}}
### Authorization
{{^authMethods}}No authorization required{{/authMethods}}{{#authMethods}}[{{name}}](../README.md#{{name}}){{^-last}}, {{/-last}}{{/authMethods}}
### HTTP request headers
- **Content-Type**: {{#consumes}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/consumes}}{{^consumes}}Not defined{{/consumes}}
- **Accept**: {{#produces}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/produces}}{{^produces}}Not defined{{/produces}}
{{#responses.0}}
### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
{{#responses}}
| **{{code}}** | {{message}} | {{#headers}} * {{baseName}} - {{description}} <br> {{/headers}}{{^headers.0}} - {{/headers.0}} |
{{/responses}}
{{/responses.0}}
{{/operation}}
{{/operations}}

View File

@@ -0,0 +1,59 @@
{{>licenseInfo}}
package {{package}};
import {{invokerPackage}}.*;
import {{invokerPackage}}.auth.*;
{{#imports}}import {{import}};
{{/imports}}
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
{{^fullJavaUtil}}
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
{{/fullJavaUtil}}
/**
* API tests for {{classname}}
*/
public class {{classname}}Test {
private final {{classname}} api = new {{classname}}();
{{#operations}}
{{#operation}}
/**
{{#summary}}
* {{summary}}
*
{{/summary}}
{{#notes}}
* {{notes}}
*
{{/notes}}
* @throws ApiException if the Api call fails
*/
@Test
public void {{operationId}}Test() throws ApiException {
{{#allParams}}
//{{{dataType}}} {{paramName}} = null;
{{/allParams}}
{{^vendorExtensions.x-group-parameters}}
//{{#returnType}}{{{.}}} response = {{/returnType}}api.{{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}});
{{/vendorExtensions.x-group-parameters}}
{{#vendorExtensions.x-group-parameters}}
//{{#returnType}}{{{.}}} response = {{/returnType}}api.{{operationId}}({{#pathParams}}{{paramName}}{{^-last}}, {{/-last}}{{/pathParams}}){{#allParams}}{{^isPathParam}}
// .{{paramName}}({{paramName}}){{/isPathParam}}{{/allParams}}
// .execute();
{{/vendorExtensions.x-group-parameters}}
// TODO: test validations
}
{{/operation}}
{{/operations}}
}

View File

@@ -0,0 +1,68 @@
{{>licenseInfo}}
package {{invokerPackage}}.auth;
import {{invokerPackage}}.Pair;
import {{invokerPackage}}.ApiException;
import java.net.URI;
import java.util.Map;
import java.util.List;
{{>generatedAnnotation}}
public class ApiKeyAuth implements Authentication {
private final String location;
private final String paramName;
private String apiKey;
private String apiKeyPrefix;
public ApiKeyAuth(String location, String paramName) {
this.location = location;
this.paramName = paramName;
}
public String getLocation() {
return location;
}
public String getParamName() {
return paramName;
}
public String getApiKey() {
return apiKey;
}
public void setApiKey(String apiKey) {
this.apiKey = apiKey;
}
public String getApiKeyPrefix() {
return apiKeyPrefix;
}
public void setApiKeyPrefix(String apiKeyPrefix) {
this.apiKeyPrefix = apiKeyPrefix;
}
@Override
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams, Map<String, String> cookieParams, String payload, String method, URI uri) throws ApiException {
if (apiKey == null) {
return;
}
String value;
if (apiKeyPrefix != null) {
value = apiKeyPrefix + " " + apiKey;
} else {
value = apiKey;
}
if ("query".equals(location)) {
queryParams.add(new Pair(paramName, value));
} else if ("header".equals(location)) {
headerParams.put(paramName, value);
} else if ("cookie".equals(location)) {
cookieParams.put(paramName, value);
}
}
}

View File

@@ -0,0 +1,22 @@
{{>licenseInfo}}
package {{invokerPackage}}.auth;
import {{invokerPackage}}.Pair;
import {{invokerPackage}}.ApiException;
import java.net.URI;
import java.util.Map;
import java.util.List;
public interface Authentication {
/**
* Apply authentication settings to header and query params.
*
* @param queryParams List of query parameters
* @param headerParams Map of header parameters
* @param cookieParams Map of cookie parameters
*/
void applyToParams(List<Pair> queryParams, Map<String, String> headerParams, Map<String, String> cookieParams, String payload, String method, URI uri) throws ApiException;
}

View File

@@ -0,0 +1,44 @@
{{>licenseInfo}}
package {{invokerPackage}}.auth;
import {{invokerPackage}}.Pair;
import {{invokerPackage}}.ApiException;
import java.util.Base64;
import java.nio.charset.StandardCharsets;
import java.net.URI;
import java.util.Map;
import java.util.List;
{{>generatedAnnotation}}
public class HttpBasicAuth implements Authentication {
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams, Map<String, String> cookieParams, String payload, String method, URI uri) throws ApiException {
if (username == null && password == null) {
return;
}
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
headerParams.put("Authorization", "Basic " + Base64.getEncoder().encodeToString(str.getBytes(StandardCharsets.UTF_8)));
}
}

View File

@@ -0,0 +1,51 @@
{{>licenseInfo}}
package {{invokerPackage}}.auth;
import {{invokerPackage}}.Pair;
import {{invokerPackage}}.ApiException;
import java.net.URI;
import java.util.Map;
import java.util.List;
{{>generatedAnnotation}}
public class HttpBearerAuth implements Authentication {
private final String scheme;
private String bearerToken;
public HttpBearerAuth(String scheme) {
this.scheme = scheme;
}
/**
* Gets the token, which together with the scheme, will be sent as the value of the Authorization header.
*
* @return The bearer token
*/
public String getBearerToken() {
return bearerToken;
}
/**
* Sets the token, which together with the scheme, will be sent as the value of the Authorization header.
*
* @param bearerToken The bearer token to send in the Authorization header
*/
public void setBearerToken(String bearerToken) {
this.bearerToken = bearerToken;
}
@Override
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams, Map<String, String> cookieParams, String payload, String method, URI uri) throws ApiException {
if(bearerToken == null) {
return;
}
headerParams.put("Authorization", (scheme != null ? upperCaseBearer(scheme) + " " : "") + bearerToken);
}
private static String upperCaseBearer(String scheme) {
return ("bearer".equalsIgnoreCase(scheme)) ? "Bearer" : scheme;
}
}

View File

@@ -0,0 +1,269 @@
{{>licenseInfo}}
package {{invokerPackage}}.auth;
import {{invokerPackage}}.Pair;
import {{invokerPackage}}.ApiException;
import java.net.URI;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.Key;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
import java.util.List;
import java.util.TimeZone;
import java.security.spec.AlgorithmParameterSpec;
import java.security.InvalidKeyException;
import org.tomitribe.auth.signatures.Algorithm;
import org.tomitribe.auth.signatures.Signer;
import org.tomitribe.auth.signatures.Signature;
import org.tomitribe.auth.signatures.SigningAlgorithm;
/**
* A Configuration object for the HTTP message signature security scheme.
*/
public class HttpSignatureAuth implements Authentication {
private Signer signer;
// An opaque string that the server can use to look up the component they need to validate the signature.
private String keyId;
// The HTTP signature algorithm.
private SigningAlgorithm signingAlgorithm;
// The HTTP cryptographic algorithm.
private Algorithm algorithm;
// The cryptographic parameters.
private AlgorithmParameterSpec parameterSpec;
// The list of HTTP headers that should be included in the HTTP signature.
private List<String> headers;
// The digest algorithm which is used to calculate a cryptographic digest of the HTTP request body.
private String digestAlgorithm;
// The maximum validity duration of the HTTP signature.
private Long maxSignatureValidity;
/**
* Construct a new HTTP signature auth configuration object.
*
* @param keyId An opaque string that the server can use to look up the component they need to validate the signature.
* @param signingAlgorithm The signature algorithm.
* @param algorithm The cryptographic algorithm.
* @param digestAlgorithm The digest algorithm.
* @param headers The list of HTTP headers that should be included in the HTTP signature.
* @param maxSignatureValidity The maximum validity duration of the HTTP signature.
* Used to set the '(expires)' field in the HTTP signature.
*/
public HttpSignatureAuth(String keyId,
SigningAlgorithm signingAlgorithm,
Algorithm algorithm,
String digestAlgorithm,
AlgorithmParameterSpec parameterSpec,
List<String> headers,
Long maxSignatureValidity) {
this.keyId = keyId;
this.signingAlgorithm = signingAlgorithm;
this.algorithm = algorithm;
this.parameterSpec = parameterSpec;
this.digestAlgorithm = digestAlgorithm;
this.headers = headers;
this.maxSignatureValidity = maxSignatureValidity;
}
/**
* Returns the opaque string that the server can use to look up the component they need to validate the signature.
*
* @return The keyId.
*/
public String getKeyId() {
return keyId;
}
/**
* Set the HTTP signature key id.
*
* @param keyId An opaque string that the server can use to look up the component they need to validate the signature.
*/
public void setKeyId(String keyId) {
this.keyId = keyId;
}
/**
* Returns the HTTP signature algorithm which is used to sign HTTP requests.
*/
public SigningAlgorithm getSigningAlgorithm() {
return signingAlgorithm;
}
/**
* Sets the HTTP signature algorithm which is used to sign HTTP requests.
*
* @param signingAlgorithm The HTTP signature algorithm.
*/
public void setSigningAlgorithm(SigningAlgorithm signingAlgorithm) {
this.signingAlgorithm = signingAlgorithm;
}
/**
* Returns the HTTP cryptographic algorithm which is used to sign HTTP requests.
*/
public Algorithm getAlgorithm() {
return algorithm;
}
/**
* Sets the HTTP cryptographic algorithm which is used to sign HTTP requests.
*
* @param algorithm The HTTP signature algorithm.
*/
public void setAlgorithm(Algorithm algorithm) {
this.algorithm = algorithm;
}
/**
* Returns the cryptographic parameters which are used to sign HTTP requests.
*/
public AlgorithmParameterSpec getAlgorithmParameterSpec() {
return parameterSpec;
}
/**
* Sets the cryptographic parameters which are used to sign HTTP requests.
*
* @param parameterSpec The cryptographic parameters.
*/
public void setAlgorithmParameterSpec(AlgorithmParameterSpec parameterSpec) {
this.parameterSpec = parameterSpec;
}
/**
* Returns the digest algorithm which is used to calculate a cryptographic digest of the HTTP request body.
*
* @see java.security.MessageDigest
*/
public String getDigestAlgorithm() {
return digestAlgorithm;
}
/**
* Sets the digest algorithm which is used to calculate a cryptographic digest of the HTTP request body.
*
* The exact list of supported digest algorithms depends on the installed security providers.
* Every implementation of the Java platform is required to support "MD5", "SHA-1" and "SHA-256".
* Do not use "MD5" and "SHA-1", they are vulnerable to multiple known attacks.
* By default, "SHA-256" is used.
*
* @param digestAlgorithm The digest algorithm.
*
* @see java.security.MessageDigest
*/
public void setDigestAlgorithm(String digestAlgorithm) {
this.digestAlgorithm = digestAlgorithm;
}
/**
* Returns the list of HTTP headers that should be included in the HTTP signature.
*/
public List<String> getHeaders() {
return headers;
}
/**
* Sets the list of HTTP headers that should be included in the HTTP signature.
*
* @param headers The HTTP headers.
*/
public void setHeaders(List<String> headers) {
this.headers = headers;
}
/**
* Returns the maximum validity duration of the HTTP signature.
* @return The maximum validity duration of the HTTP signature.
*/
public Long getMaxSignatureValidity() {
return maxSignatureValidity;
}
/**
* Returns the signer instance used to sign HTTP messages.
*
* @return the signer instance.
*/
public Signer getSigner() {
return signer;
}
/**
* Sets the signer instance used to sign HTTP messages.
*
* @param signer The signer instance to set.
*/
public void setSigner(Signer signer) {
this.signer = signer;
}
/**
* Set the private key used to sign HTTP requests using the HTTP signature scheme.
*
* @param key The private key.
*
* @throws InvalidKeyException Unable to parse the key, or the security provider for this key
* is not installed.
*/
public void setPrivateKey(Key key) throws InvalidKeyException, ApiException {
if (key == null) {
throw new ApiException("Private key (java.security.Key) cannot be null");
}
signer = new Signer(key, new Signature(keyId, signingAlgorithm, algorithm, parameterSpec, null, headers, maxSignatureValidity));
}
@Override
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams, Map<String, String> cookieParams,
String payload, String method, URI uri) throws ApiException {
try {
if (headers.contains("host")) {
headerParams.put("host", uri.getHost());
}
if (headers.contains("date")) {
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
headerParams.put("date", dateFormat.format(Calendar.getInstance().getTime()));
}
if (headers.contains("digest")) {
headerParams.put("digest",
this.digestAlgorithm + "=" +
new String(Base64.getEncoder().encode(MessageDigest.getInstance(this.digestAlgorithm).digest(payload.getBytes()))));
}
if (signer == null) {
throw new ApiException("Signer cannot be null. Please call the method `setPrivateKey` to set it up correctly");
}
// construct the path with the URL-encoded path and query.
// Calling getRawPath and getRawQuery ensures the path is URL-encoded as it will be serialized
// on the wire. The HTTP signature must use the encode URL as it is sent on the wire.
String path = uri.getRawPath();
if (uri.getRawQuery() != null && !"".equals(uri.getRawQuery())) {
path += "?" + uri.getRawQuery();
}
headerParams.put("Authorization", signer.sign(method, path, headerParams).toString());
} catch (Exception ex) {
throw new ApiException("Failed to create signature in the HTTP request header: " + ex.toString());
}
}
}

View File

@@ -0,0 +1,182 @@
{{>licenseInfo}}
package {{invokerPackage}}.auth;
import {{invokerPackage}}.Pair;
import {{invokerPackage}}.ApiException;
import com.github.scribejava.core.builder.ServiceBuilder;
import com.github.scribejava.core.builder.api.DefaultApi20;
import com.github.scribejava.core.exceptions.OAuthException;
import com.github.scribejava.core.model.OAuth2AccessToken;
import com.github.scribejava.core.oauth.OAuth20Service;
import jakarta.ws.rs.core.UriBuilder;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
{{>generatedAnnotation}}
public class OAuth implements Authentication {
private static final Logger log = Logger.getLogger(OAuth.class.getName());
private String tokenUrl;
private String absoluteTokenUrl;
private OAuthFlow flow = OAuthFlow.APPLICATION;
private OAuth20Service service;
private DefaultApi20 authApi;
private String scope;
private String username;
private String password;
private String code;
private volatile OAuth2AccessToken accessToken;
public OAuth(String basePath, String tokenUrl) {
this.tokenUrl = tokenUrl;
this.absoluteTokenUrl = createAbsoluteTokenUrl(basePath, tokenUrl);
authApi = new DefaultApi20() {
@Override
public String getAccessTokenEndpoint() {
return absoluteTokenUrl;
}
@Override
protected String getAuthorizationBaseUrl() {
throw new UnsupportedOperationException("Shouldn't get there !");
}
};
}
private static String createAbsoluteTokenUrl(String basePath, String tokenUrl) {
if (!URI.create(tokenUrl).isAbsolute()) {
try {
return UriBuilder.fromPath(basePath).path(tokenUrl).build().toURL().toString();
} catch (MalformedURLException e) {
log.log(Level.SEVERE, "Couldn't create absolute token URL", e);
}
}
return tokenUrl;
}
@Override
public void applyToParams(
List<Pair> queryParams,
Map<String, String> headerParams,
Map<String, String> cookieParams,
String payload,
String method,
URI uri)
throws ApiException {
if (accessToken == null) {
obtainAccessToken(null);
}
if (accessToken != null) {
headerParams.put("Authorization", "Bearer " + accessToken.getAccessToken());
}
}
public OAuth2AccessToken renewAccessToken() throws ApiException {
String refreshToken = null;
if (accessToken != null) {
refreshToken = accessToken.getRefreshToken();
accessToken = null;
}
return obtainAccessToken(refreshToken);
}
public synchronized OAuth2AccessToken obtainAccessToken(String refreshToken) throws ApiException {
if (service == null) {
log.log(Level.FINE, "service is null in obtainAccessToken.");
return null;
}
try {
if (refreshToken != null) {
return service.refreshAccessToken(refreshToken);
}
} catch (OAuthException | InterruptedException | ExecutionException | IOException e) {
log.log(Level.FINE, "Refreshing the access token using the refresh token failed", e);
}
try {
switch (flow) {
case PASSWORD:
if (username != null && password != null) {
accessToken = service.getAccessTokenPasswordGrant(username, password, scope);
}
break;
case ACCESS_CODE:
if (code != null) {
accessToken = service.getAccessToken(code);
code = null;
}
break;
case APPLICATION:
accessToken = service.getAccessTokenClientCredentialsGrant(scope);
break;
default:
log.log(Level.SEVERE, "Invalid flow in obtainAccessToken: " + flow);
}
} catch (OAuthException | InterruptedException | ExecutionException | IOException e) {
throw new ApiException(e);
}
return accessToken;
}
public OAuth2AccessToken getAccessToken() {
return accessToken;
}
public OAuth setAccessToken(OAuth2AccessToken accessToken) {
this.accessToken = accessToken;
return this;
}
public OAuth setAccessToken(String accessToken) {
this.accessToken = new OAuth2AccessToken(accessToken);
return this;
}
public OAuth setScope(String scope) {
this.scope = scope;
return this;
}
public OAuth setCredentials(String clientId, String clientSecret, Boolean debug) {
if (Boolean.TRUE.equals(debug)) {
service = new ServiceBuilder(clientId)
.apiSecret(clientSecret).debug()
.build(authApi);
} else {
service = new ServiceBuilder(clientId)
.apiSecret(clientSecret)
.build(authApi);
}
return this;
}
public OAuth usePasswordFlow(String username, String password) {
this.flow = OAuthFlow.PASSWORD;
this.username = username;
this.password = password;
return this;
}
public OAuth useAuthorizationCodeFlow(String code) {
this.flow = OAuthFlow.ACCESS_CODE;
this.code = code;
return this;
}
public OAuth setFlow(OAuthFlow flow) {
this.flow = flow;
return this;
}
public void setBasePath(String basePath) {
this.absoluteTokenUrl = createAbsoluteTokenUrl(basePath, tokenUrl);
}
}

View File

@@ -0,0 +1,13 @@
{{>licenseInfo}}
package {{invokerPackage}}.auth;
/**
* OAuth flows that are supported by this client
*/
public enum OAuthFlow {
ACCESS_CODE,
IMPLICIT,
PASSWORD,
APPLICATION
}

View File

@@ -0,0 +1,177 @@
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'com.diffplug.spotless'
group = '{{groupId}}'
version = '{{artifactVersion}}'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.+'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath 'com.diffplug.spotless:spotless-plugin-gradle:6.3.0'
}
}
repositories {
mavenCentral()
}
if(hasProperty('target') && target == 'android') {
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
defaultConfig {
minSdkVersion 14
targetSdkVersion 25
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
// Rename the aar correctly
libraryVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.aar')) {
def fileName = "${project.name}-${variant.baseName}-${version}.aar"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
dependencies {
provided "jakarta.annotation:jakarta.annotation-api:$jakarta_annotation_version"
}
}
afterEvaluate {
android.libraryVariants.all { variant ->
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
task.description = "Create jar artifact for ${variant.name}"
task.dependsOn variant.javaCompile
task.from variant.javaCompile.destinationDir
task.destinationDir = project.file("${project.buildDir}/outputs/jar")
task.archiveName = "${project.name}-${variant.baseName}-${version}.jar"
artifacts.add('archives', task);
}
}
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
artifacts {
archives sourcesJar
}
} else {
apply plugin: 'java'
apply plugin: 'maven-publish'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
publishing {
publications {
maven(MavenPublication) {
artifactId = '{{artifactId}}'
from components.java
}
}
}
task execute(type:JavaExec) {
main = System.getProperty('mainClass')
classpath = sourceSets.main.runtimeClasspath
}
}
ext {
swagger_annotations_version = "1.6.5"
jackson_version = "2.13.2"
jackson_databind_version = "2.13.2"
{{#openApiNullable}}
jackson_databind_nullable_version = "0.2.2"
{{/openApiNullable}}
jakarta_annotation_version = "2.1.0"
jersey_version = "3.0.4"
junit_version = "5.8.2"
{{#hasOAuthMethods}}
scribejava_apis_version = "8.3.1"
{{/hasOAuthMethods}}
{{#hasHttpSignatureMethods}}
tomitribe_http_signatures_version = "1.7"
{{/hasHttpSignatureMethods}}
}
dependencies {
implementation "io.swagger:swagger-annotations:$swagger_annotations_version"
implementation "com.google.code.findbugs:jsr305:3.0.2"
implementation "org.glassfish.jersey.core:jersey-client:$jersey_version"
implementation "org.glassfish.jersey.inject:jersey-hk2:$jersey_version"
implementation "org.glassfish.jersey.media:jersey-media-multipart:$jersey_version"
implementation "org.glassfish.jersey.media:jersey-media-json-jackson:$jersey_version"
implementation "org.glassfish.jersey.connectors:jersey-apache-connector:$jersey_version"
implementation "com.fasterxml.jackson.core:jackson-core:$jackson_version"
implementation "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
implementation "com.fasterxml.jackson.core:jackson-databind:$jackson_databind_version"
{{#openApiNullable}}
implementation "org.openapitools:jackson-databind-nullable:$jackson_databind_nullable_version"
{{/openApiNullable}}
{{#joda}}
implementation "com.fasterxml.jackson.datatype:jackson-datatype-joda:$jackson_version"
{{/joda}}
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson_version"
{{#hasOAuthMethods}}
implementation "com.github.scribejava:scribejava-apis:$scribejava_apis_version"
{{/hasOAuthMethods}}
{{#hasHttpSignatureMethods}}
implementation "org.tomitribe:tomitribe-http-signatures:$tomitribe_http_signatures_version"
{{/hasHttpSignatureMethods}}
implementation "jakarta.annotation:jakarta.annotation-api:$jakarta_annotation_version"
testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_version"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit_version"
}
test {
useJUnitPlatform()
}
javadoc {
options.tags = [ "http.response.details:a:Http Response Details" ]
}
// Use spotless plugin to automatically format code, remove unused import, etc
// To apply changes directly to the file, run `gradlew spotlessApply`
// Ref: https://github.com/diffplug/spotless/tree/main/plugin-gradle
spotless {
// comment out below to run spotless as part of the `check` task
enforceCheck false
format 'misc', {
// define the files (e.g. '*.gradle', '*.md') to apply `misc` to
target '.gitignore'
// define the steps to apply to those files
trimTrailingWhitespace()
indentWithSpaces() // Takes an integer argument if you don't like 4
endWithNewline()
}
java {
// don't need to set target, it is inferred from java
// apply a specific flavor of google-java-format
googleJavaFormat('1.8').aosp().reflowLongStrings()
removeUnusedImports()
importOrder()
}
}

View File

@@ -0,0 +1,38 @@
lazy val root = (project in file(".")).
settings(
organization := "{{groupId}}",
name := "{{artifactId}}",
version := "{{artifactVersion}}",
scalaVersion := "2.11.4",
scalacOptions ++= Seq("-feature"),
Compile / javacOptions ++= Seq("-Xlint:deprecation"),
Compile / packageDoc / publishArtifact := false,
resolvers += Resolver.mavenLocal,
libraryDependencies ++= Seq(
"com.google.code.findbugs" % "jsr305" % "3.0.0",
"io.swagger" % "swagger-annotations" % "1.6.5",
"org.glassfish.jersey.core" % "jersey-client" % "3.0.4",
"org.glassfish.jersey.inject" % "jersey-hk2" % "3.0.4",
"org.glassfish.jersey.media" % "jersey-media-multipart" % "3.0.4",
"org.glassfish.jersey.media" % "jersey-media-json-jackson" % "3.0.4",
"org.glassfish.jersey.connectors" % "jersey-apache-connector" % "3.0.4",
"com.fasterxml.jackson.core" % "jackson-core" % "2.13.2" % "compile",
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.13.2" % "compile",
"com.fasterxml.jackson.core" % "jackson-databind" % "2.13.2" % "compile",
{{#joda}}
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % "2.13.0" % "compile",
{{/joda}}
"com.fasterxml.jackson.datatype" % "jackson-datatype-jsr310" % "2.13.0" % "compile",
{{#openApiNullable}}
"org.openapitools" % "jackson-databind-nullable" % "0.2.2" % "compile",
{{/openApiNullable}}
{{#hasOAuthMethods}}
"com.github.scribejava" % "scribejava-apis" % "8.3.1" % "compile",
{{/hasOAuthMethods}}
{{#hasHttpSignatureMethods}}
"org.tomitribe" % "tomitribe-http-signatures" % "1.7" % "compile",
{{/hasHttpSignatureMethods}}
"jakarta.annotation" % "jakarta.annotation-api" % "2.1.0" % "compile",
"org.junit.jupiter" % "junit-jupiter-api" % "5.8.2" % "test"
)
)

View File

@@ -0,0 +1 @@
@jakarta.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}})

View File

@@ -0,0 +1,64 @@
{{>licenseInfo}}
package {{package}};
{{#useReflectionEqualsHashCode}}
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
{{/useReflectionEqualsHashCode}}
{{#models}}
{{#model}}
{{#additionalPropertiesType}}
import java.util.Map;
import java.util.HashMap;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
{{/additionalPropertiesType}}
{{/model}}
{{/models}}
import java.util.Objects;
import java.util.Arrays;
import java.util.Map;
import java.util.HashMap;
{{#imports}}
import {{import}};
{{/imports}}
{{#serializableModel}}
import java.io.Serializable;
{{/serializableModel}}
{{#jackson}}
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
{{#withXml}}
import com.fasterxml.jackson.dataformat.xml.annotation.*;
{{/withXml}}
{{#vendorExtensions.x-has-readonly-properties}}
import com.fasterxml.jackson.annotation.JsonCreator;
{{/vendorExtensions.x-has-readonly-properties}}
{{/jackson}}
{{#withXml}}
import javax.xml.bind.annotation.*;
{{/withXml}}
{{#parcelableModel}}
import android.os.Parcelable;
import android.os.Parcel;
{{/parcelableModel}}
{{#useBeanValidation}}
import javax.validation.constraints.*;
import javax.validation.Valid;
{{/useBeanValidation}}
{{#performBeanValidation}}
import org.hibernate.validator.constraints.*;
{{/performBeanValidation}}
import {{invokerPackage}}.JSON;
{{#models}}
{{#model}}
{{#oneOf}}
{{#-first}}
import com.fasterxml.jackson.core.type.TypeReference;
{{/-first}}
{{/oneOf}}
{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{#oneOf}}{{#-first}}{{>oneof_model}}{{/-first}}{{/oneOf}}{{^oneOf}}{{#anyOf}}{{#-first}}{{>anyof_model}}{{/-first}}{{/anyOf}}{{^anyOf}}{{>pojo}}{{/anyOf}}{{/oneOf}}{{/isEnum}}
{{/model}}
{{/models}}

View File

@@ -0,0 +1,38 @@
# {{classname}}
{{#description}}
{{&description}}
{{/description}}
## anyOf schemas
{{#anyOf}}
* [{{{.}}}]({{{.}}}.md)
{{/anyOf}}
{{#isNullable}}
NOTE: this class is nullable.
{{/isNullable}}
## Example
```java
// Import classes:
import {{{package}}}.{{{classname}}};
{{#anyOf}}
import {{{package}}}.{{{.}}};
{{/anyOf}}
public class Example {
public static void main(String[] args) {
{{classname}} example{{classname}} = new {{classname}}();
{{#anyOf}}
// create a new {{{.}}}
{{{.}}} example{{{.}}} = new {{{.}}}();
// set {{{classname}}} to {{{.}}}
example{{classname}}.setActualInstance(example{{{.}}});
// to get back the {{{.}}} set earlier
{{{.}}} test{{{.}}} = ({{{.}}}) example{{classname}}.getActualInstance();
{{/anyOf}}
}
}
```

View File

@@ -0,0 +1,19 @@
{{#models}}{{#model}}
{{#isEnum}}
{{>enum_outer_doc}}
{{/isEnum}}
{{^isEnum}}
{{^oneOf.isEmpty}}
{{>model_oneof_doc}}
{{/oneOf.isEmpty}}
{{^anyOf.isEmpty}}
{{>model_anyof_doc}}
{{/anyOf.isEmpty}}
{{^anyOf}}
{{^oneOf}}
{{>pojo_doc}}
{{/oneOf}}
{{/anyOf}}
{{/isEnum}}
{{/model}}{{/models}}

View File

@@ -0,0 +1,38 @@
# {{classname}}
{{#description}}
{{&description}}
{{/description}}
## oneOf schemas
{{#oneOf}}
* [{{{.}}}]({{{.}}}.md)
{{/oneOf}}
{{#isNullable}}
NOTE: this class is nullable.
{{/isNullable}}
## Example
```java
// Import classes:
import {{{package}}}.{{{classname}}};
{{#oneOf}}
import {{{package}}}.{{{.}}};
{{/oneOf}}
public class Example {
public static void main(String[] args) {
{{classname}} example{{classname}} = new {{classname}}();
{{#oneOf}}
// create a new {{{.}}}
{{{.}}} example{{{.}}} = new {{{.}}}();
// set {{{classname}}} to {{{.}}}
example{{classname}}.setActualInstance(example{{{.}}});
// to get back the {{{.}}} set earlier
{{{.}}} test{{{.}}} = ({{{.}}}) example{{classname}}.getActualInstance();
{{/oneOf}}
}
}
```

View File

@@ -0,0 +1,51 @@
{{>licenseInfo}}
package {{package}};
{{#imports}}import {{import}};
{{/imports}}
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
{{#fullJavaUtil}}
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
{{/fullJavaUtil}}
/**
* Model tests for {{classname}}
*/
public class {{classname}}Test {
{{#models}}
{{#model}}
{{^vendorExtensions.x-is-one-of-interface}}
{{^isEnum}}
private final {{classname}} model = new {{classname}}();
{{/isEnum}}
/**
* Model tests for {{classname}}
*/
@Test
public void test{{classname}}() {
// TODO: test {{classname}}
}
{{#allVars}}
/**
* Test the property '{{name}}'
*/
@Test
public void {{name}}Test() {
// TODO: test {{name}}
}
{{/allVars}}
{{/vendorExtensions.x-is-one-of-interface}}
{{/model}}
{{/models}}
}

View File

@@ -0,0 +1,235 @@
import jakarta.ws.rs.core.GenericType;
import jakarta.ws.rs.core.Response;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import {{invokerPackage}}.JSON;
{{>additionalModelTypeAnnotations}}{{>generatedAnnotation}}{{>xmlAnnotation}}
@JsonDeserialize(using = {{classname}}.{{classname}}Deserializer.class)
@JsonSerialize(using = {{classname}}.{{classname}}Serializer.class)
public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-implements}}, {{{.}}}{{/vendorExtensions.x-implements}} {
private static final Logger log = Logger.getLogger({{classname}}.class.getName());
public static class {{classname}}Serializer extends StdSerializer<{{classname}}> {
public {{classname}}Serializer(Class<{{classname}}> t) {
super(t);
}
public {{classname}}Serializer() {
this(null);
}
@Override
public void serialize({{classname}} value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
jgen.writeObject(value.getActualInstance());
}
}
public static class {{classname}}Deserializer extends StdDeserializer<{{classname}}> {
public {{classname}}Deserializer() {
this({{classname}}.class);
}
public {{classname}}Deserializer(Class<?> vc) {
super(vc);
}
@Override
public {{classname}} deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
JsonNode tree = jp.readValueAsTree();
Object deserialized = null;
{{#useOneOfDiscriminatorLookup}}
{{#discriminator}}
{{classname}} new{{classname}} = new {{classname}}();
Map<String,Object> result2 = tree.traverse(jp.getCodec()).readValueAs(new TypeReference<Map<String, Object>>() {});
String discriminatorValue = (String)result2.get("{{{propertyBaseName}}}");
switch (discriminatorValue) {
{{#mappedModels}}
case "{{{mappingName}}}":
deserialized = tree.traverse(jp.getCodec()).readValueAs({{{modelName}}}.class);
new{{classname}}.setActualInstance(deserialized);
return new{{classname}};
{{/mappedModels}}
default:
log.log(Level.WARNING, String.format("Failed to lookup discriminator value `%s` for {{classname}}. Possible values:{{#mappedModels}} {{{mappingName}}}{{/mappedModels}}", discriminatorValue));
}
{{/discriminator}}
{{/useOneOfDiscriminatorLookup}}
boolean typeCoercion = ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS);
int match = 0;
JsonToken token = tree.traverse(jp.getCodec()).nextToken();
{{#oneOf}}
// deserialize {{{.}}}
try {
boolean attemptParsing = true;
// ensure that we respect type coercion as set on the client ObjectMapper
if ({{{.}}}.class.equals(Integer.class) || {{{.}}}.class.equals(Long.class) || {{{.}}}.class.equals(Float.class) || {{{.}}}.class.equals(Double.class) || {{{.}}}.class.equals(Boolean.class) || {{{.}}}.class.equals(String.class)) {
attemptParsing = typeCoercion;
if (!attemptParsing) {
attemptParsing |= (({{{.}}}.class.equals(Integer.class) || {{{.}}}.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT);
attemptParsing |= (({{{.}}}.class.equals(Float.class) || {{{.}}}.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT);
attemptParsing |= ({{{.}}}.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE));
attemptParsing |= ({{{.}}}.class.equals(String.class) && token == JsonToken.VALUE_STRING);
{{#isNullable}}
attemptParsing |= (token == JsonToken.VALUE_NULL);
{{/isNullable}}
}
}
if (attemptParsing) {
deserialized = tree.traverse(jp.getCodec()).readValueAs({{{.}}}.class);
// TODO: there is no validation against JSON schema constraints
// (min, max, enum, pattern...), this does not perform a strict JSON
// validation, which means the 'match' count may be higher than it should be.
match++;
log.log(Level.FINER, "Input data matches schema '{{{.}}}'");
}
} catch (Exception e) {
// deserialization failed, continue
log.log(Level.FINER, "Input data does not match schema '{{{.}}}'", e);
}
{{/oneOf}}
if (match == 1) {
{{classname}} ret = new {{classname}}();
ret.setActualInstance(deserialized);
return ret;
}
throw new IOException(String.format("Failed deserialization for {{classname}}: %d classes match result, expected 1", match));
}
/**
* Handle deserialization of the 'null' value.
*/
@Override
public {{classname}} getNullValue(DeserializationContext ctxt) throws JsonMappingException {
{{#isNullable}}
return null;
{{/isNullable}}
{{^isNullable}}
throw new JsonMappingException(ctxt.getParser(), "{{classname}} cannot be null");
{{/isNullable}}
}
}
// store a list of schema names defined in oneOf
public static final Map<String, GenericType> schemas = new HashMap<String, GenericType>();
public {{classname}}() {
super("oneOf", {{#isNullable}}Boolean.TRUE{{/isNullable}}{{^isNullable}}Boolean.FALSE{{/isNullable}});
}
{{> libraries/jersey2/additional_properties }}
{{#additionalPropertiesType}}
/**
* Return true if this {{name}} object is equal to o.
*/
@Override
public boolean equals(Object o) {
return super.equals(o) && Objects.equals(this.additionalProperties, (({{classname}})o).additionalProperties);
}
@Override
public int hashCode() {
return Objects.hash(getActualInstance(), isNullable(), getSchemaType(), additionalProperties);
}
{{/additionalPropertiesType}}
{{#oneOf}}
public {{classname}}({{{.}}} o) {
super("oneOf", {{#isNullable}}Boolean.TRUE{{/isNullable}}{{^isNullable}}Boolean.FALSE{{/isNullable}});
setActualInstance(o);
}
{{/oneOf}}
static {
{{#oneOf}}
schemas.put("{{{.}}}", new GenericType<{{{.}}}>() {
});
{{/oneOf}}
JSON.registerDescendants({{classname}}.class, Collections.unmodifiableMap(schemas));
{{#discriminator}}
// Initialize and register the discriminator mappings.
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
{{#mappedModels}}
mappings.put("{{mappingName}}", {{modelName}}.class);
{{/mappedModels}}
mappings.put("{{name}}", {{classname}}.class);
JSON.registerDiscriminator({{classname}}.class, "{{propertyBaseName}}", mappings);
{{/discriminator}}
}
@Override
public Map<String, GenericType> getSchemas() {
return {{classname}}.schemas;
}
/**
* Set the instance that matches the oneOf child schema, check
* the instance parameter is valid against the oneOf child schemas:
* {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}
*
* It could be an instance of the 'oneOf' schemas.
* The oneOf child schemas may themselves be a composed schema (allOf, anyOf, oneOf).
*/
@Override
public void setActualInstance(Object instance) {
{{#isNullable}}
if (instance == null) {
super.setActualInstance(instance);
return;
}
{{/isNullable}}
{{#oneOf}}
if (JSON.isInstanceOf({{{.}}}.class, instance, new HashSet<Class<?>>())) {
super.setActualInstance(instance);
return;
}
{{/oneOf}}
throw new RuntimeException("Invalid instance type. Must be {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}");
}
/**
* Get the actual instance, which can be the following:
* {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}
*
* @return The actual instance ({{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}})
*/
@Override
public Object getActualInstance() {
return super.getActualInstance();
}
{{#oneOf}}
/**
* Get the actual instance of `{{{.}}}`. If the actual instance is not `{{{.}}}`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `{{{.}}}`
* @throws ClassCastException if the instance is not `{{{.}}}`
*/
public {{{.}}} get{{{.}}}() throws ClassCastException {
return ({{{.}}})super.getActualInstance();
}
{{/oneOf}}
}

View File

@@ -0,0 +1,413 @@
/**
* {{description}}{{^description}}{{classname}}{{/description}}{{#isDeprecated}}
* @deprecated{{/isDeprecated}}
*/{{#isDeprecated}}
@Deprecated{{/isDeprecated}}{{#description}}
@ApiModel(description = "{{{.}}}"){{/description}}
{{#jackson}}
@JsonPropertyOrder({
{{#vars}}
{{classname}}.JSON_PROPERTY_{{nameInSnakeCase}}{{^-last}},{{/-last}}
{{/vars}}
})
{{#isClassnameSanitized}}
@JsonTypeName("{{name}}")
{{/isClassnameSanitized}}
{{/jackson}}
{{>additionalModelTypeAnnotations}}{{>generatedAnnotation}}{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}{{>xmlAnnotation}}
{{#vendorExtensions.x-class-extra-annotation}}
{{{vendorExtensions.x-class-extra-annotation}}}
{{/vendorExtensions.x-class-extra-annotation}}
public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtensions.x-implements}}{{#-first}}implements {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{#-last}} {{/-last}}{{/vendorExtensions.x-implements}}{
{{#serializableModel}}
private static final long serialVersionUID = 1L;
{{/serializableModel}}
{{#vars}}
{{#isEnum}}
{{^isContainer}}
{{^vendorExtensions.x-enum-as-string}}
{{>modelInnerEnum}}
{{/vendorExtensions.x-enum-as-string}}
{{/isContainer}}
{{#isContainer}}
{{#mostInnerItems}}
{{>modelInnerEnum}}
{{/mostInnerItems}}
{{/isContainer}}
{{/isEnum}}
{{#gson}}
public static final String SERIALIZED_NAME_{{nameInSnakeCase}} = "{{baseName}}";
{{/gson}}
{{#jackson}}
public static final String JSON_PROPERTY_{{nameInSnakeCase}} = "{{baseName}}";
{{/jackson}}
{{#withXml}}
{{#isXmlAttribute}}
@XmlAttribute(name = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}")
{{/isXmlAttribute}}
{{^isXmlAttribute}}
{{^isContainer}}
@XmlElement({{#xmlNamespace}}namespace="{{.}}", {{/xmlNamespace}}name = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}")
{{/isContainer}}
{{#isContainer}}
// Is a container wrapped={{isXmlWrapped}}
{{#items}}
// items.name={{name}} items.baseName={{baseName}} items.xmlName={{xmlName}} items.xmlNamespace={{xmlNamespace}}
// items.example={{example}} items.type={{dataType}}
@XmlElement({{#xmlNamespace}}namespace="{{.}}", {{/xmlNamespace}}name = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}")
{{/items}}
{{#isXmlWrapped}}
@XmlElementWrapper({{#xmlNamespace}}namespace="{{.}}", {{/xmlNamespace}}name = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}")
{{/isXmlWrapped}}
{{/isContainer}}
{{/isXmlAttribute}}
{{/withXml}}
{{#gson}}
@SerializedName(SERIALIZED_NAME_{{nameInSnakeCase}})
{{/gson}}
{{#vendorExtensions.x-field-extra-annotation}}
{{{vendorExtensions.x-field-extra-annotation}}}
{{/vendorExtensions.x-field-extra-annotation}}
{{#vendorExtensions.x-is-jackson-optional-nullable}}
{{#isContainer}}
private JsonNullable<{{{datatypeWithEnum}}}> {{name}} = JsonNullable.<{{{datatypeWithEnum}}}>undefined();
{{/isContainer}}
{{^isContainer}}
private JsonNullable<{{{datatypeWithEnum}}}> {{name}} = JsonNullable.<{{{datatypeWithEnum}}}>{{#defaultValue}}of({{{.}}}){{/defaultValue}}{{^defaultValue}}undefined(){{/defaultValue}};
{{/isContainer}}
{{/vendorExtensions.x-is-jackson-optional-nullable}}
{{^vendorExtensions.x-is-jackson-optional-nullable}}
{{#isContainer}}
private {{{datatypeWithEnum}}} {{name}}{{#required}}{{#defaultValue}} = {{{.}}}{{/defaultValue}}{{/required}}{{^required}} = null{{/required}};
{{/isContainer}}
{{^isContainer}}
private {{{datatypeWithEnum}}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};
{{/isContainer}}
{{/vendorExtensions.x-is-jackson-optional-nullable}}
{{/vars}}
public {{classname}}() { {{#parent}}{{#parcelableModel}}
super();{{/parcelableModel}}{{/parent}}{{#gson}}{{#discriminator}}
this.{{{discriminatorName}}} = this.getClass().getSimpleName();{{/discriminator}}{{/gson}}
}{{#vendorExtensions.x-has-readonly-properties}}{{^withXml}}{{#jackson}}
@JsonCreator
public {{classname}}(
{{#readOnlyVars}}
{{#jackson}}@JsonProperty(JSON_PROPERTY_{{nameInSnakeCase}}){{/jackson}} {{{datatypeWithEnum}}} {{name}}{{^-last}}, {{/-last}}
{{/readOnlyVars}}
) {
this();
{{#readOnlyVars}}
this.{{name}} = {{name}};
{{/readOnlyVars}}
}{{/jackson}}{{/withXml}}{{/vendorExtensions.x-has-readonly-properties}}
{{#vars}}
{{^isReadOnly}}
{{#vendorExtensions.x-enum-as-string}}
public static final Set<String> {{{nameInSnakeCase}}}_VALUES = new HashSet<>(Arrays.asList(
{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}
));
{{/vendorExtensions.x-enum-as-string}}
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
{{#vendorExtensions.x-enum-as-string}}
if (!{{{nameInSnakeCase}}}_VALUES.contains({{name}})) {
throw new IllegalArgumentException({{name}} + " is invalid. Possible values for {{name}}: " + String.join(", ", {{{nameInSnakeCase}}}_VALUES));
}
{{/vendorExtensions.x-enum-as-string}}
{{#vendorExtensions.x-is-jackson-optional-nullable}}
this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{name}});
{{/vendorExtensions.x-is-jackson-optional-nullable}}
{{^vendorExtensions.x-is-jackson-optional-nullable}}
this.{{name}} = {{name}};
{{/vendorExtensions.x-is-jackson-optional-nullable}}
return this;
}
{{#isArray}}
public {{classname}} add{{nameInCamelCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) {
{{#vendorExtensions.x-is-jackson-optional-nullable}}
if (this.{{name}} == null || !this.{{name}}.isPresent()) {
this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{{defaultValue}}});
}
try {
this.{{name}}.get().add({{name}}Item);
} catch (java.util.NoSuchElementException e) {
// this can never happen, as we make sure above that the value is present
}
return this;
{{/vendorExtensions.x-is-jackson-optional-nullable}}
{{^vendorExtensions.x-is-jackson-optional-nullable}}
{{^required}}
if (this.{{name}} == null) {
this.{{name}} = {{{defaultValue}}};
}
{{/required}}
this.{{name}}.add({{name}}Item);
return this;
{{/vendorExtensions.x-is-jackson-optional-nullable}}
}
{{/isArray}}
{{#isMap}}
public {{classname}} put{{nameInCamelCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) {
{{#vendorExtensions.x-is-jackson-optional-nullable}}
if (this.{{name}} == null || !this.{{name}}.isPresent()) {
this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{{defaultValue}}});
}
try {
this.{{name}}.get().put(key, {{name}}Item);
} catch (java.util.NoSuchElementException e) {
// this can never happen, as we make sure above that the value is present
}
return this;
{{/vendorExtensions.x-is-jackson-optional-nullable}}
{{^vendorExtensions.x-is-jackson-optional-nullable}}
{{^required}}
if (this.{{name}} == null) {
this.{{name}} = {{{defaultValue}}};
}
{{/required}}
this.{{name}}.put(key, {{name}}Item);
return this;
{{/vendorExtensions.x-is-jackson-optional-nullable}}
}
{{/isMap}}
{{/isReadOnly}}
/**
{{#description}}
* {{.}}
{{/description}}
{{^description}}
* Get {{name}}
{{/description}}
{{#minimum}}
* minimum: {{.}}
{{/minimum}}
{{#maximum}}
* maximum: {{.}}
{{/maximum}}
* @return {{name}}
{{#deprecated}}
* @deprecated
{{/deprecated}}
**/
{{#deprecated}}
@Deprecated
{{/deprecated}}
{{#required}}
{{#isNullable}}
@jakarta.annotation.Nullable
{{/isNullable}}
{{^isNullable}}
@jakarta.annotation.Nonnull
{{/isNullable}}
{{/required}}
{{^required}}
@jakarta.annotation.Nullable
{{/required}}
{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} @ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
{{#vendorExtensions.x-extra-annotation}}
{{{vendorExtensions.x-extra-annotation}}}
{{/vendorExtensions.x-extra-annotation}}
{{#vendorExtensions.x-is-jackson-optional-nullable}}
{{!unannotated, Jackson would pick this up automatically and add it *in addition* to the _JsonNullable getter field}}
@JsonIgnore
{{/vendorExtensions.x-is-jackson-optional-nullable}}
{{^vendorExtensions.x-is-jackson-optional-nullable}}{{#jackson}}{{> jackson_annotations}}{{/jackson}}{{/vendorExtensions.x-is-jackson-optional-nullable}}
public {{{datatypeWithEnum}}} {{getter}}() {
{{#vendorExtensions.x-is-jackson-optional-nullable}}
{{#isReadOnly}}{{! A readonly attribute doesn't have setter => jackson will set null directly if explicitly returned by API, so make sure we have an empty JsonNullable}}
if ({{name}} == null) {
{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>{{#defaultValue}}of({{{.}}}){{/defaultValue}}{{^defaultValue}}undefined(){{/defaultValue}};
}
{{/isReadOnly}}
return {{name}}.orElse(null);
{{/vendorExtensions.x-is-jackson-optional-nullable}}
{{^vendorExtensions.x-is-jackson-optional-nullable}}
return {{name}};
{{/vendorExtensions.x-is-jackson-optional-nullable}}
}
{{#vendorExtensions.x-is-jackson-optional-nullable}}
{{> jackson_annotations}}
public JsonNullable<{{{datatypeWithEnum}}}> {{getter}}_JsonNullable() {
return {{name}};
}
{{/vendorExtensions.x-is-jackson-optional-nullable}}{{#vendorExtensions.x-is-jackson-optional-nullable}}
@JsonProperty(JSON_PROPERTY_{{nameInSnakeCase}})
{{#isReadOnly}}private{{/isReadOnly}}{{^isReadOnly}}public{{/isReadOnly}} void {{setter}}_JsonNullable(JsonNullable<{{{datatypeWithEnum}}}> {{name}}) {
{{! For getters/setters that have name differing from attribute name, we must include setter (albeit private) for jackson to be able to set the attribute}}
this.{{name}} = {{name}};
}
{{/vendorExtensions.x-is-jackson-optional-nullable}}
{{^isReadOnly}}
{{#vendorExtensions.x-setter-extra-annotation}} {{{vendorExtensions.x-setter-extra-annotation}}}
{{/vendorExtensions.x-setter-extra-annotation}}{{#jackson}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{> jackson_annotations}}{{/vendorExtensions.x-is-jackson-optional-nullable}}{{/jackson}} public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
{{#vendorExtensions.x-enum-as-string}}
if (!{{{nameInSnakeCase}}}_VALUES.contains({{name}})) {
throw new IllegalArgumentException({{name}} + " is invalid. Possible values for {{name}}: " + String.join(", ", {{{nameInSnakeCase}}}_VALUES));
}
{{/vendorExtensions.x-enum-as-string}}
{{#vendorExtensions.x-is-jackson-optional-nullable}}
this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{name}});
{{/vendorExtensions.x-is-jackson-optional-nullable}}
{{^vendorExtensions.x-is-jackson-optional-nullable}}
this.{{name}} = {{name}};
{{/vendorExtensions.x-is-jackson-optional-nullable}}
}
{{/isReadOnly}}
{{/vars}}
{{>libraries/jersey2/additional_properties}}
/**
* Return true if this {{name}} object is equal to o.
*/
@Override
public boolean equals(Object o) {
{{#useReflectionEqualsHashCode}}
return EqualsBuilder.reflectionEquals(this, o, false, null, true);
{{/useReflectionEqualsHashCode}}
{{^useReflectionEqualsHashCode}}
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}{{#hasVars}}
{{classname}} {{classVarName}} = ({{classname}}) o;
return {{#vars}}{{#vendorExtensions.x-is-jackson-optional-nullable}}equalsNullable(this.{{name}}, {{classVarName}}.{{name}}){{/vendorExtensions.x-is-jackson-optional-nullable}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{#isByteArray}}Arrays{{/isByteArray}}{{^isByteArray}}Objects{{/isByteArray}}.equals(this.{{name}}, {{classVarName}}.{{name}}){{/vendorExtensions.x-is-jackson-optional-nullable}}{{^-last}} &&
{{/-last}}{{/vars}}{{#additionalPropertiesType}}&&
Objects.equals(this.additionalProperties, {{classVarName}}.additionalProperties){{/additionalPropertiesType}}{{#parent}} &&
super.equals(o){{/parent}};{{/hasVars}}{{^hasVars}}
return {{#parent}}super.equals(o){{/parent}}{{^parent}}true{{/parent}};{{/hasVars}}
{{/useReflectionEqualsHashCode}}
}{{#vendorExtensions.x-jackson-optional-nullable-helpers}}
private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && Objects.deepEquals(a.get(), b.get()));
}{{/vendorExtensions.x-jackson-optional-nullable-helpers}}
@Override
public int hashCode() {
{{#useReflectionEqualsHashCode}}
return HashCodeBuilder.reflectionHashCode(this);
{{/useReflectionEqualsHashCode}}
{{^useReflectionEqualsHashCode}}
return Objects.hash({{#vars}}{{#vendorExtensions.x-is-jackson-optional-nullable}}hashCodeNullable({{name}}){{/vendorExtensions.x-is-jackson-optional-nullable}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{^isByteArray}}{{name}}{{/isByteArray}}{{#isByteArray}}Arrays.hashCode({{name}}){{/isByteArray}}{{/vendorExtensions.x-is-jackson-optional-nullable}}{{^-last}}, {{/-last}}{{/vars}}{{#parent}}{{#hasVars}}, {{/hasVars}}super.hashCode(){{/parent}}{{#additionalPropertiesType}}{{#hasVars}}, {{/hasVars}}{{^hasVars}}{{#parent}}, {{/parent}}{{/hasVars}}additionalProperties{{/additionalPropertiesType}});
{{/useReflectionEqualsHashCode}}
}{{#vendorExtensions.x-jackson-optional-nullable-helpers}}
private static <T> int hashCodeNullable(JsonNullable<T> a) {
if (a == null) {
return 1;
}
return a.isPresent() ? Arrays.deepHashCode(new Object[]{a.get()}) : 31;
}{{/vendorExtensions.x-jackson-optional-nullable-helpers}}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class {{classname}} {\n");
{{#parent}}
sb.append(" ").append(toIndentedString(super.toString())).append("\n");
{{/parent}}
{{#vars}}
sb.append(" {{name}}: ").append(toIndentedString({{name}})).append("\n");
{{/vars}}
{{#additionalPropertiesType}}
sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n");
{{/additionalPropertiesType}}
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
{{#parcelableModel}}
public void writeToParcel(Parcel out, int flags) {
{{#model}}
{{#isArray}}
out.writeList(this);
{{/isArray}}
{{^isArray}}
{{#parent}}
super.writeToParcel(out, flags);
{{/parent}}
{{#vars}}
out.writeValue({{name}});
{{/vars}}
{{/isArray}}
{{/model}}
}
{{classname}}(Parcel in) {
{{#isArray}}
in.readTypedList(this, {{arrayModelType}}.CREATOR);
{{/isArray}}
{{^isArray}}
{{#parent}}
super(in);
{{/parent}}
{{#vars}}
{{#isPrimitiveType}}
{{name}} = ({{{datatypeWithEnum}}})in.readValue(null);
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{name}} = ({{{datatypeWithEnum}}})in.readValue({{complexType}}.class.getClassLoader());
{{/isPrimitiveType}}
{{/vars}}
{{/isArray}}
}
public int describeContents() {
return 0;
}
public static final Parcelable.Creator<{{classname}}> CREATOR = new Parcelable.Creator<{{classname}}>() {
public {{classname}} createFromParcel(Parcel in) {
{{#model}}
{{#isArray}}
{{classname}} result = new {{classname}}();
result.addAll(in.readArrayList({{arrayModelType}}.class.getClassLoader()));
return result;
{{/isArray}}
{{^isArray}}
return new {{classname}}(in);
{{/isArray}}
{{/model}}
}
public {{classname}}[] newArray(int size) {
return new {{classname}}[size];
}
};
{{/parcelableModel}}
{{#discriminator}}
static {
// Initialize and register the discriminator mappings.
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
{{#mappedModels}}
mappings.put("{{mappingName}}", {{modelName}}.class);
{{/mappedModels}}
mappings.put("{{name}}", {{classname}}.class);
JSON.registerDiscriminator({{classname}}.class, "{{propertyBaseName}}", mappings);
}
{{/discriminator}}
}

View File

@@ -0,0 +1,401 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>{{groupId}}</groupId>
<artifactId>{{artifactId}}</artifactId>
<packaging>jar</packaging>
<name>{{artifactId}}</name>
<version>{{artifactVersion}}</version>
<url>{{artifactUrl}}</url>
<description>{{artifactDescription}}</description>
<scm>
<connection>{{scmConnection}}</connection>
<developerConnection>{{scmDeveloperConnection}}</developerConnection>
<url>{{scmUrl}}</url>
</scm>
{{#parentOverridden}}
<parent>
<groupId>{{{parentGroupId}}}</groupId>
<artifactId>{{{parentArtifactId}}}</artifactId>
<version>{{{parentVersion}}}</version>
</parent>
{{/parentOverridden}}
<licenses>
<license>
<name>{{licenseName}}</name>
<url>{{licenseUrl}}</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<name>{{developerName}}</name>
<email>{{developerEmail}}</email>
<organization>{{developerOrganization}}</organization>
<organizationUrl>{{developerOrganizationUrl}}</organizationUrl>
</developer>
</developers>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>2.2.0</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<systemProperties>
<property>
<name>loggerPath</name>
<value>conf/log4j.properties</value>
</property>
</systemProperties>
<argLine>-Xms512m -Xmx1500m</argLine>
<parallel>methods</parallel>
<threadCount>10</threadCount>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- attach test jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
<configuration>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>add_sources</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add_test_sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<fork>true</fork>
<meminitial>128m</meminitial>
<maxmem>512m</maxmem>
<compilerArgs>
<arg>-Xlint:all</arg>
<arg>-J-Xss4m</arg><!-- Compiling the generated JSON.java file may require larger stack size. -->
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.2</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<doclint>none</doclint>
<source>1.8</source>
<tags>
<tag>
<name>http.response.details</name>
<placement>a</placement>
<head>Http Response Details:</head>
</tag>
</tags>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Use spotless plugin to automatically format code, remove unused import, etc
To apply changes directly to the file, run `mvn spotless:apply`
Ref: https://github.com/diffplug/spotless/tree/main/plugin-maven
-->
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>${spotless.version}</version>
<configuration>
<formats>
<!-- you can define as many formats as you want, each is independent -->
<format>
<!-- define the files to apply to -->
<includes>
<include>.gitignore</include>
</includes>
<!-- define the steps to apply to those files -->
<trimTrailingWhitespace/>
<endWithNewline/>
<indent>
<spaces>true</spaces> <!-- or <tabs>true</tabs> -->
<spacesPerTab>4</spacesPerTab> <!-- optional, default is 4 -->
</indent>
</format>
</formats>
<!-- define a language-specific format -->
<java>
<!-- no need to specify files, inferred automatically, but you can if you want -->
<!-- apply a specific flavor of google-java-format and reflow long strings -->
<googleJavaFormat>
<version>1.8</version>
<style>AOSP</style>
<reflowLongStrings>true</reflowLongStrings>
</googleJavaFormat>
<removeUnusedImports/>
<importOrder/>
</java>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>sign-artifacts</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${swagger-annotations-version}</version>
</dependency>
<!-- @Nullable annotation -->
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
</dependency>
<!-- HTTP client: jersey-client -->
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey-version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>${jersey-version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>${jersey-version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>${jersey-version}</version>
</dependency>
<!-- JSON processing: jackson -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind-version}</version>
</dependency>
{{#openApiNullable}}
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
<version>${jackson-databind-nullable-version}</version>
</dependency>
{{/openApiNullable}}
{{#withXml}}
<!-- XML processing: JAXB -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-jaxb</artifactId>
<version>${jersey-version}</version>
</dependency>
{{/withXml}}
{{#joda}}
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>${jackson-version}</version>
</dependency>
{{/joda}}
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson-version}</version>
</dependency>
{{#hasHttpSignatureMethods}}
<dependency>
<groupId>org.tomitribe</groupId>
<artifactId>tomitribe-http-signatures</artifactId>
<version>${http-signature-version}</version>
</dependency>
{{/hasHttpSignatureMethods}}
{{#hasOAuthMethods}}
<dependency>
<groupId>com.github.scribejava</groupId>
<artifactId>scribejava-apis</artifactId>
<version>${scribejava-apis-version}</version>
</dependency>
{{/hasOAuthMethods}}
{{#useBeanValidation}}
<!-- Bean Validation API support -->
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>${beanvalidation-version}</version>
<scope>provided</scope>
</dependency>
{{/useBeanValidation}}
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>${jakarta-annotation-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.connectors</groupId>
<artifactId>jersey-apache-connector</artifactId>
<version>${jersey-version}</version>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<swagger-annotations-version>1.6.5</swagger-annotations-version>
<jersey-version>3.0.4</jersey-version>
<jackson-version>2.13.2</jackson-version>
<jackson-databind-version>2.13.2</jackson-databind-version>
<jackson-databind-nullable-version>0.2.2</jackson-databind-nullable-version>
<jakarta-annotation-version>2.1.0</jakarta-annotation-version>
{{#useBeanValidation}}
<beanvalidation-version>2.0.2</beanvalidation-version>
{{/useBeanValidation}}
<junit-version>5.8.2</junit-version>
{{#hasHttpSignatureMethods}}
<http-signature-version>1.7</http-signature-version>
{{/hasHttpSignatureMethods}}
{{#hasOAuthMethods}}
<scribejava-apis-version>8.3.1</scribejava-apis-version>
{{/hasOAuthMethods}}
<spotless.version>2.21.0</spotless.version>
</properties>
</project>

View File

@@ -1197,7 +1197,7 @@ public class ApiClient {
try {
Response response = call.execute();
if (!response.isSuccessful()) {
throw new ApiException(response.code(), response.message());
throw new ApiException(response.code(), response.message(), response.headers().toMultimap(), null);
}
if (response.body() == null) {
return null;

View File

@@ -457,22 +457,43 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
{{#items.isModel}}
JsonArray jsonArray{{name}} = jsonObj.getAsJsonArray("{{{baseName}}}");
{{#isRequired}}
// ensure the json data is an array
if (!jsonObj.get("{{{baseName}}}").isJsonArray()) {
throw new IllegalArgumentException(String.format("Expected the field `{{{baseName}}}` to be an array in the JSON string but got `%s`", jsonObj.get("{{{baseName}}}").toString()));
}
// validate the required field `{{{baseName}}}` (array)
for (int i = 0; i < jsonArray{{name}}.size(); i++) {
{{{items.dataType}}}.validateJsonObject(jsonArray{{name}}.get(i).getAsJsonObject());
};
{{/isRequired}}
{{^isRequired}}
// validate the optional field `{{{baseName}}}` (array)
if (jsonArray{{name}} != null) {
// ensure the json data is an array
if (!jsonObj.get("{{{baseName}}}").isJsonArray()) {
throw new IllegalArgumentException(String.format("Expected the field `{{{baseName}}}` to be an array in the JSON string but got `%s`", jsonObj.get("{{{baseName}}}").toString()));
}
// validate the optional field `{{{baseName}}}` (array)
for (int i = 0; i < jsonArray{{name}}.size(); i++) {
{{{items.dataType}}}.validateJsonObject(jsonArray{{name}}.get(i).getAsJsonObject());
};
}
{{/isRequired}}
{{/items.isModel}}
{{^items.isModel}}
// ensure the json data is an array
if ({{^isRequired}}jsonObj.get("{{{baseName}}}") != null && {{/isRequired}}!jsonObj.get("{{{baseName}}}").isJsonArray()) {
throw new IllegalArgumentException(String.format("Expected the field `{{{baseName}}}` to be an array in the JSON string but got `%s`", jsonObj.get("{{{baseName}}}").toString()));
}
{{/items.isModel}}
{{/isArray}}
{{^isContainer}}
{{#isString}}
if ({{^isRequired}}jsonObj.get("{{{baseName}}}") != null && {{/isRequired}}!jsonObj.get("{{{baseName}}}").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `{{{baseName}}}` to be a primitive type in the JSON string but got `%s`", jsonObj.get("{{{baseName}}}").toString()));
}
{{/isString}}
{{#isModel}}
{{#isRequired}}
// validate the required field `{{{baseName}}}`

View File

@@ -10,7 +10,7 @@
# raise a `RecursionError`.
# In order to avoid this, import only the API that you directly need like:
#
# from {{packagename}}.{{apiPackage}}.{{classFilename}} import {{classname}}
# from {{packageName}}.{{apiPackage}}.{{classFilename}} import {{classname}}
#
# or import this package, but before doing it, use:
#

View File

@@ -9,7 +9,7 @@
# raise a `RecursionError`.
# In order to avoid this, import only the API that you directly need like:
#
# from {{packagename}}.api.{{classFilename}} import {{classname}}
# from {{packageName}}.api.{{classFilename}} import {{classname}}
#
# or import this package, but before doing it, use:
#

View File

@@ -39,7 +39,7 @@ export class BaseAPI {
if (response.status >= 200 && response.status < 300) {
return response;
}
throw response;
throw new ResponseError(response, 'Response returned an error code');
}
private createFetchParams(context: RequestOpts, initOverrides?: RequestInit) {
@@ -103,6 +103,13 @@ export class BaseAPI {
}
};
export class ResponseError extends Error {
name: "ResponseError" = "ResponseError";
constructor(public response: Response, msg?: string) {
super(msg);
}
}
export class RequiredError extends Error {
name: "RequiredError" = "RequiredError";
constructor(public field: string, msg?: string) {

View File

@@ -11,7 +11,7 @@
<packaging>pom</packaging>
<name>openapi-generator-project</name>
<!-- RELEASE_VERSION -->
<version>6.0.0-beta</version>
<version>6.0.0-SNAPSHOT</version>
<!-- /RELEASE_VERSION -->
<url>https://github.com/openapitools/openapi-generator</url>
<scm>
@@ -1250,6 +1250,7 @@
<module>samples/client/petstore/clojure</module>
<module>samples/client/petstore/java/jersey2-java8</module>
<module>samples/openapi3/client/petstore/java/jersey2-java8</module>
<module>samples/client/petstore/java/jersey3</module>
<module>samples/client/others/java/okhttp-gson-streaming</module>
<module>samples/client/petstore/java/okhttp-gson</module>
</modules>

View File

@@ -1 +1 @@
6.0.0-beta
6.0.0-SNAPSHOT

View File

@@ -1 +1 @@
6.0.0-beta
6.0.0-SNAPSHOT

View File

@@ -993,7 +993,7 @@ public class ApiClient {
try {
Response response = call.execute();
if (!response.isSuccessful()) {
throw new ApiException(response.code(), response.message());
throw new ApiException(response.code(), response.message(), response.headers().toMultimap(), null);
}
if (response.body() == null) {
return null;

View File

@@ -317,6 +317,15 @@ public class SomeObj {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `SomeObj` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
}
}
if (jsonObj.get("$_type") != null && !jsonObj.get("$_type").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `$_type` to be a primitive type in the JSON string but got `%s`", jsonObj.get("$_type").toString()));
}
if (jsonObj.get("name") != null && !jsonObj.get("name").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `name` to be a primitive type in the JSON string but got `%s`", jsonObj.get("name").toString()));
}
if (jsonObj.get("type") != null && !jsonObj.get("type").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `type` to be a primitive type in the JSON string but got `%s`", jsonObj.get("type").toString()));
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {

View File

@@ -1 +1 @@
6.0.0-beta
6.0.0-SNAPSHOT

View File

@@ -1 +1 @@
6.0.0-beta
6.0.0-SNAPSHOT

View File

@@ -1 +1 @@
6.0.0-beta
6.0.0-SNAPSHOT

View File

@@ -1 +1 @@
6.0.0-beta
6.0.0-SNAPSHOT

View File

@@ -1 +1 @@
6.0.0-beta
6.0.0-SNAPSHOT

View File

@@ -1 +1 @@
6.0.0-beta
6.0.0-SNAPSHOT

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-beta.
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

Some files were not shown because too many files have changed in this diff Show More