diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-08-09 05:00:50 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-08-09 05:00:50 +0800 |
commit | 9aacceb0e4549a7a72cae7cbf74ea819db184d80 (patch) | |
tree | 059e0de4b423d78e50d6175a86d11fd541ab0244 | |
parent | c9e1b7c5dc4eebf447fdc97568f08db0e2546904 (diff) | |
download | dexon-sol-tools-9aacceb0e4549a7a72cae7cbf74ea819db184d80.tar dexon-sol-tools-9aacceb0e4549a7a72cae7cbf74ea819db184d80.tar.gz dexon-sol-tools-9aacceb0e4549a7a72cae7cbf74ea819db184d80.tar.bz2 dexon-sol-tools-9aacceb0e4549a7a72cae7cbf74ea819db184d80.tar.lz dexon-sol-tools-9aacceb0e4549a7a72cae7cbf74ea819db184d80.tar.xz dexon-sol-tools-9aacceb0e4549a7a72cae7cbf74ea819db184d80.tar.zst dexon-sol-tools-9aacceb0e4549a7a72cae7cbf74ea819db184d80.zip |
Remove tests directory, use swagger api, make json api compliant
-rw-r--r-- | packages/sra-api/package.json | 5 | ||||
-rw-r--r-- | packages/sra-api/src/api.ts | 6 | ||||
-rw-r--r-- | packages/sra-api/src/json-schemas.ts | 63 | ||||
-rw-r--r-- | packages/sra-api/src/parameters.ts | 1 | ||||
-rw-r--r-- | packages/sra-api/test/api_test.ts | 15 | ||||
-rw-r--r-- | packages/sra-api/tsconfig.json | 2 | ||||
-rw-r--r-- | yarn.lock | 138 |
7 files changed, 201 insertions, 29 deletions
diff --git a/packages/sra-api/package.json b/packages/sra-api/package.json index 4e0fb1637..a9bc934fe 100644 --- a/packages/sra-api/package.json +++ b/packages/sra-api/package.json @@ -11,12 +11,11 @@ "serve": "redoc-cli serve lib/api.json --watch", "watch_without_deps": "run-p build-json:watch serve", "lint": "tslint --project .", - "test": "yarn run_mocha", + "test": "swagger-cli validate lib/api.json", "rebuild_and_test": "run-s clean build test", "test:coverage": "nyc npm run test --all && yarn coverage:report:lcov", "coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info", "test:circleci": "yarn test:coverage", - "run_mocha": "mocha lib/test/**/*_test.js --exit", "clean": "shx rm -rf lib", "build": "tsc && yarn build-json", "build-site": "yarn build && redoc-cli bundle lib/api.json --output public/index.html", @@ -49,9 +48,9 @@ "mocha": "^4.0.1", "npm-run-all": "^4.1.3", "nyc": "^11.0.1", - "openapi-schema-validation": "^0.4.1", "redoc-cli": "^0.6.1", "shx": "^0.2.2", + "swagger-cli": "^2.1.1", "ts-node": "^7.0.0", "tslint": "5.11.0", "typescript": "2.7.1" diff --git a/packages/sra-api/src/api.ts b/packages/sra-api/src/api.ts index 5973e11cd..e578ddc74 100644 --- a/packages/sra-api/src/api.ts +++ b/packages/sra-api/src/api.ts @@ -1,12 +1,10 @@ -import { schemas } from '@0xproject/json-schemas'; import { OpenApiSpec } from '@loopback/openapi-v3-types'; import { examples } from './examples'; +import { schemas } from './json-schemas'; import { md } from './md'; 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}`)); export const api: OpenApiSpec = { openapi: '3.0.0', @@ -298,6 +296,6 @@ export const api: OpenApiSpec = { }, }, components: { - schemas: openApiSchemas, + schemas, }, }; diff --git a/packages/sra-api/src/json-schemas.ts b/packages/sra-api/src/json-schemas.ts new file mode 100644 index 000000000..5b222a43f --- /dev/null +++ b/packages/sra-api/src/json-schemas.ts @@ -0,0 +1,63 @@ +import { schemas as jsonSchemas } from '@0xproject/json-schemas'; + +// Only include schemas we actually need +const { + numberSchema, + addressSchema, + hexSchema, + orderHashSchema, + orderSchema, + signedOrderSchema, + signedOrdersSchema, + ordersSchema, + paginatedCollectionSchema, + relayerApiErrorResponseSchema, + relayerApiFeeRecipientsResponseSchema, + relayerApiOrderSchema, + relayerApiOrdersSchema, + relayerApiOrderConfigPayloadSchema, + relayerApiOrderConfigResponseSchema, + relayerApiOrderBookResponseSchema, + relayerApiAssetDataPairsResponseSchema, + relayerApiAssetDataTradeInfoSchema, + relayerApiOrdersChannelSubscribeSchema, + relayerApiOrdersChannelSubscribePayload, + relayerApiOrdersChannelUpdateSchema, + relayerApiOrdersResponseSchema, + relayerApiAssetDataPairsSchema, +} = jsonSchemas; + +const usedSchemas = { + numberSchema, + addressSchema, + hexSchema, + orderHashSchema, + orderSchema, + signedOrderSchema, + signedOrdersSchema, + ordersSchema, + paginatedCollectionSchema, + relayerApiErrorResponseSchema, + relayerApiFeeRecipientsResponseSchema, + relayerApiOrderSchema, + relayerApiOrdersSchema, + relayerApiOrderConfigPayloadSchema, + relayerApiOrderConfigResponseSchema, + relayerApiOrderBookResponseSchema, + relayerApiAssetDataPairsResponseSchema, + relayerApiAssetDataTradeInfoSchema, + relayerApiOrdersChannelSubscribeSchema, + relayerApiOrdersChannelSubscribePayload, + relayerApiOrdersChannelUpdateSchema, + relayerApiOrdersResponseSchema, + relayerApiAssetDataPairsSchema, +}; + +// We need to replace the `$ref`s to be OpenAPI compliant. +const openApiSchemas = JSON.parse( + JSON.stringify(usedSchemas).replace(/(\/\w+)/g, match => `#/components/schemas${match}`), +); +// The json schema used by OpenAPI does not accept ids +Object.keys(openApiSchemas).forEach(key => delete openApiSchemas[key].id); + +export const schemas = openApiSchemas; diff --git a/packages/sra-api/src/parameters.ts b/packages/sra-api/src/parameters.ts index bfa261df0..7b54fe9a0 100644 --- a/packages/sra-api/src/parameters.ts +++ b/packages/sra-api/src/parameters.ts @@ -25,7 +25,6 @@ export const networkdIdParameter: ParameterObject = { in: 'query', description: 'The id of the Ethereum network', example: 42, - default: 1, schema: { type: 'number', }, diff --git a/packages/sra-api/test/api_test.ts b/packages/sra-api/test/api_test.ts deleted file mode 100644 index 47353ca80..000000000 --- a/packages/sra-api/test/api_test.ts +++ /dev/null @@ -1,15 +0,0 @@ -import * as chai from 'chai'; -import * as dirtyChai from 'dirty-chai'; -import { validate } from 'openapi-schema-validation'; - -import { api } from '../src/index'; - -chai.config.includeStack = true; -chai.use(dirtyChai); - -describe('SRA OpenAPI Schema', () => { - it('should be a valid OpenAPI schema', () => { - const result = validate(api, 3); - chai.expect(result.errors).to.have.length(0); - }); -}); diff --git a/packages/sra-api/tsconfig.json b/packages/sra-api/tsconfig.json index c56d255d5..e60028885 100644 --- a/packages/sra-api/tsconfig.json +++ b/packages/sra-api/tsconfig.json @@ -3,5 +3,5 @@ "compilerOptions": { "outDir": "lib" }, - "include": ["./src/**/*"] + "include": ["./src/**/*", "./test/*"] } @@ -3150,6 +3150,14 @@ chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.0, chalk@^2.3.1, chalk@^2.3 escape-string-regexp "^1.0.5" supports-color "^5.3.0" +chalk@^2.4.1: + version "2.4.1" + resolved "https://registry.npmjs.org/chalk/-/chalk-2.4.1.tgz#18c49ab16a037b6eb0152cc83e3471338215b66e" + dependencies: + ansi-styles "^3.2.1" + escape-string-regexp "^1.0.5" + supports-color "^5.3.0" + chalk@~0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/chalk/-/chalk-0.4.0.tgz#5199a3ddcd0c1efe23bc08c1b027b06176e0c64f" @@ -3524,6 +3532,10 @@ commander@2.15.1, commander@^2.12.1, commander@^2.8.1: version "2.15.1" resolved "https://registry.yarnpkg.com/commander/-/commander-2.15.1.tgz#df46e867d0fc2aec66a34662b406a9ccafff5b0f" +commander@^2.7.1: + version "2.17.1" + resolved "https://registry.npmjs.org/commander/-/commander-2.17.1.tgz#bd77ab7de6de94205ceacc72f1716d29f20a77bf" + commander@~2.8.1: version "2.8.1" resolved "https://registry.yarnpkg.com/commander/-/commander-2.8.1.tgz#06be367febfda0c330aa1e2a072d3dc9762425d4" @@ -4170,6 +4182,12 @@ decamelize@^1.0.0, decamelize@^1.1.0, decamelize@^1.1.1, decamelize@^1.1.2: version "1.2.0" resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290" +decamelize@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/decamelize/-/decamelize-2.0.0.tgz#656d7bbc8094c4c788ea53c5840908c9c7d063c7" + dependencies: + xregexp "4.0.0" + decko@^1.2.0: version "1.2.0" resolved "https://registry.npmjs.org/decko/-/decko-1.2.0.tgz#fd43c735e967b8013306884a56fbe665996b6817" @@ -5257,9 +5275,9 @@ ethereumjs-wallet@~0.6.0: utf8 "^2.1.1" uuid "^2.0.1" -ethers@3.0.22: - version "3.0.22" - resolved "https://registry.npmjs.org/ethers/-/ethers-3.0.22.tgz#7fab1ea16521705837aa43c15831877b2716b436" +ethers@0xproject/ethers.js#eip-838-reasons, ethers@3.0.22: + version "3.0.18" + resolved "https://codeload.github.com/0xproject/ethers.js/tar.gz/b91342bd200d142af0165d6befddf783c8ae8447" dependencies: aes-js "3.0.0" bn.js "^4.4.0" @@ -5722,6 +5740,12 @@ find-up@^2.0.0, find-up@^2.1.0: dependencies: locate-path "^2.0.0" +find-up@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz#49169f1d7993430646da61ecc5ae355c21c97b73" + dependencies: + locate-path "^3.0.0" + find-versions@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/find-versions/-/find-versions-2.0.0.tgz#2ad90d490f6828c1aa40292cf709ac3318210c3c" @@ -7788,6 +7812,15 @@ json-schema-ref-parser@^5.1.0: js-yaml "^3.12.0" ono "^4.0.5" +json-schema-ref-parser@^5.1.1: + version "5.1.2" + resolved "https://registry.npmjs.org/json-schema-ref-parser/-/json-schema-ref-parser-5.1.2.tgz#c9cdaec76ea894f71eb3776c3b3291dfa62e56c9" + dependencies: + call-me-maybe "^1.0.1" + debug "^3.1.0" + js-yaml "^3.12.0" + ono "^4.0.5" + json-schema-traverse@^0.3.0: version "0.3.1" resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz#349a6d44c53a51de89b40805c5d5e59b417d3340" @@ -8230,6 +8263,13 @@ locate-path@^2.0.0: p-locate "^2.0.0" path-exists "^3.0.0" +locate-path@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz#dbec3b3ab759758071b58fe59fc41871af21400e" + dependencies: + p-locate "^3.0.0" + path-exists "^3.0.0" + lodash-es@^4.17.5, lodash-es@^4.2.1: version "4.17.8" resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.8.tgz#6fa8c8c5d337481df0bdf1c0d899d42473121e45" @@ -8319,7 +8359,7 @@ lodash.foreach@^4.2.0, lodash.foreach@^4.5.0: version "4.5.0" resolved "https://registry.yarnpkg.com/lodash.foreach/-/lodash.foreach-4.5.0.tgz#1a6a35eace401280c7f06dddec35165ab27e3e53" -lodash.get@^4.4.2: +lodash.get@^4.0.0, lodash.get@^4.4.2: version "4.4.2" resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99" @@ -8339,6 +8379,10 @@ lodash.isarray@^3.0.0: version "3.0.4" resolved "https://registry.yarnpkg.com/lodash.isarray/-/lodash.isarray-3.0.4.tgz#79e4eb88c36a8122af86f844aa9bcd851b5fbb55" +lodash.isequal@^4.0.0: + version "4.5.0" + resolved "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0" + lodash.keys@^3.0.0: version "3.1.2" resolved "https://registry.yarnpkg.com/lodash.keys/-/lodash.keys-3.1.2.tgz#4dbc0472b156be50a0b286855d1bd0b0c656098a" @@ -9804,12 +9848,24 @@ p-limit@^1.0.0, p-limit@^1.1.0: dependencies: p-try "^1.0.0" +p-limit@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/p-limit/-/p-limit-2.0.0.tgz#e624ed54ee8c460a778b3c9f3670496ff8a57aec" + dependencies: + p-try "^2.0.0" + p-locate@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-2.0.0.tgz#20a0103b222a70c8fd39cc2e580680f3dde5ec43" dependencies: p-limit "^1.1.0" +p-locate@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz#322d69a05c0264b25997d9f40cd8a891ab0064a4" + dependencies: + p-limit "^2.0.0" + p-map-series@^1.0.0: version "1.0.0" resolved "http://registry.yarnpkg.com/p-map-series/-/p-map-series-1.0.0.tgz#bf98fe575705658a9e1351befb85ae4c1f07bdca" @@ -9840,6 +9896,10 @@ p-try@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/p-try/-/p-try-1.0.0.tgz#cbc79cdbaf8fd4228e13f621f2b1a237c1b207b3" +p-try@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/p-try/-/p-try-2.0.0.tgz#85080bb87c64688fa47996fe8f7dfbe8211760b1" + p-waterfall@^1.0.0: version "1.0.0" resolved "http://registry.yarnpkg.com/p-waterfall/-/p-waterfall-1.0.0.tgz#7ed94b3ceb3332782353af6aae11aa9fc235bb00" @@ -12979,6 +13039,33 @@ svgo@^0.7.0: sax "~1.2.1" whet.extend "~0.9.9" +swagger-cli@^2.1.1: + version "2.1.1" + resolved "https://registry.npmjs.org/swagger-cli/-/swagger-cli-2.1.1.tgz#f91748e9dabbd659091228af6bb86529d6d12d2a" + dependencies: + chalk "^2.4.1" + js-yaml "^3.12.0" + mkdirp "^0.5.1" + swagger-parser "^5.0.1" + yargs "^12.0.1" + +swagger-methods@^1.0.4: + version "1.0.4" + resolved "https://registry.npmjs.org/swagger-methods/-/swagger-methods-1.0.4.tgz#2c5b844f4a22ab2f5e773f98193c28e386b1c37e" + +swagger-parser@^5.0.1: + version "5.0.2" + resolved "https://registry.npmjs.org/swagger-parser/-/swagger-parser-5.0.2.tgz#8ff382dd7b2ce39d8ad68b9d56ee9973abfb7f19" + dependencies: + call-me-maybe "^1.0.1" + debug "^3.1.0" + json-schema-ref-parser "^5.1.1" + ono "^4.0.5" + openapi-schema-validation "^0.4.1" + swagger-methods "^1.0.4" + swagger-schema-official "2.0.0-bab6bed" + z-schema "^3.19.1" + swagger-schema-official@2.0.0-bab6bed: version "2.0.0-bab6bed" resolved "https://registry.npmjs.org/swagger-schema-official/-/swagger-schema-official-2.0.0-bab6bed.tgz#70070468d6d2977ca5237b2e519ca7d06a2ea3fd" @@ -14036,6 +14123,10 @@ validate-npm-package-name@^3.0.0: dependencies: builtins "^1.0.3" +validator@^10.0.0: + version "10.5.0" + resolved "https://registry.npmjs.org/validator/-/validator-10.5.0.tgz#1debbe1e6f5fd0c920ed2af47516f3762033939c" + value-equal@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/value-equal/-/value-equal-0.4.0.tgz#c5bdd2f54ee093c04839d71ce2e4758a6890abc7" @@ -14905,6 +14996,10 @@ xmlhttprequest@*, xmlhttprequest@1.8.0: version "1.8.0" resolved "https://registry.yarnpkg.com/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz#67fe075c5c24fef39f9d65f5f7b7fe75171968fc" +xregexp@4.0.0: + version "4.0.0" + resolved "https://registry.npmjs.org/xregexp/-/xregexp-4.0.0.tgz#e698189de49dd2a18cc5687b05e17c8e43943020" + "xtend@>=4.0.0 <4.1.0-0", xtend@^4.0.0, xtend@^4.0.1, xtend@~4.0.0, xtend@~4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af" @@ -14923,7 +15018,7 @@ y18n@^3.2.0, y18n@^3.2.1: version "3.2.1" resolved "https://registry.yarnpkg.com/y18n/-/y18n-3.2.1.tgz#6d15fba884c08679c0d77e88e7759e811e07fa41" -y18n@^4.0.0: +"y18n@^3.2.1 || ^4.0.0", y18n@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.0.tgz#95ef94f85ecc81d007c264e190a120f0a3c8566b" @@ -14939,6 +15034,12 @@ yallist@^3.0.0, yallist@^3.0.2: version "3.0.2" resolved "https://registry.npmjs.org/yallist/-/yallist-3.0.2.tgz#8452b4bb7e83c7c188d8041c1a837c773d6d8bb9" +yargs-parser@^10.1.0: + version "10.1.0" + resolved "https://registry.npmjs.org/yargs-parser/-/yargs-parser-10.1.0.tgz#7202265b89f7e9e9f2e5765e0fe735a905edbaa8" + dependencies: + camelcase "^4.1.0" + yargs-parser@^2.4.1: version "2.4.1" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-2.4.1.tgz#85568de3cf150ff49fa51825f03a8c880ddcc5c4" @@ -15045,6 +15146,23 @@ yargs@^11.0.0: y18n "^3.2.1" yargs-parser "^9.0.2" +yargs@^12.0.1: + version "12.0.1" + resolved "https://registry.npmjs.org/yargs/-/yargs-12.0.1.tgz#6432e56123bb4e7c3562115401e98374060261c2" + dependencies: + cliui "^4.0.0" + decamelize "^2.0.0" + find-up "^3.0.0" + get-caller-file "^1.0.1" + os-locale "^2.0.0" + require-directory "^2.1.1" + require-main-filename "^1.0.1" + set-blocking "^2.0.0" + string-width "^2.0.0" + which-module "^2.0.0" + y18n "^3.2.1 || ^4.0.0" + yargs-parser "^10.1.0" + yargs@^3.7.2: version "3.32.0" resolved "https://registry.npmjs.org/yargs/-/yargs-3.32.0.tgz#03088e9ebf9e756b69751611d2a5ef591482c995" @@ -15188,6 +15306,16 @@ yn@^2.0.0: version "2.0.0" resolved "https://registry.npmjs.org/yn/-/yn-2.0.0.tgz#e5adabc8acf408f6385fc76495684c88e6af689a" +z-schema@^3.19.1: + version "3.22.0" + resolved "https://registry.npmjs.org/z-schema/-/z-schema-3.22.0.tgz#e1326063cb438f348c648350770258ff5e20a22b" + dependencies: + lodash.get "^4.0.0" + lodash.isequal "^4.0.0" + validator "^10.0.0" + optionalDependencies: + commander "^2.7.1" + zeppelin-solidity@1.8.0: version "1.8.0" resolved "https://registry.yarnpkg.com/zeppelin-solidity/-/zeppelin-solidity-1.8.0.tgz#049fcde7daea9fc85210f8c6db9f8cd1ab8a853a" |