Skip to content

Commit

Permalink
APIGOV-DG000 - fix NPE on spec.components (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgghinea authored Jul 5, 2024
1 parent 19a9540 commit c7f7f39
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
toolchain go1.21.3

require (
github.com/Axway/agent-sdk v1.1.89
github.com/Axway/agent-sdk v1.1.90-0.20240703131051-2f7d0eeca272
github.com/elastic/beats/v7 v7.17.20
github.com/getkin/kin-openapi v0.125.0
github.com/google/uuid v1.6.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/Axway/agent-sdk v1.1.89 h1:YEtScppqRLbX730g1RAzwgoMP45dnJCOdPluphQYk3Q=
github.com/Axway/agent-sdk v1.1.89/go.mod h1:LvcLFYbRJnI1iWXpkK01mSdMMwoIKd49M5Aik07gZhM=
github.com/Axway/agent-sdk v1.1.90-0.20240703131051-2f7d0eeca272 h1:x/cKr0Lc5PflLlWlgTdQBh/N/0mssv61Vf/D5BYNs+Q=
github.com/Axway/agent-sdk v1.1.90-0.20240703131051-2f7d0eeca272/go.mod h1:LvcLFYbRJnI1iWXpkK01mSdMMwoIKd49M5Aik07gZhM=
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8=
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
github.com/Azure/go-autorest v12.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
Expand Down
7 changes: 5 additions & 2 deletions pkg/discovery/servicehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ func setOAS2policies(swagger *openapi2.T, configuration map[string]interface{})
}
swagger.SecurityDefinitions[common.BasicAuthName] = &ss
swagger.Security = append(swagger.Security, map[string][]string{
common.BasicAuthName: []string{},
common.BasicAuthName: {},
})

case apic.Oauth:
Expand All @@ -371,7 +371,7 @@ func setOAS2policies(swagger *openapi2.T, configuration map[string]interface{})
})
} else {
swagger.Security = append(swagger.Security, map[string][]string{
common.Oauth2Name: []string{},
common.Oauth2Name: {},
})
}

Expand All @@ -390,6 +390,9 @@ func setOAS2policies(swagger *openapi2.T, configuration map[string]interface{})
}

func setOAS3policies(spec *openapi3.T, configuration map[string]interface{}) ([]byte, error) {
if spec.Components == nil {
spec.Components = &openapi3.Components{}
}
// remove existing security
spec.Components.SecuritySchemes = make(openapi3.SecuritySchemes)
spec.Security = *openapi3.NewSecurityRequirements()
Expand Down
6 changes: 3 additions & 3 deletions pkg/discovery/servicehandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func TestSetPolicies(t *testing.T) {
Info: &openapi3.Info{
Title: "petstore3",
},
Paths: openapi3.Paths{},
Paths: &openapi3.Paths{},
Servers: openapi3.Servers{{URL: "http://google.com"}},
},
expectedContent: map[string]interface{}{
Expand Down Expand Up @@ -479,7 +479,7 @@ func TestSetPolicies(t *testing.T) {
Info: &openapi3.Info{
Title: "petstore3",
},
Paths: openapi3.Paths{},
Paths: &openapi3.Paths{},
Servers: openapi3.Servers{{URL: "http://google.com"}},
},
expectedContent: map[string]interface{}{
Expand Down Expand Up @@ -528,7 +528,7 @@ func TestSetPolicies(t *testing.T) {
Info: &openapi3.Info{
Title: "petstore3",
},
Paths: openapi3.Paths{},
Paths: &openapi3.Paths{},
Servers: openapi3.Servers{{URL: "http://google.com"}},
},
expectedContent: map[string]interface{}{
Expand Down

0 comments on commit c7f7f39

Please sign in to comment.