@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 CHANGED
@@ -27592,7 +27592,7 @@ var Ajv$1 = /*@__PURE__*/getDefaultExportFromCjs(ajvExports);
27592
27592
  // a full schema can be found at https://github.com/pactflow/pact-schemas
27593
27593
  // but we don't use that here, because we try to be permissive with input
27594
27594
  const Interaction = Type.Object({
27595
- _skip: Type.Optional(Type.Boolean()),
27595
+ _nonHTTP: Type.Optional(Type.Boolean()),
27596
27596
  type: Type.Optional(Type.String()),
27597
27597
  description: Type.Optional(Type.String()),
27598
27598
  providerState: Type.Optional(Type.String()),
@@ -27622,6 +27622,10 @@ const Interaction = Type.Object({
27622
27622
  status: Type.Number(),
27623
27623
  }),
27624
27624
  });
27625
+ const Message = Type.Object({
27626
+ description: Type.Optional(Type.String()),
27627
+ providerState: Type.Optional(Type.String()),
27628
+ });
27625
27629
  const Pact = Type.Object({
27626
27630
  metadata: Type.Optional(Type.Object({
27627
27631
  pactSpecification: Type.Optional(Type.Object({
@@ -27632,7 +27636,8 @@ const Pact = Type.Object({
27632
27636
  version: Type.String(),
27633
27637
  })),
27634
27638
  })),
27635
- interactions: Type.Array(Interaction),
27639
+ interactions: Type.Optional(Type.Array(Interaction)),
27640
+ messages: Type.Optional(Type.Array(Message)),
27636
27641
  });
27637
27642
  const supportedInteractions = (i) => !i.type || i.type.toLowerCase() === "synchronous/http";
27638
27643
  const parseAsPactV4Body = (body) => {
@@ -27703,13 +27708,18 @@ const interactionV4 = (i) => ({
27703
27708
  headers: flattenValues(i.response.headers),
27704
27709
  },
27705
27710
  });
27711
+ const interactionNonHTTP = (i) => ({
27712
+ ...i,
27713
+ _nonHTTP: true,
27714
+ });
27706
27715
  const ajv = new Ajv$1();
27707
27716
  const validate = ajv.compile(Pact);
27708
27717
  const parse = (pact) => {
27709
- const { metadata, interactions } = pact;
27718
+ const { metadata, interactions, messages } = pact;
27710
27719
  const isValid = validate({
27711
27720
  metadata,
27712
- interactions: interactions.filter(supportedInteractions),
27721
+ interactions: interactions?.filter(supportedInteractions),
27722
+ messages,
27713
27723
  });
27714
27724
  if (!isValid) {
27715
27725
  throw new ParserError(validate.errors);
@@ -27721,9 +27731,8 @@ const parse = (pact) => {
27721
27731
  const interactionParser = version >= 4 ? interactionV4 : version >= 3 ? interactionV3 : interactionV1;
27722
27732
  return {
27723
27733
  metadata,
27724
- interactions: interactions.map((i) => supportedInteractions(i)
27725
- ? interactionParser(i)
27726
- : { _skip: true }),
27734
+ interactions: interactions?.map((i) => supportedInteractions(i) ? interactionParser(i) : interactionNonHTTP(i)),
27735
+ messages,
27727
27736
  };
27728
27737
  };
27729
27738
  class ParserError extends Error {
@@ -32504,9 +32513,19 @@ class Comparator {
32504
32513
  this.#router = setupRouter(this.#oas, this.#config);
32505
32514
  }
32506
32515
  const parsedPact = parse(pact);
32507
- for (const [index, interaction] of parsedPact.interactions.entries()) {
32508
- if (interaction._skip) {
32509
- // non http/synchronous have been zero-ed out
32516
+ const parsedInteractions = parsedPact.interactions || [];
32517
+ for (const [index, interaction] of parsedInteractions.entries()) {
32518
+ if (interaction._nonHTTP) {
32519
+ yield {
32520
+ code: "interaction.type.unsupported",
32521
+ mockDetails: {
32522
+ ...baseMockDetails(interaction),
32523
+ location: `[root].interactions[${index}].type`,
32524
+ value: interaction.type,
32525
+ },
32526
+ message: `Non-HTTP messages cannot be verified against an HTTP-only OpenAPI Document.`,
32527
+ type: "warning",
32528
+ };
32510
32529
  continue;
32511
32530
  }
32512
32531
  const { method, path, query } = interaction.request;
@@ -32554,10 +32573,25 @@ class Comparator {
32554
32573
  yield* compareResHeader(this.#ajvCoerce, route, interaction, index, this.#config);
32555
32574
  yield* compareResBody(this.#ajvNocoerce, route, interaction, index, this.#config);
32556
32575
  }
32576
+ if (parsedPact.messages) {
32577
+ for (const [index, message] of parsedPact.messages.entries()) {
32578
+ yield {
32579
+ code: "interaction.type.unsupported",
32580
+ mockDetails: {
32581
+ interactionDescription: message.description,
32582
+ interactionState: message.providerState || "[none]",
32583
+ location: `[root].messages[${index}]`,
32584
+ value: message,
32585
+ },
32586
+ message: `Non-HTTP messages cannot be verified against an HTTP-only OpenAPI Document.`,
32587
+ type: "warning",
32588
+ };
32589
+ }
32590
+ }
32557
32591
  }
32558
32592
  }
32559
32593
 
32560
- var version = "1.7.1";
32594
+ var version = "1.8.1";
32561
32595
  var packageJson = {
32562
32596
  version: version};
32563
32597