Open fmvilas opened 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?
@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. 🤔
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:
I think this will increase DX a lot and still makes sense.
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:
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 therepeat
field):Right now, the following code will fail if
event.payload.repeat
is undefined: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:
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.