@pactflow/openapi-pact-comparator 1.7.1 → 1.8.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/dist/cli.cjs +45 -11
- package/dist/cli.cjs.map +1 -1
- package/dist/index.cjs +44 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +44 -10
- package/dist/index.mjs.map +1 -1
- package/dist/src/documents/pact.d.ts +13 -4
- package/dist/src/results/index.d.ts +1 -1
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -19433,7 +19433,7 @@ var Ajv$1 = /*@__PURE__*/getDefaultExportFromCjs(ajvExports);
|
|
|
19433
19433
|
// a full schema can be found at https://github.com/pactflow/pact-schemas
|
|
19434
19434
|
// but we don't use that here, because we try to be permissive with input
|
|
19435
19435
|
const Interaction = Type.Object({
|
|
19436
|
-
|
|
19436
|
+
_nonHTTP: Type.Optional(Type.Boolean()),
|
|
19437
19437
|
type: Type.Optional(Type.String()),
|
|
19438
19438
|
description: Type.Optional(Type.String()),
|
|
19439
19439
|
providerState: Type.Optional(Type.String()),
|
|
@@ -19463,6 +19463,10 @@ const Interaction = Type.Object({
|
|
|
19463
19463
|
status: Type.Number(),
|
|
19464
19464
|
}),
|
|
19465
19465
|
});
|
|
19466
|
+
const Message = Type.Object({
|
|
19467
|
+
description: Type.Optional(Type.String()),
|
|
19468
|
+
providerState: Type.Optional(Type.String()),
|
|
19469
|
+
});
|
|
19466
19470
|
const Pact = Type.Object({
|
|
19467
19471
|
metadata: Type.Optional(Type.Object({
|
|
19468
19472
|
pactSpecification: Type.Optional(Type.Object({
|
|
@@ -19473,7 +19477,8 @@ const Pact = Type.Object({
|
|
|
19473
19477
|
version: Type.String(),
|
|
19474
19478
|
})),
|
|
19475
19479
|
})),
|
|
19476
|
-
interactions: Type.Array(Interaction),
|
|
19480
|
+
interactions: Type.Optional(Type.Array(Interaction)),
|
|
19481
|
+
messages: Type.Optional(Type.Array(Message)),
|
|
19477
19482
|
});
|
|
19478
19483
|
const supportedInteractions = (i) => !i.type || i.type.toLowerCase() === "synchronous/http";
|
|
19479
19484
|
const parseAsPactV4Body = (body) => {
|
|
@@ -19544,13 +19549,18 @@ const interactionV4 = (i) => ({
|
|
|
19544
19549
|
headers: flattenValues(i.response.headers),
|
|
19545
19550
|
},
|
|
19546
19551
|
});
|
|
19552
|
+
const interactionNonHTTP = (i) => ({
|
|
19553
|
+
...i,
|
|
19554
|
+
_nonHTTP: true,
|
|
19555
|
+
});
|
|
19547
19556
|
const ajv = new Ajv$1();
|
|
19548
19557
|
const validate = ajv.compile(Pact);
|
|
19549
19558
|
const parse = (pact) => {
|
|
19550
|
-
const { metadata, interactions } = pact;
|
|
19559
|
+
const { metadata, interactions, messages } = pact;
|
|
19551
19560
|
const isValid = validate({
|
|
19552
19561
|
metadata,
|
|
19553
|
-
interactions: interactions
|
|
19562
|
+
interactions: interactions?.filter(supportedInteractions),
|
|
19563
|
+
messages,
|
|
19554
19564
|
});
|
|
19555
19565
|
if (!isValid) {
|
|
19556
19566
|
throw new ParserError(validate.errors);
|
|
@@ -19562,9 +19572,8 @@ const parse = (pact) => {
|
|
|
19562
19572
|
const interactionParser = version >= 4 ? interactionV4 : version >= 3 ? interactionV3 : interactionV1;
|
|
19563
19573
|
return {
|
|
19564
19574
|
metadata,
|
|
19565
|
-
interactions: interactions
|
|
19566
|
-
|
|
19567
|
-
: { _skip: true }),
|
|
19575
|
+
interactions: interactions?.map((i) => supportedInteractions(i) ? interactionParser(i) : interactionNonHTTP(i)),
|
|
19576
|
+
messages,
|
|
19568
19577
|
};
|
|
19569
19578
|
};
|
|
19570
19579
|
class ParserError extends Error {
|
|
@@ -24345,9 +24354,19 @@ class Comparator {
|
|
|
24345
24354
|
this.#router = setupRouter(this.#oas, this.#config);
|
|
24346
24355
|
}
|
|
24347
24356
|
const parsedPact = parse(pact);
|
|
24348
|
-
|
|
24349
|
-
|
|
24350
|
-
|
|
24357
|
+
const parsedInteractions = parsedPact.interactions || [];
|
|
24358
|
+
for (const [index, interaction] of parsedInteractions.entries()) {
|
|
24359
|
+
if (interaction._nonHTTP) {
|
|
24360
|
+
yield {
|
|
24361
|
+
code: "interaction.type.unsupported",
|
|
24362
|
+
mockDetails: {
|
|
24363
|
+
...baseMockDetails(interaction),
|
|
24364
|
+
location: `[root].interactions[${index}].type`,
|
|
24365
|
+
value: interaction.type,
|
|
24366
|
+
},
|
|
24367
|
+
message: `Non-HTTP messages cannot be verified against an HTTP-only OpenAPI Document.`,
|
|
24368
|
+
type: "warning",
|
|
24369
|
+
};
|
|
24351
24370
|
continue;
|
|
24352
24371
|
}
|
|
24353
24372
|
const { method, path, query } = interaction.request;
|
|
@@ -24395,6 +24414,21 @@ class Comparator {
|
|
|
24395
24414
|
yield* compareResHeader(this.#ajvCoerce, route, interaction, index, this.#config);
|
|
24396
24415
|
yield* compareResBody(this.#ajvNocoerce, route, interaction, index, this.#config);
|
|
24397
24416
|
}
|
|
24417
|
+
if (parsedPact.messages) {
|
|
24418
|
+
for (const [index, message] of parsedPact.messages.entries()) {
|
|
24419
|
+
yield {
|
|
24420
|
+
code: "interaction.type.unsupported",
|
|
24421
|
+
mockDetails: {
|
|
24422
|
+
interactionDescription: message.description,
|
|
24423
|
+
interactionState: message.providerState || "[none]",
|
|
24424
|
+
location: `[root].messages[${index}]`,
|
|
24425
|
+
value: message,
|
|
24426
|
+
},
|
|
24427
|
+
message: `Non-HTTP messages cannot be verified against an HTTP-only OpenAPI Document.`,
|
|
24428
|
+
type: "warning",
|
|
24429
|
+
};
|
|
24430
|
+
}
|
|
24431
|
+
}
|
|
24398
24432
|
}
|
|
24399
24433
|
}
|
|
24400
24434
|
|