refactor: swagger导入body参数的顺序不变

This commit is contained in:
AnAngle 2021-09-14 15:46:38 +08:00 committed by jianxing
parent eab143abfb
commit 35109cee86
2 changed files with 6 additions and 6 deletions

View File

@ -262,7 +262,7 @@ public class Swagger2Parser extends SwaggerAbstractParser {
if (model != null) { if (model != null) {
propertyList.add(getBodyParameters(model.getProperties(), refSet)); propertyList.add(getBodyParameters(model.getProperties(), refSet));
} else { } else {
propertyList.add(new JSONObject()); propertyList.add(new JSONObject(true));
} }
} }
return propertyList.toString(); return propertyList.toString();
@ -278,7 +278,7 @@ public class Swagger2Parser extends SwaggerAbstractParser {
} }
private JSONObject getBodyParameters(Map<String, Property> properties, HashSet<String> refSet) { private JSONObject getBodyParameters(Map<String, Property> properties, HashSet<String> refSet) {
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject(true);
if (properties != null) { if (properties != null) {
properties.forEach((key, value) -> { properties.forEach((key, value) -> {
if (value instanceof ObjectProperty) { if (value instanceof ObjectProperty) {
@ -301,7 +301,7 @@ public class Swagger2Parser extends SwaggerAbstractParser {
if (model != null) { if (model != null) {
propertyList.add(getBodyParameters(model.getProperties(), refSet)); propertyList.add(getBodyParameters(model.getProperties(), refSet));
} else { } else {
propertyList.add(new JSONObject()); propertyList.add(new JSONObject(true));
} }
jsonObject.put(key, propertyList); jsonObject.put(key, propertyList);
} else if (items instanceof ObjectProperty) { } else if (items instanceof ObjectProperty) {

View File

@ -340,12 +340,12 @@ public class Swagger3Parser extends SwaggerAbstractParser {
private Object parseSchema(Schema schema, Set<String> refSet, Map<String, Schema> infoMap) { private Object parseSchema(Schema schema, Set<String> refSet, Map<String, Schema> infoMap) {
if (schema == null) { if (schema == null) {
return new JSONObject(); return new JSONObject(true);
} }
infoMap.put(schema.getName(), schema); infoMap.put(schema.getName(), schema);
if (StringUtils.isNotBlank(schema.get$ref())) { if (StringUtils.isNotBlank(schema.get$ref())) {
if (refSet.contains(schema.get$ref())) { if (refSet.contains(schema.get$ref())) {
return new JSONObject(); return new JSONObject(true);
} }
refSet.add(schema.get$ref()); refSet.add(schema.get$ref());
Object propertiesResult = parseSchemaProperties(getModelByRef(schema.get$ref()), refSet, infoMap); Object propertiesResult = parseSchemaProperties(getModelByRef(schema.get$ref()), refSet, infoMap);
@ -386,7 +386,7 @@ public class Swagger3Parser extends SwaggerAbstractParser {
if (MapUtils.isEmpty(properties)) { if (MapUtils.isEmpty(properties)) {
return null; return null;
} }
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject(true);
properties.forEach((key, value) -> { properties.forEach((key, value) -> {
jsonObject.put(key, parseSchema(value, refSet, infoMap)); jsonObject.put(key, parseSchema(value, refSet, infoMap));
}); });