-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from bitgopatmcl/consistent-path-parameters
fix: use consistent format for path parameters between server and client
- Loading branch information
Showing
4 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Converts an io-ts-http path to an express one | ||
// assumes that only simple path parameters are present and the wildcard features in express | ||
// arent used. | ||
|
||
const PATH_PARAM = /{(\w+)}/g; | ||
|
||
export const apiTsPathToExpress = (inputPath: string) => | ||
inputPath.replace(PATH_PARAM, ':$1'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import test from 'ava'; | ||
|
||
import { apiTsPathToExpress } from '../src/path'; | ||
|
||
test('should pass through paths with no parameters', (t) => { | ||
const input = '/foo/bar'; | ||
const output = apiTsPathToExpress(input); | ||
t.deepEqual(output, input); | ||
}); | ||
|
||
test('should translate a path segment that specifies a parameter', (t) => { | ||
const input = '/foo/{bar}'; | ||
const output = apiTsPathToExpress(input); | ||
t.deepEqual(output, '/foo/:bar'); | ||
}); | ||
|
||
test('should translate multiple path segments', (t) => { | ||
const input = '/foo/{bar}/baz/{id}'; | ||
const output = apiTsPathToExpress(input); | ||
t.deepEqual(output, '/foo/:bar/baz/:id'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters