@pactflow/openapi-pact-comparator 1.5.1 → 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 +20 -10
- package/dist/cli.cjs.map +1 -1
- package/dist/index.cjs +19 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +19 -9
- package/dist/index.mjs.map +1 -1
- package/dist/src/compare/utils/statusCodes.d.ts +1 -0
- package/package.json +5 -5
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);
|
|
@@ -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
|
|
7776
|
-
|
|
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
|
|
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
|
// -----------------
|