Skip to content

Commit 5031bd4

Browse files
committed
updated response value, toString/hashCode
1 parent 6609090 commit 5031bd4

File tree

2 files changed

+58
-117
lines changed

2 files changed

+58
-117
lines changed

modules/swagger-jaxrs/src/test/java/io/swagger/SimpleScannerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ public void scanClassWithExampleQuery() {
547547
Parameter param = swagger.getPaths().get("/external/info").getGet().getParameters().get(0);
548548
QueryParameter bp = (QueryParameter) param;
549549
assertNotNull(bp.getExample());
550-
String value = bp.getExample();
550+
Object value = bp.getExample();
551551
assertEquals("a,b,c", value);
552552
}
553553

@@ -557,7 +557,7 @@ public void scanClassWithImplicitExampleQuery() {
557557
Parameter param = swagger.getPaths().get("/external/info2").getGet().getParameters().get(0);
558558
QueryParameter bp = (QueryParameter) param;
559559
assertNotNull(bp.getExample());
560-
String value = bp.getExample();
560+
Object value = bp.getExample();
561561
assertEquals("77", value);
562562
}
563563
}

modules/swagger-models/src/main/java/io/swagger/models/parameters/AbstractSerializableParameter.java

Lines changed: 56 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,25 @@ public void setMinItems(Integer minItems) {
225225
}
226226

227227
@JsonProperty("x-example")
228-
public String getExample() {
228+
public Object getExample() {
229+
if (example == null) {
230+
return null;
231+
}
232+
try {
233+
if (BaseIntegerProperty.TYPE.equals(type)) {
234+
return Long.valueOf(example);
235+
} else if (DecimalProperty.TYPE.equals(type)) {
236+
return Double.valueOf(example);
237+
} else if (BooleanProperty.TYPE.equals(type)) {
238+
if ("true".equalsIgnoreCase(example) || "false".equalsIgnoreCase(defaultValue)) {
239+
return Boolean.valueOf(example);
240+
}
241+
}
242+
} catch (NumberFormatException e) {
243+
LOGGER.warn(String.format("Illegal DefaultValue %s for parameter type %s", defaultValue, type), e);
244+
}
229245
return example;
230246
}
231-
232247
public void setExample(String example) {
233248
this.example = example;
234249
}
@@ -241,124 +256,50 @@ private T castThis() {
241256
}
242257

243258
@Override
244-
public int hashCode() {
245-
final int prime = 31;
246-
int result = super.hashCode();
247-
result = prime * result + ((_enum == null) ? 0 : _enum.hashCode());
248-
result = prime * result
249-
+ ((collectionFormat == null) ? 0 : collectionFormat.hashCode());
250-
result = prime * result
251-
+ ((defaultValue == null) ? 0 : defaultValue.hashCode());
252-
result = prime * result
253-
+ ((exclusiveMaximum == null) ? 0 : exclusiveMaximum.hashCode());
254-
result = prime * result
255-
+ ((exclusiveMinimum == null) ? 0 : exclusiveMinimum.hashCode());
256-
result = prime * result + ((format == null) ? 0 : format.hashCode());
257-
result = prime * result + ((items == null) ? 0 : items.hashCode());
258-
result = prime * result + ((maximum == null) ? 0 : maximum.hashCode());
259-
result = prime * result + ((minimum == null) ? 0 : minimum.hashCode());
260-
result = prime * result + ((type == null) ? 0 : type.hashCode());
261-
result = prime * result + ((maxItems == null) ? 0 : maxItems.hashCode());
262-
result = prime * result + ((minItems == null) ? 0 : minItems.hashCode());
263-
return result;
264-
}
259+
public boolean equals(Object o) {
260+
if (this == o) return true;
261+
if (!(o instanceof AbstractSerializableParameter)) return false;
262+
if (!super.equals(o)) return false;
265263

266-
@Override
267-
public boolean equals(Object obj) {
268-
if (this == obj) {
269-
return true;
270-
}
271-
if (!super.equals(obj)) {
272-
return false;
273-
}
274-
if (getClass() != obj.getClass()) {
275-
return false;
276-
}
277-
AbstractSerializableParameter<?> other = (AbstractSerializableParameter<?>) obj;
278-
if (_enum == null) {
279-
if (other._enum != null) {
280-
return false;
281-
}
282-
} else if (!_enum.equals(other._enum)) {
283-
return false;
284-
}
285-
if (collectionFormat == null) {
286-
if (other.collectionFormat != null) {
287-
return false;
288-
}
289-
} else if (!collectionFormat.equals(other.collectionFormat)) {
290-
return false;
291-
}
292-
if (defaultValue == null) {
293-
if (other.defaultValue != null) {
294-
return false;
295-
}
296-
} else if (!defaultValue.equals(other.defaultValue)) {
297-
return false;
298-
}
299-
if (exclusiveMaximum == null) {
300-
if (other.exclusiveMaximum != null) {
301-
return false;
302-
}
303-
} else if (!exclusiveMaximum.equals(other.exclusiveMaximum)) {
304-
return false;
305-
}
306-
if (exclusiveMinimum == null) {
307-
if (other.exclusiveMinimum != null) {
308-
return false;
309-
}
310-
} else if (!exclusiveMinimum.equals(other.exclusiveMinimum)) {
264+
AbstractSerializableParameter<?> that = (AbstractSerializableParameter<?>) o;
265+
266+
if (getType() != null ? !getType().equals(that.getType()) : that.getType() != null) return false;
267+
if (getFormat() != null ? !getFormat().equals(that.getFormat()) : that.getFormat() != null) return false;
268+
if (getCollectionFormat() != null ? !getCollectionFormat().equals(that.getCollectionFormat()) : that.getCollectionFormat() != null)
311269
return false;
312-
}
313-
if (format == null) {
314-
if (other.format != null) {
315-
return false;
316-
}
317-
} else if (!format.equals(other.format)) {
270+
if (getItems() != null ? !getItems().equals(that.getItems()) : that.getItems() != null) return false;
271+
if (_enum != null ? !_enum.equals(that._enum) : that._enum != null) return false;
272+
if (exclusiveMaximum != null ? !exclusiveMaximum.equals(that.exclusiveMaximum) : that.exclusiveMaximum != null)
318273
return false;
319-
}
320-
if (items == null) {
321-
if (other.items != null) {
322-
return false;
323-
}
324-
} else if (!items.equals(other.items)) {
274+
if (getMaximum() != null ? !getMaximum().equals(that.getMaximum()) : that.getMaximum() != null) return false;
275+
if (exclusiveMinimum != null ? !exclusiveMinimum.equals(that.exclusiveMinimum) : that.exclusiveMinimum != null)
325276
return false;
326-
}
327-
if (maximum == null) {
328-
if (other.maximum != null) {
329-
return false;
330-
}
331-
} else if (!maximum.equals(other.maximum)) {
277+
if (getMinimum() != null ? !getMinimum().equals(that.getMinimum()) : that.getMinimum() != null) return false;
278+
if (getExample() != null ? !getExample().equals(that.getExample()) : that.getExample() != null) return false;
279+
if (getMaxItems() != null ? !getMaxItems().equals(that.getMaxItems()) : that.getMaxItems() != null)
332280
return false;
333-
}
334-
if (minimum == null) {
335-
if (other.minimum != null) {
336-
return false;
337-
}
338-
} else if (!minimum.equals(other.minimum)) {
281+
if (getMinItems() != null ? !getMinItems().equals(that.getMinItems()) : that.getMinItems() != null)
339282
return false;
340-
}
341-
if (type == null) {
342-
if (other.type != null) {
343-
return false;
344-
}
345-
} else if (!type.equals(other.type)) {
346-
return false;
347-
}
348-
if (maxItems == null) {
349-
if (other.maxItems != null) {
350-
return false;
351-
}
352-
} else if (!maxItems.equals(other.maxItems)) {
353-
return false;
354-
}
355-
if (minItems == null) {
356-
if (other.minItems != null) {
357-
return false;
358-
}
359-
} else if (!minItems.equals(other.minItems)) {
360-
return false;
361-
}
362-
return true;
283+
return !(getDefaultValue() != null ? !getDefaultValue().equals(that.getDefaultValue()) : that.getDefaultValue() != null);
284+
285+
}
286+
287+
@Override
288+
public int hashCode() {
289+
int result = super.hashCode();
290+
result = 31 * result + (getType() != null ? getType().hashCode() : 0);
291+
result = 31 * result + (getFormat() != null ? getFormat().hashCode() : 0);
292+
result = 31 * result + (getCollectionFormat() != null ? getCollectionFormat().hashCode() : 0);
293+
result = 31 * result + (getItems() != null ? getItems().hashCode() : 0);
294+
result = 31 * result + (_enum != null ? _enum.hashCode() : 0);
295+
result = 31 * result + (exclusiveMaximum != null ? exclusiveMaximum.hashCode() : 0);
296+
result = 31 * result + (getMaximum() != null ? getMaximum().hashCode() : 0);
297+
result = 31 * result + (exclusiveMinimum != null ? exclusiveMinimum.hashCode() : 0);
298+
result = 31 * result + (getMinimum() != null ? getMinimum().hashCode() : 0);
299+
result = 31 * result + (getExample() != null ? getExample().hashCode() : 0);
300+
result = 31 * result + (getMaxItems() != null ? getMaxItems().hashCode() : 0);
301+
result = 31 * result + (getMinItems() != null ? getMinItems().hashCode() : 0);
302+
result = 31 * result + (getDefaultValue() != null ? getDefaultValue().hashCode() : 0);
303+
return result;
363304
}
364305
}

0 commit comments

Comments
 (0)