diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-11-12 21:04:28 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-12 21:04:28 +0800 |
commit | b866ce787ce276ae22095529002f63f8c374c75f (patch) | |
tree | 036a9001b08fd07dddd6c5336846c829377b4682 | |
parent | c41622c20aea8ba89dc9899ff8b3ab6f22f53503 (diff) | |
parent | 4d5bc8b8eec4da97ff82c8785fb7c1f9392ca768 (diff) | |
download | dexon-0x-contracts-b866ce787ce276ae22095529002f63f8c374c75f.tar dexon-0x-contracts-b866ce787ce276ae22095529002f63f8c374c75f.tar.gz dexon-0x-contracts-b866ce787ce276ae22095529002f63f8c374c75f.tar.bz2 dexon-0x-contracts-b866ce787ce276ae22095529002f63f8c374c75f.tar.lz dexon-0x-contracts-b866ce787ce276ae22095529002f63f8c374c75f.tar.xz dexon-0x-contracts-b866ce787ce276ae22095529002f63f8c374c75f.tar.zst dexon-0x-contracts-b866ce787ce276ae22095529002f63f8c374c75f.zip |
Merge pull request #1250 from 0xProject/feature/json-schemas-connect
Move @0x/connect schemas to @0x/json-schemas
17 files changed, 113 insertions, 107 deletions
diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts index b6c031fa8..c52425431 100644 --- a/packages/connect/src/http_client.ts +++ b/packages/connect/src/http_client.ts @@ -19,7 +19,6 @@ import { fetchAsync } from '@0x/utils'; import * as _ from 'lodash'; import * as queryString from 'query-string'; -import { schemas as clientSchemas } from './schemas/schemas'; import { Client, HttpRequestOptions, HttpRequestType } from './types'; import { relayerResponseJsonParsers } from './utils/relayer_response_json_parsers'; @@ -61,9 +60,9 @@ export class HttpClient implements Client { requestOpts?: RequestOpts & AssetPairsRequestOpts & PagedRequestOpts, ): Promise<AssetPairsResponse> { if (!_.isUndefined(requestOpts)) { - assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.assetPairsRequestOptsSchema); - assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema); - assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.requestOptsSchema); + assert.doesConformToSchema('requestOpts', requestOpts, schemas.assetPairsRequestOptsSchema); + assert.doesConformToSchema('requestOpts', requestOpts, schemas.pagedRequestOptsSchema); + assert.doesConformToSchema('requestOpts', requestOpts, schemas.requestOptsSchema); } const httpRequestOpts = { params: requestOpts, @@ -81,9 +80,9 @@ export class HttpClient implements Client { requestOpts?: RequestOpts & OrdersRequestOpts & PagedRequestOpts, ): Promise<OrdersResponse> { if (!_.isUndefined(requestOpts)) { - assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.ordersRequestOptsSchema); - assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema); - assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.requestOptsSchema); + assert.doesConformToSchema('requestOpts', requestOpts, schemas.ordersRequestOptsSchema); + assert.doesConformToSchema('requestOpts', requestOpts, schemas.pagedRequestOptsSchema); + assert.doesConformToSchema('requestOpts', requestOpts, schemas.requestOptsSchema); } const httpRequestOpts = { params: requestOpts, @@ -99,7 +98,7 @@ export class HttpClient implements Client { */ public async getOrderAsync(orderHash: string, requestOpts?: RequestOpts): Promise<APIOrder> { if (!_.isUndefined(requestOpts)) { - assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.requestOptsSchema); + assert.doesConformToSchema('requestOpts', requestOpts, schemas.requestOptsSchema); } assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema); const httpRequestOpts = { @@ -119,10 +118,10 @@ export class HttpClient implements Client { request: OrderbookRequest, requestOpts?: RequestOpts & PagedRequestOpts, ): Promise<OrderbookResponse> { - assert.doesConformToSchema('request', request, clientSchemas.orderBookRequestSchema); + assert.doesConformToSchema('request', request, schemas.orderBookRequestSchema); if (!_.isUndefined(requestOpts)) { - assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema); - assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.requestOptsSchema); + assert.doesConformToSchema('requestOpts', requestOpts, schemas.pagedRequestOptsSchema); + assert.doesConformToSchema('requestOpts', requestOpts, schemas.requestOptsSchema); } const httpRequestOpts = { params: _.defaults({}, request, requestOpts), @@ -142,9 +141,9 @@ export class HttpClient implements Client { requestOpts?: RequestOpts, ): Promise<OrderConfigResponse> { if (!_.isUndefined(requestOpts)) { - assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.requestOptsSchema); + assert.doesConformToSchema('requestOpts', requestOpts, schemas.requestOptsSchema); } - assert.doesConformToSchema('request', request, clientSchemas.orderConfigRequestSchema); + assert.doesConformToSchema('request', request, schemas.orderConfigRequestSchema); const httpRequestOpts = { params: requestOpts, payload: request, @@ -160,8 +159,8 @@ export class HttpClient implements Client { */ public async getFeeRecipientsAsync(requestOpts?: RequestOpts & PagedRequestOpts): Promise<FeeRecipientsResponse> { if (!_.isUndefined(requestOpts)) { - assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema); - assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.requestOptsSchema); + assert.doesConformToSchema('requestOpts', requestOpts, schemas.pagedRequestOptsSchema); + assert.doesConformToSchema('requestOpts', requestOpts, schemas.requestOptsSchema); } const httpRequestOpts = { params: requestOpts, diff --git a/packages/connect/src/schemas/asset_pairs_request_opts_schema.ts b/packages/connect/src/schemas/asset_pairs_request_opts_schema.ts deleted file mode 100644 index a9e3942a4..000000000 --- a/packages/connect/src/schemas/asset_pairs_request_opts_schema.ts +++ /dev/null @@ -1,8 +0,0 @@ -export const assetPairsRequestOptsSchema = { - id: '/AssetPairsRequestOpts', - type: 'object', - properties: { - assetDataA: { $ref: '/hexSchema' }, - assetDataB: { $ref: '/hexSchema' }, - }, -}; diff --git a/packages/connect/src/schemas/order_config_request_schema.ts b/packages/connect/src/schemas/order_config_request_schema.ts deleted file mode 100644 index 0eda430e8..000000000 --- a/packages/connect/src/schemas/order_config_request_schema.ts +++ /dev/null @@ -1,24 +0,0 @@ -export const orderConfigRequestSchema = { - id: '/OrderConfigRequest', - type: 'object', - properties: { - makerAddress: { $ref: '/addressSchema' }, - takerAddress: { $ref: '/addressSchema' }, - makerAssetAmount: { $ref: '/numberSchema' }, - takerAssetAmount: { $ref: '/numberSchema' }, - makerAssetData: { $ref: '/hexSchema' }, - takerAssetData: { $ref: '/hexSchema' }, - exchangeAddress: { $ref: '/addressSchema' }, - expirationTimeSeconds: { $ref: '/numberSchema' }, - }, - required: [ - 'makerAddress', - 'takerAddress', - 'makerAssetAmount', - 'takerAssetAmount', - 'makerAssetData', - 'takerAssetData', - 'exchangeAddress', - 'expirationTimeSeconds', - ], -}; diff --git a/packages/connect/src/schemas/orderbook_request_schema.ts b/packages/connect/src/schemas/orderbook_request_schema.ts deleted file mode 100644 index 0c9389d50..000000000 --- a/packages/connect/src/schemas/orderbook_request_schema.ts +++ /dev/null @@ -1,9 +0,0 @@ -export const orderBookRequestSchema = { - id: '/OrderBookRequest', - type: 'object', - properties: { - baseAssetData: { $ref: '/hexSchema' }, - quoteAssetData: { $ref: '/hexSchema' }, - }, - required: ['baseAssetData', 'quoteAssetData'], -}; diff --git a/packages/connect/src/schemas/orders_request_opts_schema.ts b/packages/connect/src/schemas/orders_request_opts_schema.ts deleted file mode 100644 index 71ce3d06f..000000000 --- a/packages/connect/src/schemas/orders_request_opts_schema.ts +++ /dev/null @@ -1,19 +0,0 @@ -export const ordersRequestOptsSchema = { - id: '/OrdersRequestOpts', - type: 'object', - properties: { - makerAssetProxyId: { $ref: '/hexSchema' }, - takerAssetProxyId: { $ref: '/hexSchema' }, - makerAssetAddress: { $ref: '/addressSchema' }, - takerAssetAddress: { $ref: '/addressSchema' }, - exchangeAddress: { $ref: '/addressSchema' }, - senderAddress: { $ref: '/addressSchema' }, - makerAssetData: { $ref: '/hexSchema' }, - takerAssetData: { $ref: '/hexSchema' }, - traderAssetData: { $ref: '/hexSchema' }, - makerAddress: { $ref: '/addressSchema' }, - takerAddress: { $ref: '/addressSchema' }, - traderAddress: { $ref: '/addressSchema' }, - feeRecipientAddress: { $ref: '/addressSchema' }, - }, -}; diff --git a/packages/connect/src/schemas/paged_request_opts_schema.ts b/packages/connect/src/schemas/paged_request_opts_schema.ts deleted file mode 100644 index eb2e52100..000000000 --- a/packages/connect/src/schemas/paged_request_opts_schema.ts +++ /dev/null @@ -1,8 +0,0 @@ -export const pagedRequestOptsSchema = { - id: '/PagedRequestOpts', - type: 'object', - properties: { - page: { type: 'number' }, - perPage: { type: 'number' }, - }, -}; diff --git a/packages/connect/src/schemas/request_opts_schema.ts b/packages/connect/src/schemas/request_opts_schema.ts deleted file mode 100644 index a51e98069..000000000 --- a/packages/connect/src/schemas/request_opts_schema.ts +++ /dev/null @@ -1,7 +0,0 @@ -export const requestOptsSchema = { - id: '/RequestOpts', - type: 'object', - properties: { - networkId: { type: 'number' }, - }, -}; diff --git a/packages/connect/src/schemas/schemas.ts b/packages/connect/src/schemas/schemas.ts deleted file mode 100644 index 8d101ed6f..000000000 --- a/packages/connect/src/schemas/schemas.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { assetPairsRequestOptsSchema } from './asset_pairs_request_opts_schema'; -import { orderConfigRequestSchema } from './order_config_request_schema'; -import { orderBookRequestSchema } from './orderbook_request_schema'; -import { ordersRequestOptsSchema } from './orders_request_opts_schema'; -import { pagedRequestOptsSchema } from './paged_request_opts_schema'; -import { requestOptsSchema } from './request_opts_schema'; - -export const schemas = { - orderConfigRequestSchema, - orderBookRequestSchema, - ordersRequestOptsSchema, - pagedRequestOptsSchema, - requestOptsSchema, - assetPairsRequestOptsSchema, -}; diff --git a/packages/json-schemas/CHANGELOG.json b/packages/json-schemas/CHANGELOG.json index f25a487b8..c273c09af 100644 --- a/packages/json-schemas/CHANGELOG.json +++ b/packages/json-schemas/CHANGELOG.json @@ -1,11 +1,15 @@ [ { - "version": "2.0.1", + "version": "2.1.0", "changes": [ { "note": "Improve schemas by enforcing that amounts that must be whole numbers (e.g Order asset amounts) no longer allow decimal amounts", "pr": 1173 + }, + { + "note": "Add schemas from @0x/connect", + "pr": 1250 } ], "timestamp": 1541740904 diff --git a/packages/json-schemas/schemas/asset_pairs_request_opts_schema.json b/packages/json-schemas/schemas/asset_pairs_request_opts_schema.json new file mode 100644 index 000000000..174a8fdc3 --- /dev/null +++ b/packages/json-schemas/schemas/asset_pairs_request_opts_schema.json @@ -0,0 +1,8 @@ +{ + "id": "/AssetPairsRequestOpts", + "type": "object", + "properties": { + "assetDataA": { "$ref": "/hexSchema" }, + "assetDataB": { "$ref": "/hexSchema" } + } +} diff --git a/packages/json-schemas/schemas/order_config_request_schema.json b/packages/json-schemas/schemas/order_config_request_schema.json new file mode 100644 index 000000000..ca9b2e30e --- /dev/null +++ b/packages/json-schemas/schemas/order_config_request_schema.json @@ -0,0 +1,24 @@ +{ + "id": "/OrderConfigRequest", + "type": "object", + "properties": { + "makerAddress": { "$ref": "/addressSchema" }, + "takerAddress": { "$ref": "/addressSchema" }, + "makerAssetAmount": { "$ref": "/wholeNumberSchema" }, + "takerAssetAmount": { "$ref": "/wholeNumberSchema" }, + "makerAssetData": { "$ref": "/hexSchema" }, + "takerAssetData": { "$ref": "/hexSchema" }, + "exchangeAddress": { "$ref": "/addressSchema" }, + "expirationTimeSeconds": { "$ref": "/wholeNumberSchema" } + }, + "required": [ + "makerAddress", + "takerAddress", + "makerAssetAmount", + "takerAssetAmount", + "makerAssetData", + "takerAssetData", + "exchangeAddress", + "expirationTimeSeconds" + ] +} diff --git a/packages/json-schemas/schemas/orderbook_request_schema.json b/packages/json-schemas/schemas/orderbook_request_schema.json new file mode 100644 index 000000000..27848bdcb --- /dev/null +++ b/packages/json-schemas/schemas/orderbook_request_schema.json @@ -0,0 +1,9 @@ +{ + "id": "/OrderBookRequest", + "type": "object", + "properties": { + "baseAssetData": { "$ref": "/hexSchema" }, + "quoteAssetData": { "$ref": "/hexSchema" } + }, + "required": ["baseAssetData", "quoteAssetData"] +}
\ No newline at end of file diff --git a/packages/json-schemas/schemas/orders_request_opts_schema.json b/packages/json-schemas/schemas/orders_request_opts_schema.json new file mode 100644 index 000000000..10da51060 --- /dev/null +++ b/packages/json-schemas/schemas/orders_request_opts_schema.json @@ -0,0 +1,19 @@ +{ + "id": "/OrdersRequestOpts", + "type": "object", + "properties": { + "makerAssetProxyId": { "$ref": "/hexSchema" }, + "takerAssetProxyId": { "$ref": "/hexSchema" }, + "makerAssetAddress": { "$ref": "/addressSchema" }, + "takerAssetAddress": { "$ref": "/addressSchema" }, + "exchangeAddress": { "$ref": "/addressSchema" }, + "senderAddress": { "$ref": "/addressSchema" }, + "makerAssetData": { "$ref": "/hexSchema" }, + "takerAssetData": { "$ref": "/hexSchema" }, + "traderAssetData": { "$ref": "/hexSchema" }, + "makerAddress": { "$ref": "/addressSchema" }, + "takerAddress": { "$ref": "/addressSchema" }, + "traderAddress": { "$ref": "/addressSchema" }, + "feeRecipientAddress": { "$ref": "/addressSchema" } + } +} diff --git a/packages/json-schemas/schemas/paged_request_opts_schema.json b/packages/json-schemas/schemas/paged_request_opts_schema.json new file mode 100644 index 000000000..7cfc73947 --- /dev/null +++ b/packages/json-schemas/schemas/paged_request_opts_schema.json @@ -0,0 +1,8 @@ +{ + "id": "/PagedRequestOpts", + "type": "object", + "properties": { + "page": { "type": "number" }, + "perPage": { "type": "number" } + } +} diff --git a/packages/json-schemas/schemas/request_opts_schema.json b/packages/json-schemas/schemas/request_opts_schema.json new file mode 100644 index 000000000..b50547d18 --- /dev/null +++ b/packages/json-schemas/schemas/request_opts_schema.json @@ -0,0 +1,7 @@ +{ + "id": "/RequestOpts", + "type": "object", + "properties": { + "networkId": { "type": "number" } + } +} diff --git a/packages/json-schemas/src/schemas.ts b/packages/json-schemas/src/schemas.ts index 8ece5de75..21a6f424c 100644 --- a/packages/json-schemas/src/schemas.ts +++ b/packages/json-schemas/src/schemas.ts @@ -1,4 +1,5 @@ import * as addressSchema from '../schemas/address_schema.json'; +import * as assetPairsRequestOptsSchema from '../schemas/asset_pairs_request_opts_schema.json'; import * as blockParamSchema from '../schemas/block_param_schema.json'; import * as blockRangeSchema from '../schemas/block_range_schema.json'; import * as callDataSchema from '../schemas/call_data_schema.json'; @@ -10,11 +11,15 @@ import * as indexFilterValuesSchema from '../schemas/index_filter_values_schema. import * as jsNumber from '../schemas/js_number.json'; import * as numberSchema from '../schemas/number_schema.json'; import * as orderCancellationRequestsSchema from '../schemas/order_cancel_schema.json'; +import * as orderConfigRequestSchema from '../schemas/order_config_request_schema.json'; import * as orderFillOrKillRequestsSchema from '../schemas/order_fill_or_kill_requests_schema.json'; import * as orderFillRequestsSchema from '../schemas/order_fill_requests_schema.json'; import * as orderHashSchema from '../schemas/order_hash_schema.json'; import * as orderSchema from '../schemas/order_schema.json'; +import * as orderBookRequestSchema from '../schemas/orderbook_request_schema.json'; +import * as ordersRequestOptsSchema from '../schemas/orders_request_opts_schema.json'; import * as ordersSchema from '../schemas/orders_schema.json'; +import * as pagedRequestOptsSchema from '../schemas/paged_request_opts_schema.json'; import * as paginatedCollectionSchema from '../schemas/paginated_collection_schema.json'; import * as relayerApiAssetDataPairsResponseSchema from '../schemas/relayer_api_asset_data_pairs_response_schema.json'; import * as relayerApiAssetDataPairsSchema from '../schemas/relayer_api_asset_data_pairs_schema.json'; @@ -30,6 +35,7 @@ import * as relayerApiOrdersChannelSubscribeSchema from '../schemas/relayer_api_ import * as relayerApiOrdersChannelUpdateSchema from '../schemas/relayer_api_orders_channel_update_response_schema.json'; import * as relayerApiOrdersResponseSchema from '../schemas/relayer_api_orders_response_schema.json'; import * as relayerApiOrdersSchema from '../schemas/relayer_api_orders_schema.json'; +import * as requestOptsSchema from '../schemas/request_opts_schema.json'; import * as signedOrderSchema from '../schemas/signed_order_schema.json'; import * as signedOrdersSchema from '../schemas/signed_orders_schema.json'; import * as tokenSchema from '../schemas/token_schema.json'; @@ -58,6 +64,12 @@ export const schemas = { blockRangeSchema, tokenSchema, jsNumber, + requestOptsSchema, + pagedRequestOptsSchema, + ordersRequestOptsSchema, + orderBookRequestSchema, + orderConfigRequestSchema, + assetPairsRequestOptsSchema, txDataSchema, paginatedCollectionSchema, relayerApiErrorResponseSchema, diff --git a/packages/json-schemas/tsconfig.json b/packages/json-schemas/tsconfig.json index 7b14166c0..a79d54385 100644 --- a/packages/json-schemas/tsconfig.json +++ b/packages/json-schemas/tsconfig.json @@ -44,6 +44,12 @@ "./schemas/zero_ex_transaction_schema.json", "./schemas/tx_data_schema.json", "./schemas/index_filter_values_schema.json", - "./schemas/whole_number_schema.json" + "./schemas/whole_number_schema.json", + "./schemas/asset_pairs_request_opts_schema.json", + "./schemas/orderbook_request_schema.json", + "./schemas/orders_request_opts_schema.json", + "./schemas/paged_request_opts_schema.json", + "./schemas/request_opts_schema.json", + "./schemas/order_config_request_schema.json" ] } |