Nikhil S created FLINK-39422:
--------------------------------
Summary: [FLINK][OpenAPI] OpenApiSpecGenerator produces incorrect
schemas for types with custom Jackson serializers
Key: FLINK-39422
URL: https://issues.apache.org/jira/browse/FLINK-39422
Project: Flink
Issue Type: Bug
Components: Runtime / REST
Reporter: Nikhil S
Flink's {{OpenApiSpecGenerator}} derives OpenAPI schemas from Java class
structure via Swagger reflection. When a type has a custom Jackson serializer
({{{}@JsonSerialize{}}}), the generator still produces a schema based on the
class fields rather than the actual serialized output. This causes spec-driven
clients to fail at deserialization.
h3. Affected types
||Type||Spec (incorrect)||Wire format (actual)||Root cause||
|{{SlotSharingGroupId}}|Object with {{{}bytes{}}}, {{{}lowerPart{}}},
{{upperPart}} fields|32-char hex string
(e.g.{{{}924418a21792216c4f44149a174997fc{}}})|[SlotSharingGroupIDSerializer|https://github.com/apache/flink/blob/release-1.20/flink-runtime/src/main/java/org/apache/flink/runtime/rest/messages/json/SlotSharingGroupIDSerializer.java]
calls {{value.toString()}}|
|{{MetricCollectionResponseBody}}|Object with {{metrics}} array property|Raw
JSON array ({{{}[\{"id":"...", "value":"..."}]{}}})|[Inline
Serializer|https://github.com/apache/flink/blob/release-1.20/flink-runtime/src/main/java/org/apache/flink/runtime/rest/messages/job/metrics/MetricCollectionResponseBody.java#L69-L86]
writes the collection directly via {{writeObject(getMetrics())}}|
|{{SerializedThrowable}}|Object with only {{serialized-throwable}} field|Object
with {{{}class{}}}, {{{}stack-trace{}}}, and {{serialized-throwable}}
fields|[SerializedThrowableSerializer|https://github.com/apache/flink/blob/release-1.20/flink-runtime/src/main/java/org/apache/flink/runtime/rest/messages/json/SerializedThrowableSerializer.java]
writes additional fields not present on the class|
h3. Context
The generator already handles similar ID types ({{{}JobID{}}},
{{{}JobVertexID{}}}, {{{}IntermediateDataSetID{}}}, {{{}TriggerId{}}},
{{{}ResourceID{}}}) via manual overrides in {{{}overrideIdSchemas(){}}}, but
{{SlotSharingGroupId}} was missed when it was added in
[FLINK-20090|https://issues.apache.org/jira/browse/FLINK-20090].
h3. Fix
- Add {{SlotSharingGroupId}} to {{overrideIdSchemas()}}
- Add {{overrideMetricCollectionSchema()}} for {{MetricCollectionResponseBody}}
- Add {{class}} and {{stack-trace}} fields to the {{SerializedThrowable}}
override using the public field name constants from
{{SerializedThrowableSerializer}}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)