Skip to content
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

Apply default property to event fields #659

Open
fmvilas opened this issue Dec 18, 2023 · 4 comments
Open

Apply default property to event fields #659

fmvilas opened this issue Dec 18, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@fmvilas
Copy link
Member

fmvilas commented Dec 18, 2023

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 fmvilas added the enhancement New feature or request label Dec 18, 2023
@Gmin2
Copy link

Gmin2 commented Dec 29, 2023

@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
Copy link
Member

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

Copy link
Contributor

github-actions bot commented May 3, 2024

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

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 ❤️

@github-actions github-actions bot added the stale label May 3, 2024
@fmvilas
Copy link
Member Author

fmvilas commented May 3, 2024

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

@github-actions github-actions bot removed the stale label May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants