-
Notifications
You must be signed in to change notification settings - Fork 25
add WebhookPayload definition #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Add `WebhookPayload` which contains a `discriminator` to map the different payload types based on the value of `event_type`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
Add
WebhookPayload
which contains adiscriminator
to map the different payload types based on the value ofevent_type
.