swaggest / rest

Web services with OpenAPI and JSON Schema done quick in Go
https://pkg.go.dev/github.com/swaggest/rest
MIT License
362 stars 17 forks source link

Missing security operation #96

Closed chriskolenko closed 1 year ago

chriskolenko commented 1 year ago

I'm trying to add a security operation to a subset of routes. However, the security op isn't set on the paths.

    s.Route("/github", func(r chi.Router) {
        r.Group(func(r chi.Router) {
            r.Use(sessionMiddleware, nethttp.SecurityMiddleware(s.OpenAPICollector, "User", openapi3.SecurityScheme{
                APIKeySecurityScheme: &openapi3.APIKeySecurityScheme{
                    In:   "cookie",
                    Name: appcfg.CookieName,
                },
            }))
            r.Method(http.MethodGet, "/connect", nethttp.NewHandler(controllers.Connect(appcfg.GitHubAppSlug), nethttp.SuccessStatus(http.StatusTemporaryRedirect)))
            r.Method(http.MethodGet, "/install", nethttp.NewHandler(controllers.Install(orgManager, clientCreator), nethttp.SuccessfulResponseContentType("text/html")))
        })
    })

Output of json (no security :()

    "/github/connect": {
      "get": {
        "summary": "Connect",
        "description": "Connect to GitHub",
        "operationId": "function/controllers.Connect",
        "responses": {
          "307": {
            "description": "Temporary Redirect",
            "headers": {
              "Location": {
                "style": "simple",
                "description": "Redirect to GitHub",
                "schema": {
                  "type": "string",
                  "description": "Redirect to GitHub"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RestErrResponse"
                }
              }
            }
          }
        }
      }
    },
vearutop commented 1 year ago

Please try v0.2.34.

chriskolenko commented 1 year ago

Working perfectly thanks.