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

feat: add configuration to always show message examples #1016

Merged

Conversation

tsauerwein
Copy link
Contributor

@tsauerwein tsauerwein commented Jun 17, 2024

Description

Changes proposed in this pull request:

  • Adds a configuration show.messageExamples, which when true also shows examples for the messages in the Messages section (and not only for the messages in the "Operations" section).

Background:

Maybe we are using the AsyncAPI CLI not in the intended way. But we have messages that are not referenced in one of the operations, so that the examples for these messages are not visible. This PR is proposing to add a new configuration, which will show examples for the messages listed in the "Messages" section.

Related issue(s)

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@tsauerwein tsauerwein changed the title Add configuration to always show message examples feat: Add configuration to always show message examples Jun 17, 2024
@derberg derberg changed the title feat: Add configuration to always show message examples feat: add configuration to always show message examples Jun 20, 2024
@derberg
Copy link
Member

derberg commented Jun 20, 2024

@tsauerwein hey, thanks for PR. Can you clarify one thing? so normally examples are always visible, except of this single case with operation? also you mean they are collapsed by default, or not visible at all?

with your change, did you try to build this project locally and check in local playground if intended change took place?

@tsauerwein
Copy link
Contributor Author

@derberg Thanks for taking the time to reply! Currently, the examples for messages are only shown when the messages are displayed for an operation. If you have a message that is not used in one of the operations, the message is listed in the "Messages" block, but the example for the message is not visible.

Eg. it looks like this:
Screenshot 2024-06-20 at 14 24 52

With this new configuration, the example for the message would be visible:

Screenshot 2024-06-20 at 14 20 50

This screenshot was taken from the playground running locally. Also, we have built the library, and are using library/browser/standalone/without-parser.js for our documentation.

I hope this makes it a bit clearer. If not, let me know. :)

@derberg
Copy link
Member

derberg commented Jun 20, 2024

@tsauerwein ah that's what you mean. Sorry, I misunderstood the initial message.

We need I think a better name for messageExamplesAlways and additional description in docs. Hard to pick a better one, but current one can be confusing as might refer to examples in general. How about we call it just messageExamples only and in docs you provide a detailed comment what that is?

@derberg
Copy link
Member

derberg commented Jun 20, 2024

side comment, what is the use case for having one message visible in docs, that is not associated with any channel and operation

also, can you share how did you make library/browser/standalone/without-parser.js work for you, with maybe example as some users struggle with that a bit -> #956

@tsauerwein
Copy link
Contributor Author

@tsauerwein ah that's what you mean. Sorry, I misunderstood the initial message.

We need I think a better name for messageExamplesAlways and additional description in docs. Hard to pick a better one, but current one can be confusing as might refer to examples in general. How about we call it just messageExamples only and in docs you provide a detailed comment what that is?

Sure, I renamed it to messageExamples and added the following to the docs:

The examples for messages shown within an operation are always displayed. To also show examples for the
standalone messages in the "Messages" section, set messageExamples to true.

Let me know if that is clear enough.

side comment, what is the use case for having one message visible in docs, that is not associated with any channel and operation

We might be abusing AsyncAPI CLI a bit here. But we have a MQTT topic configuration/{configuration} which is published for each configuration. And we want to document the schema for each configuration. We could also list each configuration message in the operation. But then we don't have a nice table-of-content in the sidebar, where you could directly jump to the messages/configuration.

@tsauerwein
Copy link
Contributor Author

also, can you share how did you make library/browser/standalone/without-parser.js work for you, with maybe example as some users struggle with that a bit -> #956

We've built it with npm run build:standalone inside the library directory. (Node v18.20.3)

But npm run build in the project root fails with Module not found: Error: Can't resolve 'react' in ... like in this Action: https://github.com/asyncapi/asyncapi-react/actions/runs/9496432356/job/26170818977

@@ -45,7 +46,10 @@ interface ConfigInterface {
- **show?: Partial<ShowConfig>**

This field contains configuration responsible for rendering specific parts of the AsyncAPI component.
All except the `sidebar` fields are set to `true` by default.
All except the `sidebar` and `messageExamples` fields are set to `true` by default.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you meant false

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the default for sidebar and messageExamples is false. Note the "All except...".

But we could also change it to the following to make it clearer:

The sidebar and messageExamples fields are set to false by default. The default for all other fields is true.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, that sounds better, thanks 🙏🏼

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

@derberg
Copy link
Member

derberg commented Jun 24, 2024

We might be abusing AsyncAPI CLI a bit here. But we have a MQTT topic configuration/{configuration} which is published for each configuration. And we want to document the schema for each configuration. We could also list each configuration message in the operation. But then we don't have a nice table-of-content in the sidebar, where you could directly jump to the messages/configuration.

can you please clarify. So because you want to see a message in side bar navigation, you decided to provide message definition only in components, instead under the channel payload?

@derberg
Copy link
Member

derberg commented Jun 24, 2024

@tsauerwein please also look into linter errors

btw, thanks for reporting web component release is failing -> #1019

@tsauerwein
Copy link
Contributor Author

can you please clarify. So because you want to see a message in side bar navigation, you decided to provide message definition only in components, instead under the channel payload?

Basically, yes. We are using it to document schemas for configurations. So, it means there is one channel/operation and many messages (100+). If we would add each configuration message to the the operation, the message schema would be shown twice, within the operation and then again in the "Messages" sections. Also, the message links in the sidebar take you to the messages in the "Messages" section, where you don't have the example (without the proposed change). And the table-of-content for the messages is quite useful considering the big number of configurations.

To give you an idea, this is what the document structure looks like: configurations.yml.txt

I would totally understand, if you say that we are using AsyncAPI not in the intended way. But we are using AsyncAPI to document our MQTT topics and like the tooling and the rendered documentation. That's why we also wanted to use AsyncAPI to document the configuration schemas for a single operation.

Copy link

sonarcloud bot commented Jun 25, 2024

@derberg
Copy link
Member

derberg commented Jun 25, 2024

release fixed: https://github.com/asyncapi/asyncapi-react/actions/runs/9661367651

yeah the problem with how you use it is that messages are not linked with channel and channel specifies only one message, without defining a payload, which means any payload is accepted. It might work for you short term, but what if you'd like to use other AsyncAPI tools - these won't understand the workaround.

proper way would be:

channels:
  configuration:
    address: configuration/{configuration}
    messages:
      configuration_A:
        $ref: '#/components/messages/CONFIG_A'
      configuration_B:
        $ref: '#/components/messages/CONFIG_B'

If we would add each configuration message to the the operation, the message schema would be shown twice, within the operation and then again in the "Messages" sections. Also, the message links in the sidebar take you to the messages in the "Messages" section

I recommend long term focus on using AsyncAPI correct way and just contribute to this component solution that will make side bar messages navigation work in the way, that if Messages section is disabled, messages in navigation point to messages in operations. Although, because same message can be part of many different operations, probably better would be to add support for a different navigation, dedicated message navigation-list as sub-nav under each operation.

Anyway, just sharing an opinion. Not bothering you anymore and playing a smart ass 😄

@tsauerwein
Copy link
Contributor Author

@derberg Thanks for fixing the release! And thanks for the feedback, you are absolutely right.

The "Test NodeJS PR - ubuntu-latest" job has failed. Could it be that package.json and package-lock.json are out-of-sync on master?
https://github.com/asyncapi/asyncapi-react/actions/runs/9661830217/job/26650463755?pr=1016

@derberg
Copy link
Member

derberg commented Jun 25, 2024

Working on it. For some reason bump of react component in web component did not work as expected.

@derberg
Copy link
Member

derberg commented Jul 2, 2024

fix is up #1026

@tsauerwein
Copy link
Contributor Author

fix is up #1026

Thanks! I will rebase as soon as the fix is merged.

Copy link

sonarcloud bot commented Jul 3, 2024

Copy link

sonarcloud bot commented Jul 3, 2024

@derberg
Copy link
Member

derberg commented Jul 3, 2024

/rtm

@asyncapi-bot asyncapi-bot merged commit 282829f into asyncapi:master Jul 3, 2024
10 checks passed
@derberg derberg mentioned this pull request Jul 3, 2024
@asyncapi-bot
Copy link
Contributor

🎉 This PR is included in version 2.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@tsauerwein tsauerwein deleted the show-examples-for-messages branch July 4, 2024 05:57
@tsauerwein
Copy link
Contributor Author

Thanks for the review and making the release, @derberg! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants