swagger-api / swagger-api/swagger-codegen
[HASKELL] Build failure with "list" type after generation
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Haskell GHC compiler fails to build the generated haskell code due to diverging data type names when the swagger type is list:
/home/maerwald/tmp/petstore/petstore/lib/SwaggerPetstore/API.hs:12:16: warning:
-fcontext-stack=328 is deprecated: use -freduction-depth=328 instead
[1 of 2] Compiling SwaggerPetstore.Types ( lib/SwaggerPetstore/Types.hs, .stack-work/dist/x86_64-linux-tinfo6/Cabal-1.24.2.0/build/SwaggerPetstore/Types.o )
[2 of 2] Compiling SwaggerPetstore.API ( lib/SwaggerPetstore/API.hs, .stack-work/dist/x86_64-linux-tinfo6/Cabal-1.24.2.0/build/SwaggerPetstore/API.o )
/home/maerwald/tmp/petstore/petstore/lib/SwaggerPetstore/API.hs:67:43: error:
Not in scope: type constructor or class ‘List’
Perhaps you meant one of these:
‘List_’ (imported from SwaggerPetstore.Types),
‘HList’ (imported from Servant.API)
/home/maerwald/tmp/petstore/petstore/lib/SwaggerPetstore/API.hs:130:19: error:
Not in scope: type constructor or class ‘List’
Perhaps you meant one of these:
‘List_’ (imported from SwaggerPetstore.Types),
‘HList’ (imported from Servant.API)
Completed 74 action(s).
-- While building package swagger-petstore-0.1.0.0 using:
/home/maerwald/.stack/setup-exe-cache/x86_64-linux-tinfo6/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-linux-tinfo6/Cabal-1.24.2.0 build lib:swagger-petstore --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
The data type that is generated is:
-- |
data List_ = List_
{ list_Id :: Integer -- ^
, list_Name :: Text -- ^
, list_Tag :: Text -- ^
} deriving (Show, Eq, Generic)
But the API will use:
data SwaggerPetstoreBackend m = SwaggerPetstoreBackend
{ petsGet :: m [List]{- ^ Returns all pets from the system that the user has access to -}
}
The whole generated project can be viewed at https://github.com/hasufell/petstore-swagger-bug
Swagger-codegen version
2.4.0-SNAPSHOT built from git d9c4e014e6791072b1c71faa4a77098f9bdcc3a4
Swagger declaration file content or url
This is derived from the minimal swagger petstore definition. The pet type has been renamed to list:
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Swagger Petstore",
"description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification",
"termsOfService": "http://swagger.io/terms/",
"contact": {
"name": "Swagger API Team"
},
"license": {
"name": "MIT"
}
},
"host": "petstore.swagger.io",
"basePath": "/api",
"schemes": [
"http"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/pets": {
"get": {
"description": "Returns all pets from the system that the user has access to",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "A list of pets.",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/list"
}
}
}
}
}
}
},
"definitions": {
"list": {
"type": "object",
"required": [
"id",
"name"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},
"tag": {
"type": "string"
}
}
}
}
}
Command line used for generation
java -jar "modules/swagger-codegen-cli/target/swagger-codegen-cli.jar" generate -i petstore-minimal.json -l haskell -o petstore
Steps to reproduce
After generation, run:
stack build
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the supplied swagger-codegen CLI command and minimal Swagger definition, then inspect the generated lib/SwaggerPetstore/Types.hs and lib/SwaggerPetstore/API.hs files. Compare the generated type declaration with the API reference and run stack build; done means the generated Haskell project compiles without the missing List constructor error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100