Haskell-OpenAPI-Code-Generator / Haskell-OpenAPI-Client-Code-Generator

Generate Haskell client code from an OpenAPI 3 specification
46 stars 19 forks source link

Serving APIs #67

Closed alexbiehl closed 2 years ago

alexbiehl commented 2 years ago

Very impressive work! Thank you for investing your time.

Do you have any plans on supporting generating code for serving APIs?

Do you have any recommendation on how to serve an API defines through a schema right now?

alexbiehl commented 2 years ago

Nothing this down before I forget:

Since the generates has all the operation types nicely resolved and generated into Haskell it shouldn't be too hard to generate a serving component. E.g. for the Petstore example I could imagine something like

data Petstore m = Petstore
  {
    , listPets :: GHC.Maybe.Maybe GHC.Int.Int32 -- ^ limit: How many items to return at one time (max 100)
                    -> m ListPetsResponse
    , ... 
  }

together with a function to serve the API:

servePetstore 
  :: (forall a. m a -> IO a)
  -> Petstore m 
  -> Application
servePetstore = ... 

where the implementation of servePetstore dispatches to the functions in Petstore based on the request.

NorfairKing commented 2 years ago

@alexbiehl usually you build your app with servant, generate the openapi spec from that. This project is for calling apis that weren't built in Haskell.

alexbiehl commented 2 years ago

I see @NorfairKing! I was looking for solution in which the Haskell code wasn't the source of truth but rather the OpenAPI schema. Also, in my experience defining the API + Docs + Types in Haskell and Servant tends to be quite verbose and people come up with abstractions that make it even harder to understand.

Thanks for the quick response. I will see if I can find something else which fits my needs better.