asyncapi / glee

Glee — The AsyncAPI framework that will make you smile again :)
87 stars 62 forks source link

Apply `default` property to event fields #659

Open fmvilas opened 10 months ago

fmvilas commented 10 months ago

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.

Gmin2 commented 10 months ago

@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?

KhudaDad414 commented 10 months ago

@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. 🤔

github-actions[bot] commented 6 months ago

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:

fmvilas commented 6 months ago

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

github-actions[bot] commented 2 months ago

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: