Skip to content

Commit 3646b36

Browse files
committed
Fix: avoid double raw check in Documentation, cherry-picked 8d4b9d3.
1 parent 76c03e3 commit 3646b36

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

express-zod-api/src/documentation-helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
import { InputSource } from "./config-type";
3232
import { DateInSchema, ezDateInBrand } from "./date-in-schema";
3333
import { DateOutSchema, ezDateOutBrand } from "./date-out-schema";
34-
import { hasRaw } from "./deep-checks";
34+
import { contentTypes } from "./content-type";
3535
import { DocumentationError } from "./errors";
3636
import { FileSchema, ezFileBrand } from "./file-schema";
3737
import { extractObjectSchema, IOSchema } from "./io-schema";
@@ -923,7 +923,7 @@ export const depictBody = ({
923923
description,
924924
content: { [mimeType]: media },
925925
};
926-
if (hasRequired || hasRaw(schema)) body.required = true;
926+
if (hasRequired || mimeType === contentTypes.raw) body.required = true;
927927
return body;
928928
};
929929

express-zod-api/tests/documentation-helpers.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import {
4949
onEach,
5050
onMissing,
5151
reformatParamsInPath,
52+
depictBody,
5253
} from "../src/documentation-helpers";
5354
import { walkSchema } from "../src/schema-walker";
5455

@@ -731,6 +732,19 @@ describe("Documentation helpers", () => {
731732
});
732733
});
733734

735+
describe("depictBody", () => {
736+
test("should mark ez.raw() body as required", () => {
737+
const body = depictBody({
738+
...requestCtx,
739+
schema: ez.raw(),
740+
composition: "inline",
741+
mimeType: "application/octet-stream", // raw content type
742+
paramNames: [],
743+
});
744+
expect(body.required).toBe(true);
745+
});
746+
});
747+
734748
describe("depictDateIn", () => {
735749
test("should set type:string, pattern and format", () => {
736750
expect(depictDateIn(ez.dateIn(), requestCtx)).toMatchSnapshot();

0 commit comments

Comments
 (0)