wI2L / fizz

:lemon: Gin wrapper with OpenAPI 3 spec generation
https://pkg.go.dev/github.com/wI2L/fizz
MIT License
214 stars 52 forks source link

Security should be an array instead of dictionary #74

Closed jonas0616 closed 2 years ago

jonas0616 commented 2 years ago

I'm using fizz@v0.18.1 and trying to generate openapi documentation by the following code:

app.Generator().API().Components.SecuritySchemes = map[string]*openapi.SecuritySchemeOrRef{
    "basic_auth": {
        SecurityScheme: &openapi.SecurityScheme{
            Type:   "http",
            Scheme: "basic",
        },
    },
}
app.Generator().SetSecurityRequirement(&openapi.SecurityRequirement{"basic_auth": []string{}})

However, swagger UI shows it does not apply security scheme to APIs. Look into the generated openapi.json, security is:

{
  "security": {
    "basic_auth": []
  }
}

After I change the security format from dictionary to array, it works as expected:

{
  "security": [
     {
        "basic_auth": []
      }
  ]
}