haskell-servant / haskell-servant/servant

swagger-codegen issues

Open
#1,084 8 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
2k
Forks
427
Avg merge
2d 23h
Merged PRs (30d)
5

Description

I'm trying to build a servant client to query an API for which I have a swagger file. I used the swagger-codegen tool to generate a servant API library.

TL;DR

- the generated lib fails to compile using the included stack.yaml and cabal new-build for at least 2 reasons: a data mapping issue around dates and then issues around `coerce` and representations.
- for more recent versions of servant, `Servant.Common.BaseUrl` does not exist so `BaseUrl(..)` should be imported from elsewhere, e.g., Servant.Client.
- perhaps an issue with swagger-codegen producing only some models or apis. I'm not expert enough in swagger to know if this is the swagger file (I suspect it is) or the codegen module.
- compile times for the resulting Types.hs are quite long.

Details:

I downloaded the swagger-codegen tool, built it, and ran
```
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i http://api.open.fec.gov/swagger -l haskell -o OpenFEC-servant
```
then I entered the OpenFEC-servant directory (checked into github on master branch of https://github.com/adamConnerSax/swagger-codegen-servant) and ran `stack build` whic resulted in many errors, all of the form:
```
/Users/adam/DataScience/swagger-codegen/OpenFEC-servant/lib/OpenFEC/Types.hs:221:54: error:
Not in scope: type constructor or class ‘Date’
```
Doing cabal new-build with ghc-8.4 (and thus much newer versions of all the libs since the cabal file doesn't have version bounds) yields the same error.

I can "fix" that by:

1. Adding "time" to the build depends of the cabal file
2. Adding `import Data.Time.Calendar (Day)` to `lib/OpenFEC/Types.hs`
3. Adding `data Date = Day` to `lib/OpenFEC/Types.hs`
4. Adding an export of `Date` to `lib/OpenFEC/Types.hs` (for API.hs to import)

(checked into same repo, on "FixDate" branch)

I've no idea if this is a correct mapping because though this allows this file to compile, there are more errors. See below.
Also, the compilation of Types.hs, which is 4270 lines long, takes a long time on both the ghc which goes with the stack build, 8.0.2 I think, [7 min] and ghc-8.4.3 [33 min] (Mac OSX 10.14.1, 3.5 GHz, 6-core Xeon E5 with 32GB of RAM).
I'm assuming that compile time scales with size of the Types.hs file, so I tried to have the swagger-codegen produce a smaller output by restricting the models or apis produced (using the -Dmodels=XXX or -Dapis=XXX) but I couldn't get that to work. I can only produce all or nothing. I don't know if that's due to the swagger input file or the haskell-servant codegen module.

So, using the provided stack.yaml and `stack build`, I get to the next set of errors, included in the repo in "stack_build_output.txt"

I get similar issues (I think) using cabal new-build. One more small thing needs fixing, the import of BaseUrl. Once that's fixed in `API.hs` the build errors out with representation issues as well. Though they are not exactly the same in location or error message. This version is in the same repo, on the "FixBaseUrl" branch. The errors are in the "cabal_new_build_output.txt"

I'm not sure where to start with figuring any of this out, but I'd be happy to help if there's work that needs doing.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.