Conversation
ahurtado-figma
left a comment
There was a problem hiding this comment.
Took another look and leaving a request for further explanation. At face value, this change makes sense to me -- but how do you see the WebhookPayload being used in this repo? It make sense to me that each webhook endpoint returns a different webhook payload type
👋 thanks for looking at this @ahurtado-figma ! So the point of adding So in the case of generated code from the OpenAPI definition for a typed language there can be a Within this repository this functionality is used in a few places. Here's rest-api-spec/openapi/openapi.yaml Lines 5075 to 5090 in 04e02c3 |
|
For some additional context I'm working on a client library in Dart and am converting the JSON values from the Figma API into Dart types. So by the definition having a discriminator I can generate a base class abstract class WebhookPayload extends Equatable {
const WebhookPayload({
required this.passcode,
required this.timestamp,
required this.webhookId,
});
factory WebhookPayload.fromJson(Map<String, Object?> json) {
final discriminator = json['event_type'];
final construct = switch (discriminator) {
'PING' => PingPayload.fromJson,
'FILE_UPDATE' => FileUpdatePayload.fromJson,
'FILE_DELETE' => FileDeletePayload.fromJson,
'FILE_VERSION_UPDATE' => FileVersionUpdatePayload.fromJson,
'LIBRARY_PUBLISH' => LibraryPublishPayload.fromJson,
'FILE_COMMENT' => FileCommentPayload.fromJson,
'DEV_MODE_STATUS_UPDATE' => DevModeStatusUpdatePayload.fromJson,
_ => throw ArgumentError.value(
discriminator,
'event_type',
'unknown event_type',
),
};
return construct(json);
}
/// Discriminator for [WebhookPayload] types.
WebhookEvent get eventType;
}You can see from ☝️ that it looks at the value of A good chunk of the patches I have locally are adding discriminators so I'd like to know if this change is acceptable before preparing those patches. |
|
Hey @ahurtado-figma any chance any of my PRs can get a review and potentially integrated in? I'm pretty sure that all the changes improve the output of any 3rd party API client that would use the OpenAPI spec. |
Add `WebhookPayload` which contains a `discriminator` to map the different payload types based on the value of `event_type`.
458703d to
cc47730
Compare
Add
WebhookPayloadwhich contains adiscriminatorto map the different payload types based on the value ofevent_type.