feat: set required field when a request body is present

This commit is contained in:
hagishi
2024-04-05 10:02:13 +09:00
parent ca692c417a
commit eafe5d5ee6
2 changed files with 13 additions and 0 deletions

View File

@@ -156,4 +156,16 @@ describe('Swagger', () => {
response.paths['/null'].get.responses['204'].content
).toBeUndefined()
})
it("should set the required field to true when a request body is present", async () => {
const app = new Elysia().use(swagger()).post("/post", () => {}, {
body: t.Object({ name: t.String() }),
});
const res = await app.handle(req("/swagger/json"));
expect(res.status).toBe(200);
const response = await res.json();
expect(response.paths['/post'].post.requestBody.required).toBe(true);
})
})