wenjin272 commented on code in PR #1260:
URL: https://github.com/apache/flink-agents/pull/1260#discussion_r4282437077
##########
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:
Could we keep the previous handling for object-shaped enums? For an enum
annotated with `@JsonFormat(shape = OBJECT)` and a public `code` field,
enabling `FORBIDDEN_ADDITIONAL_PROPERTIES_BY_DEFAULT` now produces:
```json
{"type":"object","enum":[{"code":1},{"code":2}],"additionalProperties":false}
```
With no `properties.code` declared, neither enum value satisfies the schema.
The default `ObjectMapper` also cannot deserialize these objects without a
custom creator, whereas the previous string values round-tripped successfully.
Could we limit this custom handling to scalar values (return `null` for
object/array values so the existing provider handles the enum) and add a
regression test covering the strict schema and read-back?
--
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]