Search code examples
haskellswaggerservant

Haskell servant: Swagger description for MultiPart upload


I am using servant-swagger to define a REST service and to generate a Swagger file from it. It uses an extended version of the File upload combinator to define a client for an endpoint to add a file. I'd like to add a Swagger description to the upload API. I would be happy if I could add a parameter like

{
  "in": "formData",
  "name": "file",
  "type": "file",
  "description": "File to upload"
}

to Swagger. Any idea how to do that? I was trying

instance HasSwagger api => HasSwagger (Files b :> api) where
  toSwagger _ = toSwagger (Proxy :: Proxy api)
    & allOperations.description .~ Just (Text.pack "Files description")

but that doesn't generate a description in the Swagger file (although it compiles).


Solution

  • Went with this:

    instance HasSwagger api =>
             HasSwagger (Files b :> api) where
      toSwagger _ = toSwagger (Proxy :: Proxy api)
        & addParam param
        where
          param = mempty
            & name .~ "file"
            & required ?~ True
            & description ?~ "File to upload"
            & schema .~ ParamOther (mempty
                & in_ .~ ParamFormData
                & paramSchema .~ (mempty & type_ .~ SwaggerFile))