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