@pactflow/openapi-pact-comparator 1.8.0 → 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({
@@ -19472,7 +19476,7 @@ const Pact = Type.Object({
19472
19476
  })),
19473
19477
  })),
19474
19478
  interactions: Type.Optional(Type.Array(Interaction)),
19475
- messages: Type.Optional(Type.Array(Type.Unknown())),
19479
+ messages: Type.Optional(Type.Array(Message)),
19476
19480
  });
19477
19481
  const supportedInteractions = (i) => !i.type || i.type.toLowerCase() === "synchronous/http";
19478
19482
  const parseAsPactV4Body = (body) => {
@@ -19543,6 +19547,10 @@ const interactionV4 = (i) => ({
19543
19547
  headers: flattenValues(i.response.headers),
19544
19548
  },
19545
19549
  });
19550
+ const interactionNonHTTP = (i) => ({
19551
+ ...i,
19552
+ _nonHTTP: true,
19553
+ });
19546
19554
  const ajv = new Ajv$1();
19547
19555
  const validate = ajv.compile(Pact);
19548
19556
  const parse = (pact) => {
@@ -19562,9 +19570,7 @@ const parse = (pact) => {
19562
19570
  const interactionParser = version >= 4 ? interactionV4 : version >= 3 ? interactionV3 : interactionV1;
19563
19571
  return {
19564
19572
  metadata,
19565
- interactions: interactions?.map((i) => supportedInteractions(i)
19566
- ? interactionParser(i)
19567
- : { _skip: true }),
19573
+ interactions: interactions?.map((i) => supportedInteractions(i) ? interactionParser(i) : interactionNonHTTP(i)),
19568
19574
  messages,
19569
19575
  };
19570
19576
  };
@@ -24347,14 +24353,18 @@ class Comparator {
24347
24353
  }
24348
24354
  const parsedPact = parse(pact);
24349
24355
  const parsedInteractions = parsedPact.interactions || [];
24350
- const UNSUPPORTED_INTERACTION_WARNING = {
24351
- code: "interaction.type.unsupported",
24352
- message: `Non-HTTP Interaction is not supported, OPC can only compare HTTP interactions.`,
24353
- type: "warning",
24354
- };
24355
24356
  for (const [index, interaction] of parsedInteractions.entries()) {
24356
- if (interaction._skip) {
24357
- yield UNSUPPORTED_INTERACTION_WARNING;
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
+ };
24358
24368
  continue;
24359
24369
  }
24360
24370
  const { method, path, query } = interaction.request;
@@ -24403,8 +24413,18 @@ class Comparator {
24403
24413
  yield* compareResBody(this.#ajvNocoerce, route, interaction, index, this.#config);
24404
24414
  }
24405
24415
  if (parsedPact.messages) {
24406
- for (const [_message] of parsedPact.messages.entries()) {
24407
- yield UNSUPPORTED_INTERACTION_WARNING;
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
+ };
24408
24428
  }
24409
24429
  }
24410
24430
  }