From 307ec79ad4a09a4f03cf2f864b3a3464e74c56e5 Mon Sep 17 00:00:00 2001 From: Alexandre Date: Tue, 23 Apr 2024 18:32:35 +0200 Subject: [PATCH] required request body by default (#543) --- .changeset/angry-windows-fold.md | 5 +++ packages/effect-http/src/internal/open-api.ts | 2 +- packages/effect-http/test/openapi.test.ts | 33 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 .changeset/angry-windows-fold.md diff --git a/.changeset/angry-windows-fold.md b/.changeset/angry-windows-fold.md new file mode 100644 index 000000000..4183e5e9f --- /dev/null +++ b/.changeset/angry-windows-fold.md @@ -0,0 +1,5 @@ +--- +"effect-http": patch +--- + +Request body should be required by default diff --git a/packages/effect-http/src/internal/open-api.ts b/packages/effect-http/src/internal/open-api.ts index b7677e644..833094b52 100644 --- a/packages/effect-http/src/internal/open-api.ts +++ b/packages/effect-http/src/internal/open-api.ts @@ -69,7 +69,7 @@ export const make = ( } if (!ApiSchema.isIgnored(body)) { - operationSpec.push(OpenApi.jsonRequest(body, descriptionSetter(body))) + operationSpec.push(OpenApi.jsonRequest(body, OpenApi.required, descriptionSetter(body))) } const securityResult = pipe( diff --git a/packages/effect-http/test/openapi.test.ts b/packages/effect-http/test/openapi.test.ts index d43c5be01..302d42071 100644 --- a/packages/effect-http/test/openapi.test.ts +++ b/packages/effect-http/test/openapi.test.ts @@ -204,6 +204,39 @@ test("group info", () => { }) }) +test("request body", () => { + const api = pipe( + Api.make(), + Api.addEndpoint( + Api.post("myOperation", "/my-operation").pipe( + Api.setRequestBody(Schema.Struct({ a: Schema.String })) + ) + ) + ) + + const openApi = OpenApi.make(api) + + expect(openApi.paths["/my-operation"].post?.requestBody).toEqual({ + content: { + "application/json": { + schema: { + properties: { + a: { + "description": "a string", + "type": "string" + } + }, + required: [ + "a" + ], + type: "object" + } + } + }, + required: true + }) +}) + test("union in query params", () => { const api = pipe( Api.make(),