-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimise Optional Determining Logic (#352)
- Loading branch information
Showing
13 changed files
with
359 additions
and
423 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,31 @@ | ||
import type { ZodCatch, ZodTypeAny } from 'zod'; | ||
|
||
import type { oas31 } from '../../../../dist'; | ||
import { | ||
type Schema, | ||
type SchemaState, | ||
createSchemaObject, | ||
} from '../../schema'; | ||
import { enhanceWithMetadata } from '../metadata'; | ||
|
||
export const createCatchSchema = <T extends ZodTypeAny>( | ||
zodCatch: ZodCatch<T>, | ||
state: SchemaState, | ||
): Schema => createSchemaObject(zodCatch._def.innerType, state, ['catch']); | ||
): Schema => { | ||
const schemaObject = createSchemaObject(zodCatch._def.innerType, state, [ | ||
'default', | ||
]); | ||
|
||
const catchResult = zodCatch.safeParse(undefined); | ||
|
||
const maybeDefaultValue: Pick<oas31.SchemaObject, 'default'> | undefined = | ||
catchResult.success | ||
? { | ||
default: catchResult.data, | ||
} | ||
: undefined; | ||
|
||
return enhanceWithMetadata(schemaObject, { | ||
...maybeDefaultValue, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.