Skip to content

Commit 1d80a5c

Browse files
authored
Merge branch 'main' into feature/remove-cost-from-python-blacklist
2 parents a67f5ca + 9341e4b commit 1d80a5c

8 files changed

Lines changed: 123 additions & 91 deletions

File tree

languages/java/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# STACKIT Java SDK Generator
2+
3+
The `templates` directory contains only our customized Java templates. Beside these customized templates,
4+
the original templates of openapi-generator for Java are used. These can be found in the
5+
official GitHub repo of the [openapi-generator](https://github.com/OpenAPITools/openapi-generator/tree/v7.14.0/modules/openapi-generator/src/main/resources/Java).
6+
7+
If you need to change something in the Java Generator, try always first to add
8+
[user-defined templates](https://openapi-generator.tech/docs/customization#user-defined-templates),
9+
instead of overwriting existing templates. These ensure an easier upgrade process, to newer
10+
versions of the openapi-generator.
11+
12+
If it's required to customize the original templates, you can copy them into this directory.
13+
Try to minimize the customization as much as possible, to ensure, that we can easily upgrade
14+
to newer versions in the future.
15+
16+
## Template adjustments
17+
18+
The following templates were customized but don't need to be adjusted when updating the Java SDK generator to a new a newer upstream version:
19+
20+
- `README.mustache`: This template was entirely overwritten. It has no technical impact on the Java SDK.
21+
- `api_test.mustache`: This template had to be customized because of our changes to the DefaultApi and ApiClient classes.
22+
23+
The following templates were customized and need to be checked for adjustments when updating the Java SDK generator to a newer upstream version:
24+
25+
- `ApiCallback.mustache`: This template was customized use the `ApiException` class from the core module instead of the one generated by default.
26+
- `ApiClient.mustache`: This template was customized to initialize the ApiClient with the CoreConfiguration to easily setup the KeyFlow Authentication and custom endpoints.
27+
- `api.mustache`: This template was customized to initialize the DefaultApi with the CoreConfiguration to easily setup the KeyFlow Authentication and custom endpoints.
28+
- `build.gradle.mustache`: This template was customized to allow the services to be subprojects in one big gradle project.
29+
30+
## Custom templates
31+
32+
The custom templates don't need to be adjusted when updating the Java SDK generator to a new a newer upstream version.
33+
34+
- `ApiClientTest.mustache`: Implements additional test cases.
35+
- `serviceApi.mustache` and `serviceApiTest.mustache`: The classes generated by this template (`IaasApi`, `AlbApi`, ...) just inherit from the corresponding `DefaultApi` class. This way users of the Java SDK can use two STACKIT SDK modules for different STACKIT services within the same file without being forced to use fully qualified names for classes.
36+

languages/java/templates/ApiCallback.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
package {{invokerPackage}};
66

77
import java.io.IOException;
8+
{{! TEMPLATE CUSTOMIZATION - BEGIN - use the ApiException class from the core module instead of the one generated by default }}
89
import cloud.stackit.sdk.core.exception.ApiException;
10+
{{! TEMPLATE CUSTOMIZATION - END - use the ApiException class from the core module instead of the one generated by default }}
911

1012
import java.util.Map;
1113
import java.util.List;

languages/java/templates/ApiClient.mustache

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ import {{invokerPackage}}.auth.OAuthFlow;
7575
import {{invokerPackage}}.auth.AWS4Auth;
7676
{{/withAWSV4Signature}}
7777

78-
{{! BEGIN - Added imports for core module }}
78+
{{! TEMPLATE CUSTOMIZATION - BEGIN - Added imports for core module }}
7979
import cloud.stackit.sdk.core.auth.SetupAuth;
8080
import cloud.stackit.sdk.core.config.CoreConfiguration;
8181
import cloud.stackit.sdk.core.exception.ApiException;
8282
import cloud.stackit.sdk.core.KeyFlowAuthenticator;
83-
{{! END - Added imports for core module }}
83+
{{! TEMPLATE CUSTOMIZATION - END - Added imports for core module }}
8484

8585
/**
8686
* <p>ApiClient class.</p>
@@ -120,7 +120,7 @@ public class ApiClient {
120120
protected Map<String, String> defaultCookieMap = new HashMap<String, String>();
121121
protected String tempFolderPath = null;
122122

123-
{{! BEGIN - deleted field authentications, we use our own Authenticator
123+
{{! TEMPLATE CUSTOMIZATION - BEGIN - deleted field authentications, we use our own Authenticator
124124
protected Map<String, Authentication> authentications;
125125
}}
126126

@@ -139,15 +139,15 @@ public class ApiClient {
139139

140140
protected HttpLoggingInterceptor loggingInterceptor;
141141

142-
{{! BEGIN - Added CoreConfiguration field to ApiClient }}
142+
{{! TEMPLATE CUSTOMIZATION - BEGIN - Added CoreConfiguration field to ApiClient }}
143143
protected CoreConfiguration configuration;
144-
{{! END - Added CoreConfiguration field to ApiClient }}
144+
{{! TEMPLATE CUSTOMIZATION - END - Added CoreConfiguration field to ApiClient }}
145145

146146
{{#dynamicOperations}}
147147
protected Map<String, ApiOperation> operationLookupMap = new HashMap<>();
148148

149149
{{/dynamicOperations}}
150-
{{! BEGIN - Removed ApiClient constructor and replaced it with a custom constructors which create the ApiClient with the CoreConfiguration }}
150+
{{! TEMPLATE CUSTOMIZATION - BEGIN - Removed ApiClient constructor and replaced it with a custom constructors which create the ApiClient with the CoreConfiguration }}
151151
/**
152152
* Basic constructor for ApiClient.
153153
*
@@ -208,7 +208,7 @@ public class ApiClient {
208208
this.httpClient = httpClient;
209209
}
210210
}
211-
{{! END - Removed ApiClient constructor and replaced it with a custom constructors which create the ApiClient with the CoreConfiguration }}
211+
{{! TEMPLATE CUSTOMIZATION - END - Removed ApiClient constructor and replaced it with a custom constructors which create the ApiClient with the CoreConfiguration }}
212212

213213
{{#hasOAuthMethods}}
214214
{{#oauthMethods}}
@@ -312,7 +312,7 @@ public class ApiClient {
312312
// Set default User-Agent.
313313
setUserAgent("{{{httpUserAgent}}}{{^httpUserAgent}}OpenAPI-Generator/{{{artifactVersion}}}/java{{/httpUserAgent}}");
314314
315-
{{! BEGIN - delete line setting authentications
315+
{{! TEMPLATE CUSTOMIZATION - BEGIN - delete line setting authentications
316316
authentications = new HashMap<String, Authentication>();
317317
}}
318318
{{#dynamicOperations}}
@@ -568,7 +568,7 @@ public class ApiClient {
568568
JSON.setLenientOnJson(lenientOnJson);
569569
return this;
570570
}
571-
{{! BEGIN - delete authentications getter, we use our own Authenticator
571+
{{! TEMPLATE CUSTOMIZATION - BEGIN - delete authentications getter, we use our own Authenticator
572572
/**
573573
* Get authentications (key: authentication name, value: authentication).
574574
*
@@ -614,7 +614,7 @@ public class ApiClient {
614614
}
615615
{{/hasHttpBearerMethods}}
616616

617-
{{! BEGIN - delete auth related methods, we use our own Authenticator
617+
{{! TEMPLATE CUSTOMIZATION - BEGIN - delete auth related methods, we use our own Authenticator
618618
deleted methods:
619619
setUsername
620620
setPassword
@@ -1461,7 +1461,7 @@ public class ApiClient {
14611461

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

1464-
{{! BEGIN - delete updateParamsForAuth, we use our own Authenticator
1464+
{{! TEMPLATE CUSTOMIZATION - BEGIN - delete updateParamsForAuth, we use our own Authenticator
14651465
// update parameters with authentication settings
14661466
updateParamsForAuth(authNames, updatedQueryParams, headerParams, cookieParams, requestBodyToString(reqBody), method, URI.create(url));
14671467
}}
@@ -1585,7 +1585,7 @@ public class ApiClient {
15851585
}
15861586
}
15871587

1588-
{{! BEGIN - delete updateParamsForAuth method, we use our own Authenticator }}
1588+
{{! TEMPLATE CUSTOMIZATION - BEGIN - delete updateParamsForAuth method, we use our own Authenticator }}
15891589

15901590
/**
15911591
* Build a form-encoding request body with the given form parameters.

languages/java/templates/README.md

Lines changed: 0 additions & 14 deletions
This file was deleted.

languages/java/templates/README.mustache

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
# STACKIT Java SDK for {{appName}}
22

3-
- API version: {{appVersion}}
4-
5-
{{{appDescriptionWithNewLines}}}
6-
7-
{{#infoUrl}}
8-
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
9-
{{/infoUrl}}
10-
113
This package is part of the STACKIT Java SDK. For additional information, please visit the [GitHub repository](https://{{gitHost}}/{{{gitUserId}}}/{{{gitRepoId}}}) of the SDK.
124

135
## Installation from Maven Central (recommended)

languages/java/templates/api.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class {{classname}} {
6363
private int localHostIndex;
6464
private String localCustomBaseUrl;
6565
66-
{{! BEGIN - Remove default constructor and replaced with constructor which uses CoreConfiguration }}
66+
{{! TEMPLATE CUSTOMIZATION - BEGIN - Remove default constructor and replaced with constructor which uses CoreConfiguration }}
6767
/**
6868
* Basic constructor for DefaultApi
6969
*
@@ -110,7 +110,7 @@ class {{classname}} {
110110
}
111111
this.localVarApiClient = new ApiClient(httpClient, config);
112112
}
113-
{{! END - Remove default constructor and replaced with constructor which uses CoreConfiguration }}
113+
{{! TEMPLATE CUSTOMIZATION - END - Remove default constructor and replaced with constructor which uses CoreConfiguration }}
114114

115115
public ApiClient getApiClient() {
116116
return localVarApiClient;

languages/java/templates/custom/serviceApi.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class {{serviceName}}Api extends DefaultApi {
2323
*
2424
* For production use consider using the constructor with the OkHttpClient parameter.
2525
*
26-
* @param config your STACKIT SDK CoreConfiguration
26+
* @param configuration your STACKIT SDK CoreConfiguration
2727
* @throws IOException
2828
*/
2929
public {{serviceName}}Api(CoreConfiguration configuration)

scripts/generate-sdk/languages/java.sh

Lines changed: 70 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ generate_java_sdk() {
7676
mkdir -p "${SERVICES_FOLDER}"
7777

7878
warning=""
79-
79+
8080
# Generate SDK for each service
81-
for service_json in "${ROOT_DIR}"/oas/legacy/*.json; do
82-
service="${service_json##*/}"
81+
for service_dir in "${ROOT_DIR}/oas/services"/*; do
82+
service="${service_dir##*/}"
8383
service="${service%.json}"
8484

8585
service_pascal_case=$(to_pascal_case "${service}")
@@ -101,63 +101,79 @@ generate_java_sdk() {
101101
continue
102102
fi
103103

104+
# check if the whole service is blocklisted
104105
if grep -E "^$service$" "${ROOT_DIR}/languages/java/blocklist.txt"; then
105106
echo "Skipping blocklisted service ${service}"
106107
warning+="Skipping blocklisted service ${service}\n"
107-
cp -r "${sdk_services_backup_dir}/${service}" "${SERVICES_FOLDER}"
108108
continue
109109
fi
110-
111-
echo ">> Generating \"${service}\" service..."
112-
cd "${ROOT_DIR}"
113-
114-
mkdir -p "${SERVICES_FOLDER}/${service}/"
115-
cp "${ROOT_DIR}/languages/java/.openapi-generator-ignore" "${SERVICES_FOLDER}/${service}/.openapi-generator-ignore"
116-
117-
SERVICE_DESCRIPTION=$(cat "${service_json}" | jq .info.title --raw-output)
118-
119-
# TODO: add to generator below when adding multi-API-version support:
120-
# --inline-schema-options "SKIP_SCHEMA_REUSE=true"
121-
122-
# Run the generator
123-
java -Dlog.level="${GENERATOR_LOG_LEVEL}" -jar "${GENERATOR_JAR_PATH}" generate \
124-
--generator-name java \
125-
--input-spec "${service_json}" \
126-
--output "${SERVICES_FOLDER}/${service}" \
127-
--git-host "${GIT_HOST}" \
128-
--git-user-id "${GIT_USER_ID}" \
129-
--git-repo-id "${GIT_REPO_ID}" \
130-
--global-property apis,models,modelTests=false,modelDocs=false,apiDocs=false,apiTests=true,supportingFiles \
131-
--additional-properties="artifactId=${service},artifactDescription=${SERVICE_DESCRIPTION},invokerPackage=cloud.stackit.sdk.${service},modelPackage=cloud.stackit.sdk.${service}.model,apiPackage=cloud.stackit.sdk.${service}.api,serviceName=${service_pascal_case}" >/dev/null \
132-
--http-user-agent stackit-sdk-java/"${service}" \
133-
--config "${ROOT_DIR}/languages/java/openapi-generator-config.yml"
134-
135-
# Rename DefaultApiServiceApi.java to {serviceName}Api.java
136-
# This approach is a workaround because the file name cannot be set dynamically via --additional-properties or the config file in OpenAPI Generator.
137-
api_file="${SERVICES_FOLDER}/${service}/src/main/java/cloud/stackit/sdk/${service}/api/DefaultApiServiceApi.java"
138-
if [ -f "$api_file" ]; then
139-
mv "$api_file" "${SERVICES_FOLDER}/${service}/src/main/java/cloud/stackit/sdk/${service}/api/${service_pascal_case}Api.java"
140-
fi
141-
api_test_file="${SERVICES_FOLDER}/${service}/src/test/java/cloud/stackit/sdk/${service}/api/DefaultApiTestServiceApiTest.java"
142-
if [ -f "$api_test_file" ]; then
143-
mv "$api_test_file" "${SERVICES_FOLDER}/${service}/src/test/java/cloud/stackit/sdk/${service}/api/${service_pascal_case}ApiTest.java"
144-
fi
145-
146-
# Remove unnecessary files
147-
rm "${SERVICES_FOLDER}/${service}/.openapi-generator-ignore"
148-
rm -r "${SERVICES_FOLDER}/${service}/.openapi-generator/"
149-
150-
# If the service has a wait package, move them inside the service folder
151-
if [ -d "${sdk_services_backup_dir}/${service}/src/main/java/cloud/stackit/sdk/${service}/wait" ]; then
152-
echo "Found ${service} \"wait\" package"
153-
cp -r "${sdk_services_backup_dir}/${service}/src/main/java/cloud/stackit/sdk/${service}/wait" "${SERVICES_FOLDER}/${service}/src/main/java/cloud/stackit/sdk/${service}/wait"
154-
fi
155110

156-
# If the service has a wait test package, move them inside the service folder
157-
if [ -d "${sdk_services_backup_dir}/${service}/src/test/java/cloud/stackit/sdk/${service}/wait" ]; then
158-
echo "Found ${service} \"wait\" test package"
159-
cp -r "${sdk_services_backup_dir}/${service}/src/test/java/cloud/stackit/sdk/${service}/wait" "${SERVICES_FOLDER}/${service}/src/test/java/cloud/stackit/sdk/${service}/wait"
160-
fi
111+
echo -e "\n>> Generating SDK for \"${service}\" service..."
112+
for version_dir in "${service_dir}"/*; do
113+
service_version_json="${version_dir}/${service_dir##*/}.json"
114+
version="${version_dir##*/}"
115+
116+
# check if that specific API version of the service is blocklisted
117+
if grep -E "^${service}-${version}$" "${ROOT_DIR}/languages/java/blocklist.txt"; then
118+
echo "Skipping blocklisted API version ${version} of service ${service}"
119+
warning+="Skipping blocklisted API version ${version} of service ${service}\n"
120+
continue
121+
fi
122+
123+
echo -e "\n>> Generating SDK package \"${version}api\" for \"${service}\" service..."
124+
cd "${ROOT_DIR}"
125+
126+
mkdir -p "${SERVICES_FOLDER}/${service}"
127+
cp "${ROOT_DIR}/languages/java/.openapi-generator-ignore" "${SERVICES_FOLDER}/${service}/.openapi-generator-ignore"
128+
129+
SERVICE_DESCRIPTION=$(cat "${service_version_json}" | jq .info.title --raw-output)
130+
131+
# Run the generator
132+
java -Dlog.level="${GENERATOR_LOG_LEVEL}" -jar "${GENERATOR_JAR_PATH}" generate \
133+
--generator-name java \
134+
--input-spec "${service_version_json}" \
135+
--output "${SERVICES_FOLDER}/${service}" \
136+
--git-host "${GIT_HOST}" \
137+
--git-user-id "${GIT_USER_ID}" \
138+
--git-repo-id "${GIT_REPO_ID}" \
139+
--global-property apis,models,modelTests=false,modelDocs=false,apiDocs=false,apiTests=true,supportingFiles \
140+
--additional-properties="artifactId=${service},artifactDescription=${SERVICE_DESCRIPTION},invokerPackage=cloud.stackit.sdk.${service}.${version}api,modelPackage=cloud.stackit.sdk.${service}.${version}api.model,apiPackage=cloud.stackit.sdk.${service}.${version}api.api,serviceName=${service_pascal_case}" \
141+
--inline-schema-options "SKIP_SCHEMA_REUSE=true" \
142+
--http-user-agent stackit-sdk-java/"${service}" \
143+
--config "${ROOT_DIR}/languages/java/openapi-generator-config.yml"
144+
145+
# Rename DefaultApiServiceApi.java to {serviceName}Api.java
146+
# This approach is a workaround because the file name cannot be set dynamically via --additional-properties or the config file in OpenAPI Generator.
147+
api_file="${SERVICES_FOLDER}/${service}/src/main/java/cloud/stackit/sdk/${service}/${version}api/api/DefaultApiServiceApi.java"
148+
if [ -f "$api_file" ]; then
149+
mv "$api_file" "${SERVICES_FOLDER}/${service}/src/main/java/cloud/stackit/sdk/${service}/${version}api/api/${service_pascal_case}Api.java"
150+
fi
151+
api_test_file="${SERVICES_FOLDER}/${service}/src/test/java/cloud/stackit/sdk/${service}/${version}api/api/DefaultApiTestServiceApiTest.java"
152+
if [ -f "$api_test_file" ]; then
153+
mv "$api_test_file" "${SERVICES_FOLDER}/${service}/src/test/java/cloud/stackit/sdk/${service}/${version}api/api/${service_pascal_case}ApiTest.java"
154+
fi
155+
156+
build_gradle="${SERVICES_FOLDER}/${service}/${version}api/build.gradle"
157+
if [ -f "$build_gradle" ]; then
158+
mv "$build_gradle" "${SERVICES_FOLDER}/${service}/build.gradle"
159+
fi
160+
161+
# Remove unnecessary files
162+
rm "${SERVICES_FOLDER}/${service}/.openapi-generator-ignore"
163+
rm -r "${SERVICES_FOLDER}/${service}/.openapi-generator/"
164+
165+
# If the service version has a wait package, move them inside the service folder
166+
if [ -d "${sdk_services_backup_dir}/${service}/src/main/java/cloud/stackit/sdk/${service}/${version}api/wait" ]; then
167+
echo "Found ${service} \"wait\" package"
168+
cp -r "${sdk_services_backup_dir}/${service}/src/main/java/cloud/stackit/sdk/${service}/${version}api/wait" "${SERVICES_FOLDER}/${service}/src/main/java/cloud/stackit/sdk/${service}/${version}api/wait"
169+
fi
170+
171+
# If the service version has a wait test package, move them inside the service folder
172+
if [ -d "${sdk_services_backup_dir}/${service}/src/test/java/cloud/stackit/sdk/${service}/${version}api/wait" ]; then
173+
echo "Found ${service} \"wait\" test package"
174+
cp -r "${sdk_services_backup_dir}/${service}/src/test/java/cloud/stackit/sdk/${service}/${version}api/wait" "${SERVICES_FOLDER}/${service}/src/test/java/cloud/stackit/sdk/${service}/${version}api/wait"
175+
fi
176+
done
161177

162178
# If the service has a CHANGELOG file, move it inside the service folder
163179
if [ -f "${sdk_services_backup_dir}/${service}/CHANGELOG.md" ]; then

0 commit comments

Comments
 (0)