Skip to content

Commit f88959f

Browse files
committed
Fix ifThen ifThenElse and required types #34
1 parent 7357913 commit f88959f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/FluentSchema.d.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ export interface BaseSchema<T> {
77
enum: (values: Array<any>) => T
88
const: (value: any) => T
99
default: (value: any) => T
10-
required: () => T
10+
required: (fields?: string[]) => T
11+
ifThen: (ifClause: JSONSchema, thenClause: JSONSchema) => T
12+
ifThenElse: (
13+
ifClause: JSONSchema,
14+
thenClause: JSONSchema,
15+
elseClause: JSONSchema
16+
) => T
1117
not: (schema: JSONSchema) => T
1218
anyOf: (schema: Array<JSONSchema>) => T
1319
allOf: (schema: Array<JSONSchema>) => T
@@ -58,7 +64,7 @@ export interface StringSchema extends BaseSchema<StringSchema> {
5864
minLength: (min: number) => StringSchema
5965
maxLength: (min: number) => StringSchema
6066
format: (format: FORMATS) => StringSchema
61-
pattern: (pattern: string) => StringSchema
67+
pattern: (pattern: string | RegExp) => StringSchema
6268
contentEncoding: (encoding: string) => StringSchema
6369
contentMediaType: (mediaType: string) => StringSchema
6470
}

src/types/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ const schema = S.object()
4747
)
4848
.required()
4949
.prop('age', S.mixed<NumberSchema & StringSchema>(['string', 'integer']))
50+
.ifThen(S.object().prop('age', S.string()), S.required(['age']))
5051

5152
.valueOf()
5253

53-
console.log({ schema })
54+
console.log(JSON.stringify(schema))

0 commit comments

Comments
 (0)