git.iko.soy/typeable/mock-server-client
on d876333 help sign in
.github/workflows/haskell-ci.ymldeleted−25
since splitsnapshots
unifiedsplit
@@ -1,25 +0,0 @@
1−name: Haskell-CI
2−on: [push]
3−jobs:
4− linux:
5− name: GHC-${{ matrix.ghc-version }}
6− runs-on: ubuntu-latest
7− strategy:
8− matrix:
9− ghc-version:
10− - 9.0.2
11− - 9.2.5
12− steps:
13− - uses: actions/checkout@v3
14− - uses: haskell/actions/setup@v2
15− with:
16− enable-stack: true
17− ghc-version: ${{ matrix.ghc-version }}
18− stack-version: 'latest'
19− - uses: actions/cache@v3
20− with:
21− path: |
22− ~/.stack
23− ./.stack-work
24− key: ${{ matrix.ghc-version }}
25− - run: stack --stack-yaml ghc-${{ matrix.ghc-version }}.yaml --install-ghc test --fast --haddock
.gitignoredeleted−2
@@ -1,2 +0,0 @@
1−.stack-work
2−TAGS
README.md+33−77
@@ -1,96 +1,52 @@
1−# About
1+## About
2
2
3The package is the client library for the [mock server](https://www.mock-server.com/). The source code is
3The package is the client library for the [mock server](https://www.mock-server.com/). The source code is
4generated by the [openapi3-code-generator](https://hackage.haskell.org/package/openapi3-code-generator), specifically its patched version.
4generated by the [openapi3-code-generator](https://hackage.haskell.org/package/openapi3-code-generator), specifically its patched version.
5
5
6−## Usage
6+## How to regenerate
7
7
8−``` haskell
9−module Main
10−
11−import MockServer as Mock
12−import Network.HTTP.Client
13−
14−conf :: Mock.Configuration
15−conf = Configuration
16− { configBaseURL = "http://localhost"
17− , configSecurityScheme = id
18− , configIncludeUserAgent = False
19− , configApplicationName = "ping-app" }
20−
21−expectation :: Mock.Expectations
22−expectation = Mock.ExpectationsExpectation $ Mock.mkExpectation
23− { expectationHttpRequest = Just request
24− , expectationHttpResponse = Just response }
25− where
26− request = Mock.mkHttpRequest
27− { httpRequestMethod = Just $ StringOrJsonSchemaText "POST"
28− , httpRequestPath = Just $ StringOrJsonSchemaText "/ping" }
29− response = Mock.mkHttpResponse
30− { httpResponseBody = Just $ BodyWithContentTypeRawStringResponseBody "pong"
31− , httpResponseStatusCode = Just 200 }
32−
33−-- | Puts the expectation which will response with "pong" body to the "POST /ping" request
34−main :: IO ()
35−main = do
36− void $ Mock.runWithConfiguration conf $ Mock.put_mockserver_expectation expectation
37```
8```
9+cd codegen && ./regen.sh
10+```
11+
12+It requires the `nix` to be installed in your system because it uses the
13+`openapi3-code-generator` built by the `nix`.
38
14
39−# Maintainance
15+After regeneration you will see some `.hs` files changed. This is because some
16+parts of the libary are modified by hand to make the more usable.
40
17
41## Files
18## Files
42
19
43### The `codegen` dir
20### The `codegen` dir
44
21
45* `regen.sh` is the simple script to regenerate the whole package.
22* `regen.sh` is the simple script to regenerate the whole package.
46−* `shell.nix` a shell in which the `regen.sh` calls the `openapi3-code-generator` to regenerate the code
23+* `shell.nix` a shell in which the `regen.sh` calls the `openapi3-code-generator` to regenerate the
47−* `mock-server-openapi.yaml` not the [original specification](https://app.swaggerhub.com/apis/jamesdbloom/mock-server-openapi) of the `mock-server` as you might
24+* `mock-server-openapi-5.13.x-swagger.yaml` not the original file as you might
48− think. The thing is that the `openapi3-code-generator` does not support all the features of the
25+ think. The thing is that the `openapi3-code-generator` does not support all
49− OpenAPI3 standard correctly, so it is hand-postprocessed. It was originally downloaded from
26+ the features of the OpenAPI3 standard correctly, so it is
50− [here](https://app.swaggerhub.com/apis/jamesdbloom/mock-server-openapi/5.13.x) and fixed.
27+ hand-postprocessed. It was originally downloaded from [here](https://app.swaggerhub.com/apis/jamesdbloom/mock-server-openapi/5.13.x) and fixed.
51−
28+* `src` contails the generted code, but not exactly. Some of the parts of the
52−### Other
29+ generted code was not very pleasant, so it was fixed too.
53
30
54−* `src` and `mock-server-client.cabal` contain the generted code, but not exactly. Some of the parts
55− of the generted code was not very pleasant, so it was fixed too.
56−
57−## What will happen if you just call the `regen.sh`?
31+### What will happen if you just call the `regen.sh`?
58
32
59It will build the `openapi3-code-generator` in `nix` and regenerate the whole
33It will build the `openapi3-code-generator` in `nix` and regenerate the whole
60Haskell source code. You will see that the code was changed, because as
34Haskell source code. You will see that the code was changed, because as
61mentioned earlier the original code was slightly modified, so watch your commits.
35mentioned earlier the original code was slightly modified, so watch your commits.
62
36
63−## How to update the package to the new version of the `mock-server` spec?
37+## How the to update the package to the new version of the `mock-server`?
64−
38+
65−* Commit or discard all changes
39+* Commit all changes in git
66−* `git checkout update-openapi-spec`
40+* Run the `regen.sh` and regenerate the whole package
67−* Replace the `codegen/mock-server-openapi.yaml` with a newer version
41+* Run `git diff -p > src.patch` and save the manual changes made to the source code
68−* `git commit -m "updated mock-server-openapi.yaml to version $NEWVERSION"`
42+* Download the [original spec](https://app.swaggerhub.com/apis/jamesdbloom/mock-server-openapi/5.13.x) in place of our patched spec file
69−* `git checkout -b "update-$NEWVERSION" master`
43+* Run the `git diff -- codegen/mock-server-openapi-5.13.x-swagger.yaml -p > spec.patch`
70−* `git merge update-openapi-spec`
44+* Download the [new spec](https://app.swaggerhub.com/apis/jamesdbloom/mock-server-openapi) and put it in place of the old one
71−* Resolve conflicts if any
45+* Try to `git apply spec.patch` to the newer version of the spec to apply manual
72−* `./codegen/regen.sh`
46+ changes to the new spec. If somethig goes wrong use AI to fix it for you, heh.
73−* `git symbolic-ref HEAD refs/heads/update-generated-code && git reset`
47+* Fix the `regen.sh` and rename the `mock-server-openapi-5.13.x-swagger.yaml` to
74− switching to the branch `update-generated-code` without checking out the working-tree
48+ the newer version.
75−* `git commit -m "update the generted code for version $NEWVERSION"`
49+* `git commit -m 'dangerous action'`
76−* `git checkout "update-$NEWVERSION"`
50+* Run the `regen.sh` so you will hopefuly have a new version of the client code
77−* `git merge update-generated-code`
51+ generated.
78−* Resolve conflicts if any
52+* `git apply src.patch` to apply manual patches to the new version.
79−* `git push origin "update-$NEWVERSION"`
80−* Create PR, wait for CI, review, merge into the master
81−
82−The algorithm is kind of weird, but for a reason.
83−
84−The branch `update-openapi-spec` is the branch tracking only original
85−`codegen/mock-server-openapi.yaml` changes, meaning changes made by authors of the
86−`mock-server`. So, when you merge changes of this branch into the master you literally merge the
87−changes made by authors of the `mock-server` with our manual changes made to please the
88−`openapi3-code-generator`.
89−
90−The bratch `update-generated-code` is for tracking "changes" made by the code generator when it is
91−feed by the new OpenAPI spec file. So, when you merge this branch into the master you literally
92−merge the "code regeneration patch" with changes made by hand.
93−
94−The `master` branch is for manual changes only. The changes made to keep things working and the
95−package usable. You can always see the manual changes just by `git diff update-generated-code
96−master` or `git diff update-openapi-spec master`
codegen/mock-server-openapi.yaml+269−257
@@ -4,7 +4,7 @@ servers:
4 - url: 'https://localhost:1080/'
4 - url: 'https://localhost:1080/'
5info:
5info:
6 title: MockServer API
6 title: MockServer API
7− version: 5.15.x
7+ version: 5.13.x
8 description: >-
8 description: >-
9 MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby and a simple REST API (as shown below).
9 MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby and a simple REST API (as shown below).
10
10
@@ -18,7 +18,7 @@ info:
18 name: Apache 2.0
18 name: Apache 2.0
19tags:
19tags:
20 - name: expectation
20 - name: expectation
21− description: Create or update expectations - updates if the id matches an existing expectations (only supported by MockServer)
21+ description: Create or update expectations - updates if the id matches an existing expecations (only supported by MockServer)
22 - name: verify
22 - name: verify
23 description: Verify requests (both MockServer & MockServer Proxy)
23 description: Verify requests (both MockServer & MockServer Proxy)
24 - name: control
24 - name: control
@@ -36,7 +36,7 @@ paths:
36 content:
36 content:
37 application/json:
37 application/json:
38 schema:
38 schema:
39− title: list of upserted expectations
39+ description: "list of upserted expectations"
40 type: array
40 type: array
41 additionalProperties: false
41 additionalProperties: false
42 items:
42 items:
@@ -63,7 +63,7 @@ paths:
63 content:
63 content:
64 application/json:
64 application/json:
65 schema:
65 schema:
66− title: list of upserted expectations
66+ description: "list of upserted expectations"
67 type: array
67 type: array
68 additionalProperties: false
68 additionalProperties: false
69 items:
69 items:
@@ -89,6 +89,15 @@ paths:
89 description: expectations and recorded requests cleared
89 description: expectations and recorded requests cleared
90 '400':
90 '400':
91 description: incorrect request format
91 description: incorrect request format
92+ parameters:
93+ - in: query
94+ name: type
95+ schema:
96+ type: string
97+ enum: ["all", "log", "expectations"]
98+ default: "all"
99+ required: false
100+ description: specifies the type of information to clear, default if not specified is "all", supported values are "all", "log", "expectations"
92 requestBody:
101 requestBody:
93 content:
102 content:
94 application/json:
103 application/json:
@@ -96,7 +105,7 @@ paths:
96 oneOf:
105 oneOf:
97 - $ref: "#/components/schemas/RequestDefinition"
106 - $ref: "#/components/schemas/RequestDefinition"
98 - $ref: "#/components/schemas/ExpectationId"
107 - $ref: "#/components/schemas/ExpectationId"
99− description: request used to match expectations and record requests to clear
108+ description: request used to match expectations and recored requests to clear
100 /mockserver/reset:
109 /mockserver/reset:
101 put:
110 put:
102 tags:
111 tags:
@@ -116,12 +125,14 @@ paths:
116 schema:
125 schema:
117 type: string
126 type: string
118 enum: [ "java", "json", "log_entries" ]
127 enum: [ "java", "json", "log_entries" ]
128+ required: false
119− description: changes response format, default if not specified is "json", supported values are "java", "json", "log_entries"
129+ description: changes response format, default if not specificed is "json", supported values are "java", "json", "log_entries"
120 - in: query
130 - in: query
121 name: type
131 name: type
122 schema:
132 schema:
123 type: string
133 type: string
124 enum: [ "logs", "requests", "request_responses", "recorded_expectations", "active_expectations" ]
134 enum: [ "logs", "requests", "request_responses", "recorded_expectations", "active_expectations" ]
135+ required: false
125 description: specifies the type of object that is retrieve, default if not specified is "requests", supported values are "logs", "requests", "recorded_expectations", "active_expectations"
136 description: specifies the type of object that is retrieve, default if not specified is "requests", supported values are "logs", "requests", "recorded_expectations", "active_expectations"
126 responses:
137 responses:
127 '200':
138 '200':
@@ -137,7 +148,11 @@ paths:
137 - type: array
148 - type: array
138 additionalProperties: false
149 additionalProperties: false
139 items:
150 items:
140− $ref: "#/components/schemas/HttpResponse"
151+ $ref: "#/components/schemas/HttpRequest"
152+ - type: array
153+ additionalProperties: false
154+ items:
155+ $ref: "#/components/schemas/HttpRequestAndHttpResponse"
141 application/java:
156 application/java:
142 schema:
157 schema:
143 type: string
158 type: string
@@ -257,7 +272,7 @@ paths:
257components:
272components:
258 schemas:
273 schemas:
259 Expectations:
274 Expectations:
260− title: "list of expectations"
275+ description: "list of expectations"
261 oneOf:
276 oneOf:
262 - $ref: "#/components/schemas/Expectation"
277 - $ref: "#/components/schemas/Expectation"
263 - type: array
278 - type: array
@@ -265,7 +280,7 @@ components:
265 items:
280 items:
266 $ref: "#/components/schemas/Expectation"
281 $ref: "#/components/schemas/Expectation"
267 Expectation:
282 Expectation:
268− title: "expectation"
283+ description: "expectation"
269 type: object
284 type: object
270 additionalProperties: false
285 additionalProperties: false
271 properties:
286 properties:
@@ -275,8 +290,6 @@ components:
275 type: integer
290 type: integer
276 httpRequest:
291 httpRequest:
277 $ref: "#/components/schemas/RequestDefinition"
292 $ref: "#/components/schemas/RequestDefinition"
278− openAPIDefinition:
279− $ref: "#/components/schemas/OpenAPIDefinition"
280 httpResponse:
293 httpResponse:
281 $ref: "#/components/schemas/HttpResponse"
294 $ref: "#/components/schemas/HttpResponse"
282 httpResponseTemplate:
295 httpResponseTemplate:
@@ -301,8 +314,29 @@ components:
301 $ref: "#/components/schemas/Times"
314 $ref: "#/components/schemas/Times"
302 timeToLive:
315 timeToLive:
303 $ref: "#/components/schemas/TimeToLive"
316 $ref: "#/components/schemas/TimeToLive"
317+ oneOf:
318+ - required:
319+ - httpResponse
320+ - required:
321+ - httpResponseTemplate
322+ - required:
323+ - httpResponseClassCallback
324+ - required:
325+ - httpResponseObjectCallback
326+ - required:
327+ - httpForward
328+ - required:
329+ - httpForwardTemplate
330+ - required:
331+ - httpForwardClassCallback
332+ - required:
333+ - httpForwardObjectCallback
334+ - required:
335+ - httpOverrideForwardedRequest
336+ - required:
337+ - httpError
304 ExpectationId:
338 ExpectationId:
305− title: "pointer to existing expectation"
339+ description: "pointer to existing expectation"
306 type: object
340 type: object
307 additionalProperties: false
341 additionalProperties: false
308 properties:
342 properties:
@@ -311,7 +345,7 @@ components:
311 required:
345 required:
312 - id
346 - id
313 OpenAPIExpectations:
347 OpenAPIExpectations:
314− title: "list of open api expectations"
348+ description: "list of open api expectations"
315 oneOf:
349 oneOf:
316 - $ref: "#/components/schemas/OpenAPIExpectation"
350 - $ref: "#/components/schemas/OpenAPIExpectation"
317 - type: array
351 - type: array
@@ -319,7 +353,7 @@ components:
319 items:
353 items:
320 $ref: "#/components/schemas/OpenAPIExpectation"
354 $ref: "#/components/schemas/OpenAPIExpectation"
321 OpenAPIExpectation:
355 OpenAPIExpectation:
322− title: "open api or swagger expectation"
356+ description: "open api or swagger expectation"
323 type: object
357 type: object
324 additionalProperties: false
358 additionalProperties: false
325 properties:
359 properties:
@@ -334,12 +368,12 @@ components:
334 required:
368 required:
335 - specUrlOrPayload
369 - specUrlOrPayload
336 RequestDefinition:
370 RequestDefinition:
337− title: "request definition"
371+ description: "request definition"
338 oneOf:
372 oneOf:
339 - $ref: "#/components/schemas/HttpRequest"
373 - $ref: "#/components/schemas/HttpRequest"
340 - $ref: "#/components/schemas/OpenAPIDefinition"
374 - $ref: "#/components/schemas/OpenAPIDefinition"
341 HttpRequest:
375 HttpRequest:
342− title: "request properties matcher"
376+ description: "request properties matcher"
343 type: object
377 type: object
344 additionalProperties: false
378 additionalProperties: false
345 properties:
379 properties:
@@ -363,10 +397,8 @@ components:
363 $ref: "#/components/schemas/KeyToValue"
397 $ref: "#/components/schemas/KeyToValue"
364 socketAddress:
398 socketAddress:
365 $ref: "#/components/schemas/SocketAddress"
399 $ref: "#/components/schemas/SocketAddress"
366− protocol:
367− $ref: "#/components/schemas/Protocol"
368 OpenAPIDefinition:
400 OpenAPIDefinition:
369− title: "open api or swagger request matcher"
401+ description: "open api or swagger request matcher"
370 type: object
402 type: object
371 additionalProperties: false
403 additionalProperties: false
372 properties:
404 properties:
@@ -375,7 +407,7 @@ components:
375 operationId:
407 operationId:
376 type: string
408 type: string
377 HttpResponse:
409 HttpResponse:
378− title: "response to return"
410+ description: "response to return"
379 type: object
411 type: object
380 additionalProperties: false
412 additionalProperties: false
381 properties:
413 properties:
@@ -394,7 +426,7 @@ components:
394 reasonPhrase:
426 reasonPhrase:
395 type: string
427 type: string
396 HttpTemplate:
428 HttpTemplate:
397− title: "template to generate response / request"
429+ description: "template to generate response / request"
398 type: object
430 type: object
399 additionalProperties: false
431 additionalProperties: false
400 properties:
432 properties:
@@ -408,7 +440,7 @@ components:
408 template:
440 template:
409 type: string
441 type: string
410 HttpForward:
442 HttpForward:
411− title: host and port to forward to
443+ description: "host and port to forward to"
412 type: object
444 type: object
413 additionalProperties: false
445 additionalProperties: false
414 properties:
446 properties:
@@ -423,7 +455,7 @@ components:
423 - HTTP
455 - HTTP
424 - HTTPS
456 - HTTPS
425 HttpClassCallback:
457 HttpClassCallback:
426− title: class callback
458+ description: "class callback"
427 type: object
459 type: object
428 additionalProperties: false
460 additionalProperties: false
429 properties:
461 properties:
@@ -432,7 +464,7 @@ components:
432 callbackClass:
464 callbackClass:
433 type: string
465 type: string
434 HttpObjectCallback:
466 HttpObjectCallback:
435− title: object / method callback
467+ description: "object / method callback"
436 type: object
468 type: object
437 additionalProperties: false
469 additionalProperties: false
438 properties:
470 properties:
@@ -443,7 +475,7 @@ components:
443 responseCallback:
475 responseCallback:
444 type: boolean
476 type: boolean
445 HttpOverrideForwardedRequest:
477 HttpOverrideForwardedRequest:
446− title: override forwarded request
478+ description: "override forwarded request"
447 oneOf:
479 oneOf:
448 - type: object
480 - type: object
449 additionalProperties: false
481 additionalProperties: false
@@ -545,7 +577,7 @@ components:
545 httpResponse:
577 httpResponse:
546 "$ref": "#/components/schemas/HttpResponse"
578 "$ref": "#/components/schemas/HttpResponse"
547 HttpError:
579 HttpError:
548− title: error behaviour
580+ description: "error behaviour"
549 type: object
581 type: object
550 additionalProperties: false
582 additionalProperties: false
551 properties:
583 properties:
@@ -556,7 +588,7 @@ components:
556 responseBytes:
588 responseBytes:
557 type: string
589 type: string
558 Times:
590 Times:
559− title: "number of responses"
591+ description: "number of responses"
560 type: object
592 type: object
561 additionalProperties: false
593 additionalProperties: false
562 properties:
594 properties:
@@ -565,7 +597,7 @@ components:
565 unlimited:
597 unlimited:
566 type: boolean
598 type: boolean
567 TimeToLive:
599 TimeToLive:
568− title: "time expectation is valid for"
600+ description: "time expectation is valid for"
569 type: object
601 type: object
570 additionalProperties: false
602 additionalProperties: false
571 properties:
603 properties:
@@ -655,7 +687,7 @@ components:
655 # "^\\S+$":
687 # "^\\S+$":
656 # $ref: "#/components/schemas/StringOrJsonSchema"
688 # $ref: "#/components/schemas/StringOrJsonSchema"
657 StringOrJsonSchema:
689 StringOrJsonSchema:
658− title: string value that can be support nottable, optional or a json schema
690+ description: "string value that can be support nottable, optional or a json schema"
659 oneOf:
691 oneOf:
660 - type: string
692 - type: string
661 - type: object
693 - type: object
@@ -686,7 +718,7 @@ components:
686 - PIPE_DELIMITED
718 - PIPE_DELIMITED
687 - DEEP_OBJECT
719 - DEEP_OBJECT
688 SocketAddress:
720 SocketAddress:
689− title: remote address to send request to
721+ description: "remote address to send request to, only used for request overrides"
690 type: object
722 type: object
691 additionalProperties: false
723 additionalProperties: false
692 properties:
724 properties:
@@ -698,239 +730,198 @@ components:
698 enum:
730 enum:
699 - HTTP
731 - HTTP
700 - HTTPS
732 - HTTPS
701− BinaryBodyMatcher:
702− type: object
703− description: "binary body matcher"
704− additionalProperties: false
705− properties:
706− not:
707− type: boolean
708− type:
709− enum:
710− - BINARY
711− base64Bytes:
712− type: string
713− contentType:
714− type: string
715− JsonBodyMatcher:
716− type: object
717− description: "json body matcher"
718− additionalProperties: false
719− properties:
720− not:
721− type: boolean
722− type:
723− enum:
724− - JSON
725− json:
726− type: string
727− contentType:
728− type: string
729− matchType:
730− enum:
731− - STRICT
732− - ONLY_MATCHING_FIELDS
733− RawJsonBodyMatcher:
734− type: object
735− description: "json matching fields body matcher"
736− additionalProperties: true
737− JsonSchemaBodyMatcher:
738− type: object
739− description: "json schema body matcher"
740− additionalProperties: false
741− properties:
742− not:
743− type: boolean
744− type:
745− enum:
746− - JSON_SCHEMA
747− jsonSchema:
748− $ref: http://json-schema.org/draft-04/schema
749− JsonPathBodyMatcher:
750− type: object
751− description: "JSON path body matcher"
752− additionalProperties: false
753− properties:
754− not:
755− type: boolean
756− type:
757− enum:
758− - JSON_PATH
759− jsonPath:
760− type: string
761− ParameterBodyMatcher:
762− type: object
763− description: "parameter body matcher"
764− additionalProperties: false
765− properties:
766− not:
767− type: boolean
768− type:
769− enum:
770− - PARAMETERS
771− parameters:
772− $ref: "#/components/schemas/KeyToMultiValue"
773− RegexBodyMatcher:
774− type: object
775− description: "regex body matcher"
776− additionalProperties: false
777− properties:
778− not:
779− type: boolean
780− type:
781− enum:
782− - REGEX
783− regex:
784− type: string
785− StringBodyMatcher:
786− type: object
787− description: "string body matcher"
788− additionalProperties: false
789− properties:
790− not:
791− type: boolean
792− type:
793− enum:
794− - STRING
795− string:
796− type: string
797− contentType:
798− type: string
799− subString:
800− type: boolean
801− RawStringBodyMatcher:
802− type: string
803− description: "substring body matcher"
804− XmlBodyMatcher:
805− type: object
806− description: "xml body matcher"
807− additionalProperties: false
808− properties:
809− not:
810− type: boolean
811− type:
812− enum:
813− - XML
814− xml:
815− type: string
816− contentType:
817− type: string
818− XmlSchemaBodyMatcher:
819− type: object
820− description: "xml schema body matcher"
821− additionalProperties: false
822− properties:
823− not:
824− type: boolean
825− type:
826− enum:
827− - XML_SCHEMA
828− xmlSchema:
829− type: string
830− XpathBodyMatcher:
831− type: object
832− description: "xpath body matcher"
833− additionalProperties: false
834− properties:
835− not:
836− type: boolean
837− type:
838− enum:
839− - XPATH
840− xpath:
841− type: string
842− Protocol:
843− description: "protocol matcher"
844− enum:
845− - HTTP_1_1
846− - HTTP_2
847 Body:
733 Body:
848 description: "request body matcher"
734 description: "request body matcher"
849 anyOf:
735 anyOf:
850− - $ref: "#/components/schemas/BinaryBodyMatcher"
851− - $ref: "#/components/schemas/JsonBodyMatcher"
852− - $ref: "#/components/schemas/RawJsonBodyMatcher"
853− - $ref: "#/components/schemas/JsonSchemaBodyMatcher"
854− - $ref: "#/components/schemas/JsonPathBodyMatcher"
855− - $ref: "#/components/schemas/ParameterBodyMatcher"
856− - $ref: "#/components/schemas/RegexBodyMatcher"
857− - $ref: "#/components/schemas/StringBodyMatcher"
858− - $ref: "#/components/schemas/RawStringBodyMatcher"
859− - $ref: "#/components/schemas/XmlBodyMatcher"
860− - $ref: "#/components/schemas/XmlSchemaBodyMatcher"
861− - $ref: "#/components/schemas/XpathBodyMatcher"
862− BinaryBodyResponse:
863− type: object
736+ - type: object
864− description: "binary response body"
737+ description: "binary body matcher"
865− additionalProperties: false
738+ additionalProperties: false
866− properties:
739+ properties:
867− not:
740+ not:
868− type: boolean
741+ type: boolean
869− type:
742+ type:
870− enum:
743+ enum:
871− - BINARY
744+ - BINARY
872− base64Bytes:
745+ base64Bytes:
873− type: string
746+ type: string
874− contentType:
747+ contentType:
875− type: string
748+ type: string
876− JsonResponseBody:
877− type: object
749+ - type: object
878− description: "json response body"
750+ description: "json body matcher"
879− additionalProperties: false
751+ additionalProperties: false
880− properties:
752+ properties:
881− not:
753+ not:
882− type: boolean
754+ type: boolean
883− type:
755+ type:
884− enum:
756+ enum:
885− - JSON
757+ - JSON
886− json:
758+ json:
887− type: string
759+ type: string
888− contentType:
760+ contentType:
889− type: string
761+ type: string
890− RawJsonResponseBody:
762+ matchType:
763+ enum:
764+ - STRICT
765+ - ONLY_MATCHING_FIELDS
891− type: object
766+ - type: object
892− description: "json response body"
767+ description: "json matching fields body matcher"
893− additionalProperties: true
768+ additionalProperties: true
894− StringResponseBody:
769+ - type: object
770+ description: "json schema body matcher"
771+ additionalProperties: false
772+ properties:
773+ not:
774+ type: boolean
775+ type:
776+ enum:
777+ - JSON_SCHEMA
778+ jsonSchema:
779+ $ref: http://json-schema.org/draft-04/schema
895− type: object
780+ - type: object
896− description: "string response body"
781+ description: "JSON path body matcher"
782+ additionalProperties: false
783+ properties:
784+ not:
785+ type: boolean
786+ type:
787+ enum:
788+ - JSON_PATH
789+ jsonPath:
790+ type: string
791+ - type: object
792+ description: "parameter body matcher"
897− additionalProperties: false
793+ additionalProperties: false
898− properties:
794+ properties:
899− not:
795+ not:
900− type: boolean
796+ type: boolean
797+ type:
798+ enum:
799+ - PARAMETERS
800+ parameters:
801+ $ref: "#/components/schemas/KeyToMultiValue"
901− type:
802+ - type: object
803+ description: "regex body matcher"
804+ additionalProperties: false
805+ properties:
806+ not:
807+ type: boolean
808+ type:
902− enum:
809+ enum:
810+ - REGEX
811+ regex:
812+ type: string
813+ - type: object
814+ description: "string body matcher"
815+ additionalProperties: false
816+ properties:
817+ not:
818+ type: boolean
819+ type:
820+ enum:
903− - STRING
821+ - STRING
904− string:
822+ string:
905− type: string
823+ type: string
906− contentType:
824+ contentType:
907− type: string
825+ type: string
908− RawStringResponseBody:
826+ subString:
827+ type: boolean
909− type: string
828+ - type: string
910− description: "string response body"
829+ description: "substring body matcher"
911− XmlResponseBody:
912− type: object
830+ - type: object
913− description: "xml response body"
831+ description: "xml body matcher"
914− additionalProperties: false
832+ additionalProperties: false
915− properties:
833+ properties:
916− not:
834+ not:
917− type: boolean
835+ type: boolean
918− type:
836+ type:
919− enum:
837+ enum:
920− - XML
838+ - XML
921− xml:
839+ xml:
840+ type: string
841+ contentType:
842+ type: string
843+ - type: object
844+ description: "xml schema body matcher"
845+ additionalProperties: false
846+ properties:
847+ not:
848+ type: boolean
849+ type:
850+ enum:
851+ - XML_SCHEMA
852+ xmlSchema:
922− type: string
853+ type: string
923− contentType:
854+ - type: object
855+ description: "xpath body matcher"
856+ additionalProperties: false
857+ properties:
858+ not:
859+ type: boolean
860+ type:
861+ enum:
862+ - XPATH
863+ xpath:
924− type: string
864+ type: string
925 BodyWithContentType:
865 BodyWithContentType:
926 description: "response body"
866 description: "response body"
927 anyOf:
867 anyOf:
928− - $ref: "#/components/schemas/BinaryBodyResponse"
868+ - type: object
929− - $ref: "#/components/schemas/JsonResponseBody"
869+ description: "binary response body"
930− - $ref: "#/components/schemas/RawJsonResponseBody"
870+ additionalProperties: false
931− - $ref: "#/components/schemas/StringResponseBody"
871+ properties:
932− - $ref: "#/components/schemas/RawStringResponseBody"
872+ not:
933− - $ref: "#/components/schemas/XmlResponseBody"
873+ type: boolean
874+ type:
875+ enum:
876+ - BINARY
877+ base64Bytes:
878+ type: string
879+ contentType:
880+ type: string
881+ - type: object
882+ description: "json response body"
883+ additionalProperties: false
884+ properties:
885+ not:
886+ type: boolean
887+ type:
888+ enum:
889+ - JSON
890+ json:
891+ type: string
892+ contentType:
893+ type: string
894+ - type: object
895+ description: "json response body"
896+ additionalProperties: true
897+ - type: object
898+ description: "string response body"
899+ additionalProperties: false
900+ properties:
901+ not:
902+ type: boolean
903+ type:
904+ enum:
905+ - STRING
906+ string:
907+ type: string
908+ contentType:
909+ type: string
910+ - type: string
911+ description: "string response body"
912+ - type: object
913+ description: "xml response body"
914+ additionalProperties: false
915+ properties:
916+ not:
917+ type: boolean
918+ type:
919+ enum:
920+ - XML
921+ xml:
922+ type: string
923+ contentType:
924+ type: string
934 Delay:
925 Delay:
935 description: "response delay"
926 description: "response delay"
936 type: object
927 type: object
@@ -972,6 +963,11 @@ components:
972 $ref: "#/components/schemas/VerificationTimes"
963 $ref: "#/components/schemas/VerificationTimes"
973 maximumNumberOfRequestToReturnInVerificationFailure:
964 maximumNumberOfRequestToReturnInVerificationFailure:
974 type: integer
965 type: integer
966+ oneOf:
967+ - required:
968+ - expectationId
969+ - required:
970+ - httpRequest
975 VerificationTimes:
971 VerificationTimes:
976 description: "number of request to verify"
972 description: "number of request to verify"
977 type: object
973 type: object
@@ -997,6 +993,11 @@ components:
997 $ref: "#/components/schemas/RequestDefinition"
993 $ref: "#/components/schemas/RequestDefinition"
998 maximumNumberOfRequestToReturnInVerificationFailure:
994 maximumNumberOfRequestToReturnInVerificationFailure:
999 type: integer
995 type: integer
996+ oneOf:
997+ - required:
998+ - expectationIds
999+ - required:
1000+ - httpRequests
1000 Ports:
1001 Ports:
1001 description: "list of ports"
1002 description: "list of ports"
1002 type: object
1003 type: object
@@ -1006,3 +1007,14 @@ components:
1006 items:
1007 items:
1007 type: number
1008 type: number
1008 type: array
1009 type: array
1010+ HttpRequestAndHttpResponse:
1011+ description: "request and response"
1012+ type: object
1013+ additionalProperties: false
1014+ properties:
1015+ httpRequest:
1016+ $ref: "#/components/schemas/HttpRequest"
1017+ httpResponse:
1018+ $ref: "#/components/schemas/HttpResponse"
1019+ timestamp:
1020+ type: string
ghc-9.0.2.yamldeleted−8
@@ -1,8 +0,0 @@
1−resolver: lts-19.33
2−
3−nix:
4− packages:
5− - zlib
6−
7−packages:
8− - .
ghc-9.0.2.yaml.lockdeleted−12
@@ -1,12 +0,0 @@
1−# This file was autogenerated by Stack.
2−# You should not edit this file by hand.
3−# For more information, please see the documentation at:
4−# https://docs.haskellstack.org/en/stable/lock_files
5−
6−packages: []
7−snapshots:
8−- completed:
9− sha256: 6d1532d40621957a25bad5195bfca7938e8a06d923c91bc52aa0f3c41181f2d4
10− size: 619204
11− url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/19/33.yaml
12− original: lts-19.33
ghc-9.2.5.yamldeleted−8
@@ -1,8 +0,0 @@
1−resolver: lts-20.8
2−
3−nix:
4− packages:
5− - zlib
6−
7−packages:
8− - .
ghc-9.2.5.yaml.lockdeleted−12
@@ -1,12 +0,0 @@
1−# This file was autogenerated by Stack.
2−# You should not edit this file by hand.
3−# For more information, please see the documentation at:
4−# https://docs.haskellstack.org/en/stable/lock_files
5−
6−packages: []
7−snapshots:
8−- completed:
9− sha256: bfafe5735ccb74527d754b1f9999ded72d7c3a6c3a88529449661431ccfbd6cc
10− size: 649327
11− url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/20/8.yaml
12− original: lts-20.8
mock-server-client.cabal−2
@@ -77,7 +77,6 @@ library
77 , http-types
77 , http-types
78 , bytestring
78 , bytestring
79 , aeson
79 , aeson
80− , openapi3
81 , unordered-containers
80 , unordered-containers
82 , vector
81 , vector
83 , scientific
82 , scientific
@@ -85,4 +84,3 @@ library
85 , mtl
84 , mtl
86 , transformers
85 , transformers
87 default-language: Haskell2010
86 default-language: Haskell2010
88− default-extensions: DeriveGeneric
src/MockServer/Common.hs+5−23
@@ -1,4 +1,3 @@
1−{-# LANGUAGE CPP #-}
2{-# LANGUAGE FlexibleInstances #-}
1{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE GeneralizedNewtypeDeriving #-}
2{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4{-# LANGUAGE LambdaCase #-}
3{-# LANGUAGE LambdaCase #-}
@@ -34,18 +33,12 @@ where
34import qualified Control.Monad.IO.Class as MIO
33import qualified Control.Monad.IO.Class as MIO
35import qualified Control.Monad.Reader as MR
34import qualified Control.Monad.Reader as MR
36import qualified Control.Monad.Trans.Class as MT
35import qualified Control.Monad.Trans.Class as MT
37−#if MIN_VERSION_aeson(2,0,0)
38−import qualified Data.Aeson.KeyMap as KeyMap
39−import qualified Data.Aeson.Key as Key
40−import Data.Bifunctor
41−#else
42−import qualified Data.HashMap.Strict as HashMap
43−#endif
44import qualified Data.Aeson as Aeson
36import qualified Data.Aeson as Aeson
45import qualified Data.Aeson.Encoding as Encoding
37import qualified Data.Aeson.Encoding as Encoding
46import qualified Data.Bifunctor as BF
38import qualified Data.Bifunctor as BF
47import qualified Data.ByteString.Char8 as B8
39import qualified Data.ByteString.Char8 as B8
48import qualified Data.ByteString.Lazy.Char8 as LB8
40import qualified Data.ByteString.Lazy.Char8 as LB8
41+import qualified Data.HashMap.Strict as HMap
49import qualified Data.Maybe as Maybe
42import qualified Data.Maybe as Maybe
50import qualified Data.Scientific as Scientific
43import qualified Data.Scientific as Scientific
51import Data.Text (Text)
44import Data.Text (Text)
@@ -57,15 +50,6 @@ import qualified Network.HTTP.Client as HC
57import qualified Network.HTTP.Simple as HS
50import qualified Network.HTTP.Simple as HS
58import qualified Network.HTTP.Types as HT
51import qualified Network.HTTP.Types as HT
59
52
60−
61−#if MIN_VERSION_aeson(2,0,0)
62−toList' :: Aeson.Object -> [(Text, Aeson.Value)]
63−toList' = fmap (first Key.toText) . KeyMap.toList
64−#else
65−toList' :: Aeson.Object -> [(Text, Aeson.Value)]
66−toList' = HashMap.toList
67−#endif
68−
69-- | Abstracts the usage of 'Network.HTTP.Simple.httpBS' away,
53-- | Abstracts the usage of 'Network.HTTP.Simple.httpBS' away,
70-- so that it can be used for testing
54-- so that it can be used for testing
71class Monad m => MonadHTTP m where
55class Monad m => MonadHTTP m where
@@ -301,10 +285,8 @@ jsonToFormDataFlat _ Aeson.Null = []
301jsonToFormDataFlat name (Aeson.Number a) = [(name, encodeStrict a)]
285jsonToFormDataFlat name (Aeson.Number a) = [(name, encodeStrict a)]
302jsonToFormDataFlat name (Aeson.String a) = [(name, textToByte a)]
286jsonToFormDataFlat name (Aeson.String a) = [(name, textToByte a)]
303jsonToFormDataFlat name (Aeson.Bool a) = [(name, encodeStrict a)]
287jsonToFormDataFlat name (Aeson.Bool a) = [(name, encodeStrict a)]
304−jsonToFormDataFlat _ (Aeson.Object object) =
305− toList' object >>= uncurry jsonToFormDataFlat . BF.first Just
288+jsonToFormDataFlat _ (Aeson.Object object) = HMap.toList object >>= uncurry jsonToFormDataFlat . BF.first Just
306−jsonToFormDataFlat name (Aeson.Array vector) =
307− Vector.toList vector >>= jsonToFormDataFlat name
289+jsonToFormDataFlat name (Aeson.Array vector) = Vector.toList vector >>= jsonToFormDataFlat name
308
290
309-- | creates form data bytestring array
291-- | creates form data bytestring array
310createFormData :: (Aeson.ToJSON a) => a -> [(B8.ByteString, B8.ByteString)]
292createFormData :: (Aeson.ToJSON a) => a -> [(B8.ByteString, B8.ByteString)]
@@ -338,9 +320,9 @@ jsonToFormDataPrefixed prefix (Aeson.Bool False) = [(prefix, "false")]
338jsonToFormDataPrefixed _ Aeson.Null = []
320jsonToFormDataPrefixed _ Aeson.Null = []
339jsonToFormDataPrefixed prefix (Aeson.String a) = [(prefix, a)]
321jsonToFormDataPrefixed prefix (Aeson.String a) = [(prefix, a)]
340jsonToFormDataPrefixed "" (Aeson.Object object) =
322jsonToFormDataPrefixed "" (Aeson.Object object) =
341− toList' object >>= uncurry jsonToFormDataPrefixed
323+ HMap.toList object >>= uncurry jsonToFormDataPrefixed
342jsonToFormDataPrefixed prefix (Aeson.Object object) =
324jsonToFormDataPrefixed prefix (Aeson.Object object) =
343− toList' object >>= (\(x, y) -> jsonToFormDataPrefixed (prefix <> "[" <> x <> "]") y)
325+ HMap.toList object >>= (\(x, y) -> jsonToFormDataPrefixed (prefix <> "[" <> x <> "]") y)
344jsonToFormDataPrefixed prefix (Aeson.Array vector) =
326jsonToFormDataPrefixed prefix (Aeson.Array vector) =
345 Vector.toList vector >>= jsonToFormDataPrefixed (prefix <> "[]")
327 Vector.toList vector >>= jsonToFormDataPrefixed (prefix <> "[]")
346
328
src/MockServer/Types/JsonSchemaBodyMatcher.hs+6−6
@@ -6,19 +6,20 @@
6-- | Contains the types generated from the schema JsonSchemaBodyMatcher
6-- | Contains the types generated from the schema JsonSchemaBodyMatcher
7module MockServer.Types.JsonSchemaBodyMatcher where
7module MockServer.Types.JsonSchemaBodyMatcher where
8
8
9+import qualified Prelude as GHC.Integer.Type
10+import qualified Prelude as GHC.Maybe
9import qualified Control.Monad.Fail
11import qualified Control.Monad.Fail
10import qualified Data.Aeson
12import qualified Data.Aeson
11import qualified Data.Aeson as Data.Aeson.Encoding.Internal
13import qualified Data.Aeson as Data.Aeson.Encoding.Internal
12import qualified Data.Aeson as Data.Aeson.Types
14import qualified Data.Aeson as Data.Aeson.Types
13import qualified Data.Aeson as Data.Aeson.Types.FromJSON
15import qualified Data.Aeson as Data.Aeson.Types.FromJSON
14−import qualified Data.Aeson as Data.Aeson.Types.Internal
15import qualified Data.Aeson as Data.Aeson.Types.ToJSON
16import qualified Data.Aeson as Data.Aeson.Types.ToJSON
17+import qualified Data.Aeson as Data.Aeson.Types.Internal
16import qualified Data.ByteString.Char8
18import qualified Data.ByteString.Char8
17import qualified Data.ByteString.Char8 as Data.ByteString.Internal
19import qualified Data.ByteString.Char8 as Data.ByteString.Internal
18import qualified Data.Foldable
20import qualified Data.Foldable
19import qualified Data.Functor
21import qualified Data.Functor
20import qualified Data.Maybe
22import qualified Data.Maybe
21−import Data.OpenApi.Internal (Schema)
22import qualified Data.Scientific
23import qualified Data.Scientific
23import qualified Data.Text
24import qualified Data.Text
24import qualified Data.Text.Internal
25import qualified Data.Text.Internal
@@ -31,15 +32,14 @@ import qualified GHC.Show
31import qualified GHC.Types
32import qualified GHC.Types
32import qualified MockServer.Common
33import qualified MockServer.Common
33import MockServer.TypeAlias
34import MockServer.TypeAlias
34−import qualified Prelude as GHC.Integer.Type
35+import {-# SOURCE #-} MockServer.Types.Http__JsonSchema_OrgDraft_04Schema
35−import qualified Prelude as GHC.Maybe
36
36
37-- | Defines the object schema located at @components.schemas.JsonSchemaBodyMatcher@ in the specification.
37-- | Defines the object schema located at @components.schemas.JsonSchemaBodyMatcher@ in the specification.
38−--
38+--
39-- json schema body matcher
39-- json schema body matcher
40data JsonSchemaBodyMatcher = JsonSchemaBodyMatcher {
40data JsonSchemaBodyMatcher = JsonSchemaBodyMatcher {
41 -- | jsonSchema
41 -- | jsonSchema
42− jsonSchemaBodyMatcherJsonSchema :: (GHC.Maybe.Maybe Schema)
42+ jsonSchemaBodyMatcherJsonSchema :: (GHC.Maybe.Maybe Http___json_schema'org_draft_04_schema)
43 -- | not
43 -- | not
44 , jsonSchemaBodyMatcherNot :: (GHC.Maybe.Maybe GHC.Types.Bool)
44 , jsonSchemaBodyMatcherNot :: (GHC.Maybe.Maybe GHC.Types.Bool)
45 -- | type
45 -- | type
src/MockServer/Types/StringOrJsonSchema.hs+7−7
@@ -6,19 +6,20 @@
6-- | Contains the types generated from the schema StringOrJsonSchema
6-- | Contains the types generated from the schema StringOrJsonSchema
7module MockServer.Types.StringOrJsonSchema where
7module MockServer.Types.StringOrJsonSchema where
8
8
9+import qualified Prelude as GHC.Integer.Type
10+import qualified Prelude as GHC.Maybe
9import qualified Control.Monad.Fail
11import qualified Control.Monad.Fail
10import qualified Data.Aeson
12import qualified Data.Aeson
11import qualified Data.Aeson as Data.Aeson.Encoding.Internal
13import qualified Data.Aeson as Data.Aeson.Encoding.Internal
12import qualified Data.Aeson as Data.Aeson.Types
14import qualified Data.Aeson as Data.Aeson.Types
13import qualified Data.Aeson as Data.Aeson.Types.FromJSON
15import qualified Data.Aeson as Data.Aeson.Types.FromJSON
14−import qualified Data.Aeson as Data.Aeson.Types.Internal
15import qualified Data.Aeson as Data.Aeson.Types.ToJSON
16import qualified Data.Aeson as Data.Aeson.Types.ToJSON
17+import qualified Data.Aeson as Data.Aeson.Types.Internal
16import qualified Data.ByteString.Char8
18import qualified Data.ByteString.Char8
17import qualified Data.ByteString.Char8 as Data.ByteString.Internal
19import qualified Data.ByteString.Char8 as Data.ByteString.Internal
18import qualified Data.Foldable
20import qualified Data.Foldable
19import qualified Data.Functor
21import qualified Data.Functor
20import qualified Data.Maybe
22import qualified Data.Maybe
21−import Data.OpenApi.Internal (Schema)
22import qualified Data.Scientific
23import qualified Data.Scientific
23import qualified Data.Text
24import qualified Data.Text
24import qualified Data.Text.Internal
25import qualified Data.Text.Internal
@@ -31,12 +32,11 @@ import qualified GHC.Show
31import qualified GHC.Types
32import qualified GHC.Types
32import qualified MockServer.Common
33import qualified MockServer.Common
33import MockServer.TypeAlias
34import MockServer.TypeAlias
34−import qualified Prelude as GHC.Integer.Type
35+import {-# SOURCE #-} MockServer.Types.Http__JsonSchema_OrgDraft_04Schema
35−import qualified Prelude as GHC.Maybe
36
36
37-- | Defines the object schema located at @components.schemas.StringOrJsonSchema.oneOf@ in the specification.
37-- | Defines the object schema located at @components.schemas.StringOrJsonSchema.oneOf@ in the specification.
38−--
38+--
39−--
39+--
40data StringOrJsonSchemaOneOf2 = StringOrJsonSchemaOneOf2 {
40data StringOrJsonSchemaOneOf2 = StringOrJsonSchemaOneOf2 {
41 -- | not
41 -- | not
42 stringOrJsonSchemaOneOf2Not :: (GHC.Maybe.Maybe GHC.Types.Bool)
42 stringOrJsonSchemaOneOf2Not :: (GHC.Maybe.Maybe GHC.Types.Bool)
@@ -45,7 +45,7 @@ data StringOrJsonSchemaOneOf2 = StringOrJsonSchemaOneOf2 {
45 -- | parameterStyle
45 -- | parameterStyle
46 , stringOrJsonSchemaOneOf2ParameterStyle :: (GHC.Maybe.Maybe StringOrJsonSchemaOneOf2ParameterStyle)
46 , stringOrJsonSchemaOneOf2ParameterStyle :: (GHC.Maybe.Maybe StringOrJsonSchemaOneOf2ParameterStyle)
47 -- | schema
47 -- | schema
48− , stringOrJsonSchemaOneOf2Schema :: (GHC.Maybe.Maybe Schema)
48+ , stringOrJsonSchemaOneOf2Schema :: (GHC.Maybe.Maybe Http___json_schema'org_draft_04_schema)
49 -- | value
49 -- | value
50 , stringOrJsonSchemaOneOf2Value :: (GHC.Maybe.Maybe Data.Text.Internal.Text)
50 , stringOrJsonSchemaOneOf2Value :: (GHC.Maybe.Maybe Data.Text.Internal.Text)
51 } deriving (GHC.Show.Show
51 } deriving (GHC.Show.Show