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

fix(asyncapi/v3): fix servers #210

Merged
merged 1 commit into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 1 addition & 6 deletions pkg/asyncapi/v3/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Channel struct {
Title string `json:"title"`
Summary string `json:"summary"`
Description string `json:"description"`
Servers []*Server `json:"servers"`
Servers []*Server `json:"servers"` // Reference only
Parameters map[string]*Parameter `json:"parameters"`
Tags []*Tag `json:"tags"`
ExternalDocs *ExternalDocumentation `json:"externalDocs"`
Expand Down Expand Up @@ -58,11 +58,6 @@ func (ch *Channel) generateMetadata(parentName, name string) error {
}
}

// Generate servers metadata
for i, srv := range ch.Servers {
srv.generateMetadata(ch.Name, "", &i)
}

// Generate parameters metadata
for name, param := range ch.Parameters {
param.generateMetadata(ch.Name, name)
Expand Down
2 changes: 1 addition & 1 deletion pkg/asyncapi/v3/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (c *Components) setDependencies(spec Specification) error {
func (c *Components) generateMetadataFromMaps() error {
// Generate metadata for servers
for name, entity := range c.Servers {
entity.generateMetadata("", name, nil)
entity.generateMetadata("", name)
}

// Generate metadata for channels
Expand Down
4 changes: 2 additions & 2 deletions pkg/asyncapi/v3/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ type Server struct {
}

// generateMetadata generates metadata for the Server.
func (srv *Server) generateMetadata(parentName, name string, number *int) {
func (srv *Server) generateMetadata(parentName, name string) {
// Prevent modification if nil
if srv == nil {
return
}

// Set name
srv.Name = generateFullName(parentName, name, "Server", number)
srv.Name = generateFullName(parentName, name, "Server", nil)

// Generate variables metadata
for n, s := range srv.Variables {
Expand Down
6 changes: 3 additions & 3 deletions pkg/asyncapi/v3/specification.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Specification struct {
Version string `json:"asyncapi"`
ID string `json:"id"`
Info Info `json:"info"`
Servers []*Server `json:"servers"`
Servers map[string]*Server `json:"servers"`
DefaultContentType string `json:"defaultContentType"`
Channels map[string]*Channel `json:"channels"`
Operations map[string]*Operation `json:"operations"`
Expand Down Expand Up @@ -105,8 +105,8 @@ func (s *Specification) generateMetadata() error {
}

// Generate servers metadata
for i, srv := range s.Servers {
srv.generateMetadata("", "Server", &i)
for name, srv := range s.Servers {
srv.generateMetadata("", name)
}

// Generate metadata for channels
Expand Down
68 changes: 68 additions & 0 deletions test/v3/issues/209/asyncapi.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions test/v3/issues/209/asyncapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
asyncapi: 3.0.0
info:
title: Hello world application
version: '0.1.0'
servers:
local:
host: localhost:9092
protocol: kafka
protocolVersion: '3.5'
description: Local Kafka broker
test:
host: test.k8s.cluster.local:9092
protocol: kafka
protocolVersion: '3.5'
description: Test environment K8S Kafka cluster
5 changes: 5 additions & 0 deletions test/v3/issues/209/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:generate go run ../../../../cmd/asyncapi-codegen -g types -p issue209 -i ./asyncapi.yaml -o ./asyncapi.gen.go

package issue209

// This is just to test that the generation is correct