Skip to content

Commit 59af887

Browse files
authored
feat(java-sdk): generate iaas service (#180)
relates to STACKITSDK-209
1 parent 810d30a commit 59af887

File tree

4 files changed

+5
-72
lines changed

4 files changed

+5
-72
lines changed

scripts/generate-sdk/generate-sdk.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ python)
6565
java)
6666
# When the GENERATOR_VERSION changes, migrate also the templates in templates/java
6767
# Renovate: datasource=github-tags depName=OpenAPITools/openapi-generator versioning=semver
68-
GENERATOR_VERSION="v7.14.0"
68+
GENERATOR_VERSION="v7.15.0"
6969
;;
7070
*)
7171
echo "SDK language not supported."

scripts/generate-sdk/languages/java.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ SERVICES_FOLDER="${SDK_REPO_LOCAL_PATH}/services"
1010

1111
GENERATOR_LOG_LEVEL="error" # Must be a Java log level (error, warn, info...)
1212

13-
INCLUDE_SERVICES=("resourcemanager")
13+
INCLUDE_SERVICES=("resourcemanager" "iaas")
1414

1515
generate_java_sdk() {
1616
# Required parameters
@@ -119,7 +119,7 @@ generate_java_sdk() {
119119
--git-user-id ${GIT_USER_ID} \
120120
--git-repo-id ${GIT_REPO_ID} \
121121
--global-property apis,models,modelTests=false,modelDocs=false,apiDocs=false,apiTests=false,supportingFiles \
122-
--additional-properties=artifactId="stackit-sdk-${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 \
122+
--additional-properties=artifactId="stackit-sdk-${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},serviceId=${service}" >/dev/null \
123123
--http-user-agent stackit-sdk-java/"${service}" \
124124
--config openapi-generator-config-java.yml
125125

@@ -174,4 +174,4 @@ to_pascal_case() {
174174
for (i=2; i<=NF; i++) printf "%s", $i
175175
print ""
176176
}'
177-
}
177+
}

templates/java/README.mustache

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -105,74 +105,8 @@ defaultClient.setClientConfig(clientConfig);
105105
{{/jersey2}}
106106
## Getting Started
107107

108-
Please follow the [installation](#installation) instruction and execute the following Java code:
108+
See the [{{serviceId}} examples]({{scmUrl}}/tree/main/examples/{{serviceId}}/src/main/java/cloud/stackit/sdk/{{serviceId}}/examples).
109109

110-
```java
111-
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}
112-
import {{{invokerPackage}}}.*;
113-
import {{{invokerPackage}}}.auth.*;
114-
import {{{modelPackage}}}.*;
115-
import {{{package}}}.{{{classname}}};
116-
117-
public class {{{classname}}}Example {
118-
119-
public static void main(String[] args) {
120-
ApiClient defaultClient = Configuration.getDefaultApiClient();
121-
defaultClient.setBasePath("{{{basePath}}}");
122-
{{#hasAuthMethods}}{{#authMethods}}{{#isBasic}}{{#isBasicBasic}}
123-
// Configure HTTP basic authorization: {{{name}}}
124-
HttpBasicAuth {{{name}}} = (HttpBasicAuth) defaultClient.getAuthentication("{{{name}}}");
125-
{{{name}}}.setUsername("YOUR USERNAME");
126-
{{{name}}}.setPassword("YOUR PASSWORD");{{/isBasicBasic}}{{#isBasicBearer}}
127-
// Configure HTTP bearer authorization: {{{name}}}
128-
HttpBearerAuth {{{name}}} = (HttpBearerAuth) defaultClient.getAuthentication("{{{name}}}");
129-
{{{name}}}.setBearerToken("BEARER TOKEN");{{/isBasicBearer}}{{/isBasic}}{{#isApiKey}}
130-
// Configure API key authorization: {{{name}}}
131-
ApiKeyAuth {{{name}}} = (ApiKeyAuth) defaultClient.getAuthentication("{{{name}}}");
132-
{{{name}}}.setApiKey("YOUR API KEY");
133-
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
134-
//{{{name}}}.setApiKeyPrefix("Token");{{/isApiKey}}{{#isOAuth}}
135-
// Configure OAuth2 access token for authorization: {{{name}}}
136-
OAuth {{{name}}} = (OAuth) defaultClient.getAuthentication("{{{name}}}");
137-
{{{name}}}.setAccessToken("YOUR ACCESS TOKEN");{{/isOAuth}}{{#isHttpSignature}}
138-
// Configure HTTP signature authorization: {{{name}}}
139-
HttpSignatureAuth {{{name}}} = (HttpSignatureAuth) defaultClient.getAuthentication("{{{name}}}");
140-
// All the HTTP signature parameters below should be customized to your environment.
141-
// Configure the keyId
142-
{{{name}}}.setKeyId("YOUR KEY ID");
143-
// Configure the signature algorithm
144-
{{{name}}}.setSigningAlgorithm(SigningAlgorithm.HS2019);
145-
// Configure the specific cryptographic algorithm
146-
{{{name}}}.setAlgorithm(Algorithm.ECDSA_SHA256);
147-
// Configure the cryptographic algorithm parameters, if applicable
148-
{{{name}}}.setAlgorithmParameterSpec(null);
149-
// Set the cryptographic digest algorithm.
150-
{{{name}}}.setDigestAlgorithm("SHA-256");
151-
// Set the HTTP headers that should be included in the HTTP signature.
152-
{{{name}}}.setHeaders(Arrays.asList("date", "host"));
153-
// Set the private key used to sign the HTTP messages
154-
{{{name}}}.setPrivateKey();{{/isHttpSignature}}
155-
{{/authMethods}}
156-
{{/hasAuthMethods}}
157-
158-
{{{classname}}} apiInstance = new {{{classname}}}(defaultClient);
159-
{{#allParams}}
160-
{{{dataType}}} {{{paramName}}} = {{{example}}}; // {{{dataType}}} | {{{description}}}
161-
{{/allParams}}
162-
try {
163-
{{#returnType}}{{{.}}} result = {{/returnType}}apiInstance.{{{operationId}}}({{#allParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}});{{#returnType}}
164-
System.out.println(result);{{/returnType}}
165-
} catch (ApiException e) {
166-
System.err.println("Exception when calling {{{classname}}}#{{{operationId}}}");
167-
System.err.println("Status code: " + e.getCode());
168-
System.err.println("Reason: " + e.getResponseBody());
169-
System.err.println("Response headers: " + e.getResponseHeaders());
170-
e.printStackTrace();
171-
}
172-
}
173-
}
174-
{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}}
175-
```
176110

177111
## Recommendation
178112

templates/java/build.gradle.mustache

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ ext {
1515
}
1616

1717
dependencies {
18-
implementation project (':core')
1918
{{#swagger1AnnotationLibrary}}
2019
implementation "io.swagger:swagger-annotations:$swagger_annotations_version"
2120
{{/swagger1AnnotationLibrary}}

0 commit comments

Comments
 (0)