Skip to content

Commit

Permalink
fix(plugin): ensure open-api docs generation for types named with Pro…
Browse files Browse the repository at this point in the history
…mise or Observable
  • Loading branch information
jinyongp committed Mar 9, 2024
1 parent 2ee9b7c commit 9465e0e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
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

0 comments on commit 9465e0e

Please sign in to comment.