Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cc339e5246 |
@@ -61,12 +61,19 @@ const parserSchema = (
|
|||||||
return schema instanceof z.ZodObject ? schema : undefined;
|
return schema instanceof z.ZodObject ? schema : undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reject a key only when an object parse that omits it fails.
|
||||||
|
* `exactOptional()` rejects explicit `undefined` and still accepts omission.
|
||||||
|
*/
|
||||||
const omissionRejected = (schema: z.ZodObject | undefined): string[] =>
|
const omissionRejected = (schema: z.ZodObject | undefined): string[] =>
|
||||||
Object.entries(schema?.shape ?? {})
|
Object.entries(schema?.shape ?? {})
|
||||||
.filter(([, field]) => !field.safeParse(undefined).success)
|
.filter(([key, field]) => !acceptsOmittedKey(key, field))
|
||||||
.map(([key]) => key)
|
.map(([key]) => key)
|
||||||
.sort();
|
.sort();
|
||||||
|
|
||||||
|
const acceptsOmittedKey = (key: string, field: z.ZodType): boolean =>
|
||||||
|
z.object({ [key]: field }).safeParse({}).success;
|
||||||
|
|
||||||
describe("CLI advertised input schemas", () => {
|
describe("CLI advertised input schemas", () => {
|
||||||
it("require exactly the inputs whose omission the parser rejects", async () => {
|
it("require exactly the inputs whose omission the parser rejects", async () => {
|
||||||
const cli = createCli({});
|
const cli = createCli({});
|
||||||
|
|||||||
Reference in new issue
Block a user