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