Skip to content

Commit

Permalink
Fix OpenAPI import issue
Browse files Browse the repository at this point in the history
  • Loading branch information
pubudu538 authored Apr 8, 2024
1 parent 7486324 commit 187903b
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions apim-apk-agent/pkg/managementserver/rest_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,21 +241,31 @@ func createAPIYaml(apiCPEvent *APICPEvent) (string, string) {
for _, scopeWrapper := range scopes {
scopesForOpenAPIComponents[scopeWrapper.Scope.Name] = ""
}
components := map[string]interface{}{
"securitySchemes": map[string]interface{}{
"default": map[string]interface{}{
"type": "oauth2",
"flows": map[string]interface{}{
"implicit": map[string]interface{}{
"authorizationUrl": "https://test.com",
"scopes": scopesForOpenAPIComponents,
"x-scopes-bindings": scopesForOpenAPIComponents,
},
},
},
},
}

components, ok := openAPI["components"].(map[interface{}]interface{})
if !ok {
components = make(map[interface{}]interface{})
}
securitySchemes, ok := components["securitySchemes"].(map[interface{}]interface{})
if !ok {
securitySchemes = make(map[interface{}]interface{})
}

securitySchemes["default"] = map[interface{}]interface{}{
"type": "oauth2",
"flows": map[interface{}]interface{}{
"implicit": map[interface{}]interface{}{
"authorizationUrl": "https://test.com",
"scopes": scopesForOpenAPIComponents,
"x-scopes-bindings": scopesForOpenAPIComponents,
},
},
}

// Update the components in the OpenAPI spec
components["securitySchemes"] = securitySchemes
openAPI["components"] = components

yamlBytes, err := yaml.Marshal(&openAPI)
if err != nil {
logger.LoggerMgtServer.Errorf("Error while converting openAPI struct to yaml content. openAPI struct: %+v", openAPI)
Expand Down

0 comments on commit 187903b

Please sign in to comment.