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

fix(plugin): ensure open-api docs generation for types named with Promise or Observable #2869

Open
wants to merge 1 commit 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/plugin/utils/plugin-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export function getTypeReferenceAsString(
}

export function isPromiseOrObservable(type: string) {
return type.includes('Promise') || type.includes('Observable');
return type.includes('Promise<') || type.includes('Observable<');
}

export function hasPropertyKey(
Expand Down
50 changes: 50 additions & 0 deletions test/plugin/fixtures/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { ApiOperation } from '@nestjs/swagger';

class Cat {}

class PromiseCat {}

class ObservableCat {}

@Controller('cats')
export class AppController {
onApplicationBootstrap() {}
Expand Down Expand Up @@ -39,6 +43,24 @@ export class AppController {
@Post()
async testCreate2(): Promise<Cat> {}

/**
* create a test PromiseCat
*
* @returns {Promise<PromiseCat>>}
* @memberof AppController
*/
@Post()
async testCreate3(): Promise<PromiseCat> {}

/**
* create a test ObservableCat
*
* @returns {Promise<ObservableCat>}
* @memberof AppController
*/
@Post()
async testCreate4(): Promise<ObservableCat> {}

/**
* find a Cat
*/
Expand Down Expand Up @@ -68,6 +90,10 @@ const common_1 = require(\"@nestjs/common\");
const swagger_1 = require(\"@nestjs/swagger\");
class Cat {
}
class PromiseCat {
}
class ObservableCat {
}
let AppController = exports.AppController = class AppController {
onApplicationBootstrap() { }
/**
Expand Down Expand Up @@ -95,6 +121,20 @@ let AppController = exports.AppController = class AppController {
* @memberof AppController
*/
async testCreate2() { }
/**
* create a test PromiseCat
*
* @returns {Promise<PromiseCat>>}
* @memberof AppController
*/
async testCreate3() { }
/**
* create a test ObservableCat
*
* @returns {Promise<ObservableCat>}
* @memberof AppController
*/
async testCreate4() { }
/**
* find a Cat
*/
Expand Down Expand Up @@ -122,6 +162,16 @@ __decorate([
(0, common_1.Post)(),
openapi.ApiResponse({ status: 201, type: Cat })
], AppController.prototype, \"testCreate2\", null);
__decorate([
openapi.ApiOperation({ summary: \"create a test PromiseCat\" }),
(0, common_1.Post)(),
openapi.ApiResponse({ status: 201, type: PromiseCat })
], AppController.prototype, \"testCreate3\", null);
__decorate([
openapi.ApiOperation({ summary: \"create a test ObservableCat\" }),
(0, common_1.Post)(),
openapi.ApiResponse({ status: 201, type: ObservableCat })
], AppController.prototype, \"testCreate4\", null);
__decorate([
(0, swagger_1.ApiOperation)({ summary: \"find a Cat\" }),
Get(),
Expand Down