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

Handle in proper way empty object/array in has* like functions #201

Closed
Tracked by #481
magicmatatjahu opened this issue Nov 19, 2020 · 8 comments
Closed
Tracked by #481
Labels
enhancement New feature or request keep-open

Comments

@magicmatatjahu
Copy link
Member

Reason/Context

After discussion in this PR #192 (comment #192 (comment)) we should consider in which way we should go with handling empty object/array in has* like functions. At this moment, parser-js returns true if given field has object/array with values, and also true if object/array is empty - in those functions is used !! statement to convert value to boolean. Unfortunately JS treats empty object/array as true value. In opposite, empty object/array should treat as false value.

Description

If we decide to change default behavior, then changing logic will be huge breaking change to handle schema in templates.

Also we should discuss point of view from this comment: #173 (comment)

@magicmatatjahu magicmatatjahu added the enhancement New feature or request label Nov 19, 2020
@jonaslagoni
Copy link
Sponsor Member

I still have the point of view that has* implies something has been defined i.e. it has values or has been defined with values in which empty arrays/objects does not 😄

@derberg
Copy link
Member

derberg commented Nov 19, 2020

I like has* functions (didn't think if they can have better name) as they imply clearly what function is for. We should have those functions all around and use them only to determine if given part of spec is present or not. This way, in the future, it will be easy to change the logic inside those, depending how we understand that something is there or isn't. Function like properties should be only to extract properties, but I'd like to easily check if they are there with hasProperties.

For me, if object or array are empty, has* function should return false

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity 😴
It will be closed in 60 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation.
Thank you for your contributions ❤️

@derberg
Copy link
Member

derberg commented Oct 5, 2021

I'm wondering what is the point of keeping it open 😄

@magicmatatjahu
Copy link
Member Author

@derberg

At this moment, parser-js returns true if given field has object/array with values, and also true if object/array is empty - in those functions is used !! statement to convert value to boolean. Unfortunately JS treats empty object/array as true value. In opposite, empty object/array should treat as false value

for that :) Probably when we will release 3.0.0 version of AsyncAPI ParserJS will have breaking changes and we can think about handling such a problem.

@smoya
Copy link
Member

smoya commented Mar 7, 2022

I think you might be interested in joining #453

@smoya
Copy link
Member

smoya commented Jul 11, 2022

This is already being handled in the future v2.0.0 release, which follows the Intent-Driven API.

We could close this ticket once the v2.0.0 version of the parser is fixed.

@magicmatatjahu
Copy link
Member Author

Issue is resolved in v2 ParserJS - now in https://github.com/asyncapi/parser-js/tree/next-major branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request keep-open
Projects
None yet
Development

No branches or pull requests

4 participants