Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for observables. #111

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 19 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/metadata/resolveType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ export function resolveType(typeNode?: ts.TypeNode, genericTypeMap?: Map<String,
if (typeName === 'DownloadBinaryData') { return { typeName: 'buffer' }; }
if (typeName === 'DownloadResource') { return { typeName: 'buffer' }; }

if (typeName === 'Promise') {
if (typeName === 'Promise' || typeName === 'Observable') {
typeReference = typeReference.typeArguments[0];
return resolveType(typeReference, genericTypeMap);
}

if (typeName === 'Array') {
typeReference = typeReference.typeArguments[0];
return {
Expand Down
45 changes: 45 additions & 0 deletions test/data/apis.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

import {Observable, of} from "rxjs";
import {
Accept, DELETE, FormParam, GET, Path,
PathParam, POST, PUT, QueryParam,
Expand Down Expand Up @@ -464,3 +465,47 @@ export class ResponseController {
return 'OK';
}
}

@Path('observable')
export class ObservableController {
@GET
public get(): Observable<string> {
return of('hello');
}

@GET
@Path('array')
public getArray(): Observable<Array<string>> {
return of([]);
}

@GET
@Path('person')
public getPerson(): Observable<Person> {
return of({
address: {
street: 'Fleet Street'
} as Address,
name: 'Jon'
} as Person);
}

@GET
@Path('population')
public getPersons(): Observable<Array<Person>> {
return of([
{
address: {
street: 'Fleet Street'
} as Address,
name: 'Jon'
},
{
address: {
street: 'Cannon Street'
} as Address,
name: 'Jessica'
}
]);
}
}
10 changes: 10 additions & 0 deletions test/server/server.js
Original file line number Diff line number Diff line change
@@ -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");
});
8 changes: 8 additions & 0 deletions test/unit/definitions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});