@pactflow/openapi-pact-comparator 1.5.0 → 1.6.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
@@ -3671,6 +3671,15 @@ const convertExclusiveMinMax = (s) => {
3671
3671
  delete s.exclusiveMinimum;
3672
3672
  }
3673
3673
  };
3674
+ const cleanupDiscriminators = (s) => {
3675
+ // no-op from a validation perspective
3676
+ if (s.discriminator?.mapping) {
3677
+ delete s.discriminator.mapping;
3678
+ }
3679
+ if (s.discriminator && !s.oneOf) {
3680
+ delete s.discriminator;
3681
+ }
3682
+ };
3674
3683
  const minimumSchema = (originalSchema, oas) => {
3675
3684
  const refToAdd = [];
3676
3685
  const refAdded = [];
@@ -3678,10 +3687,6 @@ const minimumSchema = (originalSchema, oas) => {
3678
3687
  if (s.$ref && !refToAdd.includes(s.$ref) && !refAdded.includes(s.$ref)) {
3679
3688
  refToAdd.push(s.$ref);
3680
3689
  }
3681
- // no-op from a validation perspective
3682
- if (s.discriminator?.mapping) {
3683
- delete s.discriminator.mapping;
3684
- }
3685
3690
  };
3686
3691
  const handleNullableSchema = (s) => {
3687
3692
  if (s.$ref) {
@@ -3700,6 +3705,7 @@ const minimumSchema = (originalSchema, oas) => {
3700
3705
  const schema = cloneDeep(originalSchema);
3701
3706
  delete schema.description;
3702
3707
  delete schema.example;
3708
+ traverse(schema, cleanupDiscriminators);
3703
3709
  traverse(schema, collectReferences);
3704
3710
  traverse(schema, handleNullableSchema);
3705
3711
  traverse(schema, convertExclusiveMinMax);
@@ -3707,7 +3713,7 @@ const minimumSchema = (originalSchema, oas) => {
3707
3713
  const ref = refToAdd.shift();
3708
3714
  const path = splitPath(ref);
3709
3715
  refAdded.push(ref);
3710
- const subschema = cloneDeep(get$1(oas, path));
3716
+ const subschema = cloneDeep(get$1(oas, path, {}));
3711
3717
  delete subschema.description;
3712
3718
  delete subschema.example;
3713
3719
  traverse(subschema, collectReferences);
@@ -7621,9 +7627,9 @@ function* compareReqSecurity(ajv, route, interaction, index, config) {
7621
7627
  }
7622
7628
  for (const schemeName of Object.keys(scheme)) {
7623
7629
  const scheme = securitySchemes[schemeName];
7624
- switch (scheme?.type) {
7625
- case "apiKey":
7626
- switch (scheme.in) {
7630
+ switch (scheme?.type?.toLowerCase()) {
7631
+ case "apikey":
7632
+ switch (scheme.in.toLowerCase()) {
7627
7633
  case "header":
7628
7634
  if (requestHeaders.has(scheme.name)) {
7629
7635
  isSecured = true;
@@ -7718,7 +7724,7 @@ function* compareReqSecurity(ajv, route, interaction, index, config) {
7718
7724
  isValidSchema = requestHeaders.get("authorization") !== null;
7719
7725
  }
7720
7726
  else {
7721
- switch (scheme.scheme) {
7727
+ switch (scheme.scheme.toLowerCase()) {
7722
7728
  case "basic":
7723
7729
  isValidSchema = auth.toLowerCase().startsWith("basic ");
7724
7730
  break;
@@ -7750,9 +7756,9 @@ function* compareReqSecurity(ajv, route, interaction, index, config) {
7750
7756
  }
7751
7757
  break;
7752
7758
  }
7753
- case "mutualTLS":
7759
+ case "mutualtls":
7754
7760
  case "oauth2":
7755
- case "openIdConnect":
7761
+ case "openidconnect":
7756
7762
  // nothing can be validated, assume meets security requirements
7757
7763
  isSecured = true;
7758
7764
  break;
@@ -7765,6 +7771,8 @@ function* compareReqSecurity(ajv, route, interaction, index, config) {
7765
7771
  }
7766
7772
  }
7767
7773
 
7774
+ const patternedStatus = (status) => `${Math.floor(status / 100)}XX`;
7775
+
7768
7776
  const canValidate = (contentType = "") => {
7769
7777
  return !!findMatchingType(contentType, ["application/json"]);
7770
7778
  };
@@ -7774,9 +7782,9 @@ function* compareResBody(ajv, route, interaction, index, config) {
7774
7782
  const { body, status } = interaction.response;
7775
7783
  const requestHeaders = new Headers(interaction.request.headers);
7776
7784
  const statusResponse = operation.responses?.[status];
7777
- const defaultResponse = operation.responses
7778
- ?.default;
7779
- const response = statusResponse || defaultResponse;
7785
+ const patternedResponse = operation.responses?.[patternedStatus(status)];
7786
+ const defaultResponse = operation.responses?.["default"];
7787
+ const response = statusResponse || patternedResponse || defaultResponse;
7780
7788
  if (!response) {
7781
7789
  yield {
7782
7790
  code: "response.status.unknown",
@@ -7804,7 +7812,7 @@ function* compareResBody(ajv, route, interaction, index, config) {
7804
7812
  const schema = dereferencedResponse?.schema ||
7805
7813
  getByContentType(dereferencedResponse.content || {}, contentType)?.schema;
7806
7814
  const value = body;
7807
- if (!statusResponse) {
7815
+ if (!statusResponse && !patternedResponse) {
7808
7816
  yield {
7809
7817
  code: "response.status.default",
7810
7818
  message: `Response status code matched default response in spec file: ${status}`,
@@ -7871,7 +7879,9 @@ function* compareResBody(ajv, route, interaction, index, config) {
7871
7879
 
7872
7880
  function* compareResHeader(ajv, route, interaction, index, _config) {
7873
7881
  const { method, oas, operation, path } = route.store;
7874
- const response = operation.responses[interaction.response.status] ||
7882
+ const { status } = interaction.response;
7883
+ const response = operation.responses[status] ||
7884
+ operation.responses[patternedStatus(status)] ||
7875
7885
  operation.responses["default"];
7876
7886
  // no response found
7877
7887
  // -----------------