Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion packages/plugins/openapi/tests/openapi-restful.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ model Bar {
}
});

it('options', async () => {
it('common options', async () => {
const { model, dmmf, modelFile } = await loadZModelAndDmmf(`
plugin openapi {
provider = '${normalizePath(path.resolve(__dirname, '../dist'))}'
Expand Down Expand Up @@ -396,6 +396,39 @@ model User {
expect.arrayContaining(['role', 'company'])
);
});

it('works with mapped model name', async () => {
const { model, dmmf, modelFile } = await loadZModelAndDmmf(`
plugin openapi {
provider = '${normalizePath(path.resolve(__dirname, '../dist'))}'
title = 'My Awesome API'
prefix = '/api'
modelNameMapping = {
User: 'myUser'
}
}

model User {
id String @id
posts Post[]
}

model Post {
id String @id
author User @relation(fields: [authorId], references: [id])
authorId String
}
`);

const { name: output } = tmp.fileSync({ postfix: '.yaml' });
const options = buildOptions(model, modelFile, output);
await generate(model, options, dmmf);
console.log('OpenAPI specification generated:', output);
const api = await OpenAPIParser.validate(output);
expect(api.paths?.['/api/myUser']).toBeTruthy();
expect(api.paths?.['/api/user']).toBeFalsy();
expect(api.paths?.['/api/post']).toBeTruthy();
});
});

function buildOptions(model: Model, modelFile: string, output: string, specVersion = '3.0.0') {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/tests/api/rest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3038,7 +3038,7 @@ describe('REST server tests', () => {
const _handler = makeHandler({
endpoint: 'http://localhost/api',
modelNameMapping: {
user: 'myUser',
User: 'myUser',
},
});
handler = (args) =>
Expand Down
Loading