Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade OpenAPI generator to v7.9.0 (was v7.6.0) #127

Merged
merged 5 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/update-specs-and-client-libraries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
python_version: ${{ steps.generator.outputs.python_urllib3_version }}
ruby_version: ${{ steps.generator.outputs.ruby_faraday_version }}
container:
image: openapitools/openapi-generator-cli:v7.6.0
image: openapitools/openapi-generator-cli:v7.9.0
env:
OPENAPI_GENERATOR_COMMAND: docker-entrypoint.sh
BUMP_CLIENT_LIBRARY_VERSION: ${{ inputs.type-of-change }}
Expand Down
8 changes: 4 additions & 4 deletions generators/java/okhttp-gson/templates/SHA256SUM
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

16502193337397367078434a27f67edfc6410f4c06d12db876155885d6a49394 ./README.mustache
7b635a5f3fcc4cb2ace38f0dd0ca8252a78090e592a6c35fe5a08f7bc407ef6b ./libraries/okhttp-gson/ApiClient.mustache
133ba02513dba3fa805f364770b5a2fcc87a4c6ed0cf7afd322376e03143859f ./libraries/okhttp-gson/api.mustache
9866a9e83531d72f155a0fdea252cfe5d340deea3d6e2da7eb64c941dc88577a ./libraries/okhttp-gson/ApiClient.mustache
7db4829dd39d1e769cfe38a07e976684f71e5db4077030ea1b423703958da223 ./libraries/okhttp-gson/api.mustache
0e77feaf2d6b0818194161ac7e621189aa6e7900b45d46fa4ff1232894bb1a7a ./libraries/okhttp-gson/oneof_model.mustache
9a768c6d6b3ffcf21e5aa73e2d23ca524deb4b8503e73b0bc7e48e54403e5afb ./libraries/okhttp-gson/pojo.mustache
e83ff873cc6a5a7e064b4732ab4bfbb3fa32660d015b9ca1b6bdb5884335c506 ./libraries/okhttp-gson/pom.mustache
f20b6129f3b473ecaa4e39f760bb1028d6c1f832928fa2f460131e2c54d66ed0 ./libraries/okhttp-gson/pojo.mustache
2f63581598dd2ba1373a51c0c3dfbcfa2a43d25f278a048c04c6679ef03f1224 ./libraries/okhttp-gson/pom.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,29 @@ public class ApiClient {
throw new RuntimeException("No AWS4 authentication configured!");
}

/**
* Helper method to set credentials for AWSV4 Signature
*
* @param accessKey Access Key
* @param secretKey Secret Key
* @param sessionToken Session Token
* @param region Region
* @param service Service to access to
*/
public void setAWS4Configuration(String accessKey, String secretKey, String sessionToken, String region, String service) {
{{#withAWSV4Signature}}
for (Authentication auth : authentications.values()) {
if (auth instanceof AWS4Auth) {
((AWS4Auth) auth).setCredentials(accessKey, secretKey, sessionToken);
((AWS4Auth) auth).setRegion(region);
((AWS4Auth) auth).setService(service);
return;
}
}
{{/withAWSV4Signature}}
throw new RuntimeException("No AWS4 authentication configured!");
}

/**
* Set the User-Agent header's value (by adding to the default header map).
*
Expand Down Expand Up @@ -939,6 +962,30 @@ public class ApiClient {
}
{{/dynamicOperations}}
/**
* Formats the specified free-form query parameters to a list of {@code Pair} objects.
*
* @param value The free-form query parameters.
* @return A list of {@code Pair} objects.
*/
public List<Pair> freeFormParameterToPairs(Object value) {
List<Pair> params = new ArrayList<>();
// preconditions
if (value == null || !(value instanceof Map )) {
return params;
}
final Map<String, Object> valuesMap = (Map<String, Object>) value;
for (Map.Entry<String, Object> entry : valuesMap.entrySet()) {
params.add(new Pair(entry.getKey(), parameterToString(entry.getValue())));
}
return params;
}
/**
* Formats the specified collection path parameter to a string value.
*
Expand Down Expand Up @@ -1192,7 +1239,7 @@ public class ApiClient {
* @throws java.io.IOException If fail to prepare file for download
*/
public File prepareDownloadFile(Response response) throws IOException {
{{! Code extrated to getFilenameFromResponse }}
{{! Code extracted to getFilenameFromResponse }}
String filename = getFilenameFromResponse(response);

String prefix = null;
Expand Down Expand Up @@ -1402,10 +1449,6 @@ public class ApiClient {
* @throws {{invokerPackage}}.ApiException If fail to serialize the request body object
*/
public Request buildRequest(String baseUrl, String path, String method, List<Pair> queryParams, List<Pair> collectionQueryParams, Object body, Map<String, String> headerParams, Map<String, String> cookieParams, Map<String, Object> formParams, String[] authNames, ApiCallback callback) throws ApiException {
// aggregate queryParams (non-collection) and collectionQueryParams into allQueryParams
List<Pair> allQueryParams = new ArrayList<Pair>(queryParams);
allQueryParams.addAll(collectionQueryParams);
final String url = buildUrl(baseUrl, path, queryParams, collectionQueryParams);
// prepare HTTP request body
Expand Down Expand Up @@ -1433,10 +1476,12 @@ public class ApiClient {
reqBody = serialize(body, contentType);
}

List<Pair> updatedQueryParams = new ArrayList<>(queryParams);

// update parameters with authentication settings
updateParamsForAuth(authNames, allQueryParams, headerParams, cookieParams, requestBodyToString(reqBody), method, URI.create(url));
updateParamsForAuth(authNames, updatedQueryParams, headerParams, cookieParams, requestBodyToString(reqBody), method, URI.create(url));

final Request.Builder reqBuilder = new Request.Builder().url(url);
final Request.Builder reqBuilder = new Request.Builder().url(buildUrl(baseUrl, path, updatedQueryParams, collectionQueryParams));
processHeaderParams(headerParams, reqBuilder);
processCookieParams(cookieParams, reqBuilder);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public class {{classname}} {
{{^dynamicOperations}}
{{#queryParams}}
if ({{paramName}} != null) {
{{#collectionFormat}}localVarCollectionQueryParams.addAll(localVarApiClient.parameterToPairs("{{{.}}}", {{/collectionFormat}}{{^collectionFormat}}localVarQueryParams.addAll(localVarApiClient.parameterToPair({{/collectionFormat}}"{{baseName}}", {{paramName}}));
{{#isFreeFormObject}}localVarQueryParams.addAll(localVarApiClient.freeFormParameterToPairs({{paramName}}));{{/isFreeFormObject}}{{^isFreeFormObject}}{{#collectionFormat}}localVarCollectionQueryParams.addAll(localVarApiClient.parameterToPairs("{{{.}}}", {{/collectionFormat}}{{^collectionFormat}}localVarQueryParams.addAll(localVarApiClient.parameterToPair({{/collectionFormat}}"{{baseName}}", {{paramName}}));{{/isFreeFormObject}}
}

{{/queryParams}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,21 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
{{#composedSchemas}}
{{#oneOf}}
{{^isArray}}
{{^isMap}}
{{^vendorExtensions.x-duplicated-data-type}}
final TypeAdapter<{{{dataType}}}> adapter{{{dataType}}} = gson.getDelegateAdapter(this, TypeToken.get({{{dataType}}}.class));
{{/vendorExtensions.x-duplicated-data-type}}
{{/isMap}}
{{/isArray}}
{{#isArray}}

final Type typeInstance = new TypeToken<{{{dataType}}}>(){}.getType();
final TypeAdapter<{{{dataType}}}> adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}} = (TypeAdapter<{{{dataType}}}>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance));
final Type typeInstance{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}} = new TypeToken<{{{dataType}}}>(){}.getType();
final TypeAdapter<{{{dataType}}}> adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}} = (TypeAdapter<{{{dataType}}}>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}));
{{/isArray}}
{{#isMap}}
final Type typeInstance{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}} = new TypeToken<{{{dataType}}}>(){}.getType();
final TypeAdapter<{{{dataType}}}> adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}} = (TypeAdapter<{{{dataType}}}>) gson.getDelegateAdapter(this, TypeToken.get(typeInstance{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}));
{{/isMap}}
{{/oneOf}}
{{/composedSchemas}}

Expand All @@ -76,8 +82,9 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
{{#oneOf}}
{{^vendorExtensions.x-duplicated-data-type}}
// check if the actual instance is of the type `{{{dataType}}}`
if (value.getActualInstance() instanceof {{#isArray}}List<?>{{/isArray}}{{^isArray}}{{{dataType}}}{{/isArray}}) {
if (value.getActualInstance() instanceof {{#isArray}}List<?>{{/isArray}}{{#isMap}}Map<?, ?>{{/isMap}}{{^isMap}}{{^isArray}}{{{dataType}}}{{/isArray}}{{/isMap}}) {
{{#isPrimitiveType}}
{{^isMap}}
{{! Updated code - BEGIN }}
{{#isArray}}
JsonElement element = adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}.toJsonTree(({{{dataType}}})value.getActualInstance());
Expand All @@ -88,6 +95,12 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
elementAdapter.write(out, element);
{{! Updated code - END }}
return;
{{/isMap}}
{{#isMap}}
JsonObject object = adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}.toJsonTree(({{{dataType}}})value.getActualInstance()).getAsJsonObject();
elementAdapter.write(out, object);
return;
{{/isMap}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{#isArray}}
Expand All @@ -99,13 +112,15 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
}
{{/isArray}}
{{/isPrimitiveType}}
{{^isMap}}
{{^isArray}}
{{^isPrimitiveType}}
JsonElement element = adapter{{{dataType}}}.toJsonTree(({{{dataType}}})value.getActualInstance());
elementAdapter.write(out, element);
return;
{{/isPrimitiveType}}
{{/isArray}}
{{/isMap}}
}
{{/vendorExtensions.x-duplicated-data-type}}
{{/oneOf}}
Expand Down Expand Up @@ -157,6 +172,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
try {
// validate the JSON object to see if any exception is thrown
{{^isArray}}
{{^isMap}}
{{#isNumber}}
if (!jsonElement.getAsJsonPrimitive().isNumber()) {
throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString()));
Expand All @@ -177,6 +193,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
actualAdapter = adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}};
{{/isPrimitiveType}}
{{/isNumber}}
{{/isMap}}
{{/isArray}}
{{#isArray}}
if (!jsonElement.isJsonArray()) {
Expand Down Expand Up @@ -208,6 +225,38 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
}
actualAdapter = adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}};
{{/isArray}}
{{#isMap}}
if (!jsonElement.isJsonObject()) {
throw new IllegalArgumentException(String.format("Expected json element to be a object type in the JSON string but got `%s`", jsonElement.toString()));
}

{{^isFreeFormObject}}
Map<String, JsonElement> map = jsonElement.getAsJsonObject().asMap();
// validate map items
for(JsonElement element : map.values()) {
{{#items}}
{{#isNumber}}
if (!jsonElement.getAsJsonPrimitive().isNumber()) {
throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString()));
}
{{/isNumber}}
{{^isNumber}}
{{#isPrimitiveType}}
if (!element.getAsJsonPrimitive().is{{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}}()) {
throw new IllegalArgumentException(String.format("Expected array items to be of type {{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}} in the JSON string but got `%s`", jsonElement.toString()));
}
{{/isPrimitiveType}}
{{/isNumber}}
{{^isNumber}}
{{^isPrimitiveType}}
{{{dataType}}}.validateJsonElement(element);
{{/isPrimitiveType}}
{{/isNumber}}
{{/items}}
}
{{/isFreeFormObject}}
actualAdapter = adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}};
{{/isMap}}
match++;
log.log(Level.FINER, "Input data matches schema '{{{dataType}}}'");
} catch (Exception e) {
Expand Down Expand Up @@ -256,13 +305,11 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
super("oneOf", {{#isNullable}}Boolean.TRUE{{/isNullable}}{{^isNullable}}Boolean.FALSE{{/isNullable}});
}

{{#oneOf}}
public {{classname}}({{{.}}} o) {
public {{classname}}(Object o) {
super("oneOf", {{#isNullable}}Boolean.TRUE{{/isNullable}}{{^isNullable}}Boolean.FALSE{{/isNullable}});
setActualInstance(o);
}

{{/oneOf}}
static {
{{#composedSchemas}}
{{#oneOf}}
Expand Down Expand Up @@ -297,7 +344,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
{{#composedSchemas}}
{{#oneOf}}
{{^vendorExtensions.x-duplicated-data-type}}
if (instance instanceof {{#isArray}}List<?>{{/isArray}}{{^isArray}}{{{dataType}}}{{/isArray}}) {
if (instance instanceof {{#isArray}}List<?>{{/isArray}}{{#isMap}}Map<?, ?>{{/isMap}}{{^isMap}}{{^isArray}}{{{dataType}}}{{/isArray}}{{/isMap}}) {
{{#isArray}}
List<?> list = (List<?>) instance;
if (list.get(0) instanceof {{{items.dataType}}}) {
Expand Down Expand Up @@ -341,7 +388,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
*/
{{! Suppress unchecked cast warning }}
@SuppressWarnings("unchecked")
public {{{dataType}}} get{{#isArray}}{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}{{/isArray}}{{^isArray}}{{{dataType}}}{{/isArray}}() throws ClassCastException {
public {{{dataType}}} get{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}() throws ClassCastException {
return ({{{dataType}}})super.getActualInstance();
}
{{/vendorExtensions.x-duplicated-data-type}}
Expand All @@ -364,6 +411,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
// validate the json string with {{{dataType}}}
try {
{{^hasVars}}
{{^isMap}}
{{^isArray}}
{{#isNumber}}
if (!jsonElement.getAsJsonPrimitive().isNumber()) {
Expand All @@ -383,6 +431,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
{{/isPrimitiveType}}
{{/isNumber}}
{{/isArray}}
{{/isMap}}
{{#isArray}}
if (!jsonElement.isJsonArray()) {
throw new IllegalArgumentException(String.format("Expected json element to be a array type in the JSON string but got `%s`", jsonElement.toString()));
Expand Down Expand Up @@ -411,6 +460,37 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
{{/items}}
}
{{/isArray}}
{{#isMap}}
if (!jsonElement.isJsonObject()) {
throw new IllegalArgumentException(String.format("Expected json element to be a object type in the JSON string but got `%s`", jsonElement.toString()));
}

{{^isFreeFormObject}}
Map<String, JsonElement> map = jsonElement.getAsJsonObject().asMap();
// validate map items
for(JsonElement element : map.values()) {
{{#items}}
{{#isNumber}}
if (!jsonElement.getAsJsonPrimitive().isNumber()) {
throw new IllegalArgumentException(String.format("Expected json element to be of type Number in the JSON string but got `%s`", jsonElement.toString()));
}
{{/isNumber}}
{{^isNumber}}
{{#isPrimitiveType}}
if (!element.getAsJsonPrimitive().is{{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}}()) {
throw new IllegalArgumentException(String.format("Expected array items to be of type {{#isBoolean}}Boolean{{/isBoolean}}{{#isString}}String{{/isString}}{{^isString}}{{^isBoolean}}Number{{/isBoolean}}{{/isString}} in the JSON string but got `%s`", jsonElement.toString()));
}
{{/isPrimitiveType}}
{{/isNumber}}
{{^isNumber}}
{{^isPrimitiveType}}
{{{dataType}}}.validateJsonElement(element);
{{/isPrimitiveType}}
{{/isNumber}}
{{/items}}
}
{{/isFreeFormObject}}
{{/isMap}}
{{/hasVars}}
{{#hasVars}}
{{{.}}}.validateJsonElement(jsonElement);
Expand Down
Loading