Skip to content

Commit 09cc7ee

Browse files
committed
Enable backwards compatibility for type unions - match against success objects even if they contain extra params.
1 parent d919ff4 commit 09cc7ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3322
-406
lines changed

client/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Add this dependency to your project's POM:
4040
<dependency>
4141
<groupId>com.fastcomments</groupId>
4242
<artifactId>client</artifactId>
43-
<version>0.0.22</version>
43+
<version>0.0.23</version>
4444
<scope>compile</scope>
4545
</dependency>
4646
```
@@ -56,7 +56,7 @@ Add this dependency to your project's build file:
5656
}
5757
5858
dependencies {
59-
implementation "com.fastcomments:client:0.0.22"
59+
implementation "com.fastcomments:client:0.0.23"
6060
}
6161
```
6262

@@ -70,7 +70,7 @@ mvn clean package
7070

7171
Then manually install the following JARs:
7272

73-
* `target/client-0.0.22.jar`
73+
* `target/client-0.0.23.jar`
7474
* `target/lib/*.jar`
7575

7676
## Getting Started

client/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ apply plugin: 'java'
44
apply plugin: 'com.diffplug.spotless'
55

66
group = 'com.fastcomments'
7-
version = '0.0.22'
7+
version = '0.0.23'
88

99
buildscript {
1010
repositories {

client/build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ lazy val root = (project in file(".")).
22
settings(
33
organization := "com.fastcomments",
44
name := "client",
5-
version := "0.0.22",
5+
version := "0.0.23",
66
scalaVersion := "2.11.4",
77
scalacOptions ++= Seq("-feature"),
88
javacOptions in compile ++= Seq("-Xlint:deprecation"),

client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<artifactId>client</artifactId>
66
<packaging>jar</packaging>
77
<name>client</name>
8-
<version>0.0.22</version>
8+
<version>0.0.23</version>
99
<url>https://fastcomments.com</url>
1010
<description>FastComments API Client - A SDK for interacting with the FastComments API</description>
1111
<scm>

client/src/main/java/com/fastcomments/invoker/ApiClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ private void init() {
141141
json = new JSON();
142142

143143
// Set default User-Agent.
144-
setUserAgent("OpenAPI-Generator/0.0.22/java");
144+
setUserAgent("OpenAPI-Generator/0.0.23/java");
145145

146146
authentications = new HashMap<String, Authentication>();
147147
}

client/src/main/java/com/fastcomments/invoker/Configuration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.11.0")
1717
public class Configuration {
18-
public static final String VERSION = "0.0.22";
18+
public static final String VERSION = "0.0.23";
1919

2020
private static ApiClient defaultApiClient = new ApiClient();
2121

client/src/main/java/com/fastcomments/model/APIEmptyResponse.java

Lines changed: 92 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,50 @@ public void setStatus(@javax.annotation.Nonnull ImportedAPIStatusSUCCESS status)
7777
this.status = status;
7878
}
7979

80+
/**
81+
* A container for additional, undeclared properties.
82+
* This is a holder for any undeclared properties as specified with
83+
* the 'additionalProperties' keyword in the OAS document.
84+
*/
85+
private Map<String, Object> additionalProperties;
86+
87+
/**
88+
* Set the additional (undeclared) property with the specified name and value.
89+
* If the property does not already exist, create it otherwise replace it.
90+
*
91+
* @param key name of the property
92+
* @param value value of the property
93+
* @return the APIEmptyResponse instance itself
94+
*/
95+
public APIEmptyResponse putAdditionalProperty(String key, Object value) {
96+
if (this.additionalProperties == null) {
97+
this.additionalProperties = new HashMap<String, Object>();
98+
}
99+
this.additionalProperties.put(key, value);
100+
return this;
101+
}
102+
103+
/**
104+
* Return the additional (undeclared) property.
105+
*
106+
* @return a map of objects
107+
*/
108+
public Map<String, Object> getAdditionalProperties() {
109+
return additionalProperties;
110+
}
111+
112+
/**
113+
* Return the additional (undeclared) property with the specified name.
114+
*
115+
* @param key name of the property
116+
* @return an object
117+
*/
118+
public Object getAdditionalProperty(String key) {
119+
if (this.additionalProperties == null) {
120+
return null;
121+
}
122+
return this.additionalProperties.get(key);
123+
}
80124

81125

82126
@Override
@@ -88,19 +132,21 @@ public boolean equals(Object o) {
88132
return false;
89133
}
90134
APIEmptyResponse apIEmptyResponse = (APIEmptyResponse) o;
91-
return Objects.equals(this.status, apIEmptyResponse.status);
135+
return Objects.equals(this.status, apIEmptyResponse.status)&&
136+
Objects.equals(this.additionalProperties, apIEmptyResponse.additionalProperties);
92137
}
93138

94139
@Override
95140
public int hashCode() {
96-
return Objects.hash(status);
141+
return Objects.hash(status, additionalProperties);
97142
}
98143

99144
@Override
100145
public String toString() {
101146
StringBuilder sb = new StringBuilder();
102147
sb.append("class APIEmptyResponse {\n");
103148
sb.append(" status: ").append(toIndentedString(status)).append("\n");
149+
sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n");
104150
sb.append("}");
105151
return sb.toString();
106152
}
@@ -143,14 +189,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
143189
}
144190
}
145191

146-
Set<Map.Entry<String, JsonElement>> entries = jsonElement.getAsJsonObject().entrySet();
147-
// check to see if the JSON string contains additional fields
148-
for (Map.Entry<String, JsonElement> entry : entries) {
149-
if (!APIEmptyResponse.openapiFields.contains(entry.getKey())) {
150-
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `APIEmptyResponse` properties. JSON: %s", entry.getKey(), jsonElement.toString()));
151-
}
152-
}
153-
154192
// check to make sure all required properties/fields are present in the JSON string
155193
for (String requiredField : APIEmptyResponse.openapiRequiredFields) {
156194
if (jsonElement.getAsJsonObject().get(requiredField) == null) {
@@ -177,14 +215,57 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
177215
@Override
178216
public void write(JsonWriter out, APIEmptyResponse value) throws IOException {
179217
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
218+
obj.remove("additionalProperties");
219+
// serialize additional properties
220+
if (value.getAdditionalProperties() != null) {
221+
for (Map.Entry<String, Object> entry : value.getAdditionalProperties().entrySet()) {
222+
if (entry.getValue() instanceof String)
223+
obj.addProperty(entry.getKey(), (String) entry.getValue());
224+
else if (entry.getValue() instanceof Number)
225+
obj.addProperty(entry.getKey(), (Number) entry.getValue());
226+
else if (entry.getValue() instanceof Boolean)
227+
obj.addProperty(entry.getKey(), (Boolean) entry.getValue());
228+
else if (entry.getValue() instanceof Character)
229+
obj.addProperty(entry.getKey(), (Character) entry.getValue());
230+
else {
231+
JsonElement jsonElement = gson.toJsonTree(entry.getValue());
232+
if (jsonElement.isJsonArray()) {
233+
obj.add(entry.getKey(), jsonElement.getAsJsonArray());
234+
} else {
235+
obj.add(entry.getKey(), jsonElement.getAsJsonObject());
236+
}
237+
}
238+
}
239+
}
180240
elementAdapter.write(out, obj);
181241
}
182242

183243
@Override
184244
public APIEmptyResponse read(JsonReader in) throws IOException {
185245
JsonElement jsonElement = elementAdapter.read(in);
186246
validateJsonElement(jsonElement);
187-
return thisAdapter.fromJsonTree(jsonElement);
247+
JsonObject jsonObj = jsonElement.getAsJsonObject();
248+
// store additional fields in the deserialized instance
249+
APIEmptyResponse instance = thisAdapter.fromJsonTree(jsonObj);
250+
for (Map.Entry<String, JsonElement> entry : jsonObj.entrySet()) {
251+
if (!openapiFields.contains(entry.getKey())) {
252+
if (entry.getValue().isJsonPrimitive()) { // primitive type
253+
if (entry.getValue().getAsJsonPrimitive().isString())
254+
instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsString());
255+
else if (entry.getValue().getAsJsonPrimitive().isNumber())
256+
instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsNumber());
257+
else if (entry.getValue().getAsJsonPrimitive().isBoolean())
258+
instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsBoolean());
259+
else
260+
throw new IllegalArgumentException(String.format("The field `%s` has unknown primitive type. Value: %s", entry.getKey(), entry.getValue().toString()));
261+
} else if (entry.getValue().isJsonArray()) {
262+
instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), List.class));
263+
} else { // JSON object
264+
instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), HashMap.class));
265+
}
266+
}
267+
}
268+
return instance;
188269
}
189270

190271
}.nullSafe();

client/src/main/java/com/fastcomments/model/AddDomainConfig200ResponseAnyOf.java

Lines changed: 92 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,50 @@ public void setStatus(@javax.annotation.Nullable Object status) {
100100
this.status = status;
101101
}
102102

103+
/**
104+
* A container for additional, undeclared properties.
105+
* This is a holder for any undeclared properties as specified with
106+
* the 'additionalProperties' keyword in the OAS document.
107+
*/
108+
private Map<String, Object> additionalProperties;
109+
110+
/**
111+
* Set the additional (undeclared) property with the specified name and value.
112+
* If the property does not already exist, create it otherwise replace it.
113+
*
114+
* @param key name of the property
115+
* @param value value of the property
116+
* @return the AddDomainConfig200ResponseAnyOf instance itself
117+
*/
118+
public AddDomainConfig200ResponseAnyOf putAdditionalProperty(String key, Object value) {
119+
if (this.additionalProperties == null) {
120+
this.additionalProperties = new HashMap<String, Object>();
121+
}
122+
this.additionalProperties.put(key, value);
123+
return this;
124+
}
125+
126+
/**
127+
* Return the additional (undeclared) property.
128+
*
129+
* @return a map of objects
130+
*/
131+
public Map<String, Object> getAdditionalProperties() {
132+
return additionalProperties;
133+
}
134+
135+
/**
136+
* Return the additional (undeclared) property with the specified name.
137+
*
138+
* @param key name of the property
139+
* @return an object
140+
*/
141+
public Object getAdditionalProperty(String key) {
142+
if (this.additionalProperties == null) {
143+
return null;
144+
}
145+
return this.additionalProperties.get(key);
146+
}
103147

104148

105149
@Override
@@ -112,12 +156,13 @@ public boolean equals(Object o) {
112156
}
113157
AddDomainConfig200ResponseAnyOf addDomainConfig200ResponseAnyOf = (AddDomainConfig200ResponseAnyOf) o;
114158
return Objects.equals(this._configuration, addDomainConfig200ResponseAnyOf._configuration) &&
115-
Objects.equals(this.status, addDomainConfig200ResponseAnyOf.status);
159+
Objects.equals(this.status, addDomainConfig200ResponseAnyOf.status)&&
160+
Objects.equals(this.additionalProperties, addDomainConfig200ResponseAnyOf.additionalProperties);
116161
}
117162

118163
@Override
119164
public int hashCode() {
120-
return Objects.hash(_configuration, status);
165+
return Objects.hash(_configuration, status, additionalProperties);
121166
}
122167

123168
@Override
@@ -126,6 +171,7 @@ public String toString() {
126171
sb.append("class AddDomainConfig200ResponseAnyOf {\n");
127172
sb.append(" _configuration: ").append(toIndentedString(_configuration)).append("\n");
128173
sb.append(" status: ").append(toIndentedString(status)).append("\n");
174+
sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n");
129175
sb.append("}");
130176
return sb.toString();
131177
}
@@ -170,14 +216,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
170216
}
171217
}
172218

173-
Set<Map.Entry<String, JsonElement>> entries = jsonElement.getAsJsonObject().entrySet();
174-
// check to see if the JSON string contains additional fields
175-
for (Map.Entry<String, JsonElement> entry : entries) {
176-
if (!AddDomainConfig200ResponseAnyOf.openapiFields.contains(entry.getKey())) {
177-
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `AddDomainConfig200ResponseAnyOf` properties. JSON: %s", entry.getKey(), jsonElement.toString()));
178-
}
179-
}
180-
181219
// check to make sure all required properties/fields are present in the JSON string
182220
for (String requiredField : AddDomainConfig200ResponseAnyOf.openapiRequiredFields) {
183221
if (jsonElement.getAsJsonObject().get(requiredField) == null) {
@@ -202,14 +240,57 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
202240
@Override
203241
public void write(JsonWriter out, AddDomainConfig200ResponseAnyOf value) throws IOException {
204242
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
243+
obj.remove("additionalProperties");
244+
// serialize additional properties
245+
if (value.getAdditionalProperties() != null) {
246+
for (Map.Entry<String, Object> entry : value.getAdditionalProperties().entrySet()) {
247+
if (entry.getValue() instanceof String)
248+
obj.addProperty(entry.getKey(), (String) entry.getValue());
249+
else if (entry.getValue() instanceof Number)
250+
obj.addProperty(entry.getKey(), (Number) entry.getValue());
251+
else if (entry.getValue() instanceof Boolean)
252+
obj.addProperty(entry.getKey(), (Boolean) entry.getValue());
253+
else if (entry.getValue() instanceof Character)
254+
obj.addProperty(entry.getKey(), (Character) entry.getValue());
255+
else {
256+
JsonElement jsonElement = gson.toJsonTree(entry.getValue());
257+
if (jsonElement.isJsonArray()) {
258+
obj.add(entry.getKey(), jsonElement.getAsJsonArray());
259+
} else {
260+
obj.add(entry.getKey(), jsonElement.getAsJsonObject());
261+
}
262+
}
263+
}
264+
}
205265
elementAdapter.write(out, obj);
206266
}
207267

208268
@Override
209269
public AddDomainConfig200ResponseAnyOf read(JsonReader in) throws IOException {
210270
JsonElement jsonElement = elementAdapter.read(in);
211271
validateJsonElement(jsonElement);
212-
return thisAdapter.fromJsonTree(jsonElement);
272+
JsonObject jsonObj = jsonElement.getAsJsonObject();
273+
// store additional fields in the deserialized instance
274+
AddDomainConfig200ResponseAnyOf instance = thisAdapter.fromJsonTree(jsonObj);
275+
for (Map.Entry<String, JsonElement> entry : jsonObj.entrySet()) {
276+
if (!openapiFields.contains(entry.getKey())) {
277+
if (entry.getValue().isJsonPrimitive()) { // primitive type
278+
if (entry.getValue().getAsJsonPrimitive().isString())
279+
instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsString());
280+
else if (entry.getValue().getAsJsonPrimitive().isNumber())
281+
instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsNumber());
282+
else if (entry.getValue().getAsJsonPrimitive().isBoolean())
283+
instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsBoolean());
284+
else
285+
throw new IllegalArgumentException(String.format("The field `%s` has unknown primitive type. Value: %s", entry.getKey(), entry.getValue().toString()));
286+
} else if (entry.getValue().isJsonArray()) {
287+
instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), List.class));
288+
} else { // JSON object
289+
instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), HashMap.class));
290+
}
291+
}
292+
}
293+
return instance;
213294
}
214295

215296
}.nullSafe();

0 commit comments

Comments
 (0)