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