Generating Servant client for OpenAPI 3 spec?

Hey everyone,

Servant is a type-level DSL for APIs. From a Servant API, it is straightforward to generate an OpenAPI specification. I’m trying to go in the other direction: I have a very large OpenAPI 3 spec, and I would like to query it.

So far, I have tried the openapi-generator, a project which can generate OpenAPI clients and servers for many languages, including Haskell (Servant-based and Yesod-based).

Unfortunately, it looks like the generator for haskell is rather outdated. Is there another tool that folks here use?

1 Like

I was looking for something like this as well. Is your OpenAPI spec public by chance?

When building such a generator, a number of things should be taken into account:

  • Servant APIs have a “primary” response (usually a success reponse) and alternative responses are usually served through ServerError. Should the generator should also create types for the secondary responses as well?
  • It would be nice if the generator used NamedRoutes, but where to get the names from? From the url? Perhaps the summary?
  • Should the generator create an entire library, or should it be some Template Haskell splice that could be inserted in module code?
1 Like

Here’s the spec, which is for the Enode API.

I don’t have strong opinions of what an API generator should do, simply that it works at all. If the current state of things is that there are no such API generators for Servant clients, then I will have to write the client by hand, for now at least.

Last time I tried to use openapi-generator (about a year ago) it did not generate correct code for sum types. I wrote some post code scripts to fix the code.

Then I tried an alternate generator Haskell-OpenAPI-Client-Code-Generator. As I recall, it generated correct code.

2 Likes