Skip to content

fix: render server host without scheme for AsyncAPI v3#659

Open
sahillllllllll-bit wants to merge 3 commits intoasyncapi:masterfrom
sahillllllllll-bit:fix-v3-server-host-rendering
Open

fix: render server host without scheme for AsyncAPI v3#659
sahillllllllll-bit wants to merge 3 commits intoasyncapi:masterfrom
sahillllllllll-bit:fix-v3-server-host-rendering

Conversation

@sahillllllllll-bit
Copy link

Description
This PR fixes incorrect server rendering in AsyncAPI v3 specifications where the server was displayed using the old v2-style URL with scheme prefix (kafka://.../) instead of the correct v3 host field.

Changes made:

  • Replaced server.url() with server.host() + server.pathname() in the ServerInfo component
  • Removed scheme/protocol prefix (e.g. kafka://) and trailing slash when pathname is empty
  • Keeps protocol as a separate field (unchanged)

Before (old output):

URL: kafka://kafka.example.com:9092/
Protocol: kafka

After (new output):

Host: kafka.example.com:9092
Protocol: kafka

Related issue(s)
Fixes #658

Testing

  • Tested locally with the provided minimal v3 YAML using:
asyncapi: '3.0.0'
id: 'urn:example:com:demo:app'
info:
  title: Demo Event-Driven API
  version: '1.0.0'
  description: Simple example to test generator bugs

servers:
  production:
    host: kafka.example.com:9092
    protocol: kafka
    description: Production Kafka broker

channels:
  userSignedUp:                         
    address: user/signedup              
    messages:
      UserSignedUp:                       
        $ref: '#/components/messages/UserSignedUp'

operations:
  sendUserSignedUp:
    action: send
    channel:
      $ref: '#/channels/userSignedUp'     
    messages:
      - $ref: '#/channels/userSignedUp/messages/UserSignedUp'  

components:
  messages:
    UserSignedUp:
      name: UserSignedUp
      title: User Signed Up Event
      summary: Event when a new user registers
      contentType: application/json
      payload:
        type: object
        properties:
          userId:
            type: string
            description: Unique user identifier
          email:
            type: string
            format: email
          name:
            type: string
          registeredAt:
            type: string
            format: date-time
        required:
          - userId
          - email
  • Generated markdown now shows correct Host field without scheme prefix.

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.

</Text>
);
}
ServerInfo.propTypes = {
Copy link
Member

Choose a reason for hiding this comment

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

what is that for?

Copy link
Author

@sahillllllllll-bit sahillllllllll-bit Jan 21, 2026

Choose a reason for hiding this comment

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

Reference in n

Hi @derberg,
Thanks for the quick review!
The ServerInfo.propTypes = { ... } part is PropTypes validation for the server prop passed to the ServerInfo component.
I added it because:

  • SonarQube (the project's Quality Gate) flagged code on the new lines where I used server.host() and server.pathname()
  • It complained: "'server.host' is missing in props validation" and same for pathname
  • Without PropTypes, the Maintainability Rating dropped below A on new code → Quality Gate failed

This minimal validation fixes those warnings so the PR passes SonarQube checks (now green after push).
If the project doesn't use/want PropTypes at all, we can remove it or suppress the rule — happy to adjust!
Let me know what you prefer.

Copy link
Member

Choose a reason for hiding this comment

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

but only host and protocl are required

https://www.asyncapi.com/docs/reference/specification/v3.0.0#serverObject

and if they are required on spec level, this means you can be 100% sure template will get this data, otherwise generator will not run and fail on validation - so no need to protect from it

the only issue can be pathname - but your code already handles that part, checks if provided

id remove that

Copy link
Author

Choose a reason for hiding this comment

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

Hi @derberg,

Thanks for the detailed explanation! Makes total sense — since host and protocol are required at spec level, no need for extra protection.

I removed the entire PropTypes block as you suggested.

PR updated now — only the host fix remains.

Thanks again,

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
D Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Incorrect server rendering in AsyncAPI v3: protocol prefix added (kafka://) instead of just host

2 participants