Skip to content

Commit 31a9263

Browse files
committed
review comments adaption
1 parent fb43220 commit 31a9263

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,11 @@ public String getString(String key, ObjectNode node, boolean required, String lo
714714
return getString(key, node, required, location, result, null);
715715
}
716716

717+
public String getStringWithDefaultValueSet(String key, ObjectNode node, boolean required, String location, ParseResult result) {
718+
719+
return getString(key, node, required, location, result, null);
720+
}
721+
717722
public Set<String> getKeys(ObjectNode node) {
718723
Set<String> keys = new LinkedHashSet<>();
719724
if (node == null) {
@@ -1259,6 +1264,23 @@ public Boolean getBoolean(String key, ObjectNode node, boolean required, String
12591264
return value;
12601265
}
12611266

1267+
public Boolean getBooleanWithDefaultValue(String key, ObjectNode node, String location) {
1268+
Boolean value = null;
1269+
JsonNode v = node.get(key);
1270+
if (node == null || v == null) {
1271+
return false;
1272+
} else {
1273+
if (v.getNodeType().equals(JsonNodeType.BOOLEAN)) {
1274+
value = v.asBoolean();
1275+
} else if (v.getNodeType().equals(JsonNodeType.STRING)) {
1276+
String stringValue = v.textValue();
1277+
return Boolean.parseBoolean(stringValue);
1278+
}
1279+
}
1280+
return value;
1281+
}
1282+
1283+
12621284
public BigDecimal getBigDecimal(String key, ObjectNode node, boolean required, String location, ParseResult result) {
12631285
BigDecimal value = null;
12641286
JsonNode v = node.get(key);
@@ -1408,7 +1430,7 @@ public Parameter getParameter(ObjectNode obj, String location, ParseResult resul
14081430
parameter.setDescription(value);
14091431
}
14101432

1411-
Boolean required = getBoolean("required", obj, false, location, result);
1433+
Boolean required = getBooleanWithDefaultValue("required", obj, location);
14121434
if (required != null) {
14131435
parameter.setRequired(required);
14141436
}else {
@@ -2195,14 +2217,11 @@ public Schema getSchema(ObjectNode node, String location, ParseResult result){
21952217
schema.setExample(example);
21962218
}
21972219

2198-
bool = getBoolean("deprecated", node, false, location, result);
2199-
2220+
bool = getBooleanWithDefaultValue("deprecated", node, location);
22002221
if(bool != null){
22012222
schema.setDeprecated(bool);
22022223
}
2203-
else {
2204-
schema.setDeprecated(false);
2205-
}
2224+
22062225

22072226
Map <String,Object> extensions = getExtensions(node);
22082227
if(extensions != null && extensions.size() > 0) {
@@ -2514,7 +2533,7 @@ public Operation getOperation(ObjectNode obj, String location, ParseResult resul
25142533
operation.setCallbacks(callbacks);
25152534
}
25162535

2517-
Boolean deprecated = getBoolean("deprecated", obj, false, location, result);
2536+
Boolean deprecated = getBooleanWithDefaultValue("deprecated", obj, location);
25182537
if (deprecated != null) {
25192538
operation.setDeprecated(deprecated);
25202539
}

0 commit comments

Comments
 (0)