Skip to content

Commit 3e143a3

Browse files
committed
Add Reference type
1 parent a926f99 commit 3e143a3

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/jsonSchema.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
export interface Reference {
2+
$ref: string,
3+
}
4+
5+
export function isReference(schema: any): schema is Reference {
6+
return typeof schema.$ref === 'string';
7+
}
8+
19
export interface NullJsonSchema {
210
allOf?: Array<NullJsonSchema>,
311
anyOf?: Array<NullJsonSchema>,
@@ -326,7 +334,8 @@ export interface AnyJsonSchema {
326334
}
327335

328336
export function isAnyJsonSchema(schema: any): schema is AnyJsonSchema {
329-
return !isNullJsonSchema(schema)
337+
return !isReference(schema)
338+
&& !isNullJsonSchema(schema)
330339
&& !isBooleanJsonSchema(schema)
331340
&& !isStringJsonSchema(schema)
332341
&& !isNumberJsonSchema(schema)
@@ -335,4 +344,4 @@ export function isAnyJsonSchema(schema: any): schema is AnyJsonSchema {
335344
&& !isObjectJsonSchema(schema);
336345
}
337346

338-
export type JsonSchema = NullJsonSchema | BooleanJsonSchema | StringJsonSchema | NumberJsonSchema | IntegerJsonSchema | ArrayJsonSchema | ObjectJsonSchema | AnyJsonSchema;
347+
export type JsonSchema = Reference | NullJsonSchema | BooleanJsonSchema | StringJsonSchema | NumberJsonSchema | IntegerJsonSchema | ArrayJsonSchema | ObjectJsonSchema | AnyJsonSchema;

0 commit comments

Comments
 (0)