Skip to content

Commit

Permalink
Migrate to draft-06 json-schema
Browse files Browse the repository at this point in the history
  • Loading branch information
loyd committed Dec 16, 2017
1 parent 15f4d94 commit 44e3685
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/generators/jsonSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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',
Expand All @@ -82,6 +80,7 @@ function convert(fund: Fund, type: ?Type): Schema {
};
case 'map':
// TODO: invariant(type.keys.kind === 'string');
// TODO: "propertyNames".

return {
type: 'object',
Expand Down Expand Up @@ -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 {
Expand All @@ -161,6 +160,7 @@ export default function (fund: Fund): Schema {
});

return {
$schema: 'http://json-schema.org/draft-06/schema#',
definitions: collect(schemas),
};
}

0 comments on commit 44e3685

Please sign in to comment.