- JS: 배열 내부 객체(children) 및 타입(Render, Save) 동기화 로직 개선 - 스칼라 배열 예제 추가 및 Swagger 타입 매핑 로직 구현
This commit is contained in:
@@ -280,6 +280,17 @@ public class ApiSpecManService {
|
||||
ObjectNode arrayItem = arrayNode.addObject();
|
||||
nodeMap.put(item.getLoutitempath(), arrayItem);
|
||||
break;
|
||||
|
||||
// JSON 레이아웃의 반복 항목(itemType="Array"). 자식이 있으면 객체배열, 없으면 스칼라배열.
|
||||
case "ARRAY":
|
||||
ArrayNode arrNode = parentNode.putArray(item.getLoutItemName());
|
||||
if (hasChildItems(items, item)) {
|
||||
ObjectNode arrObj = arrNode.addObject();
|
||||
nodeMap.put(item.getLoutitempath(), arrObj);
|
||||
} else {
|
||||
addScalarToArray(arrNode, item);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -357,6 +368,54 @@ public class ApiSpecManService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 지정 항목이 하위(자식) 항목을 가지는지 여부.
|
||||
* <p>JSON 레이아웃에서 배열/객체는 FIELD 노드(반복='*' → itemType="Array")로 저장되고
|
||||
* 자식 항목은 loutitempath 접두어 + depth+1 로 표현된다. 자식 유무로 객체배열/스칼라배열을 구분한다.
|
||||
*/
|
||||
private boolean hasChildItems(List<LayoutItemUI> items, LayoutItemUI parent) {
|
||||
String parentPath = parent.getLoutitempath();
|
||||
if (parentPath == null) {
|
||||
return false;
|
||||
}
|
||||
String prefix = parentPath + ".";
|
||||
int childDepth = parent.getLoutItemDepth() + 1;
|
||||
for (LayoutItemUI it : items) {
|
||||
String p = it.getLoutitempath();
|
||||
if (p != null && p.startsWith(prefix) && it.getLoutItemDepth() == childDepth) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** 스칼라 배열(자식 없는 Array)의 예시 요소 1개를 배열에 추가한다. addFieldValue 의 배열 버전. */
|
||||
private void addScalarToArray(ArrayNode arrayNode, LayoutItemUI item) {
|
||||
String dataType = item.getLoutItemDataType();
|
||||
String defaultValue = item.getLoutItemDefault();
|
||||
boolean isInteger = isIntegerType(dataType);
|
||||
|
||||
if (isNumericType(dataType)) {
|
||||
try {
|
||||
if (StringUtils.isNotEmpty(defaultValue)) {
|
||||
if (isInteger) {
|
||||
arrayNode.add(Integer.parseInt(defaultValue));
|
||||
} else {
|
||||
arrayNode.add(Double.parseDouble(defaultValue));
|
||||
}
|
||||
} else {
|
||||
arrayNode.add(isInteger ? 0 : 0.0);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
arrayNode.add(isInteger ? 0 : 0.0);
|
||||
}
|
||||
} else if ("BOOLEAN".equalsIgnoreCase(dataType)) {
|
||||
arrayNode.add(StringUtils.isNotEmpty(defaultValue) ? Boolean.parseBoolean(defaultValue) : false);
|
||||
} else {
|
||||
arrayNode.add(StringUtils.isNotEmpty(defaultValue) ? defaultValue : "sample_" + item.getLoutItemName());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isIntegerType(String dataType) {
|
||||
if (dataType == null) return false;
|
||||
switch (dataType.toUpperCase()) {
|
||||
@@ -661,6 +720,19 @@ public class ApiSpecManService {
|
||||
ObjectNode arrayItemProps = arrayItemSchema.putObject("properties");
|
||||
depthMap.put(item.getLoutItemDepth(), arrayItemProps);
|
||||
break;
|
||||
|
||||
// JSON 레이아웃의 반복 항목(itemType="Array"). 자식이 있으면 객체배열(items.properties), 없으면 스칼라배열.
|
||||
case "ARRAY":
|
||||
ObjectNode arrSchema = parentNode.putObject(item.getLoutItemName());
|
||||
arrSchema.put("type", "array");
|
||||
ObjectNode arrItems = arrSchema.putObject("items");
|
||||
if (hasChildItems(layoutItems, item)) {
|
||||
arrItems.put("type", "object");
|
||||
depthMap.put(item.getLoutItemDepth(), arrItems.putObject("properties"));
|
||||
} else {
|
||||
arrItems.put("type", mapSwaggerType(item.getLoutItemDataType()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user