git.iko.soy/typeable/mock-server-client
on master help sign in

Client library for the mock-server

git clone https://git.iko.soy/typeable/mock-server-client.git

About

The package is the client library for the mock server. The source code is generated by the openapi3-code-generator, specifically its patched version.

Usage

module Main

import MockServer as Mock
import Network.HTTP.Client

conf :: Mock.Configuration
conf = Configuration
  { configBaseURL = "http://localhost"
  , configSecurityScheme = id
  , configIncludeUserAgent = False
  , configApplicationName = "ping-app" }

expectation :: Mock.Expectations
expectation = Mock.ExpectationsExpectation $ Mock.mkExpectation
  { expectationHttpRequest = Just request
  , expectationHttpResponse = Just response }
  where
    request = Mock.mkHttpRequest
      { httpRequestMethod = Just $ StringOrJsonSchemaText "POST"
      , httpRequestPath = Just $ StringOrJsonSchemaText "/ping" }
    response = Mock.mkHttpResponse
      { httpResponseBody = Just $ BodyWithContentTypeRawStringResponseBody "pong"
      , httpResponseStatusCode = Just 200 }

-- | Puts the expectation which will response with "pong" body to the "POST /ping" request
main :: IO ()
main = do
  void $ Mock.runWithConfiguration conf $ Mock.put_mockserver_expectation expectation

Maintainance

Files

The codegen dir

Other

What will happen if you just call the regen.sh?

It will build the openapi3-code-generator in nix and regenerate the whole Haskell source code. You will see that the code was changed, because as mentioned earlier the original code was slightly modified, so watch your commits.

How to update the package to the new version of the mock-server spec?

The algorithm is kind of weird, but for a reason.

The branch update-openapi-spec is the branch tracking only original codegen/mock-server-openapi.yaml changes, meaning changes made by authors of the mock-server. So, when you merge changes of this branch into the master you literally merge the changes made by authors of the mock-server with our manual changes made to please the openapi3-code-generator.

The bratch update-generated-code is for tracking "changes" made by the code generator when it is feed by the new OpenAPI spec file. So, when you merge this branch into the master you literally merge the "code regeneration patch" with changes made by hand.

The master branch is for manual changes only. The changes made to keep things working and the package usable. You can always see the manual changes just by git diff update-generated-code master or git diff update-openapi-spec master