Skip to content

Commit 111d6b0

Browse files
committed
feat(java): enable generation of automation service
relates to STACKITSDK-410
1 parent 70d1726 commit 111d6b0

6 files changed

Lines changed: 1522 additions & 1 deletion

File tree

‎scripts/generate-sdk/languages/java.sh‎

Lines changed: 1 addition & 1 deletion
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=("alb" "iaas" "loadbalancer" "objectstorage" "resourcemanager" "serverbackup" "serverupdate" "sfs")
13+
INCLUDE_SERVICES=("alb" "automation" "iaas" "loadbalancer" "objectstorage" "resourcemanager" "serverbackup" "serverupdate" "sfs")
1414

1515
generate_java_sdk() {
1616
# Required parameters
Lines changed: 363 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,363 @@
1+
/*
2+
* STACKIT Automation Service API
3+
* API endpoints for automation management .
4+
*
5+
* The version of the OpenAPI document: 1beta.0
6+
* Contact: support@stackit.de
7+
*
8+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9+
* https://openapi-generator.tech
10+
* Do not edit the class manually.
11+
*/
12+
13+
package cloud.stackit.sdk.automation.v1betaapi.model;
14+
15+
import cloud.stackit.sdk.automation.v1betaapi.JSON;
16+
import com.google.gson.Gson;
17+
import com.google.gson.JsonElement;
18+
import com.google.gson.JsonObject;
19+
import com.google.gson.TypeAdapter;
20+
import com.google.gson.TypeAdapterFactory;
21+
import com.google.gson.annotations.SerializedName;
22+
import com.google.gson.reflect.TypeToken;
23+
import com.google.gson.stream.JsonReader;
24+
import com.google.gson.stream.JsonWriter;
25+
import java.io.IOException;
26+
import java.util.ArrayList;
27+
import java.util.Arrays;
28+
import java.util.HashMap;
29+
import java.util.HashSet;
30+
import java.util.List;
31+
import java.util.Map;
32+
import java.util.Objects;
33+
import java.util.UUID;
34+
35+
/** CreateSnapshotsResult */
36+
@javax.annotation.Generated(value = "JavaGenerator", comments = "Generator version: 7.19.0")
37+
public class CreateSnapshotsResult {
38+
public static final String SERIALIZED_NAME_CREATED_SNAPSHOT_I_DS = "createdSnapshotIDs";
39+
40+
@SerializedName(SERIALIZED_NAME_CREATED_SNAPSHOT_I_DS)
41+
@javax.annotation.Nullable private List<UUID> createdSnapshotIDs = new ArrayList<>();
42+
43+
public static final String SERIALIZED_NAME_KIND = "kind";
44+
45+
@SerializedName(SERIALIZED_NAME_KIND)
46+
@javax.annotation.Nonnull
47+
private String kind;
48+
49+
public CreateSnapshotsResult() {}
50+
51+
public CreateSnapshotsResult createdSnapshotIDs(
52+
@javax.annotation.Nullable List<UUID> createdSnapshotIDs) {
53+
this.createdSnapshotIDs = createdSnapshotIDs;
54+
return this;
55+
}
56+
57+
public CreateSnapshotsResult addCreatedSnapshotIDsItem(UUID createdSnapshotIDsItem) {
58+
if (this.createdSnapshotIDs == null) {
59+
this.createdSnapshotIDs = new ArrayList<>();
60+
}
61+
this.createdSnapshotIDs.add(createdSnapshotIDsItem);
62+
return this;
63+
}
64+
65+
/**
66+
* Get createdSnapshotIDs
67+
*
68+
* @return createdSnapshotIDs
69+
*/
70+
@javax.annotation.Nullable public List<UUID> getCreatedSnapshotIDs() {
71+
return createdSnapshotIDs;
72+
}
73+
74+
public void setCreatedSnapshotIDs(@javax.annotation.Nullable List<UUID> createdSnapshotIDs) {
75+
this.createdSnapshotIDs = createdSnapshotIDs;
76+
}
77+
78+
public CreateSnapshotsResult kind(@javax.annotation.Nonnull String kind) {
79+
this.kind = kind;
80+
return this;
81+
}
82+
83+
/**
84+
* Get kind
85+
*
86+
* @return kind
87+
*/
88+
@javax.annotation.Nonnull
89+
public String getKind() {
90+
return kind;
91+
}
92+
93+
public void setKind(@javax.annotation.Nonnull String kind) {
94+
this.kind = kind;
95+
}
96+
97+
/**
98+
* A container for additional, undeclared properties. This is a holder for any undeclared
99+
* properties as specified with the 'additionalProperties' keyword in the OAS document.
100+
*/
101+
private Map<String, Object> additionalProperties;
102+
103+
/**
104+
* Set the additional (undeclared) property with the specified name and value. If the property
105+
* does not already exist, create it otherwise replace it.
106+
*
107+
* @param key name of the property
108+
* @param value value of the property
109+
* @return the CreateSnapshotsResult instance itself
110+
*/
111+
public CreateSnapshotsResult putAdditionalProperty(String key, Object value) {
112+
if (this.additionalProperties == null) {
113+
this.additionalProperties = new HashMap<String, Object>();
114+
}
115+
this.additionalProperties.put(key, value);
116+
return this;
117+
}
118+
119+
/**
120+
* Return the additional (undeclared) property.
121+
*
122+
* @return a map of objects
123+
*/
124+
public Map<String, Object> getAdditionalProperties() {
125+
return additionalProperties;
126+
}
127+
128+
/**
129+
* Return the additional (undeclared) property with the specified name.
130+
*
131+
* @param key name of the property
132+
* @return an object
133+
*/
134+
public Object getAdditionalProperty(String key) {
135+
if (this.additionalProperties == null) {
136+
return null;
137+
}
138+
return this.additionalProperties.get(key);
139+
}
140+
141+
@Override
142+
public boolean equals(Object o) {
143+
if (this == o) {
144+
return true;
145+
}
146+
if (o == null || getClass() != o.getClass()) {
147+
return false;
148+
}
149+
CreateSnapshotsResult createSnapshotsResult = (CreateSnapshotsResult) o;
150+
return Objects.equals(this.createdSnapshotIDs, createSnapshotsResult.createdSnapshotIDs)
151+
&& Objects.equals(this.kind, createSnapshotsResult.kind)
152+
&& Objects.equals(
153+
this.additionalProperties, createSnapshotsResult.additionalProperties);
154+
}
155+
156+
@Override
157+
public int hashCode() {
158+
return Objects.hash(createdSnapshotIDs, kind, additionalProperties);
159+
}
160+
161+
@Override
162+
public String toString() {
163+
StringBuilder sb = new StringBuilder();
164+
sb.append("class CreateSnapshotsResult {\n");
165+
sb.append(" createdSnapshotIDs: ")
166+
.append(toIndentedString(createdSnapshotIDs))
167+
.append("\n");
168+
sb.append(" kind: ").append(toIndentedString(kind)).append("\n");
169+
sb.append(" additionalProperties: ")
170+
.append(toIndentedString(additionalProperties))
171+
.append("\n");
172+
sb.append("}");
173+
return sb.toString();
174+
}
175+
176+
/**
177+
* Convert the given object to string with each line indented by 4 spaces (except the first
178+
* line).
179+
*/
180+
private String toIndentedString(Object o) {
181+
if (o == null) {
182+
return "null";
183+
}
184+
return o.toString().replace("\n", "\n ");
185+
}
186+
187+
public static HashSet<String> openapiFields;
188+
public static HashSet<String> openapiRequiredFields;
189+
190+
static {
191+
// a set of all properties/fields (JSON key names)
192+
openapiFields = new HashSet<String>(Arrays.asList("createdSnapshotIDs", "kind"));
193+
194+
// a set of required properties/fields (JSON key names)
195+
openapiRequiredFields = new HashSet<String>(Arrays.asList("kind"));
196+
}
197+
198+
/**
199+
* Validates the JSON Element and throws an exception if issues found
200+
*
201+
* @param jsonElement JSON Element
202+
* @throws IOException if the JSON Element is invalid with respect to CreateSnapshotsResult
203+
*/
204+
public static void validateJsonElement(JsonElement jsonElement) throws IOException {
205+
if (jsonElement == null) {
206+
if (!CreateSnapshotsResult.openapiRequiredFields
207+
.isEmpty()) { // has required fields but JSON element is null
208+
throw new IllegalArgumentException(
209+
String.format(
210+
java.util.Locale.ROOT,
211+
"The required field(s) %s in CreateSnapshotsResult is not found in the empty JSON string",
212+
CreateSnapshotsResult.openapiRequiredFields.toString()));
213+
}
214+
}
215+
216+
// check to make sure all required properties/fields are present in the JSON string
217+
for (String requiredField : CreateSnapshotsResult.openapiRequiredFields) {
218+
if (jsonElement.getAsJsonObject().get(requiredField) == null) {
219+
throw new IllegalArgumentException(
220+
String.format(
221+
java.util.Locale.ROOT,
222+
"The required field `%s` is not found in the JSON string: %s",
223+
requiredField,
224+
jsonElement.toString()));
225+
}
226+
}
227+
JsonObject jsonObj = jsonElement.getAsJsonObject();
228+
// ensure the optional json data is an array if present
229+
if (jsonObj.get("createdSnapshotIDs") != null
230+
&& !jsonObj.get("createdSnapshotIDs").isJsonNull()
231+
&& !jsonObj.get("createdSnapshotIDs").isJsonArray()) {
232+
throw new IllegalArgumentException(
233+
String.format(
234+
java.util.Locale.ROOT,
235+
"Expected the field `createdSnapshotIDs` to be an array in the JSON string but got `%s`",
236+
jsonObj.get("createdSnapshotIDs").toString()));
237+
}
238+
if (!jsonObj.get("kind").isJsonPrimitive()) {
239+
throw new IllegalArgumentException(
240+
String.format(
241+
java.util.Locale.ROOT,
242+
"Expected the field `kind` to be a primitive type in the JSON string but got `%s`",
243+
jsonObj.get("kind").toString()));
244+
}
245+
// OVERRIDE START: this if block fixes oneOf issues
246+
if (!"CreateSnapshotsResult".equals(jsonObj.get("kind").getAsString())) {
247+
throw new IllegalArgumentException(
248+
String.format(
249+
java.util.Locale.ROOT,
250+
"Expected the field `kind` to have value `CreateSnapshotsResult` but got `%s`",
251+
jsonObj.get("kind").toString()));
252+
}
253+
// OVERRIDE END: this if block fixes oneOf issues
254+
}
255+
256+
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
257+
@SuppressWarnings("unchecked")
258+
@Override
259+
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
260+
if (!CreateSnapshotsResult.class.isAssignableFrom(type.getRawType())) {
261+
return null; // this class only serializes 'CreateSnapshotsResult' and its subtypes
262+
}
263+
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
264+
final TypeAdapter<CreateSnapshotsResult> thisAdapter =
265+
gson.getDelegateAdapter(this, TypeToken.get(CreateSnapshotsResult.class));
266+
267+
return (TypeAdapter<T>)
268+
new TypeAdapter<CreateSnapshotsResult>() {
269+
@Override
270+
public void write(JsonWriter out, CreateSnapshotsResult value)
271+
throws IOException {
272+
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
273+
obj.remove("additionalProperties");
274+
// serialize additional properties
275+
if (value.getAdditionalProperties() != null) {
276+
for (Map.Entry<String, Object> entry :
277+
value.getAdditionalProperties().entrySet()) {
278+
if (entry.getValue() instanceof String)
279+
obj.addProperty(entry.getKey(), (String) entry.getValue());
280+
else if (entry.getValue() instanceof Number)
281+
obj.addProperty(entry.getKey(), (Number) entry.getValue());
282+
else if (entry.getValue() instanceof Boolean)
283+
obj.addProperty(entry.getKey(), (Boolean) entry.getValue());
284+
else if (entry.getValue() instanceof Character)
285+
obj.addProperty(
286+
entry.getKey(), (Character) entry.getValue());
287+
else {
288+
JsonElement jsonElement = gson.toJsonTree(entry.getValue());
289+
if (jsonElement.isJsonArray()) {
290+
obj.add(entry.getKey(), jsonElement.getAsJsonArray());
291+
} else {
292+
obj.add(entry.getKey(), jsonElement.getAsJsonObject());
293+
}
294+
}
295+
}
296+
}
297+
elementAdapter.write(out, obj);
298+
}
299+
300+
@Override
301+
public CreateSnapshotsResult read(JsonReader in) throws IOException {
302+
JsonElement jsonElement = elementAdapter.read(in);
303+
validateJsonElement(jsonElement);
304+
JsonObject jsonObj = jsonElement.getAsJsonObject();
305+
// store additional fields in the deserialized instance
306+
CreateSnapshotsResult instance = thisAdapter.fromJsonTree(jsonObj);
307+
for (Map.Entry<String, JsonElement> entry : jsonObj.entrySet()) {
308+
if (!openapiFields.contains(entry.getKey())) {
309+
if (entry.getValue().isJsonPrimitive()) { // primitive type
310+
if (entry.getValue().getAsJsonPrimitive().isString())
311+
instance.putAdditionalProperty(
312+
entry.getKey(), entry.getValue().getAsString());
313+
else if (entry.getValue().getAsJsonPrimitive().isNumber())
314+
instance.putAdditionalProperty(
315+
entry.getKey(), entry.getValue().getAsNumber());
316+
else if (entry.getValue().getAsJsonPrimitive().isBoolean())
317+
instance.putAdditionalProperty(
318+
entry.getKey(),
319+
entry.getValue().getAsBoolean());
320+
else
321+
throw new IllegalArgumentException(
322+
String.format(
323+
java.util.Locale.ROOT,
324+
"The field `%s` has unknown primitive type. Value: %s",
325+
entry.getKey(),
326+
entry.getValue().toString()));
327+
} else if (entry.getValue().isJsonArray()) {
328+
instance.putAdditionalProperty(
329+
entry.getKey(),
330+
gson.fromJson(entry.getValue(), List.class));
331+
} else { // JSON object
332+
instance.putAdditionalProperty(
333+
entry.getKey(),
334+
gson.fromJson(entry.getValue(), HashMap.class));
335+
}
336+
}
337+
}
338+
return instance;
339+
}
340+
}.nullSafe();
341+
}
342+
}
343+
344+
/**
345+
* Create an instance of CreateSnapshotsResult given an JSON string
346+
*
347+
* @param jsonString JSON string
348+
* @return An instance of CreateSnapshotsResult
349+
* @throws IOException if the JSON string is invalid with respect to CreateSnapshotsResult
350+
*/
351+
public static CreateSnapshotsResult fromJson(String jsonString) throws IOException {
352+
return JSON.getGson().fromJson(jsonString, CreateSnapshotsResult.class);
353+
}
354+
355+
/**
356+
* Convert an instance of CreateSnapshotsResult to an JSON string
357+
*
358+
* @return JSON string
359+
*/
360+
public String toJson() {
361+
return JSON.getGson().toJson(this);
362+
}
363+
}

0 commit comments

Comments
 (0)