From 3aa862823098245005935ed98619f6cdac38def0 Mon Sep 17 00:00:00 2001 From: snava10 Date: Sat, 28 Mar 2020 16:58:02 +0000 Subject: [PATCH 1/3] adding if statement for the observable data type. Adding a dummy api to visualize the swagger --- package-lock.json | 29 +++++++++++++++--------- package.json | 35 ++++++++++++++++------------- src/metadata/resolveType.ts | 6 +++++ test/data/apis.ts | 45 +++++++++++++++++++++++++++++++++++++ test/server/server.js | 10 +++++++++ 5 files changed, 99 insertions(+), 26 deletions(-) create mode 100644 test/server/server.js diff --git a/package-lock.json b/package-lock.json index 31d7c21..3b01951 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3455,9 +3455,9 @@ "dev": true }, "ipaddr.js": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.0.tgz", - "integrity": "sha512-M4Sjn6N/+O6/IXSJseKqHoFc+5FdGJ22sXqnjTpdZweHK64MzEPAyQZyEU3R/KRv2GLoa7nNtg/C2Ev6m7z+eA==", + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", "dev": true }, "is-accessor-descriptor": { @@ -5658,13 +5658,13 @@ } }, "proxy-addr": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.5.tgz", - "integrity": "sha512-t/7RxHXPH6cJtP0pRG6smSr9QJidhB+3kXu0KgXnbGYMgzEnUxRQ4/LDdfOwZEMyIh3/xHb8PX3t+lfL9z+YVQ==", + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.6.tgz", + "integrity": "sha512-dh/frvCBVmSsDYzw6n926jv974gddhkFPfiN8hPOi30Wax25QZyZEGveluCgliBnqmuM+UJmBErbAUFIoDbjOw==", "dev": true, "requires": { "forwarded": "~0.1.2", - "ipaddr.js": "1.9.0" + "ipaddr.js": "1.9.1" } }, "prr": { @@ -5943,6 +5943,15 @@ "integrity": "sha512-nfMOlASu9OnRJo1mbEk2cz0D56a1MBNrJ7orjRZQG10XDyuvwksKbuXNp6qa+kbn839HwjwhBzhFmdsaEAfauA==", "dev": true }, + "rxjs": { + "version": "6.5.4", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.5.4.tgz", + "integrity": "sha512-naMQXcgEo3csAEGvw/NydRA0fuS2nDZJiw1YUWFKU7aPPAPGZEsD4Iimit96qwCieH6y614MCLYwdkrWx7z/7Q==", + "dev": true, + "requires": { + "tslib": "^1.9.0" + } + }, "safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", @@ -6541,9 +6550,9 @@ "dev": true }, "swagger-ui-express": { - "version": "4.1.3", - "resolved": "https://registry.npmjs.org/swagger-ui-express/-/swagger-ui-express-4.1.3.tgz", - "integrity": "sha512-f8SEn4YWkKh/HGK0ZjuA2VqA78i1aY6OIa5cqYNgOkBobfHV6Mz4dphQW/us8HYhEFfbENq329PyfIonWfzFrw==", + "version": "4.1.4", + "resolved": "https://registry.npmjs.org/swagger-ui-express/-/swagger-ui-express-4.1.4.tgz", + "integrity": "sha512-Ea96ecpC+Iq9GUqkeD/LFR32xSs8gYqmTW1gXCuKg81c26WV6ZC2FsBSPVExQP6WkyUuz5HEiR0sEv/HCC343g==", "dev": true, "requires": { "swagger-ui-dist": "^3.18.1" diff --git a/package.json b/package.json index 692ca7d..7777f67 100644 --- a/package.json +++ b/package.json @@ -30,40 +30,43 @@ "license": "MIT", "dependencies": {}, "devDependencies": { - "argparse": "^1.0.10", - "debug": "^4.1.1", - "fs-extra-promise": "^1.0.1", - "glob": "^7.1.6", - "lodash": "^4.17.15", - "merge": "^1.2.1", - "minimatch": "^3.0.4", - "mkdirp": "^0.5.1", - "path": "^0.12.7", - "swagger2openapi": "^5.3.3", - "typescript": "^3.7.5", - "typescript-rest": "^2.2.6", - "yamljs": "^0.2.10", "@types/argparse": "^1.0.38", - "@types/jest": "^24.0.21", "@types/debug": "^4.1.5", "@types/fs-extra-promise": "^1.0.8", "@types/glob": "^7.1.1", - "jest": "^24.9.0", + "@types/jest": "^24.0.21", "@types/lodash": "^4.14.149", "@types/minimatch": "^3.0.3", "@types/mkdirp": "^0.3.29", "@types/yamljs": "^0.2.30", + "argparse": "^1.0.10", "coveralls": "^3.0.9", "cross-env": "^4.0.0", + "debug": "^4.1.1", + "express": "^4.17.1", + "fs-extra-promise": "^1.0.1", + "glob": "^7.1.6", + "jest": "^24.9.0", "jsonata": "^1.8.1", + "lodash": "^4.17.15", + "merge": "^1.2.1", + "minimatch": "^3.0.4", + "mkdirp": "^0.5.1", "mocha": "^5.2.0", + "path": "^0.12.7", "rimraf": "^2.7.1", + "rxjs": "^6.5.4", "source-map-support": "^0.4.14", + "swagger-ui-express": "^4.1.4", + "swagger2openapi": "^5.3.3", "ts-jest": "^24.1.0", "ts-loader": "^5.3.3", "ts-node": "^8.6.2", "tslint": "^5.20.1", - "tslint-config-prettier": "^1.17.0" + "tslint-config-prettier": "^1.17.0", + "typescript": "^3.7.5", + "typescript-rest": "^2.2.6", + "yamljs": "^0.2.10" }, "repository": { "type": "git", diff --git a/src/metadata/resolveType.ts b/src/metadata/resolveType.ts index 889ac36..1251658 100644 --- a/src/metadata/resolveType.ts +++ b/src/metadata/resolveType.ts @@ -59,6 +59,12 @@ export function resolveType(typeNode?: ts.TypeNode, genericTypeMap?: Map { + return of('hello'); + } + + @GET + @Path('array') + public getArray(): Observable> { + return of([]); + } + + @GET + @Path('person') + public getPerson(): Observable { + return of({ + address: { + street: 'Fleet Street' + } as Address, + name: 'Jon' + } as Person); + } + + @GET + @Path('population') + public getPersons(): Observable> { + return of([ + { + address: { + street: 'Fleet Street' + } as Address, + name: 'Jon' + }, + { + address: { + street: 'Cannon Street' + } as Address, + name: 'Jessica' + } + ]); + } +} diff --git a/test/server/server.js b/test/server/server.js new file mode 100644 index 0000000..d9388ad --- /dev/null +++ b/test/server/server.js @@ -0,0 +1,10 @@ +express = require("express"); +swaggerUi = require('swagger-ui-express'), +swaggerDocument = require('../dist/swagger.json'); + +app = express(); + +app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument)); +app.listen(3000, () => { + console.log("Server running on port 3000"); +}); From e422bc7e4708d6586e12ae593a265b03089da507 Mon Sep 17 00:00:00 2001 From: snava10 Date: Sat, 28 Mar 2020 17:05:12 +0000 Subject: [PATCH 2/3] unit testing --- test/unit/definitions.spec.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/unit/definitions.spec.ts b/test/unit/definitions.spec.ts index e64bed5..48f91f9 100644 --- a/test/unit/definitions.spec.ts +++ b/test/unit/definitions.spec.ts @@ -432,4 +432,12 @@ describe('Definition generation', () => { }); }); + describe('Should support observables', () => { + it('', () => { + expect(spec.paths).toHaveProperty('/observable'); + expect(spec.paths).toHaveProperty('/observable/array'); + expect(spec.paths).toHaveProperty('/observable/person'); + expect(spec.paths).toHaveProperty('/observable/population'); + }); + }); }); From 7cf3c948da545e63ac5e6060b1b56ccd8b4055b1 Mon Sep 17 00:00:00 2001 From: snava10 Date: Sat, 28 Mar 2020 17:31:23 +0000 Subject: [PATCH 3/3] refactoring --- src/metadata/resolveType.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/metadata/resolveType.ts b/src/metadata/resolveType.ts index 1251658..35683b0 100644 --- a/src/metadata/resolveType.ts +++ b/src/metadata/resolveType.ts @@ -55,12 +55,7 @@ export function resolveType(typeNode?: ts.TypeNode, genericTypeMap?: Map