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
7 changes: 7 additions & 0 deletions __tests__/__snapshots__/nullables.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ exports[`nullables 1`] = `
"
`;

exports[`oneOf with type null generates v.null() 1`] = `
"import * as v from "valibot";

export const nullableImageSchema = v.union([v.string(), v.null()]);
"
`;

exports[`query and header integer params coerce strings to numbers 1`] = `
"export type Dummy = string;
export type ExpireTime = number;
Expand Down
20 changes: 20 additions & 0 deletions __tests__/nullables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,26 @@ test("const values", async () => {
expect(result.valibotFile?.getText()).toMatchSnapshot();
});

test("oneOf with type null generates v.null()", async () => {
const result = await processOpenApiDocument(
"/tmp/like-you-know-whatever",
{
openapi: "3.1.0",
info: { title: "Test", version: "1.0.0" },
paths: {},
components: {
schemas: {
NullableImage: {
oneOf: [{ type: "string", format: "uri" }, { type: "null" }],
},
},
},
},
);

expect(result.valibotFile.getText()).toMatchSnapshot();
});

test("query and header integer params coerce strings to numbers", async () => {
const schema: oas31.OpenAPIObject = {
openapi: "3.1.0",
Expand Down
4 changes: 4 additions & 0 deletions lib/valibot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ export function schemaToValidator(
return maybeNullable(vcall("strictObject", strictObjectWriter), isNullable);
}

if (schema.type === "null") {
return vcall("null");
}

return vcall("unknown");
}

Expand Down
Loading