aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sra-api/src/api.ts
diff options
context:
space:
mode:
authorfragosti <francesco.agosti93@gmail.com>2018-08-03 09:39:52 +0800
committerfragosti <francesco.agosti93@gmail.com>2018-08-03 11:19:50 +0800
commit260640feed5dcda52936873397cf3b2c899718c6 (patch)
treeac843a20251ece74878152cc742dbe9806345dfe /packages/sra-api/src/api.ts
parent36e7cb16aa086892ace18b2c6f3ed5a6e3b26a70 (diff)
downloaddexon-sol-tools-260640feed5dcda52936873397cf3b2c899718c6.tar
dexon-sol-tools-260640feed5dcda52936873397cf3b2c899718c6.tar.gz
dexon-sol-tools-260640feed5dcda52936873397cf3b2c899718c6.tar.bz2
dexon-sol-tools-260640feed5dcda52936873397cf3b2c899718c6.tar.lz
dexon-sol-tools-260640feed5dcda52936873397cf3b2c899718c6.tar.xz
dexon-sol-tools-260640feed5dcda52936873397cf3b2c899718c6.tar.zst
dexon-sol-tools-260640feed5dcda52936873397cf3b2c899718c6.zip
Refactor using some utility methods
Diffstat (limited to 'packages/sra-api/src/api.ts')
-rw-r--r--packages/sra-api/src/api.ts135
1 files changed, 26 insertions, 109 deletions
diff --git a/packages/sra-api/src/api.ts b/packages/sra-api/src/api.ts
index 2a43e3e8e..33d4d3619 100644
--- a/packages/sra-api/src/api.ts
+++ b/packages/sra-api/src/api.ts
@@ -2,86 +2,11 @@ import { schemas } from '@0xproject/json-schemas';
import { OpenApiSpec } from '@loopback/openapi-v3-types';
import { examples } from './examples';
+import { generateParameters } from './parameters';
+import { generateResponses } from './responses';
// We need to replace the `$ref`s to be openAPI compliant.
const openApiSchemas = JSON.parse(JSON.stringify(schemas).replace(/(\/\w+)/g, match => `#/components/schemas${match}`));
-const paginationParameters = [
- {
- name: 'page',
- in: 'query',
- description: 'The number of the page to request in the collection.',
- example: 3,
- schema: {
- type: 'number',
- },
- },
- {
- name: 'per_page',
- in: 'query',
- description: 'The number of records to return per page.',
- example: 10,
- schema: {
- type: 'number',
- },
- },
-];
-
-const networkdIdParameter = {
- name: 'network_id',
- in: 'query',
- description: 'The id of the Ethereum network',
- example: 42,
- default: 1,
- schema: {
- type: 'number',
- },
-};
-
-const headers = {
- 'X-Rate-Limit-Limit': {
- description: `The maximum number of requests you're permitted to make per hour.`,
- schema: {
- type: 'integer',
- },
- },
- 'X-Rate-Limit-Remaining': {
- description: 'The number of requests remaining in the current rate limit window.',
- schema: {
- type: 'integer',
- },
- },
- 'X-Rate-Limit-Reset': {
- description: 'The time at which the current rate limit window resets in UTC epoch seconds.',
- schema: {
- type: 'integer',
- },
- },
-};
-
-const errorResponses = {
- '400': {
- description: 'Validation error',
- content: {
- 'application/json': {
- schema: { $ref: '#/components/schemas/relayerApiErrorResponseSchema' },
- example: examples.validationError,
- },
- },
- },
- '404': {
- description: 'Not found',
- },
- '429': {
- description: 'Too many requests - Rate limit exceeded',
- },
- '500': {
- description: 'Internal Server Error',
- },
- '501': {
- description: 'Not implemented.',
- },
-};
-
export const api: OpenApiSpec = {
openapi: '3.0.0',
info: {
@@ -103,41 +28,33 @@ export const api: OpenApiSpec = {
description:
'Retrieves a list of available asset pairs and the information required to trade them (in any order). Setting only `asset_data_a` or `asset_data_b` returns pairs filtered by that asset only.',
operationId: 'getAssetPairs',
- parameters: [
- networkdIdParameter,
- ...paginationParameters,
- {
- name: 'asset_data_a',
- in: 'query',
- description: 'The assetData value for the first asset in the pair.',
- example: '0xf47261b04c32345ced77393b3530b1eed0f346429d',
- schema: {
- $ref: '#/components/schemas/hexSchema',
- },
- },
- {
- name: 'asset_data_b',
- in: 'query',
- description: 'The assetData value for the second asset in the pair.',
- example: '0x0257179264389b814a946f3e92105513705ca6b990',
- schema: {
- $ref: '#/components/schemas/hexSchema',
+ parameters: generateParameters(
+ [
+ {
+ name: 'asset_data_a',
+ in: 'query',
+ description: 'The assetData value for the first asset in the pair.',
+ example: '0xf47261b04c32345ced77393b3530b1eed0f346429d',
+ schema: {
+ $ref: '#/components/schemas/hexSchema',
+ },
},
- },
- ],
- responses: {
- '200': {
- headers,
- description: 'OK',
- content: {
- 'application/json': {
- schema: { $ref: '#/components/schemas/relayerApiAssetDataPairsResponseSchema' },
- example: examples.relayerApiAssetDataPairsResponseSchema,
+ {
+ name: 'asset_data_b',
+ in: 'query',
+ description: 'The assetData value for the second asset in the pair.',
+ example: '0x0257179264389b814a946f3e92105513705ca6b990',
+ schema: {
+ $ref: '#/components/schemas/hexSchema',
},
},
- },
- ...errorResponses,
- },
+ ],
+ true,
+ ),
+ responses: generateResponses(
+ 'relayerApiAssetDataPairsResponseSchema',
+ examples.relayerApiAssetDataPairsResponseSchema,
+ ),
},
},
},