feat(schema): @McpAnyOf 어노테이션 및 JSON Schema 파싱 로직 추가
All checks were successful
Deploy to OCIWP / deploy (push) Successful in 1m56s
All checks were successful
Deploy to OCIWP / deploy (push) Successful in 1m56s
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package io.shinhanlife.dap.lib.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* MCP 스키마 생성 시 anyOf (해당 필드들 중 최소 1개 이상 필수) 제약을 부여합니다.
|
||||
*/
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface McpAnyOf {
|
||||
/**
|
||||
* anyOf 제약에 포함될 필드명 목록
|
||||
* 예: @McpAnyOf({"claimNo", "contractNo"})
|
||||
*/
|
||||
String[] value();
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
|
||||
import io.shinhanlife.dap.lib.annotation.McpParameter;
|
||||
import io.shinhanlife.dap.lib.annotation.McpValidation;
|
||||
import io.shinhanlife.dap.lib.annotation.McpAnyOf;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
@@ -92,6 +93,15 @@ public class JsonSchemaGenerator {
|
||||
schema.put("required", requiredList);
|
||||
}
|
||||
|
||||
McpAnyOf anyOfAnnotation = clazz.getAnnotation(McpAnyOf.class);
|
||||
if (anyOfAnnotation != null && anyOfAnnotation.value().length > 0) {
|
||||
List<Map<String, Object>> anyOfList = new ArrayList<>();
|
||||
for (String fieldName : anyOfAnnotation.value()) {
|
||||
anyOfList.add(Map.of("required", List.of(fieldName)));
|
||||
}
|
||||
schema.put("anyOf", anyOfList);
|
||||
}
|
||||
|
||||
visiting.remove(clazz);
|
||||
return schema;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user