forked from block65/openapi-codegen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnullables.test.ts.snap
More file actions
126 lines (107 loc) · 4 KB
/
nullables.test.ts.snap
File metadata and controls
126 lines (107 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`const values 1`] = `
"export type StringConst = "hello";
export type NumberConst = 42;
export type BooleanConst = true;
export type NullConst = null;
"
`;
exports[`const values 2`] = `
"import * as v from "valibot";
export const stringConstSchema = v.literal("hello");
export const numberConstSchema = v.literal(42);
export const booleanConstSchema = v.literal(true);
export const nullConstSchema = v.null();
"
`;
exports[`header parameters 1`] = `
"export type UploadStatus = "pending" | "complete";
export type UploadDataCommandHeader = {
"content-type": "application/json" | "text/csv" | "application/xml";
"content-length": number;
"x-idempotency-key"?: string | undefined;
};
export type UploadDataCommandParams = {
uploadId: string;
};
export type UploadDataCommandInput = UploadDataCommandParams;
"
`;
exports[`header parameters 2`] = `
"import * as v from "valibot";
export const uploadStatusSchema = v.picklist(["pending", "complete"]);
export const uploadDataCommandParamsSchema = v.strictObject({
"uploadId": v.string()
});
export const uploadDataCommandHeaderSchema = v.object({
"content-type": v.picklist(["application/json", "text/csv", "application/xml"]),
"content-length": v.pipe(v.string(), v.digits(), v.transform((n) => Number.parseInt(n, 10)), v.number(), v.integer()),
"x-idempotency-key": v.exactOptional(v.pipe(v.string(), v.uuid()))
});
"
`;
exports[`header parameters 3`] = `
"import { validator } from "hono/validator";
import * as v from "valibot";
import { PublicValibotHonoError } from "@block65/rest-client";
import { uploadDataCommandParamsSchema } from "./valibot.js";
function toPublicValibotHonoError(err: unknown): never {
if (err instanceof v.ValiError) {
throw PublicValibotHonoError.from(err);
}
throw err;
}
export const uploadData = [
validator("param", (value) => {
return v.parseAsync(uploadDataCommandParamsSchema, value).catch(toPublicValibotHonoError);
}),
] as const;
"
`;
exports[`nullables 1`] = `
"export type MySchemaLolOrNullable = "lol" | "kek" | null;
"
`;
exports[`query and header integer params coerce strings to numbers 1`] = `
"export type Dummy = string;
export type ListFilesCommandQuery = {
exp: \`\${number}\`;
limit?: \`\${number}\` | undefined;
};
export type ListFilesCommandHeader = {
"x-rate-limit": number;
};
export type ListFilesCommandInput = ListFilesCommandQuery;
"
`;
exports[`query and header integer params coerce strings to numbers 2`] = `
"import * as v from "valibot";
export const dummySchema = v.string();
export const listFilesCommandQuerySchema = v.strictObject({
"exp": v.pipe(v.string(), v.digits(), v.transform((n) => Number.parseInt(n, 10)), v.number(), v.integer(), v.minValue(0)),
"limit": v.exactOptional(v.pipe(v.string(), v.digits(), v.transform((n) => Number.parseInt(n, 10)), v.number(), v.integer(), v.minValue(1), v.maxValue(100)))
});
export const listFilesCommandHeaderSchema = v.object({
"x-rate-limit": v.pipe(v.string(), v.digits(), v.transform((n) => Number.parseInt(n, 10)), v.number(), v.integer(), v.minValue(0))
});
"
`;
exports[`top-level type array with null 1`] = `
"export type NullableString = string | null;
export type NullableStringEnum = "active" | "inactive" | null;
export type NullableInteger = number | null;
export type MultiType = string | number;
"
`;
exports[`top-level type array with null 2`] = `
"import * as v from "valibot";
export const nullableStringSchema = v.nullable(v.string());
export const nullableStringEnumSchema = v.nullable(v.picklist(["active", "inactive"]));
export const nullableIntegerSchema = v.nullable(v.pipe(v.number(), v.integer()));
export const multiTypeSchema = v.union([v.string(), v.number()]);
"
`;
exports[`top-level type array with null 3`] = `
"export const nullableStringEnum = ["active", "inactive"] as const;
"
`;