Skip to content

Commit e2ed6b5

Browse files
Generate serverbackup
1 parent d382e6d commit e2ed6b5

19 files changed

+2017
-270
lines changed

services/serverbackup/oas_commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ed4e4fbee2f5db4d95725108fb3d736e5363fb2f

services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/Backup.java

Lines changed: 117 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
import java.io.IOException;
2828
import java.util.ArrayList;
2929
import java.util.Arrays;
30+
import java.util.HashMap;
3031
import java.util.HashSet;
3132
import java.util.List;
3233
import java.util.Map;
3334
import java.util.Objects;
34-
import java.util.Set;
3535

3636
/** Backup */
3737
@javax.annotation.Generated(
@@ -309,6 +309,50 @@ public void setVolumeBackups(
309309
this.volumeBackups = volumeBackups;
310310
}
311311

312+
/**
313+
* A container for additional, undeclared properties. This is a holder for any undeclared
314+
* properties as specified with the 'additionalProperties' keyword in the OAS document.
315+
*/
316+
private Map<String, Object> additionalProperties;
317+
318+
/**
319+
* Set the additional (undeclared) property with the specified name and value. If the property
320+
* does not already exist, create it otherwise replace it.
321+
*
322+
* @param key name of the property
323+
* @param value value of the property
324+
* @return the Backup instance itself
325+
*/
326+
public Backup putAdditionalProperty(String key, Object value) {
327+
if (this.additionalProperties == null) {
328+
this.additionalProperties = new HashMap<String, Object>();
329+
}
330+
this.additionalProperties.put(key, value);
331+
return this;
332+
}
333+
334+
/**
335+
* Return the additional (undeclared) property.
336+
*
337+
* @return a map of objects
338+
*/
339+
public Map<String, Object> getAdditionalProperties() {
340+
return additionalProperties;
341+
}
342+
343+
/**
344+
* Return the additional (undeclared) property with the specified name.
345+
*
346+
* @param key name of the property
347+
* @return an object
348+
*/
349+
public Object getAdditionalProperty(String key) {
350+
if (this.additionalProperties == null) {
351+
return null;
352+
}
353+
return this.additionalProperties.get(key);
354+
}
355+
312356
@Override
313357
public boolean equals(Object o) {
314358
if (this == o) {
@@ -325,13 +369,22 @@ public boolean equals(Object o) {
325369
&& Objects.equals(this.name, backup.name)
326370
&& Objects.equals(this.size, backup.size)
327371
&& Objects.equals(this.status, backup.status)
328-
&& Objects.equals(this.volumeBackups, backup.volumeBackups);
372+
&& Objects.equals(this.volumeBackups, backup.volumeBackups)
373+
&& Objects.equals(this.additionalProperties, backup.additionalProperties);
329374
}
330375

331376
@Override
332377
public int hashCode() {
333378
return Objects.hash(
334-
createdAt, expireAt, id, lastRestoredAt, name, size, status, volumeBackups);
379+
createdAt,
380+
expireAt,
381+
id,
382+
lastRestoredAt,
383+
name,
384+
size,
385+
status,
386+
volumeBackups,
387+
additionalProperties);
335388
}
336389

337390
@Override
@@ -346,6 +399,9 @@ public String toString() {
346399
sb.append(" size: ").append(toIndentedString(size)).append("\n");
347400
sb.append(" status: ").append(toIndentedString(status)).append("\n");
348401
sb.append(" volumeBackups: ").append(toIndentedString(volumeBackups)).append("\n");
402+
sb.append(" additionalProperties: ")
403+
.append(toIndentedString(additionalProperties))
404+
.append("\n");
349405
sb.append("}");
350406
return sb.toString();
351407
}
@@ -400,17 +456,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
400456
}
401457
}
402458

403-
Set<Map.Entry<String, JsonElement>> entries = jsonElement.getAsJsonObject().entrySet();
404-
// check to see if the JSON string contains additional fields
405-
for (Map.Entry<String, JsonElement> entry : entries) {
406-
if (!Backup.openapiFields.contains(entry.getKey())) {
407-
throw new IllegalArgumentException(
408-
String.format(
409-
"The field `%s` in the JSON string is not defined in the `Backup` properties. JSON: %s",
410-
entry.getKey(), jsonElement.toString()));
411-
}
412-
}
413-
414459
// check to make sure all required properties/fields are present in the JSON string
415460
for (String requiredField : Backup.openapiRequiredFields) {
416461
if (jsonElement.getAsJsonObject().get(requiredField) == null) {
@@ -496,14 +541,71 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
496541
@Override
497542
public void write(JsonWriter out, Backup value) throws IOException {
498543
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
544+
obj.remove("additionalProperties");
545+
// serialize additional properties
546+
if (value.getAdditionalProperties() != null) {
547+
for (Map.Entry<String, Object> entry :
548+
value.getAdditionalProperties().entrySet()) {
549+
if (entry.getValue() instanceof String)
550+
obj.addProperty(entry.getKey(), (String) entry.getValue());
551+
else if (entry.getValue() instanceof Number)
552+
obj.addProperty(entry.getKey(), (Number) entry.getValue());
553+
else if (entry.getValue() instanceof Boolean)
554+
obj.addProperty(entry.getKey(), (Boolean) entry.getValue());
555+
else if (entry.getValue() instanceof Character)
556+
obj.addProperty(
557+
entry.getKey(), (Character) entry.getValue());
558+
else {
559+
JsonElement jsonElement = gson.toJsonTree(entry.getValue());
560+
if (jsonElement.isJsonArray()) {
561+
obj.add(entry.getKey(), jsonElement.getAsJsonArray());
562+
} else {
563+
obj.add(entry.getKey(), jsonElement.getAsJsonObject());
564+
}
565+
}
566+
}
567+
}
499568
elementAdapter.write(out, obj);
500569
}
501570

502571
@Override
503572
public Backup read(JsonReader in) throws IOException {
504573
JsonElement jsonElement = elementAdapter.read(in);
505574
validateJsonElement(jsonElement);
506-
return thisAdapter.fromJsonTree(jsonElement);
575+
JsonObject jsonObj = jsonElement.getAsJsonObject();
576+
// store additional fields in the deserialized instance
577+
Backup instance = thisAdapter.fromJsonTree(jsonObj);
578+
for (Map.Entry<String, JsonElement> entry : jsonObj.entrySet()) {
579+
if (!openapiFields.contains(entry.getKey())) {
580+
if (entry.getValue().isJsonPrimitive()) { // primitive type
581+
if (entry.getValue().getAsJsonPrimitive().isString())
582+
instance.putAdditionalProperty(
583+
entry.getKey(), entry.getValue().getAsString());
584+
else if (entry.getValue().getAsJsonPrimitive().isNumber())
585+
instance.putAdditionalProperty(
586+
entry.getKey(), entry.getValue().getAsNumber());
587+
else if (entry.getValue().getAsJsonPrimitive().isBoolean())
588+
instance.putAdditionalProperty(
589+
entry.getKey(),
590+
entry.getValue().getAsBoolean());
591+
else
592+
throw new IllegalArgumentException(
593+
String.format(
594+
"The field `%s` has unknown primitive type. Value: %s",
595+
entry.getKey(),
596+
entry.getValue().toString()));
597+
} else if (entry.getValue().isJsonArray()) {
598+
instance.putAdditionalProperty(
599+
entry.getKey(),
600+
gson.fromJson(entry.getValue(), List.class));
601+
} else { // JSON object
602+
instance.putAdditionalProperty(
603+
entry.getKey(),
604+
gson.fromJson(entry.getValue(), HashMap.class));
605+
}
606+
}
607+
}
608+
return instance;
507609
}
508610
}.nullSafe();
509611
}

services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/BackupJob.java

Lines changed: 110 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@
2424
import com.google.gson.stream.JsonWriter;
2525
import java.io.IOException;
2626
import java.util.Arrays;
27+
import java.util.HashMap;
2728
import java.util.HashSet;
29+
import java.util.List;
2830
import java.util.Map;
2931
import java.util.Objects;
30-
import java.util.Set;
3132

3233
/** BackupJob */
3334
@javax.annotation.Generated(
@@ -61,6 +62,50 @@ public void setId(@javax.annotation.Nonnull String id) {
6162
this.id = id;
6263
}
6364

65+
/**
66+
* A container for additional, undeclared properties. This is a holder for any undeclared
67+
* properties as specified with the 'additionalProperties' keyword in the OAS document.
68+
*/
69+
private Map<String, Object> additionalProperties;
70+
71+
/**
72+
* Set the additional (undeclared) property with the specified name and value. If the property
73+
* does not already exist, create it otherwise replace it.
74+
*
75+
* @param key name of the property
76+
* @param value value of the property
77+
* @return the BackupJob instance itself
78+
*/
79+
public BackupJob putAdditionalProperty(String key, Object value) {
80+
if (this.additionalProperties == null) {
81+
this.additionalProperties = new HashMap<String, Object>();
82+
}
83+
this.additionalProperties.put(key, value);
84+
return this;
85+
}
86+
87+
/**
88+
* Return the additional (undeclared) property.
89+
*
90+
* @return a map of objects
91+
*/
92+
public Map<String, Object> getAdditionalProperties() {
93+
return additionalProperties;
94+
}
95+
96+
/**
97+
* Return the additional (undeclared) property with the specified name.
98+
*
99+
* @param key name of the property
100+
* @return an object
101+
*/
102+
public Object getAdditionalProperty(String key) {
103+
if (this.additionalProperties == null) {
104+
return null;
105+
}
106+
return this.additionalProperties.get(key);
107+
}
108+
64109
@Override
65110
public boolean equals(Object o) {
66111
if (this == o) {
@@ -70,19 +115,23 @@ public boolean equals(Object o) {
70115
return false;
71116
}
72117
BackupJob backupJob = (BackupJob) o;
73-
return Objects.equals(this.id, backupJob.id);
118+
return Objects.equals(this.id, backupJob.id)
119+
&& Objects.equals(this.additionalProperties, backupJob.additionalProperties);
74120
}
75121

76122
@Override
77123
public int hashCode() {
78-
return Objects.hash(id);
124+
return Objects.hash(id, additionalProperties);
79125
}
80126

81127
@Override
82128
public String toString() {
83129
StringBuilder sb = new StringBuilder();
84130
sb.append("class BackupJob {\n");
85131
sb.append(" id: ").append(toIndentedString(id)).append("\n");
132+
sb.append(" additionalProperties: ")
133+
.append(toIndentedString(additionalProperties))
134+
.append("\n");
86135
sb.append("}");
87136
return sb.toString();
88137
}
@@ -126,17 +175,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
126175
}
127176
}
128177

129-
Set<Map.Entry<String, JsonElement>> entries = jsonElement.getAsJsonObject().entrySet();
130-
// check to see if the JSON string contains additional fields
131-
for (Map.Entry<String, JsonElement> entry : entries) {
132-
if (!BackupJob.openapiFields.contains(entry.getKey())) {
133-
throw new IllegalArgumentException(
134-
String.format(
135-
"The field `%s` in the JSON string is not defined in the `BackupJob` properties. JSON: %s",
136-
entry.getKey(), jsonElement.toString()));
137-
}
138-
}
139-
140178
// check to make sure all required properties/fields are present in the JSON string
141179
for (String requiredField : BackupJob.openapiRequiredFields) {
142180
if (jsonElement.getAsJsonObject().get(requiredField) == null) {
@@ -171,14 +209,71 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
171209
@Override
172210
public void write(JsonWriter out, BackupJob value) throws IOException {
173211
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
212+
obj.remove("additionalProperties");
213+
// serialize additional properties
214+
if (value.getAdditionalProperties() != null) {
215+
for (Map.Entry<String, Object> entry :
216+
value.getAdditionalProperties().entrySet()) {
217+
if (entry.getValue() instanceof String)
218+
obj.addProperty(entry.getKey(), (String) entry.getValue());
219+
else if (entry.getValue() instanceof Number)
220+
obj.addProperty(entry.getKey(), (Number) entry.getValue());
221+
else if (entry.getValue() instanceof Boolean)
222+
obj.addProperty(entry.getKey(), (Boolean) entry.getValue());
223+
else if (entry.getValue() instanceof Character)
224+
obj.addProperty(
225+
entry.getKey(), (Character) entry.getValue());
226+
else {
227+
JsonElement jsonElement = gson.toJsonTree(entry.getValue());
228+
if (jsonElement.isJsonArray()) {
229+
obj.add(entry.getKey(), jsonElement.getAsJsonArray());
230+
} else {
231+
obj.add(entry.getKey(), jsonElement.getAsJsonObject());
232+
}
233+
}
234+
}
235+
}
174236
elementAdapter.write(out, obj);
175237
}
176238

177239
@Override
178240
public BackupJob read(JsonReader in) throws IOException {
179241
JsonElement jsonElement = elementAdapter.read(in);
180242
validateJsonElement(jsonElement);
181-
return thisAdapter.fromJsonTree(jsonElement);
243+
JsonObject jsonObj = jsonElement.getAsJsonObject();
244+
// store additional fields in the deserialized instance
245+
BackupJob instance = thisAdapter.fromJsonTree(jsonObj);
246+
for (Map.Entry<String, JsonElement> entry : jsonObj.entrySet()) {
247+
if (!openapiFields.contains(entry.getKey())) {
248+
if (entry.getValue().isJsonPrimitive()) { // primitive type
249+
if (entry.getValue().getAsJsonPrimitive().isString())
250+
instance.putAdditionalProperty(
251+
entry.getKey(), entry.getValue().getAsString());
252+
else if (entry.getValue().getAsJsonPrimitive().isNumber())
253+
instance.putAdditionalProperty(
254+
entry.getKey(), entry.getValue().getAsNumber());
255+
else if (entry.getValue().getAsJsonPrimitive().isBoolean())
256+
instance.putAdditionalProperty(
257+
entry.getKey(),
258+
entry.getValue().getAsBoolean());
259+
else
260+
throw new IllegalArgumentException(
261+
String.format(
262+
"The field `%s` has unknown primitive type. Value: %s",
263+
entry.getKey(),
264+
entry.getValue().toString()));
265+
} else if (entry.getValue().isJsonArray()) {
266+
instance.putAdditionalProperty(
267+
entry.getKey(),
268+
gson.fromJson(entry.getValue(), List.class));
269+
} else { // JSON object
270+
instance.putAdditionalProperty(
271+
entry.getKey(),
272+
gson.fromJson(entry.getValue(), HashMap.class));
273+
}
274+
}
275+
}
276+
return instance;
182277
}
183278
}.nullSafe();
184279
}

0 commit comments

Comments
 (0)