@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.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);
|
|
@@ -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
|
|
7778
|
-
|
|
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
|
|
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
|
// -----------------
|