Migrate to draft-06 json-schema

master
Paul Loyd 2017-12-16 19:26:52 +03:00
parent 15f4d9459d
commit 44e36854f3
1 changed files with 10 additions and 10 deletions

View File

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