-
-
Notifications
You must be signed in to change notification settings - Fork 743
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
docs: add URL variables in AsyncAPI Document #1890
Closed
Closed
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
c8e718d
Initial draft for variable urls
kakabisht fd59b5d
Peer feedback
kakabisht 615a2f5
Introduce the image
kakabisht 11dc90e
fix mermaid color
kakabisht 43d954f
Fix Yaml code
kakabisht 38d294a
Update pages/docs/concepts/asyncapi-document/variable-url.md
kakabisht ba3de47
Update pages/docs/concepts/asyncapi-document/variable-url.md
kakabisht 81162b2
Update pages/docs/concepts/asyncapi-document/variable-url.md
kakabisht d397f87
Update pages/docs/concepts/asyncapi-document/variable-url.md
kakabisht 5af9c19
Update pages/docs/concepts/asyncapi-document/variable-url.md
kakabisht f646c7c
Update pages/docs/concepts/asyncapi-document/_section.md
kakabisht 428057b
Update pages/docs/concepts/asyncapi-document/variable-url.md
kakabisht a23505c
Update pages/docs/concepts/asyncapi-document/variable-url.md
kakabisht 6ebaea5
Update pages/docs/concepts/asyncapi-document/variable-url.md
kakabisht a28c072
SME feedback
kakabisht c7ecca7
fix link
kakabisht 157e45f
Partial SME feedback
kakabisht c62d99a
fix image
kakabisht e3a487a
fix a typo
kakabisht 8ab024f
Update pages/docs/concepts/asyncapi document/variable-url.md
kakabisht 58280e4
Update pages/docs/concepts/asyncapi document/variable-url.md
kakabisht 94e814a
Update pages/docs/concepts/asyncapi document/variable-url.md
kakabisht 3064f17
Update pages/docs/concepts/asyncapi document/variable-url.md
kakabisht 462850a
Update pages/docs/concepts/asyncapi document/variable-url.md
kakabisht fa4b6cc
Update pages/docs/concepts/asyncapi document/variable-url.md
kakabisht 35330ea
Update pages/docs/concepts/asyncapi document/variable-url.md
kakabisht 8f23fe2
SME feedback except image
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 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: AsyncAPI document | ||
weight: 50 | ||
--- |
This file contains 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,105 @@ | ||
--- | ||
title: Variable URL | ||
weight: 275 | ||
--- | ||
|
||
Servers benefit from a defined base URL and rules for URL variables. You can easily manage multiple endpoints, handling various server configurations and environments. | ||
|
||
URL variables are placeholders for values you can replace during runtime. AsyncAPI enables you to construct dynamic URLs while enhancing the flexibility and maintainability of your AsyncAPI documents. | ||
|
||
## Add dynamic variables | ||
|
||
Use the `server.url` and `server.variables` to add variables to a server URL. Leverage `components.serverVariables` to enable reusable variable definitions across multiple servers. | ||
|
||
The diagram below describes how to use variable urls in AsyncAPI. | ||
|
||
```mermaid | ||
graph TD | ||
|
||
A[AsyncAPI Server] | ||
B[Components] | ||
C[Server URL] | ||
|
||
style A fill:#47BCEE,stroke:#47BCEE; | ||
style B fill:#47BCEE,stroke:#47BCEE; | ||
style C fill:#47BCEE,stroke:#47BCEE; | ||
|
||
B -->|Defines serverVariables| C | ||
C -->|Reusable variables| A | ||
``` | ||
|
||
### Servers section | ||
|
||
Define the servers section in your AsyncAPI document, and include the base URLs for your API servers. Use placeholders enclosed in curly braces {} to represent the variables in the server URL. For example: | ||
|
||
```yaml | ||
servers: | ||
production: | ||
url: 'https://{subdomain}.example.com:{port}/v1' | ||
variables: | ||
subdomain: | ||
enum: | ||
- development | ||
- staging | ||
- production | ||
port: | ||
default: '8080' | ||
``` | ||
|
||
### `serverVariables` section | ||
|
||
Define the components.serverVariables section in your AsyncAPI document. For each variable used in the server URLs, provide a default value and an optional description. This helps you avoid repeating variable defination. For example, | ||
|
||
```yaml | ||
components: | ||
serverVariables: | ||
subdomain: | ||
enum: | ||
- development | ||
- staging | ||
- production | ||
default: development | ||
port: | ||
default: '8080' | ||
``` | ||
|
||
### Define domain and port variables | ||
kakabisht marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
You can use components.serverVariables to avoid repeating variable definations such as domains and ports. To change the values of these variables, update their default values in the components.serverVariables section. Both servers' URLs will reflect the changes. | ||
|
||
Here's the complete AsyncAPI document with the server URL variables: | ||
|
||
```yaml | ||
info: | ||
title: Example API | ||
version: '1.0.0' | ||
servers: | ||
production: | ||
host: '{subdomain}.example.com:{port}' | ||
pathname: /v1 | ||
protocol: amqp | ||
variables: | ||
subdomain: | ||
$ref: '#/components/serverVariables/subdomain' | ||
port: | ||
$ref: '#/components/serverVariables/port' | ||
development: | ||
host: '{subdomain}.example.com:{port}' | ||
pathname: /v1 | ||
protocol: amqp | ||
variables: | ||
subdomain: | ||
$ref: '#/components/serverVariables/subdomain' | ||
port: | ||
$ref: '#/components/serverVariables/port' | ||
components: | ||
serverVariables: | ||
subdomain: | ||
enum: | ||
- development | ||
- staging | ||
- production | ||
default: development | ||
port: | ||
default: '8080' | ||
``` |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I honestly don't think a diagram is helping here. I'd completely remove it.