Migrate to draft-06 json-schema
parent
15f4d9459d
commit
44e36854f3
|
@ -6,7 +6,7 @@ import type {Type, NumberType} from '../types';
|
||||||
|
|
||||||
export type SchemaType = 'object' | 'array' | 'boolean' | 'integer' | 'number' | 'string' | 'null';
|
export type SchemaType = 'object' | 'array' | 'boolean' | 'integer' | 'number' | 'string' | 'null';
|
||||||
|
|
||||||
export type Schema = {
|
export type Schema = boolean | {
|
||||||
id?: string,
|
id?: string,
|
||||||
$ref?: string,
|
$ref?: string,
|
||||||
$schema?: string,
|
$schema?: string,
|
||||||
|
@ -60,16 +60,14 @@ function convert(fund: Fund, type: ?Type): Schema {
|
||||||
.pluck('name')
|
.pluck('name')
|
||||||
.toArray();
|
.toArray();
|
||||||
|
|
||||||
const schema: Schema = {
|
return required.length > 0 ? {
|
||||||
|
type: 'object',
|
||||||
|
properties,
|
||||||
|
required,
|
||||||
|
} : {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties,
|
properties,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (required.length > 0) {
|
|
||||||
schema.required = required;
|
|
||||||
}
|
|
||||||
|
|
||||||
return schema;
|
|
||||||
case 'array':
|
case 'array':
|
||||||
return {
|
return {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
|
@ -82,6 +80,7 @@ function convert(fund: Fund, type: ?Type): Schema {
|
||||||
};
|
};
|
||||||
case 'map':
|
case 'map':
|
||||||
// TODO: invariant(type.keys.kind === 'string');
|
// TODO: invariant(type.keys.kind === 'string');
|
||||||
|
// TODO: "propertyNames".
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
|
@ -140,11 +139,11 @@ function convert(fund: Fund, type: ?Type): Schema {
|
||||||
return type.value === null ? {
|
return type.value === null ? {
|
||||||
type: 'null',
|
type: 'null',
|
||||||
} : {
|
} : {
|
||||||
enum: [type.value],
|
const: type.value,
|
||||||
};
|
};
|
||||||
case 'any':
|
case 'any':
|
||||||
case 'mixed':
|
case 'mixed':
|
||||||
return {};
|
return true;
|
||||||
case 'reference':
|
case 'reference':
|
||||||
default:
|
default:
|
||||||
return {
|
return {
|
||||||
|
@ -161,6 +160,7 @@ export default function (fund: Fund): Schema {
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
$schema: 'http://json-schema.org/draft-06/schema#',
|
||||||
definitions: collect(schemas),
|
definitions: collect(schemas),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue