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