asyncapi-react icon indicating copy to clipboard operation
asyncapi-react copied to clipboard

{braces} in ServerVariables not getting replaced

Open butilka123 opened this issue 5 months ago • 10 comments

Describe the bug

Following this article: https://www.asyncapi.com/docs/concepts/asyncapi-document/variable-url

The Variables in {braces} dont get replaced.

To Reproduce

Steps to reproduce the behavior:

  1. Create a yaml file. (See Sample Document)
  2. Generate the HTML:

asyncapi generate fromTemplate file.yaml @asyncapi/[email protected] -o example --use-new-generator

Expected behavior

A Document with replaced {braces}

Sample document

asyncapi: 3.0.0
info:
  title: Example API
  version: '1.0.0'
servers:
  production:
    host: '{subdomain}.example.com:{port}'
    pathname: '/{version}'
    protocol: amqp
    variables:
      subdomain:
        $ref: '#/components/serverVariables/subdomain'
      port:
        $ref: '#/components/serverVariables/port'
      version:
        $ref: '#/components/serverVariables/version'
  development:
    host: '{subdomain}.dev.example.com:{port}'
    pathname: /v1
    protocol: amqp
    variables:
      subdomain:
        $ref: '#/components/serverVariables/subdomain'
      port:
        $ref: '#/components/serverVariables/port'
      version:
        $ref: '#/components/serverVariables/version'
components:
  serverVariables:
    subdomain:
      enum:
        - development
        - staging
        - production
      default: development
    port:
      default: '8080'
    version:
      enum:
        - v1
        - v2

Screenshots

Image

butilka123 avatar Jul 28 '25 09:07 butilka123

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup 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.

github-actions[bot] avatar Jul 28 '25 09:07 github-actions[bot]

related to react-component - moving the issue there

@butilka123 it would make sense to explain here in the issue to maintainers of react-component, what would you see the braces are replaced with

derberg avatar Jul 28 '25 13:07 derberg

/ti asyncapi-react

derberg avatar Jul 28 '25 13:07 derberg

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup 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.

github-actions[bot] avatar Jul 28 '25 13:07 github-actions[bot]

related to react-component - moving the issue there

@butilka123 it would make sense to explain here in the issue to maintainers of react-component, what would you see the braces are replaced with

I am very new to AsyncAPI itself, but in my example I would expect that the braces get replaced with the corresponding variables.

Image

Thank you for moving the issue.

butilka123 avatar Jul 28 '25 14:07 butilka123

to fix this issue , what would be the correct approach to begin with ?

mitaliiiiii avatar Aug 02 '25 12:08 mitaliiiiii

I don't think it requires a fix. If we replace braces with default value then how reader of such generated docs knows where to put other allowed values, if there are no placeholder/braces

derberg avatar Aug 04 '25 08:08 derberg

I don't think it requires a fix. If we replace braces with default value then how reader of such generated docs knows where to put other allowed values, if there are no placeholder/braces

Image

The Idea is that you define 1x Variables and re-use it.

(I accedentally closed the issue)

butilka123 avatar Aug 04 '25 09:08 butilka123

yeah, cross verified it and it's a feature, not a bug. the braces are actually supposed to be shown in the URL display because they indicate the placeholder positions for the variables. The format {variable} is the standard AsyncAPI way to show where variables will be interpolated in the URL.

When the actual connection is made, these variables would be replaced with their actual values based on the serverVariables definitions in your components section. For example:

{subdomain} could become "development", "staging", or "production" {port} would become "8080" by default {version} would become either "v1" or "v2"

Paulie-Aditya avatar Sep 25 '25 00:09 Paulie-Aditya

I don't think it requires a fix. If we replace braces with default value then how reader of such generated docs knows where to put other allowed values, if there are no placeholder/braces

Image The Idea is that you define 1x Variables and re-use it.

(I accedentally closed the issue)

@butilka123 can you elaborate on what you mean by define 1x Variables and re-use it?

AceTheCreator avatar Nov 12 '25 05:11 AceTheCreator