Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing HasOpenApi instance ? #17

Open
teto opened this issue Dec 21, 2021 · 4 comments
Open

missing HasOpenApi instance ? #17

teto opened this issue Dec 21, 2021 · 4 comments

Comments

@teto
Copy link

teto commented Dec 21, 2021

when compiling my program I get a no instance error for:

instance (HasOpenApi (Headers '[Header  ResourceMetadata String] NoContent))

-- type ResourceMetadata = "jinko-resource-type"

Here are the versions:

(ins)➜ ghc-pkg list|grep openapi
    openapi3-3.1.0
    servant-openapi3-2.0.1.2

I've tried looking into the code but there seemed to be several abstractions and I gave up. Maybe with some guidance I could try again.

@maksbotan
Copy link
Collaborator

Hi @teto,

Are you sure you are using Headers correctly? It should be embedded in a Verb, like this:

type Api = Get '[] (Headers '[Header "jinko-resource-type" String] NoContent)

openApi = toOpenApi (Proxy :: Proxy Api)

For me this example generates the following openapi:

{
  "openapi": "3.0.0",
  "info": {
    "title": "",
    "version":""
  },
  "paths": {
    "/": {
      "get": {
        "responses": {
          "200": {
            "headers": {
              "jinko-resource-type": {"schema": {"type": "string"}}
            },
            "description":""
          }
        }
      }
    }
  },
  "components": {}
}

@timbess
Copy link

timbess commented Jan 16, 2023

@maksbotan I'm not the original poster, but I'm seeing this error for my auth endpoints:

type AuthAPI =
  "register" :> ReqBody '[JSON] RegisterBody :> UVerb 'POST '[JSON] '[WithStatus 200 AuthResp, WithStatus 422 String]
    :<|> "login"
      :> ReqBody '[JSON] LoginBody
      :> UVerb
           'POST
           '[JSON]
           '[ WithStatus
                200
                ( Headers
                    '[ Header "Set-Cookie" SetCookie,
                       Header "Set-Cookie" SetCookie
                     ]
                    AuthResp
                ),
              WithStatus 401 String
            ]

Seems like there may be a missing instance around the UVerb instances when using headers.

@maksbotan
Copy link
Collaborator

Can you show the precise error message generated with that code?

And why do you have "Set-Cookie" twice in Headers?

@timbess
Copy link

timbess commented Jan 21, 2023

app/Main.hs:107:18: error:
     No instance for (ToSchema
                         (Headers
                            '[Header "Set-Cookie" SetCookie, Header "Set-Cookie" SetCookie]
                            AuthResp))
        arising from a use of toOpenApi
     In the expression: toOpenApi authApi
      In an equation for authApiSwagger’:
          authApiSwagger = toOpenApi authApi
    |
107 | authApiSwagger = toOpenApi authApi

I assume it's because acceptLogin sets two cookies? Not sure was mostly following this example:
https://github.com/haskell-servant/servant/tree/master/servant-auth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants