diff --git a/.changeset/khaki-flies-roll.md b/.changeset/khaki-flies-roll.md new file mode 100644 index 000000000..5759e147f --- /dev/null +++ b/.changeset/khaki-flies-roll.md @@ -0,0 +1,5 @@ +--- +"counterfact": minor +--- + +change path parameters from [this] to {this} for consistency with OpenAPI diff --git a/.github/workflows/coveralls.yaml b/.github/workflows/coveralls.yaml index f7bf1089c..951d9fdbe 100644 --- a/.github/workflows/coveralls.yaml +++ b/.github/workflows/coveralls.yaml @@ -1,4 +1,4 @@ -on: ["push", "pull_request"] +on: ["pull_request"] name: Coveralls diff --git a/src/registry.js b/src/registry.js index 6137bbeb1..d1705be20 100644 --- a/src/registry.js +++ b/src/registry.js @@ -57,7 +57,7 @@ export class Registry { matchedParts.push(segment); } else { const dynamicSegment = Object.keys(node.children).find( - (ds) => ds.startsWith("[") && ds.endsWith("]") + (ds) => ds.startsWith("{") && ds.endsWith("}") ); if (dynamicSegment) { diff --git a/test/dispatcher.test.js b/test/dispatcher.test.js index e12c633bc..4663e97c9 100644 --- a/test/dispatcher.test.js +++ b/test/dispatcher.test.js @@ -96,7 +96,7 @@ describe("a dispatcher", () => { it("passes a reducer function that can be used to read / update the store", async () => { const registry = new Registry({ value: 0 }); - registry.add("/increment/[value]", { + registry.add("/increment/{value}", { GET({ reduce, path }) { const amountToIncrement = Number.parseInt(path.value, 10); @@ -130,7 +130,7 @@ describe("a dispatcher", () => { it("allows the store to be mutated directly", async () => { const registry = new Registry({ value: 0 }); - registry.add("/increment/[value]", { + registry.add("/increment/{value}", { GET({ store, path }) { const amountToIncrement = Number.parseInt(path.value, 10); @@ -167,7 +167,7 @@ describe("given a in invalid path", () => { it("returns a 404 when the route is not found", () => { const registry = new Registry(); - registry.add("/your/[side]/[bodyPart]/in/and/your/left/foot/out", { + registry.add("/your/{side}/{bodyPart}/in/and/your/left/foot/out", { PUT() { return { status: 201, @@ -186,7 +186,7 @@ describe("given a in invalid path", () => { expect(response.body).toBe( "Could not find a PUT method at " + "/your/left/foot/in/and/your/right/foot/out\n" + - "Got as far as /your/[side]/[bodyPart]/in/and/your" + "Got as far as /your/{side}/{bodyPart}/in/and/your" ); }); }); diff --git a/test/registry.test.js b/test/registry.test.js index c70c78062..4bbee556b 100644 --- a/test/registry.test.js +++ b/test/registry.test.js @@ -88,7 +88,7 @@ describe("a scripted server", () => { it("handles a dynamic path", () => { const registry = new Registry(); - registry.add("/[organization]/users/[username]/friends/[page]", { + registry.add("/{organization}/users/{username}/friends/{page}", { GET({ path }) { return { body: `page ${path.page} of ${path.username}'s friends in ${path.organization}`,