Skip to content

Commit

Permalink
Merge 5cad3f7 into e532d01
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcelhaney committed Jun 29, 2022
2 parents e532d01 + 5cad3f7 commit a5e2afe
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/khaki-flies-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"counterfact": minor
---

change path parameters from [this] to {this} for consistency with OpenAPI
2 changes: 1 addition & 1 deletion .github/workflows/coveralls.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
on: ["push", "pull_request"]
on: ["pull_request"]

name: Coveralls

Expand Down
2 changes: 1 addition & 1 deletion src/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions test/dispatcher.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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,
Expand All @@ -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"
);
});
});
2 changes: 1 addition & 1 deletion test/registry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down

0 comments on commit a5e2afe

Please sign in to comment.