@pactflow/openapi-pact-comparator 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -0
- package/dist/index.cjs +38375 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.mjs +38355 -0
- package/dist/index.mjs.map +1 -0
- package/dist/src/compare/index.d.ts +8 -0
- package/dist/src/compare/requestBody.d.ts +6 -0
- package/dist/src/compare/requestHeader.d.ts +6 -0
- package/dist/src/compare/requestPath.d.ts +6 -0
- package/dist/src/compare/requestQuery.d.ts +6 -0
- package/dist/src/compare/requestSecurity.d.ts +6 -0
- package/dist/src/compare/responseBody.d.ts +6 -0
- package/dist/src/compare/responseHeader.d.ts +6 -0
- package/dist/src/compare/setup.d.ts +6 -0
- package/dist/src/compare/utils/content.d.ts +7 -0
- package/dist/src/compare/utils/parameters.d.ts +1 -0
- package/dist/src/compare/utils/parse.d.ts +5 -0
- package/dist/src/documents/oas.d.ts +5 -0
- package/dist/src/documents/pact.d.ts +54 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/results/index.d.ts +29 -0
- package/dist/src/transform/index.d.ts +3 -0
- package/dist/src/transform/minimumSchema.d.ts +3 -0
- package/dist/src/transform/requestSchema.d.ts +2 -0
- package/dist/src/transform/responseSchema.d.ts +2 -0
- package/dist/src/utils/config.d.ts +3 -0
- package/dist/src/utils/interaction.d.ts +2 -0
- package/dist/src/utils/queryParams.d.ts +1 -0
- package/dist/src/utils/quirks.d.ts +3 -0
- package/dist/src/utils/schema.d.ts +6 -0
- package/dist/src/utils/validation.d.ts +2 -0
- package/package.json +83 -0
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# OpenAPI-Pact-Comparator
|
|
2
|
+
|
|
3
|
+
## What is this?
|
|
4
|
+
|
|
5
|
+
This compares OpenAPI schemas and Pact contracts to determine if they are
|
|
6
|
+
compatible. It is inspired by
|
|
7
|
+
[swagger-mock-validator](https://github.com/pactflow/swagger-mock-validator)
|
|
8
|
+
and aims to retain a mostly compatible interface.
|
|
9
|
+
|
|
10
|
+
## Why rewrite it?
|
|
11
|
+
|
|
12
|
+
[swagger-mock-validator](https://github.com/pactflow/swagger-mock-validator)
|
|
13
|
+
has aged, and is very difficult to extend and improve on.
|
|
14
|
+
|
|
15
|
+
It is also very slow primarily due to inefficient use of
|
|
16
|
+
[ajv](https://ajv.js.org/); schemas are unnecessarily recompiled everytime
|
|
17
|
+
instead of being cached.
|
|
18
|
+
|
|
19
|
+
## How is this better?
|
|
20
|
+
|
|
21
|
+
**Schemas are compiled once, and reused where possible**. In practical terms,
|
|
22
|
+
this gives us an improvement exceeding 20x in real-world comparisons. In some
|
|
23
|
+
cases, this was 50x faster!
|
|
24
|
+
|
|
25
|
+
**Referenced schemas are NOT inlined**. They are kept as references to keep the
|
|
26
|
+
size of complex schemas down. We need to do this anyway to support circular
|
|
27
|
+
references. Further, unused references are skipped to speed up schema
|
|
28
|
+
compilation in AJV.
|
|
29
|
+
|
|
30
|
+
**Multiple pacts can be compared in one invocation to maximise schema reuse**.
|
|
31
|
+
Instead of perforing the comparison per pair of OAS + Pact, we can reuse the
|
|
32
|
+
compiled OAS schemas across multiple Pacts.
|
|
33
|
+
|
|
34
|
+
**A fast HTTP router is used to match provider routes**. Instead of iterating
|
|
35
|
+
through an array of routes, we use [Radix
|
|
36
|
+
Tree](https://en.wikipedia.org/wiki/Radix_tree) search using
|
|
37
|
+
[find-my-way](https://github.com/delvedor/find-my-way) This allows large
|
|
38
|
+
providers to be traversed quickly.
|
|
39
|
+
|
|
40
|
+
**Computation is broken up to small units using async generators**. This leads
|
|
41
|
+
to low event loop delays, suitable for high concurrency servers.
|
|
42
|
+
|
|
43
|
+
## Usage
|
|
44
|
+
|
|
45
|
+
With error handling omitted for brevity:
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
import { Comparator } from "openapi-pact-comparator";
|
|
49
|
+
|
|
50
|
+
// openapi is object from JSON.parse() or yaml.load()
|
|
51
|
+
const comparator = new Comparator(openapi);
|
|
52
|
+
|
|
53
|
+
// pacts is array of objects the same way
|
|
54
|
+
for (const pact of pacts) {
|
|
55
|
+
for await (const result of comparator.compare(pact)) {
|
|
56
|
+
console.log(result);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Quirks mode
|
|
62
|
+
|
|
63
|
+
To retain compatibility with
|
|
64
|
+
[swagger-mock-validator](https://github.com/pactflow/swagger-mock-validator),
|
|
65
|
+
an environment variable `QUIRKS` can be set [to any value]. When this is true,
|
|
66
|
+
all of SMV quirks are reproduced in case you are unable to migrate immediately.
|
|
67
|
+
|
|
68
|
+
The quirks can also be enabled/disabled by adding to the `info` section of the
|
|
69
|
+
OAS some extensions in the form of `x-opc-config-${quirk-name}`, where quirks
|
|
70
|
+
are listed [here](./src/utils/config.ts).
|
|
71
|
+
|
|
72
|
+
This mode may be removed eventually, so you should always endeavour to try to
|
|
73
|
+
update your comparisons to use the latest functionality.
|