Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"@vitest/coverage-v8": "3.0.8",
"ajv": "8.17.1",
"ajv-formats": "3.0.1",
"any-ascii": "0.3.2",
"eslint": "9.22.0",
"eslint-config-prettier": "10.1.1",
"find-my-way": "9.2.0",
Expand Down
62 changes: 51 additions & 11 deletions src/__tests__/fixtures/request-parameters-query/opc-results.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,53 @@
},
"type": "error"
},
{
"code": "request.query.unknown",
"message": "Query parameter is not defined in the spec file: unicode",
"mockDetails": {
"interactionDescription": "should handle queries with unicode characters",
"interactionState": "[none]",
"location": "[root].interactions[5].request.query.unicode",
"value": "푟Ꝫ띡ⴵ"
},
"specDetails": {
"location": "[root].paths./string.get",
"pathMethod": "get",
"pathName": "/string",
"value": {
"parameters": [
{
"in": "query",
"name": "name",
"required": true,
"schema": {
"type": "string"
}
},
{
"in": "query",
"name": "age",
"schema": {
"type": "number"
}
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"type": "warning"
},
{
"code": "request.query.incompatible",
"message": "Value is incompatible with the parameter defined in the spec file: must be string",
"mockDetails": {
"interactionDescription": "should error when missing parameter using common parameters",
"interactionState": "[none]",
"location": "[root].interactions[7].request.query.local"
"location": "[root].interactions[8].request.query.local"
},
"specDetails": {
"location": "[root].paths./common-parameters.get.parameters[0].schema.type",
Expand All @@ -38,7 +78,7 @@
"mockDetails": {
"interactionDescription": "should error when missing parameter using common parameters",
"interactionState": "[none]",
"location": "[root].interactions[7].request.query.common"
"location": "[root].interactions[8].request.query.common"
},
"specDetails": {
"location": "[root].paths./common-parameters.get.parameters[1].schema.type",
Expand All @@ -54,7 +94,7 @@
"mockDetails": {
"interactionDescription": "should error when using common parameters that has been overridden",
"interactionState": "[none]",
"location": "[root].interactions[8].request.query.common",
"location": "[root].interactions[9].request.query.common",
"value": "string"
},
"specDetails": {
Expand All @@ -71,7 +111,7 @@
"mockDetails": {
"interactionDescription": "should error when exploded query parameter in object form does not match spec",
"interactionState": "[none]",
"location": "[root].interactions[9].request.query.id.2",
"location": "[root].interactions[10].request.query.id.2",
"value": "abc"
},
"specDetails": {
Expand All @@ -88,7 +128,7 @@
"mockDetails": {
"interactionDescription": "should error when exploded query parameter in string form does not match spec",
"interactionState": "[none]",
"location": "[root].interactions[10].request.query.id.2",
"location": "[root].interactions[11].request.query.id.2",
"value": "abc"
},
"specDetails": {
Expand All @@ -105,7 +145,7 @@
"mockDetails": {
"interactionDescription": "should error when non-exploded query parameter in object form does not match spec",
"interactionState": "[none]",
"location": "[root].interactions[11].request.query.id.2",
"location": "[root].interactions[12].request.query.id.2",
"value": "abc"
},
"specDetails": {
Expand All @@ -122,7 +162,7 @@
"mockDetails": {
"interactionDescription": "should error when non-exploded query parameter in string form does not match spec",
"interactionState": "[none]",
"location": "[root].interactions[12].request.query.id.2",
"location": "[root].interactions[13].request.query.id.2",
"value": "abc"
},
"specDetails": {
Expand All @@ -139,7 +179,7 @@
"mockDetails": {
"interactionDescription": "should warn about unknown query parameters",
"interactionState": "[none]",
"location": "[root].interactions[13].request.query.unknown_key",
"location": "[root].interactions[14].request.query.unknown_key",
"value": "unknown_value"
},
"specDetails": {
Expand Down Expand Up @@ -179,7 +219,7 @@
"mockDetails": {
"interactionDescription": "should error when optional query parameter is incompatible",
"interactionState": "[none]",
"location": "[root].interactions[14].request.query.age",
"location": "[root].interactions[15].request.query.age",
"value": "abc"
},
"specDetails": {
Expand All @@ -196,7 +236,7 @@
"mockDetails": {
"interactionDescription": "should error when missing required query parameter",
"interactionState": "[none]",
"location": "[root].interactions[15].request.query.name"
"location": "[root].interactions[16].request.query.name"
},
"specDetails": {
"location": "[root].paths./string.get.parameters[0].schema.type",
Expand All @@ -212,7 +252,7 @@
"mockDetails": {
"interactionDescription": "should parse arrays, but not with strings",
"interactionState": "[none]",
"location": "[root].interactions[16].request.query.string",
"location": "[root].interactions[17].request.query.string",
"value": "first,second"
},
"specDetails": {
Expand Down
19 changes: 19 additions & 0 deletions src/__tests__/fixtures/request-parameters-query/pact.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
"consumer": { "name": "consumer" },
"provider": { "name": "provider" },
"metadata": {
"pactSpecification": {
"version": "4.0"
}
},
"interactions": [
{
"description": "should pass for query in object form",
Expand Down Expand Up @@ -67,6 +72,20 @@
"status": 200
}
},
{
"description": "should handle queries with unicode characters",
"request": {
"method": "GET",
"path": "/string",
"query": {
"unicode": ["푟Ꝫ띡ⴵ"],
"name": ["mark"]
}
},
"response": {
"status": 200
}
},
{
"description": "should pass when using common parameters",
"request": {
Expand Down
52 changes: 46 additions & 6 deletions src/__tests__/fixtures/request-parameters-query/smv-results.json
Original file line number Diff line number Diff line change
Expand Up @@ -1051,13 +1051,53 @@
},
"type": "error"
},
{
"code": "request.query.unknown",
"message": "Query parameter is not defined in the spec file: unicode",
"mockDetails": {
"interactionDescription": "should handle queries with unicode characters",
"interactionState": "[none]",
"location": "[root].interactions[5].request.query.unicode",
"value": "푟Ꝫ띡ⴵ"
},
"specDetails": {
"location": "[root].paths./string.get",
"pathMethod": "get",
"pathName": "/string",
"value": {
"parameters": [
{
"in": "query",
"name": "name",
"required": true,
"schema": {
"type": "string"
}
},
{
"in": "query",
"name": "age",
"schema": {
"type": "number"
}
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"type": "warning"
},
{
"code": "request.query.incompatible",
"message": "Value is incompatible with the parameter defined in the spec file: must have required property 'value'",
"mockDetails": {
"interactionDescription": "should error when missing parameter using common parameters",
"interactionState": "[none]",
"location": "[root].interactions[7]",
"location": "[root].interactions[8]",
"value": {
"description": "should error when missing parameter using common parameters",
"request": {
Expand Down Expand Up @@ -1090,7 +1130,7 @@
"mockDetails": {
"interactionDescription": "should error when missing parameter using common parameters",
"interactionState": "[none]",
"location": "[root].interactions[7]",
"location": "[root].interactions[8]",
"value": {
"description": "should error when missing parameter using common parameters",
"request": {
Expand Down Expand Up @@ -1123,7 +1163,7 @@
"mockDetails": {
"interactionDescription": "should error when using common parameters that has been overridden",
"interactionState": "[none]",
"location": "[root].interactions[8].request.query.common",
"location": "[root].interactions[9].request.query.common",
"value": "string"
},
"specDetails": {
Expand All @@ -1147,7 +1187,7 @@
"mockDetails": {
"interactionDescription": "should warn about unknown query parameters",
"interactionState": "[none]",
"location": "[root].interactions[13].request.query.unknown_key",
"location": "[root].interactions[14].request.query.unknown_key",
"value": "unknown_value"
},
"specDetails": {
Expand Down Expand Up @@ -1187,7 +1227,7 @@
"mockDetails": {
"interactionDescription": "should error when optional query parameter is incompatible",
"interactionState": "[none]",
"location": "[root].interactions[14].request.query.age",
"location": "[root].interactions[15].request.query.age",
"value": "abc"
},
"specDetails": {
Expand All @@ -1210,7 +1250,7 @@
"mockDetails": {
"interactionDescription": "should error when missing required query parameter",
"interactionState": "[none]",
"location": "[root].interactions[15]",
"location": "[root].interactions[16]",
"value": {
"description": "should error when missing required query parameter",
"request": {
Expand Down
3 changes: 1 addition & 2 deletions src/documents/pact.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Static, Type } from "@sinclair/typebox";
import Ajv, { ErrorObject } from "ajv";
import anyAscii from "any-ascii";

// a full schema can be found at https://github.com/pactflow/pact-schemas
// but we don't use that here, because we try to be permissive with input
Expand Down Expand Up @@ -92,7 +91,7 @@ const parseAsPactV4Body = (body: unknown) => {
}
};

const cleanString = (s: string) => anyAscii(s).replaceAll(/[\r\n\0]/g, "");
const cleanString = (s: string) => s.replaceAll(/[\r\n\0]/g, "");

const flattenValues = (
values?: null | string | Record<string, string | string[]>,
Expand Down
2 changes: 1 addition & 1 deletion src/transform/requestSchema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SchemaObject } from "ajv";
import { each } from "lodash-es";
import { traverseWithDereferencing as traverse } from "../utils/schema";
import { traverseWithDereferencing as traverse } from "#utils/schema";

export const transformRequestSchema = (schema: SchemaObject): SchemaObject => {
// OpenAPI defines allOf to mean the union of all sub-schemas. JSON-Schema
Expand Down