Skip to content
Open
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
14 changes: 10 additions & 4 deletions pkg/asyncapi/v3/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Server struct {
Title string `json:"title"`
Summary string `json:"summary"`
Variables map[string]*ServerVariable `json:"variables"`
Security *SecurityScheme `json:"security"`
Security []*SecurityScheme `json:"security"`
Tags []*Tag `json:"tags"`
ExternalDocs *ExternalDocumentation `json:"externalDocs"`
Bindings *ServerBindings `json:"bindings"`
Expand Down Expand Up @@ -42,7 +42,9 @@ func (srv *Server) generateMetadata(parentName, name string) {
}

// Generate security metadata
srv.Security.generateMetadata(srv.Name, "", nil)
for i, sec := range srv.Security {
sec.generateMetadata(srv.Name, "", &i)
}

// Generate tags metadata
for i, t := range srv.Tags {
Expand All @@ -57,6 +59,8 @@ func (srv *Server) generateMetadata(parentName, name string) {
}

// setDependencies sets dependencies between the different elements of the Server.
//
//nolint:cyclop
func (srv *Server) setDependencies(spec Specification) error {
// Prevent modification if nil
if srv == nil {
Expand All @@ -76,8 +80,10 @@ func (srv *Server) setDependencies(spec Specification) error {
}

// Set security dependencies
if err := srv.Security.setDependencies(spec); err != nil {
return err
for _, sec := range srv.Security {
if err := sec.setDependencies(spec); err != nil {
return err
}
}

// Set tags dependencies
Expand Down
135 changes: 135 additions & 0 deletions test/v3/issues/294/asyncapi.gen.go

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

53 changes: 53 additions & 0 deletions test/v3/issues/294/asyncapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
asyncapi: 3.0.0
info:
title: Server Security Array Test
version: 1.0.0
description: Test for parsing server security as array (issue #294)

servers:
production:
host: mqtt.example.com
protocol: mqtt
description: Production MQTT broker
security:
- $ref: '#/components/securitySchemes/apiKey'
- $ref: '#/components/securitySchemes/oauth2'

channels:
testChannel:
address: v3.issue294.test
messages:
testMessage:
$ref: '#/components/messages/TestMessage'

operations:
testOperation:
action: send
channel:
$ref: '#/channels/testChannel'
messages:
- $ref: '#/channels/testChannel/messages/testMessage'

components:
messages:
TestMessage:
payload:
type: object
properties:
message:
type: string

securitySchemes:
apiKey:
type: apiKey
in: user
description: API key authentication
oauth2:
type: oauth2
description: OAuth2 authentication
flows:
clientCredentials:
tokenUrl: https://example.com/oauth/token
availableScopes:
read: Read access
write: Write access
29 changes: 29 additions & 0 deletions test/v3/issues/294/suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//go:generate go run ../../../../cmd/asyncapi-codegen -p issue294 -g types -i ./asyncapi.yaml -o ./asyncapi.gen.go

package issue294

import (
"testing"

"github.com/stretchr/testify/suite"
)

func TestSuite(t *testing.T) {
suite.Run(t, NewSuite())
}

type Suite struct {
suite.Suite
}

func NewSuite() *Suite {
return &Suite{}
}

func (suite *Suite) TestServerSecurityArrayParsing() {
// This test verifies that the AsyncAPI specification with server security
// defined as an array can be parsed without errors.
// The actual test is whether the code generation succeeds (via go:generate).
// If we reach this point, the parsing was successful.
suite.T().Log("Server security array parsing successful")
}