2424import com.google.gson.stream.JsonWriter;
2525import java.io.IOException;
2626import java.util.Arrays;
27+ import java.util.HashMap;
2728import java.util.HashSet;
29+ import java.util.List;
2830import java.util.Map;
2931import java.util.Objects;
30- import java.util.Set;
3132
3233/** CreateCredentialsPayload */
3334@javax.annotation.Generated(
@@ -107,6 +108,50 @@ public void setUsername(@javax.annotation.Nullable String username) {
107108 this.username = username;
108109 }
109110
111+ /**
112+ * A container for additional, undeclared properties. This is a holder for any undeclared
113+ * properties as specified with the 'additionalProperties' keyword in the OAS document.
114+ */
115+ private Map<String, Object> additionalProperties;
116+
117+ /**
118+ * Set the additional (undeclared) property with the specified name and value. If the property
119+ * does not already exist, create it otherwise replace it.
120+ *
121+ * @param key name of the property
122+ * @param value value of the property
123+ * @return the CreateCredentialsPayload instance itself
124+ */
125+ public CreateCredentialsPayload putAdditionalProperty(String key, Object value) {
126+ if (this.additionalProperties == null) {
127+ this.additionalProperties = new HashMap<String, Object>();
128+ }
129+ this.additionalProperties.put(key, value);
130+ return this;
131+ }
132+
133+ /**
134+ * Return the additional (undeclared) property.
135+ *
136+ * @return a map of objects
137+ */
138+ public Map<String, Object> getAdditionalProperties() {
139+ return additionalProperties;
140+ }
141+
142+ /**
143+ * Return the additional (undeclared) property with the specified name.
144+ *
145+ * @param key name of the property
146+ * @return an object
147+ */
148+ public Object getAdditionalProperty(String key) {
149+ if (this.additionalProperties == null) {
150+ return null;
151+ }
152+ return this.additionalProperties.get(key);
153+ }
154+
110155 @Override
111156 public boolean equals(Object o) {
112157 if (this == o) {
@@ -118,12 +163,14 @@ public boolean equals(Object o) {
118163 CreateCredentialsPayload createCredentialsPayload = (CreateCredentialsPayload) o;
119164 return Objects.equals(this.displayName, createCredentialsPayload.displayName)
120165 && Objects.equals(this.password, createCredentialsPayload.password)
121- && Objects.equals(this.username, createCredentialsPayload.username);
166+ && Objects.equals(this.username, createCredentialsPayload.username)
167+ && Objects.equals(
168+ this.additionalProperties, createCredentialsPayload.additionalProperties);
122169 }
123170
124171 @Override
125172 public int hashCode() {
126- return Objects.hash(displayName, password, username);
173+ return Objects.hash(displayName, password, username, additionalProperties );
127174 }
128175
129176 @Override
@@ -133,6 +180,9 @@ public String toString() {
133180 sb.append(" displayName: ").append(toIndentedString(displayName)).append("\n");
134181 sb.append(" password: ").append(toIndentedString(password)).append("\n");
135182 sb.append(" username: ").append(toIndentedString(username)).append("\n");
183+ sb.append(" additionalProperties: ")
184+ .append(toIndentedString(additionalProperties))
185+ .append("\n");
136186 sb.append("}");
137187 return sb.toString();
138188 }
@@ -175,17 +225,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
175225 CreateCredentialsPayload.openapiRequiredFields.toString()));
176226 }
177227 }
178-
179- Set<Map.Entry<String, JsonElement>> entries = jsonElement.getAsJsonObject().entrySet();
180- // check to see if the JSON string contains additional fields
181- for (Map.Entry<String, JsonElement> entry : entries) {
182- if (!CreateCredentialsPayload.openapiFields.contains(entry.getKey())) {
183- throw new IllegalArgumentException(
184- String.format(
185- "The field `%s` in the JSON string is not defined in the `CreateCredentialsPayload` properties. JSON: %s",
186- entry.getKey(), jsonElement.toString()));
187- }
188- }
189228 JsonObject jsonObj = jsonElement.getAsJsonObject();
190229 if ((jsonObj.get("displayName") != null && !jsonObj.get("displayName").isJsonNull())
191230 && !jsonObj.get("displayName").isJsonPrimitive()) {
@@ -228,14 +267,71 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
228267 public void write(JsonWriter out, CreateCredentialsPayload value)
229268 throws IOException {
230269 JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
270+ obj.remove("additionalProperties");
271+ // serialize additional properties
272+ if (value.getAdditionalProperties() != null) {
273+ for (Map.Entry<String, Object> entry :
274+ value.getAdditionalProperties().entrySet()) {
275+ if (entry.getValue() instanceof String)
276+ obj.addProperty(entry.getKey(), (String) entry.getValue());
277+ else if (entry.getValue() instanceof Number)
278+ obj.addProperty(entry.getKey(), (Number) entry.getValue());
279+ else if (entry.getValue() instanceof Boolean)
280+ obj.addProperty(entry.getKey(), (Boolean) entry.getValue());
281+ else if (entry.getValue() instanceof Character)
282+ obj.addProperty(
283+ entry.getKey(), (Character) entry.getValue());
284+ else {
285+ JsonElement jsonElement = gson.toJsonTree(entry.getValue());
286+ if (jsonElement.isJsonArray()) {
287+ obj.add(entry.getKey(), jsonElement.getAsJsonArray());
288+ } else {
289+ obj.add(entry.getKey(), jsonElement.getAsJsonObject());
290+ }
291+ }
292+ }
293+ }
231294 elementAdapter.write(out, obj);
232295 }
233296
234297 @Override
235298 public CreateCredentialsPayload read(JsonReader in) throws IOException {
236299 JsonElement jsonElement = elementAdapter.read(in);
237300 validateJsonElement(jsonElement);
238- return thisAdapter.fromJsonTree(jsonElement);
301+ JsonObject jsonObj = jsonElement.getAsJsonObject();
302+ // store additional fields in the deserialized instance
303+ CreateCredentialsPayload instance = thisAdapter.fromJsonTree(jsonObj);
304+ for (Map.Entry<String, JsonElement> entry : jsonObj.entrySet()) {
305+ if (!openapiFields.contains(entry.getKey())) {
306+ if (entry.getValue().isJsonPrimitive()) { // primitive type
307+ if (entry.getValue().getAsJsonPrimitive().isString())
308+ instance.putAdditionalProperty(
309+ entry.getKey(), entry.getValue().getAsString());
310+ else if (entry.getValue().getAsJsonPrimitive().isNumber())
311+ instance.putAdditionalProperty(
312+ entry.getKey(), entry.getValue().getAsNumber());
313+ else if (entry.getValue().getAsJsonPrimitive().isBoolean())
314+ instance.putAdditionalProperty(
315+ entry.getKey(),
316+ entry.getValue().getAsBoolean());
317+ else
318+ throw new IllegalArgumentException(
319+ String.format(
320+ "The field `%s` has unknown primitive type. Value: %s",
321+ entry.getKey(),
322+ entry.getValue().toString()));
323+ } else if (entry.getValue().isJsonArray()) {
324+ instance.putAdditionalProperty(
325+ entry.getKey(),
326+ gson.fromJson(entry.getValue(), List.class));
327+ } else { // JSON object
328+ instance.putAdditionalProperty(
329+ entry.getKey(),
330+ gson.fromJson(entry.getValue(), HashMap.class));
331+ }
332+ }
333+ }
334+ return instance;
239335 }
240336 }.nullSafe();
241337 }
0 commit comments