sangkyoonnam commented on code in PR #1260:
URL: https://github.com/apache/flink-agents/pull/1260#discussion_r4283000081
##########
integrations/chat-models/common/src/main/java/org/apache/flink/agents/integrations/chatmodels/common/PojoJsonSchemaGenerator.java:
##########
@@ -105,4 +123,62 @@ private static ObjectNode generate(
builder.forFields().withRequiredCheck(requiredCheck);
return new SchemaGenerator(builder.build()).generateSchema(type);
}
+
+ private static CustomDefinition enumDefinition(
+ ResolvedType javaType, SchemaGenerationContext context) {
+ Class<?> enumType = javaType.getErasedType();
+ if (!enumType.isEnum()) {
+ return null;
+ }
+ Object[] constants = enumType.getEnumConstants();
+ if (constants.length == 0) {
+ return null;
+ }
+ ArrayNode values = context.getGeneratorConfig().createArrayNode();
+ Set<String> types = new LinkedHashSet<>();
+ for (Object constant : constants) {
+ JsonNode value;
+ try {
+ value = ENUM_VALUE_MAPPER.valueToTree(constant);
Review Comment:
Good catch. Fixed in 3ee9e7c1: `enumDefinition` now returns null when a
constant serializes to an object or array, restoring the schema from before
this PR. Your `@JsonFormat(shape = OBJECT)` case gives
`{"type":"string","enum":["GROUND","AIR"]}` again under
`FORBIDDEN_ADDITIONAL_PROPERTIES_BY_DEFAULT`.
`listsObjectShapedEnumByItsConstantNames` checks that strict schema and reads
each value back; it fails without the change. I also updated the generator
comment and the Java enum bullet in structured-output.md.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]