-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
docs: add reusable parts #1928
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
Closed
kakabisht
wants to merge
20
commits into
asyncapi:next-major-spec
from
kakabisht:docs-reusable-parts
Closed
docs: add reusable parts #1928
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
2b7c0b3
Initial draft
kakabisht 46d2c4a
peer feedback
kakabisht 6dc0e74
fix formatting
kakabisht 1691192
Add images
kakabisht 8de896c
fix typo
kakabisht d0fda16
fix mermaid color
kakabisht 07d46c7
fix yaml code
kakabisht eadc09e
fix typo
kakabisht c47f63e
Update pages/docs/concepts/asyncapi-document/resuable-parts.md
kakabisht b2602e1
Update pages/docs/concepts/asyncapi-document/resuable-parts.md
kakabisht b38eb15
partial sme feedback
kakabisht 121c784
Merge branch 'docs-reusable-parts' of https://github.com/kakabisht/we…
kakabisht 1722498
fix weights
kakabisht 621c51b
fix minor issue
kakabisht 5434ebd
Update pages/docs/concepts/asyncapi-document/resuable-parts.md
kakabisht 00536b2
partial SME feedback
kakabisht aae224a
fix image
kakabisht 07722da
Update pages/docs/concepts/asyncapi document/resuable-parts.md
kakabisht 31c090c
Update pages/docs/concepts/asyncapi document/resuable-parts.md
kakabisht 89206f7
Fix async spec version
kakabisht File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --- | ||
| title: AsycnAPI Document | ||
| weight: 50 | ||
| --- |
100 changes: 100 additions & 0 deletions
100
pages/docs/concepts/asyncapi document/resuable-parts.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| --- | ||
| title: Reusable parts | ||
| weight: 280 | ||
| --- | ||
|
|
||
| Reusable parts in AsyncAPI provide flexibility, modularity, and code reusability. You can reuse specific document sections such as Messages or schema definitions. | ||
|
|
||
| Reusable parts allow you to split up the AsyncAPI document into many files and reference them using the Reference Object. You can use the $ref keyword to reference the same or another local file or external URL. The diagram below describes how to reuse parts in AsyncAPI. | ||
|
|
||
| ```mermaid | ||
| graph TD | ||
|
|
||
| A[Message] | ||
| B[Payload] | ||
| C[Reusable Part] | ||
|
|
||
| style A fill:#47BCEE,stroke:#47BCEE; | ||
| style B fill:#47BCEE,stroke:#47BCEE; | ||
| style C fill:#47BCEE,stroke:#47BCEE; | ||
|
|
||
| A -->|references| B | ||
| B -->|local file reference| C | ||
| B -->|same file reference| C | ||
| B -->|external URL reference| C | ||
|
|
||
| ``` | ||
|
|
||
| ## Same file | ||
|
|
||
| You can use the $ref keyword to reference a component within the same document. In the example below, you define a component called MyMessageSchema under the schemas section to describe the structure of a message. Under the publish operation of myChannel, you reference the MyMessageSchema component using the $ref keyword. | ||
|
|
||
| ```yaml | ||
| channels: | ||
| myChannel: | ||
| publish: | ||
| message: | ||
| payload: | ||
| $ref: '#/components/schemas/MyMessageSchema' | ||
| components: | ||
| schemas: | ||
| MyMessageSchema: | ||
| type: object | ||
| properties: | ||
| message: | ||
| type: string | ||
| ``` | ||
|
|
||
| ## Another local file | ||
|
|
||
| You can use the $ref keyword to reference another local document. Ensure the path to the local file is correct and accessible from your main AsyncAPI document. | ||
|
|
||
| In the code below, you reference the component from another local document, such as message-schema.yaml. | ||
|
|
||
| ```yaml | ||
| UserSignup: | ||
| name: UserSignup | ||
| title: User signup | ||
| summary: Action to sign a user up. | ||
| description: A longer description | ||
| contentType: application/json | ||
| payload: null | ||
| ``` | ||
|
|
||
| In the code below, you use another local document message-schema.yaml in another local document such as consume-schema.yaml. | ||
|
|
||
| ```yaml | ||
| channels: | ||
| user/signedup: | ||
| address: user/signedup | ||
| messages: | ||
| publish.message: | ||
| $ref: './message-schema.yaml#/UserSignup' | ||
| operations: | ||
| user/signedup.publish: | ||
| action: receive | ||
| channel: | ||
| $ref: '#/channels/user~1signedup' | ||
| messages: | ||
| - $ref: '#/channels/user~1signedup/messages/publish.message' | ||
| ``` | ||
|
|
||
| ## External URL | ||
|
|
||
| You can use the $ref keyword to reference an external URL. Ensure the external URL should provide the referenced component in a compatible format, such as YAML or JSON. In the example below, you reference the component from an external URL. The $ref value specifies the full URL to the external resource and the component's location. | ||
|
|
||
| ```yaml | ||
| channels: | ||
| user/signedup: | ||
| address: user/signedup | ||
| messages: | ||
| publish.message: | ||
| $ref: https://example.com/my-components.yaml#/schemas/MySchema | ||
| operations: | ||
| user/signedup.publish: | ||
| action: receive | ||
| channel: | ||
| $ref: '#/channels/user~1signedup' | ||
| messages: | ||
| - $ref: '#/channels/user~1signedup/messages/publish.message' | ||
| ``` | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.