glee icon indicating copy to clipboard operation
glee copied to clipboard

Apply `default` property to event fields

Open fmvilas opened this issue 2 years ago • 5 comments

Reason/Context

If we apply the default property value to event fields, users will need less boilerplate in their functions (i.e., checking for the existence of a value).

Description

For instance, I have the following definition (notice the default value on the repeat field): Captura de pantalla 2023-12-18 a las 11 39 41

Right now, the following code will fail if event.payload.repeat is undefined: Captura de pantalla 2023-12-18 a las 11 40 49

I think it shouldn't fail since, in our schema definition, we're saying the default value should be 1.

EDIT: After fixing the code above so it doesn't fail, I noticed another thing:

Captura de pantalla 2023-12-18 a las 11 56 04

If we don't provide support for this, the default value of 1 is defined in two places: in the schema definition (default: 1) and implicitly in the code (... || 1). This makes things harder to maintain and keep right. For instance, if the default value changes in the code but not in the schema or vice versa, there will be an inconsistency.

fmvilas avatar Dec 18 '23 10:12 fmvilas

@fmvilas what do yu think we should try to do ? the code should not fail if the event.payload.repeat is undefined.we are trying to solve this only right?

Gmin2 avatar Dec 29 '23 18:12 Gmin2

@Min2who I think the problem here is a little more complicated. IMO we need to follow the following approach whenever we are dealing with schemas and the "data" that we validate against that schema.

  1. load the defaults from the schema.
  2. Deep merge the loaded default to the "data" giving priority to the "data" itself. 🤔

KhudaDad414 avatar Jan 03 '24 11:01 KhudaDad414

This issue has been automatically marked as stale because it has not had recent activity :sleeping:

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience :heart:

github-actions[bot] avatar May 03 '24 00:05 github-actions[bot]

I think this will increase DX a lot and still makes sense.

fmvilas avatar May 03 '24 09:05 fmvilas

This issue has been automatically marked as stale because it has not had recent activity :sleeping:

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience :heart:

github-actions[bot] avatar Sep 01 '24 00:09 github-actions[bot]