@pactflow/openapi-pact-comparator 1.7.0 → 1.8.0

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,6 +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
19437
  type: Type.Optional(Type.String()),
19437
19438
  description: Type.Optional(Type.String()),
19438
19439
  providerState: Type.Optional(Type.String()),
@@ -19472,7 +19473,8 @@ const Pact = Type.Object({
19472
19473
  version: Type.String(),
19473
19474
  })),
19474
19475
  })),
19475
- interactions: Type.Array(Interaction),
19476
+ interactions: Type.Optional(Type.Array(Interaction)),
19477
+ messages: Type.Optional(Type.Array(Type.Unknown())),
19476
19478
  });
19477
19479
  const supportedInteractions = (i) => !i.type || i.type.toLowerCase() === "synchronous/http";
19478
19480
  const parseAsPactV4Body = (body) => {
@@ -19546,10 +19548,11 @@ const interactionV4 = (i) => ({
19546
19548
  const ajv = new Ajv$1();
19547
19549
  const validate = ajv.compile(Pact);
19548
19550
  const parse = (pact) => {
19549
- const { metadata, interactions } = pact;
19551
+ const { metadata, interactions, messages } = pact;
19550
19552
  const isValid = validate({
19551
19553
  metadata,
19552
- interactions: interactions.filter(supportedInteractions),
19554
+ interactions: interactions?.filter(supportedInteractions),
19555
+ messages,
19553
19556
  });
19554
19557
  if (!isValid) {
19555
19558
  throw new ParserError(validate.errors);
@@ -19561,9 +19564,10 @@ const parse = (pact) => {
19561
19564
  const interactionParser = version >= 4 ? interactionV4 : version >= 3 ? interactionV3 : interactionV1;
19562
19565
  return {
19563
19566
  metadata,
19564
- interactions: interactions
19565
- .filter(supportedInteractions)
19566
- .map(interactionParser),
19567
+ interactions: interactions?.map((i) => supportedInteractions(i)
19568
+ ? interactionParser(i)
19569
+ : { _skip: true }),
19570
+ messages,
19567
19571
  };
19568
19572
  };
19569
19573
  class ParserError extends Error {
@@ -24344,7 +24348,17 @@ class Comparator {
24344
24348
  this.#router = setupRouter(this.#oas, this.#config);
24345
24349
  }
24346
24350
  const parsedPact = parse(pact);
24347
- for (const [index, interaction] of parsedPact.interactions.entries()) {
24351
+ 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
+ for (const [index, interaction] of parsedInteractions.entries()) {
24358
+ if (interaction._skip) {
24359
+ yield UNSUPPORTED_INTERACTION_WARNING;
24360
+ continue;
24361
+ }
24348
24362
  const { method, path, query } = interaction.request;
24349
24363
  let pathWithLeadingSlash = path.startsWith("/") ? path : `/${path}`;
24350
24364
  if (this.#config.get("no-percent-encoding")) {
@@ -24390,6 +24404,11 @@ class Comparator {
24390
24404
  yield* compareResHeader(this.#ajvCoerce, route, interaction, index, this.#config);
24391
24405
  yield* compareResBody(this.#ajvNocoerce, route, interaction, index, this.#config);
24392
24406
  }
24407
+ if (parsedPact.messages) {
24408
+ for (const [_message] of parsedPact.messages.entries()) {
24409
+ yield UNSUPPORTED_INTERACTION_WARNING;
24410
+ }
24411
+ }
24393
24412
  }
24394
24413
  }
24395
24414