Skip to content

Commit 3a9a0f4

Browse files
Merge pull request #883 from BitGo/DX-704
docs: add comments to unchecked routes
2 parents 19c4c76 + cae13b5 commit 3a9a0f4

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

packages/typed-express-router/src/types.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,84 @@ export type WrappedRouter<Spec extends ApiSpec> = Omit<
123123
put: AddRouteHandler<Spec, 'put'>;
124124
delete: AddRouteHandler<Spec, 'delete'>;
125125
patch: AddRouteHandler<Spec, 'patch'>;
126+
/**
127+
* This function will create a GET route without validating the request, or encoding the response body.
128+
* However, it will still try decode the request and set `req.decoded: Either<DecodedRequest, Error>`. To see the
129+
* result of this operation, you can check `req.decoded` in your route handler like this:
130+
*
131+
* ```typescript
132+
* import * as E from 'fp-ts/Either';
133+
*
134+
* if (E.isLeft(req.decoded)) {
135+
* // input validation failed
136+
* } else {
137+
* // input validation succeeded
138+
* }
139+
* ```
140+
*/
126141
getUnchecked: AddUncheckedRouteHandler<Spec, 'get'>;
142+
/**
143+
* This function will create a POST route without validating the request body, or encoding the response body.
144+
* However, it will still try decode the request and set `req.decoded: Either<DecodedRequest, Error>`. To see the
145+
* result of this operation, you can check `req.decoded` in your route handler like this:
146+
*
147+
* ```typescript
148+
* import * as E from 'fp-ts/Either';
149+
*
150+
* if (E.isLeft(req.decoded)) {
151+
* // input validation failed
152+
* } else {
153+
* // input validation succeeded
154+
* }
155+
* ```
156+
*/
127157
postUnchecked: AddUncheckedRouteHandler<Spec, 'post'>;
158+
/**
159+
* This function will create a PUT route without validating the request, or encoding the response body.
160+
* However, it will still try decode the request and set `req.decoded: Either<DecodedRequest, Error>`. To see the
161+
* result of this operation, you can check `req.decoded` in your route handler like this:
162+
*
163+
* ```typescript
164+
* import * as E from 'fp-ts/Either';
165+
*
166+
* if (E.isLeft(req.decoded)) {
167+
* // input validation failed
168+
* } else {
169+
* // input validation succeeded
170+
* }
171+
* ```
172+
*/
128173
putUnchecked: AddUncheckedRouteHandler<Spec, 'put'>;
174+
/**
175+
* This function will create a DELETE route without validating the request, or encoding the response body.
176+
* However, it will still try decode the request and set `req.decoded: Either<DecodedRequest, Error>`. To see the
177+
* result of this operation, you can check `req.decoded` in your route handler like this:
178+
*
179+
* ```typescript
180+
* import * as E from 'fp-ts/Either';
181+
*
182+
* if (E.isLeft(req.decoded)) {
183+
* // input validation failed
184+
* } else {
185+
* // input validation succeeded
186+
* }
187+
* ```
188+
*/
129189
deleteUnchecked: AddUncheckedRouteHandler<Spec, 'delete'>;
190+
/**
191+
* This function will create a PATCH route without validating the request, or encoding the response body.
192+
* However, it will still try decode the request and set `req.decoded: Either<DecodedRequest, Error>`. To see the
193+
* result of this operation, you can check `req.decoded` in your route handler like this:
194+
*
195+
* ```typescript
196+
* import * as E from 'fp-ts/Either';
197+
*
198+
* if (E.isLeft(req.decoded)) {
199+
* // input validation failed
200+
* } else {
201+
* // input validation succeeded
202+
* }
203+
* ```
204+
*/
130205
patchUnchecked: AddUncheckedRouteHandler<Spec, 'patch'>;
131206
};

packages/typed-express-router/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"extends": "../../tsconfig.json",
33
"include": ["src/**/*", "test/**/*"],
44
"compilerOptions": {
5-
"outDir": "./dist"
5+
"outDir": "./dist",
6+
"removeComments": false
67
},
78
"references": [
89
{

0 commit comments

Comments
 (0)