From 215e13547ef0c5185b54c8c4f0f0310f2965479e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlado=20Te=C5=A1anovi=C4=87?= Date: Tue, 9 Aug 2016 11:26:43 +0200 Subject: [PATCH 1/3] adding jsonschema --- jsonschema/jsonschema.d.ts | 114 +++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 jsonschema/jsonschema.d.ts diff --git a/jsonschema/jsonschema.d.ts b/jsonschema/jsonschema.d.ts new file mode 100644 index 0000000000..2d52fb978e --- /dev/null +++ b/jsonschema/jsonschema.d.ts @@ -0,0 +1,114 @@ +// Type definitions for jsonschema +// Project: https://github.com/tdegrunt/jsonschema +// Definitions by: Vlado Tešanovic https://github.com/vladotesanovic +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +declare module "jsonschema" { + + export interface IJSONSchemaResult { + errors: Array; + instance: any; + arguments: Array<{}>; + propertyPath: string; + name: string; + schema: {}; + throwError: any; + disableFormat: boolean; + } + + export interface IJSONSchemaValidationError { + message: string; + property: string; + stack: string; + schema: {}; + name: string; + instance: any; + argument: {}; + } + + export interface IJSONSchemaOptions { + propertyName?: string; + base?: string; + } + + /** + * How to; + * + * const v: Validator = new Validator(); + * + * const schema: {} = { + * "type": "object", + * "properties": { + * "key": { + * "type": "string", + * "required": true + * }, + * "value": { + * "type": "string", + * "required": true + * } + * } + * }; + * + * const validationResults: { errors: Array } = + * v.validate({ key: "Name", value: "A10" }, {"type": "string"}); + * + */ + export class Validator { + + /** + * Creates a new Validator object + * @name Validator + * @constructor + */ + new(): this; + + /** + * Validates instance against the provided schema + * @param instance + * @param schema + * @param [options] + * @param [ctx] + * @return {Array} + */ + validate(instance: any, schema: {}, options?: IJSONSchemaOptions, ctx?: {}): IJSONSchemaResult; + + /** + * Adds a schema with a certain urn to the Validator instance. + * @param schema + * @param urn + * @return {Object} + */ + addSchema(schema: {}, urn: string): {}; + + /** + * Add Sub schema to existing one + * @param baseuri + * @param schema + */ + addSubSchema(baseuri: string, schema: {}): {} + + /** + * Sets all the schemas of the Validator instance. + * @param schemas + */ + setSchemas (schemas: Array<{}>): void; + + /** + * Returns the schema of a certain urn + * @param urn + */ + getSchema(urn: string): {}; + + /** + * Validates an instance against the schema (the actual work horse) + * @param instance + * @param schema + * @param options + * @param ctx + * @private + * @return {IJSONSchemaResult} + */ + validateSchema(instance: any, schema: {}, options?: {}, ctx?: {}): IJSONSchemaResult + } +} + From bc8fffa7503af4aefe9886f0757a9b50c6fab498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlado=20Te=C5=A1anovi=C4=87?= Date: Tue, 9 Aug 2016 11:36:57 +0200 Subject: [PATCH 2/3] Tests added --- jsonschema/jsonschema-tests.ts | 6 ++++++ jsonschema/jsonschema.d.ts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 jsonschema/jsonschema-tests.ts diff --git a/jsonschema/jsonschema-tests.ts b/jsonschema/jsonschema-tests.ts new file mode 100644 index 0000000000..e8acc29886 --- /dev/null +++ b/jsonschema/jsonschema-tests.ts @@ -0,0 +1,6 @@ +/// +import { Validator, IJSONSchemaValidationError } from "jsonschema"; + +const v: Validator = new Validator(); + +const validationResults: { errors: Array } = v.validate("Smith", {"type": "string"}); diff --git a/jsonschema/jsonschema.d.ts b/jsonschema/jsonschema.d.ts index 2d52fb978e..9e32dbfded 100644 --- a/jsonschema/jsonschema.d.ts +++ b/jsonschema/jsonschema.d.ts @@ -1,6 +1,6 @@ // Type definitions for jsonschema // Project: https://github.com/tdegrunt/jsonschema -// Definitions by: Vlado Tešanovic https://github.com/vladotesanovic +// Definitions by: Vlado Tešanovic // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare module "jsonschema" { From 8a2c4d2aceadb8f2545c3464ef447efad428f6ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlado=20Te=C5=A1anovi=C4=87?= Date: Thu, 11 Aug 2016 15:58:47 +0200 Subject: [PATCH 3/3] removed private function --- jsonschema/jsonschema.d.ts | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/jsonschema/jsonschema.d.ts b/jsonschema/jsonschema.d.ts index 9e32dbfded..1c2f0f915e 100644 --- a/jsonschema/jsonschema.d.ts +++ b/jsonschema/jsonschema.d.ts @@ -98,17 +98,6 @@ declare module "jsonschema" { * @param urn */ getSchema(urn: string): {}; - - /** - * Validates an instance against the schema (the actual work horse) - * @param instance - * @param schema - * @param options - * @param ctx - * @private - * @return {IJSONSchemaResult} - */ - validateSchema(instance: any, schema: {}, options?: {}, ctx?: {}): IJSONSchemaResult } }