aboutsummaryrefslogtreecommitdiffstats
path: root/packages/json-schemas/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/json-schemas/src')
-rw-r--r--packages/json-schemas/src/schema_validator.ts44
-rw-r--r--packages/json-schemas/src/schemas.ts68
2 files changed, 56 insertions, 56 deletions
diff --git a/packages/json-schemas/src/schema_validator.ts b/packages/json-schemas/src/schema_validator.ts
index e13326d2a..686c38d17 100644
--- a/packages/json-schemas/src/schema_validator.ts
+++ b/packages/json-schemas/src/schema_validator.ts
@@ -4,26 +4,26 @@ import values = require('lodash.values');
import { schemas } from './schemas';
export class SchemaValidator {
- private _validator: Validator;
- constructor() {
- this._validator = new Validator();
- for (const schema of values(schemas)) {
- this._validator.addSchema(schema, schema.id);
- }
- }
- public addSchema(schema: Schema) {
- this._validator.addSchema(schema, schema.id);
- }
- // In order to validate a complex JS object using jsonschema, we must replace any complex
- // sub-types (e.g BigNumber) with a simpler string representation. Since BigNumber and other
- // complex types implement the `toString` method, we can stringify the object and
- // then parse it. The resultant object can then be checked using jsonschema.
- public validate(instance: any, schema: Schema): ValidatorResult {
- const jsonSchemaCompatibleObject = JSON.parse(JSON.stringify(instance));
- return this._validator.validate(jsonSchemaCompatibleObject, schema);
- }
- public isValid(instance: any, schema: Schema): boolean {
- const isValid = this.validate(instance, schema).errors.length === 0;
- return isValid;
- }
+ private _validator: Validator;
+ constructor() {
+ this._validator = new Validator();
+ for (const schema of values(schemas)) {
+ this._validator.addSchema(schema, schema.id);
+ }
+ }
+ public addSchema(schema: Schema) {
+ this._validator.addSchema(schema, schema.id);
+ }
+ // In order to validate a complex JS object using jsonschema, we must replace any complex
+ // sub-types (e.g BigNumber) with a simpler string representation. Since BigNumber and other
+ // complex types implement the `toString` method, we can stringify the object and
+ // then parse it. The resultant object can then be checked using jsonschema.
+ public validate(instance: any, schema: Schema): ValidatorResult {
+ const jsonSchemaCompatibleObject = JSON.parse(JSON.stringify(instance));
+ return this._validator.validate(jsonSchemaCompatibleObject, schema);
+ }
+ public isValid(instance: any, schema: Schema): boolean {
+ const isValid = this.validate(instance, schema).errors.length === 0;
+ return isValid;
+ }
}
diff --git a/packages/json-schemas/src/schemas.ts b/packages/json-schemas/src/schemas.ts
index 5cb07acfe..bdc227aea 100644
--- a/packages/json-schemas/src/schemas.ts
+++ b/packages/json-schemas/src/schemas.ts
@@ -11,50 +11,50 @@ import { relayerApiErrorResponseSchema } from '../schemas/relayer_api_error_resp
import { relayerApiFeesPayloadSchema } from '../schemas/relayer_api_fees_payload_schema';
import { relayerApiFeesResponseSchema } from '../schemas/relayer_api_fees_response_schema';
import {
- relayerApiOrderbookChannelSubscribePayload,
- relayerApiOrderbookChannelSubscribeSchema,
+ relayerApiOrderbookChannelSubscribePayload,
+ relayerApiOrderbookChannelSubscribeSchema,
} from '../schemas/relayer_api_orberbook_channel_subscribe_schema';
import {
- relayerApiOrderbookChannelSnapshotPayload,
- relayerApiOrderbookChannelSnapshotSchema,
+ relayerApiOrderbookChannelSnapshotPayload,
+ relayerApiOrderbookChannelSnapshotSchema,
} from '../schemas/relayer_api_orderbook_channel_snapshot_schema';
import { relayerApiOrderbookChannelUpdateSchema } from '../schemas/relayer_api_orderbook_channel_update_response_schema';
import { relayerApiOrderBookResponseSchema } from '../schemas/relayer_api_orderbook_response_schema';
import {
- relayerApiTokenPairsResponseSchema,
- relayerApiTokenTradeInfoSchema,
+ relayerApiTokenPairsResponseSchema,
+ relayerApiTokenTradeInfoSchema,
} from '../schemas/relayer_api_token_pairs_response_schema';
import { signedOrdersSchema } from '../schemas/signed_orders_schema';
import { tokenSchema } from '../schemas/token_schema';
import { jsNumber, txDataSchema } from '../schemas/tx_data_schema';
export const schemas = {
- numberSchema,
- addressSchema,
- ecSignatureSchema,
- ecSignatureParameterSchema,
- indexFilterValuesSchema,
- orderCancellationRequestsSchema,
- orderFillOrKillRequestsSchema,
- orderFillRequestsSchema,
- orderHashSchema,
- orderSchema,
- signedOrderSchema,
- signedOrdersSchema,
- blockParamSchema,
- blockRangeSchema,
- tokenSchema,
- jsNumber,
- txDataSchema,
- relayerApiErrorResponseSchema,
- relayerApiFeesPayloadSchema,
- relayerApiFeesResponseSchema,
- relayerApiOrderBookResponseSchema,
- relayerApiTokenPairsResponseSchema,
- relayerApiTokenTradeInfoSchema,
- relayerApiOrderbookChannelSubscribeSchema,
- relayerApiOrderbookChannelSubscribePayload,
- relayerApiOrderbookChannelUpdateSchema,
- relayerApiOrderbookChannelSnapshotSchema,
- relayerApiOrderbookChannelSnapshotPayload,
+ numberSchema,
+ addressSchema,
+ ecSignatureSchema,
+ ecSignatureParameterSchema,
+ indexFilterValuesSchema,
+ orderCancellationRequestsSchema,
+ orderFillOrKillRequestsSchema,
+ orderFillRequestsSchema,
+ orderHashSchema,
+ orderSchema,
+ signedOrderSchema,
+ signedOrdersSchema,
+ blockParamSchema,
+ blockRangeSchema,
+ tokenSchema,
+ jsNumber,
+ txDataSchema,
+ relayerApiErrorResponseSchema,
+ relayerApiFeesPayloadSchema,
+ relayerApiFeesResponseSchema,
+ relayerApiOrderBookResponseSchema,
+ relayerApiTokenPairsResponseSchema,
+ relayerApiTokenTradeInfoSchema,
+ relayerApiOrderbookChannelSubscribeSchema,
+ relayerApiOrderbookChannelSubscribePayload,
+ relayerApiOrderbookChannelUpdateSchema,
+ relayerApiOrderbookChannelSnapshotSchema,
+ relayerApiOrderbookChannelSnapshotPayload,
};