Skip to content

Commit 55d3c7a

Browse files
Add tests
1 parent 7159e66 commit 55d3c7a

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

packages/plugins/openapi/tests/openapi-restful.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,15 @@ model Bar {
108108
expect(api.paths?.['/user/{id}/relationships/posts']?.['get']).toBeTruthy();
109109
expect(api.paths?.['/user/{id}/relationships/posts']?.['post']).toBeTruthy();
110110
expect(api.paths?.['/user/{id}/relationships/posts']?.['patch']).toBeTruthy();
111+
expect(api.paths?.['/user/{id}/relationships/likes']?.['get']).toBeTruthy();
112+
expect(api.paths?.['/user/{id}/relationships/likes']?.['post']).toBeTruthy();
113+
expect(api.paths?.['/user/{id}/relationships/likes']?.['patch']).toBeTruthy();
111114
expect(api.paths?.['/post_Item/{id}/relationships/author']?.['get']).toBeTruthy();
112115
expect(api.paths?.['/post_Item/{id}/relationships/author']?.['post']).toBeUndefined();
113116
expect(api.paths?.['/post_Item/{id}/relationships/author']?.['patch']).toBeTruthy();
117+
expect(api.paths?.['/post_Item/{id}/relationships/likes']?.['get']).toBeTruthy();
118+
expect(api.paths?.['/post_Item/{id}/relationships/likes']?.['post']).toBeTruthy();
119+
expect(api.paths?.['/post_Item/{id}/relationships/likes']?.['patch']).toBeTruthy();
114120
expect(api.paths?.['/foo']).toBeUndefined();
115121
expect(api.paths?.['/bar']).toBeUndefined();
116122

@@ -333,6 +339,37 @@ model Foo {
333339
expect(parsed).toMatchObject(baseline);
334340
}
335341
});
342+
343+
it('exposes individual fields from a compound id as attributes', async () => {
344+
const { model, dmmf, modelFile } = await loadZModelAndDmmf(`
345+
plugin openapi {
346+
provider = '${normalizePath(path.resolve(__dirname, '../dist'))}'
347+
}
348+
349+
model User {
350+
email String
351+
role String
352+
company String
353+
@@id([role, company])
354+
}
355+
`);
356+
357+
const { name: output } = tmp.fileSync({ postfix: '.yaml' });
358+
359+
const options = buildOptions(model, modelFile, output, '3.1.0');
360+
await generate(model, options, dmmf);
361+
362+
await OpenAPIParser.validate(output);
363+
364+
const parsed = YAML.parse(fs.readFileSync(output, 'utf-8'));
365+
expect(parsed.openapi).toBe('3.1.0');
366+
367+
expect(Object.keys(parsed.components.schemas.User.properties.attributes.properties)).toEqual(
368+
expect.arrayContaining(['role', 'company'])
369+
);
370+
371+
console.log(JSON.stringify(parsed));
372+
});
336373
});
337374

338375
function buildOptions(model: Model, modelFile: string, output: string, specVersion = '3.0.0') {

0 commit comments

Comments
 (0)