OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Haskell] Missing ToHttpApiData/FromHttpApiData for [Int]

Open
#8,238 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Nested query arrays only use QueryList for the outermost array:

type TestAPI
    =    "v1" :> "route" :> QueryParam "connections" (QueryList 'CommaSeparated ([Int])) :> Verb 'GET 200 '[JSON] () -- 'test' route
    :<|> Raw 

resulting in missing instances for [a]:

lib\Test\API.hs:170:11: error:
    * No instance for (ToHttpApiData [Int])
        arising from a use of `client'
    * In the expression: client (Proxy :: Proxy TestAPI)
      In a pattern binding:
        ((coerce -> test) :<|> _) = client (Proxy :: Proxy TestAPI)
      In an equation for `createTestClient':
          createTestClient
            = TestBackend {..}
            where
                ((coerce -> test) :<|> _) = client (Proxy :: Proxy TestAPI)
    |
170 |      _) = client (Proxy :: Proxy TestAPI)
    |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

lib\Test\API.hs:214:57: error:
    * Could not deduce (FromHttpApiData [Int])
        arising from a use of `serve'
      from the context: (MonadIO m, MonadThrow m)
        bound by the type signature for:
                   runTestMiddlewareServer :: forall (m :: * -> *).
                                              (MonadIO m, MonadThrow m) =>
                                              Config
                                              -> Middleware
                                              -> TestBackend (ExceptT ServerError IO)
                                              -> m ()
        at lib\Test\API.hs:(206,1)-(208,73)
    * In the second argument of `($)', namely
        `serve (Proxy :: Proxy TestAPI) (serverFromBackend backend)'
      In the second argument of `($)', namely
        `middleware
           $ serve (Proxy :: Proxy TestAPI) (serverFromBackend backend)'
      In the second argument of `($)', namely
        `Warp.runSettings warpSettings
           $ middleware
               $ serve (Proxy :: Proxy TestAPI) (serverFromBackend backend)'
    |
214 |   liftIO $ Warp.runSettings warpSettings $ middleware $ serve (Proxy :: Proxy TestAPI) (serverFromBackend backend)
    |                                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Here is a minimal spec to reproduce the issue:

{
    "consumes": [
        "application/json"
    ],
    "host": "localhost",
    "info": {
        "description": "test",
        "title": "test",
        "version": "1.0.0"
    },
    "paths": {
        "/v1/route/": {
            "get": {
                "description": "test",
                "operationId": "test",
                "parameters": [{
                    "description": "connected",
                    "in": "query",
                    "items": {
                        "collectionFormat": "pipes",
                        "items": {
                            "format": "int32",
                            "type": "integer"
                        },
                        "maxItems": 2,
                        "minItems": 2,
                        "type": "array",
                        "uniqueItems": true
                    },
                    "maxItems": 100,
                    "name": "connections",
                    "type": "array",
                    "uniqueItems": true
                }],
                "responses": {
                    "200": {
                        "description": "test",
                        "examples": {
                            "application/json": [
                                1,
                                2,
                                3
                            ]
                        }
                    }
                },
                "summary": "test",
                "x-cached-seconds": 3600
            }
        }
    },
    "produces": [
        "application/json"
    ],
    "schemes": [
        "https"
    ],
    "swagger": "2.0"
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the TestAPI definition and the generated client/server uses in lib\Test\API.hs, focusing on the QueryParam "connections" declaration and its client and serve entry points. Reproduce the compilation errors with the nested [Int] query array; done means the generated Haskell code provides the required ToHttpApiData and FromHttpApiData instances and compiles.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.