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

Extend the components model with has-like functions #173

Closed
derberg opened this issue Sep 21, 2020 · 6 comments · Fixed by #192 or asyncapi/optimizer#193
Closed

Extend the components model with has-like functions #173

derberg opened this issue Sep 21, 2020 · 6 comments · Fixed by #192 or asyncapi/optimizer#193
Labels
enhancement New feature or request Hacktoberfest Label issues as available for participants of https://hacktoberfest.digitalocean.com released

Comments

@derberg
Copy link
Member

derberg commented Sep 21, 2020

Reason/Context

It would be very useful when working on docs/code generators to have a set of helper functions that let you easily determine if there is or not a specific component added to the components section of the AsyncAPI document and if it has any data. These components are not required and it is not required to have any data in them, so someone can add an empty object for example.

Many models already have useful functions like hasDescription.

Description

  • Add missing functions to Components model:

    • hasMessages
    • hasSchemas
    • hasSecuritySchemes
    • hasParameters
    • hasCorrelationIds
    • hasOperationTraits
    • hasMessageTraits

    Example hasParameter function from Channels model

  • Add missing tests here. Example test is here

@magicmatatjahu
Copy link
Member

magicmatatjahu commented Sep 27, 2020

I made a simple PR #175 and I checked that some models haven't relevant has* function for optional fields, for example Info model should have hasContact, hasLicense etc functions. Also some has-like functions should check that in checking object whole fields are required. What does it mean? contact field in Info model can be nil (null or undefined), empty (has {} value) or be an object with fields. If we write AsyncAPI schema with

"info": {
    "contact": {}
}

then json-schema-parser won't throw error, because any field in contact object isn't required, so {} is correct, so hasContact() function should check if object is nil or empty, then return false. It should be checked/fixed in other models as well.

@derberg What do you think?

@derberg derberg added the Hacktoberfest Label issues as available for participants of https://hacktoberfest.digitalocean.com label Oct 1, 2020
@derberg
Copy link
Member Author

derberg commented Oct 1, 2020

@magicmatatjahu I totally agree, we need to properly handle those not mandatory fields that could be empty

@derberg
Copy link
Member Author

derberg commented Oct 1, 2020

video about the issue https://youtu.be/Iqs_2BiNEEo?t=2060

@derberg
Copy link
Member Author

derberg commented Oct 28, 2020

@magicmatatjahu you can reopen your PR ;)

@magicmatatjahu
Copy link
Member

magicmatatjahu commented Nov 2, 2020

@derberg I force pushed commits before reopen and I had to create the new one. #192

@asyncapi-bot
Copy link
Contributor

🎉 This issue has been resolved in version 1.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Hacktoberfest Label issues as available for participants of https://hacktoberfest.digitalocean.com released
Projects
None yet
3 participants