go-fuego / fuego

Golang Fuego - web framework generating OpenAPI 3 spec from source code
https://go-fuego.github.io/fuego/
MIT License
912 stars 45 forks source link

add security scheme to endpoint /group/ middleware #221

Open simonemastella opened 1 week ago

simonemastella commented 1 week ago

I have encountered some issues adding the securityScheme to an api

After the line fuego.Use(restricted, util.MiddlewareJWT), I would like to add support for configuring OpenAPI security schemas, so that I can easily document the authentication requirements for the /ping endpoint. Specifically, I'd like to be able to do something like this if is not possible directly inside the middleware:

goCopyrestricted := fuego.Group(s, "/")
fuego.Use(restricted, util.MiddlewareJWT)

// Add support for configuring OpenAPI security schemas
fuego.WithOpenAPISecuritySchemas(map[string]fuego.SecuritySchemaInfo{
    "jwt": {
        Type:        "http",
        Scheme:      "bearer",
        BearerFormat: "JWT",
        Description: "JWT Authorization header using the Bearer scheme.",
    },
})

fuego.Get(restricted, "/ping", c.Ping, fuego.WithOpenAPISecurity("jwt"))

This would allow me to clearly define the security requirements for the /ping endpoint in the OpenAPI documentation, making it easier for API consumers to understand how to authenticate and use the endpoint.

EwenQuim commented 1 week ago

Good idea.

I did not work on Security for a lomg time but this is a good idea, we'll try to do something about it.