@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/cli.cjs CHANGED
@@ -11835,6 +11835,15 @@ const convertExclusiveMinMax = (s) => {
11835
11835
  delete s.exclusiveMinimum;
11836
11836
  }
11837
11837
  };
11838
+ const cleanupDiscriminators = (s) => {
11839
+ // no-op from a validation perspective
11840
+ if (s.discriminator?.mapping) {
11841
+ delete s.discriminator.mapping;
11842
+ }
11843
+ if (s.discriminator && !s.oneOf) {
11844
+ delete s.discriminator;
11845
+ }
11846
+ };
11838
11847
  const minimumSchema = (originalSchema, oas) => {
11839
11848
  const refToAdd = [];
11840
11849
  const refAdded = [];
@@ -11842,10 +11851,6 @@ const minimumSchema = (originalSchema, oas) => {
11842
11851
  if (s.$ref && !refToAdd.includes(s.$ref) && !refAdded.includes(s.$ref)) {
11843
11852
  refToAdd.push(s.$ref);
11844
11853
  }
11845
- // no-op from a validation perspective
11846
- if (s.discriminator?.mapping) {
11847
- delete s.discriminator.mapping;
11848
- }
11849
11854
  };
11850
11855
  const handleNullableSchema = (s) => {
11851
11856
  if (s.$ref) {
@@ -11864,6 +11869,7 @@ const minimumSchema = (originalSchema, oas) => {
11864
11869
  const schema = cloneDeep(originalSchema);
11865
11870
  delete schema.description;
11866
11871
  delete schema.example;
11872
+ traverse(schema, cleanupDiscriminators);
11867
11873
  traverse(schema, collectReferences);
11868
11874
  traverse(schema, handleNullableSchema);
11869
11875
  traverse(schema, convertExclusiveMinMax);
@@ -11871,7 +11877,7 @@ const minimumSchema = (originalSchema, oas) => {
11871
11877
  const ref = refToAdd.shift();
11872
11878
  const path = splitPath(ref);
11873
11879
  refAdded.push(ref);
11874
- const subschema = cloneDeep(get$1(oas, path));
11880
+ const subschema = cloneDeep(get$1(oas, path, {}));
11875
11881
  delete subschema.description;
11876
11882
  delete subschema.example;
11877
11883
  traverse(subschema, collectReferences);
@@ -15779,9 +15785,9 @@ function* compareReqSecurity(ajv, route, interaction, index, config) {
15779
15785
  }
15780
15786
  for (const schemeName of Object.keys(scheme)) {
15781
15787
  const scheme = securitySchemes[schemeName];
15782
- switch (scheme?.type) {
15783
- case "apiKey":
15784
- switch (scheme.in) {
15788
+ switch (scheme?.type?.toLowerCase()) {
15789
+ case "apikey":
15790
+ switch (scheme.in.toLowerCase()) {
15785
15791
  case "header":
15786
15792
  if (requestHeaders.has(scheme.name)) {
15787
15793
  isSecured = true;
@@ -15876,7 +15882,7 @@ function* compareReqSecurity(ajv, route, interaction, index, config) {
15876
15882
  isValidSchema = requestHeaders.get("authorization") !== null;
15877
15883
  }
15878
15884
  else {
15879
- switch (scheme.scheme) {
15885
+ switch (scheme.scheme.toLowerCase()) {
15880
15886
  case "basic":
15881
15887
  isValidSchema = auth.toLowerCase().startsWith("basic ");
15882
15888
  break;
@@ -15908,9 +15914,9 @@ function* compareReqSecurity(ajv, route, interaction, index, config) {
15908
15914
  }
15909
15915
  break;
15910
15916
  }
15911
- case "mutualTLS":
15917
+ case "mutualtls":
15912
15918
  case "oauth2":
15913
- case "openIdConnect":
15919
+ case "openidconnect":
15914
15920
  // nothing can be validated, assume meets security requirements
15915
15921
  isSecured = true;
15916
15922
  break;
@@ -15923,6 +15929,8 @@ function* compareReqSecurity(ajv, route, interaction, index, config) {
15923
15929
  }
15924
15930
  }
15925
15931
 
15932
+ const patternedStatus = (status) => `${Math.floor(status / 100)}XX`;
15933
+
15926
15934
  const canValidate = (contentType = "") => {
15927
15935
  return !!findMatchingType(contentType, ["application/json"]);
15928
15936
  };
@@ -15932,9 +15940,9 @@ function* compareResBody(ajv, route, interaction, index, config) {
15932
15940
  const { body, status } = interaction.response;
15933
15941
  const requestHeaders = new Headers(interaction.request.headers);
15934
15942
  const statusResponse = operation.responses?.[status];
15935
- const defaultResponse = operation.responses
15936
- ?.default;
15937
- const response = statusResponse || defaultResponse;
15943
+ const patternedResponse = operation.responses?.[patternedStatus(status)];
15944
+ const defaultResponse = operation.responses?.["default"];
15945
+ const response = statusResponse || patternedResponse || defaultResponse;
15938
15946
  if (!response) {
15939
15947
  yield {
15940
15948
  code: "response.status.unknown",
@@ -15962,7 +15970,7 @@ function* compareResBody(ajv, route, interaction, index, config) {
15962
15970
  const schema = dereferencedResponse?.schema ||
15963
15971
  getByContentType(dereferencedResponse.content || {}, contentType)?.schema;
15964
15972
  const value = body;
15965
- if (!statusResponse) {
15973
+ if (!statusResponse && !patternedResponse) {
15966
15974
  yield {
15967
15975
  code: "response.status.default",
15968
15976
  message: `Response status code matched default response in spec file: ${status}`,
@@ -16029,7 +16037,9 @@ function* compareResBody(ajv, route, interaction, index, config) {
16029
16037
 
16030
16038
  function* compareResHeader(ajv, route, interaction, index, _config) {
16031
16039
  const { method, oas, operation, path } = route.store;
16032
- const response = operation.responses[interaction.response.status] ||
16040
+ const { status } = interaction.response;
16041
+ const response = operation.responses[status] ||
16042
+ operation.responses[patternedStatus(status)] ||
16033
16043
  operation.responses["default"];
16034
16044
  // no response found
16035
16045
  // -----------------
@@ -32047,7 +32057,7 @@ class Comparator {
32047
32057
  }
32048
32058
  }
32049
32059
 
32050
- var version = "1.5.0";
32060
+ var version = "1.6.0";
32051
32061
  var packageJson = {
32052
32062
  version: version};
32053
32063