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

docs: add URL variables in AsyncAPI Document #1890

Closed
Closed
Show file tree
Hide file tree
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 Jul 3, 2023
fd59b5d
Peer feedback
kakabisht Jul 11, 2023
615a2f5
Introduce the image
kakabisht Jul 22, 2023
11dc90e
fix mermaid color
kakabisht Jul 31, 2023
43d954f
Fix Yaml code
kakabisht Aug 29, 2023
38d294a
Update pages/docs/concepts/asyncapi-document/variable-url.md
kakabisht Sep 4, 2023
ba3de47
Update pages/docs/concepts/asyncapi-document/variable-url.md
kakabisht Sep 4, 2023
81162b2
Update pages/docs/concepts/asyncapi-document/variable-url.md
kakabisht Sep 4, 2023
d397f87
Update pages/docs/concepts/asyncapi-document/variable-url.md
kakabisht Sep 4, 2023
5af9c19
Update pages/docs/concepts/asyncapi-document/variable-url.md
kakabisht Sep 4, 2023
f646c7c
Update pages/docs/concepts/asyncapi-document/_section.md
kakabisht Sep 4, 2023
428057b
Update pages/docs/concepts/asyncapi-document/variable-url.md
kakabisht Sep 4, 2023
a23505c
Update pages/docs/concepts/asyncapi-document/variable-url.md
kakabisht Sep 5, 2023
6ebaea5
Update pages/docs/concepts/asyncapi-document/variable-url.md
kakabisht Sep 5, 2023
a28c072
SME feedback
kakabisht Sep 14, 2023
c7ecca7
fix link
kakabisht Sep 14, 2023
157e45f
Partial SME feedback
kakabisht Oct 10, 2023
c62d99a
fix image
kakabisht Nov 16, 2023
e3a487a
fix a typo
kakabisht Nov 16, 2023
8ab024f
Update pages/docs/concepts/asyncapi document/variable-url.md
kakabisht Nov 27, 2023
58280e4
Update pages/docs/concepts/asyncapi document/variable-url.md
kakabisht Nov 27, 2023
94e814a
Update pages/docs/concepts/asyncapi document/variable-url.md
kakabisht Nov 27, 2023
3064f17
Update pages/docs/concepts/asyncapi document/variable-url.md
kakabisht Nov 27, 2023
462850a
Update pages/docs/concepts/asyncapi document/variable-url.md
kakabisht Nov 27, 2023
fa4b6cc
Update pages/docs/concepts/asyncapi document/variable-url.md
kakabisht Nov 27, 2023
35330ea
Update pages/docs/concepts/asyncapi document/variable-url.md
kakabisht Nov 27, 2023
8f23fe2
SME feedback except image
kakabisht Dec 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pages/docs/concepts/asyncapi document/_section.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: AsyncAPI document
weight: 50
---
105 changes: 105 additions & 0 deletions pages/docs/concepts/asyncapi document/variable-url.md
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
```
Comment on lines +14 to +29
Copy link
Member

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.


### 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'
```