Skip to content

Commit 5bc08d6

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

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,16 +276,27 @@ 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) {
287+
return;
288+
}
289+
290+
if (match.type in this.modelNameMapping) {
291+
throw new InvalidValueError(
292+
`use the mapped model name: ${this.modelNameMapping[match.type]} and not ${match.type}`
293+
);
288294
}
295+
296+
if (match.type in this.reverseModelNameMapping) {
297+
match.type = this.reverseModelNameMapping[match.type];
298+
}
299+
289300
return match;
290301
}
291302

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)