Skip to content

Commit 3729fce

Browse files
committed
update tests, explicitly check for old path when using model name mapping
1 parent 1c32b85 commit 3729fce

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

packages/server/src/api/rest/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,16 +276,21 @@ class RequestHandler extends APIHandlerBase {
276276
return this.modelNameMapping[modelName] ?? modelName;
277277
}
278278

279-
private matchUrlPattern(path: string, routeType: UrlPatterns): Match {
279+
private matchUrlPattern(path: string, routeType: UrlPatterns): Match | undefined {
280280
const pattern = this.urlPatternMap[routeType];
281281
if (!pattern) {
282282
throw new InvalidValueError(`Unknown route type: ${routeType}`);
283283
}
284284

285285
const match = pattern.match(path);
286-
if (match) {
287-
match.type = this.reverseModelNameMapping[match.type] ?? match.type;
286+
if (!match || match.type in Object.keys(this.modelNameMapping)) {
287+
return;
288+
}
289+
290+
if (match.type in this.reverseModelNameMapping) {
291+
match.type = this.reverseModelNameMapping[match.type];
288292
}
293+
289294
return match;
290295
}
291296

packages/server/tests/api/rest.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3038,8 +3038,8 @@ describe('REST server tests', () => {
30383038
const _handler = makeHandler({
30393039
endpoint: 'http://localhost/api',
30403040
modelNameMapping: {
3041-
myUser: 'user',
3042-
myPost: 'post',
3041+
user: 'myUser',
3042+
post: 'myPost',
30433043
},
30443044
});
30453045
handler = (args) =>

0 commit comments

Comments
 (0)