Skip to content

Endpoints with AuthType.Bearer gets a ghost 404 error status in OpenAPI #4041

@DoNotWorr

Description

@DoNotWorr

Describe the bug

Using AuthType.Bearer adds a ghost 404 to the generated OpenAPI spec.

To Reproduce

import zio.http.*
import zio.http.endpoint.*
import zio.http.endpoint.openapi.OpenAPIGen

val withBearer = Endpoint(Method.GET / "example").auth(AuthType.Bearer).out[String]
val noAuth   = Endpoint(Method.GET / "example").out[String]

// Includes 404 response
println(OpenAPIGen.gen(withBearer).toJsonPretty)

// No 404 response
println(OpenAPIGen.gen(noAuth).toJsonPretty)

Expected behaviour

Not sure, but I assume conform to outErrors.

Screenshots

println:

{
  "openapi" : "3.1.0",
  "info" : {
    "title" : "",
    "version" : ""
  },
  "paths" : {
    "/example" : {
      "get" : {
        "responses" : {
          "404" : {
            "description" : "Not Found\n\n"
          },
          "200" : {
            "content" : {
              "application/json" : {
                "schema" : {
                  "type" : "string"
                }
              }
            }
          }
        },
        "security" : [
          {
            "Bearer" : []
          }
        ]
      }
    }
  },
  "components" : {
    "securitySchemes" : {
      "Bearer" : {
        "type" : "http",
        "scheme" : "Bearer"
      }
    }
  },
  "security" : [
    {
      "Bearer" : []
    }
  ]
}

{
  "openapi" : "3.1.0",
  "info" : {
    "title" : "",
    "version" : ""
  },
  "paths" : {
    "/example" : {
      "get" : {
        "responses" : {
          "200" : {
            "content" : {
              "application/json" : {
                "schema" : {
                  "type" : "string"
                }
              }
            }
          }
        }
      }
    }
  },
  "components" : {
  }
}

Additional context

  1. The alternative Bearer.withUnauthorizedStatus erases the type in Endpoint to AuthType instead of AuthType.Bearer.type. Not really related to the bug.
  2. Looks like unauthorizedStatus defaults to Status.NotFound.
sealed trait AuthType { self =>
  type ClientRequirement
  def codec: HttpCodec[HttpCodecType.RequestType, ClientRequirement]

  def unauthorizedStatus: Status                       = Status.NotFound
  def withUnauthorizedStatus(status: Status): AuthType =
    AuthType
      .WithStatus(self.asInstanceOf[AuthType { type ClientRequirement = self.ClientRequirement }], status)
      .asInstanceOf[AuthType { type ClientRequirement = self.ClientRequirement }]

https://github.com/zio/zio-http/blob/main/zio-http/shared/src/main/scala/zio/http/endpoint/AuthType.scala

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions