【发布时间】:2019-02-19 20:25:30
【问题描述】:
我有以下metrics.controller.ts 文件:
import { Controller, Get } from '@nestjs/common';
import { ApiOperation, ApiResponse, ApiUseTags, ApiModelProperty } from '@nestjs/swagger';
import { PrometheusService } from './prometheus.service';
@Controller('metrics')
@ApiUseTags('Misc')
export class MetricsController {
constructor(private readonly prometheusService: PrometheusService) {}
@Get('/')
@ApiOperation({
title: 'Prometheus metrics',
description: 'Exposes default prometheus node metrics'
})
@ApiResponse({ status: 200, description: 'Prometheus metrics' })
public getMetrics(): string {
return this.prometheusService.getMetrics();
}
}
然而,当实际输出为 text/plain 时,Swagger 错误地指示 响应内容类型 为 application/json:
我尝试查看Swagger docs regarding describing responses,我正在寻找的项目是“内容”部分。但是,该文档不涵盖 TypeScript 注释。 Swagger Core 2.X documentation 谈到了一个 @Operation 注释,但我没有提到它,我不知道从哪里得到一个 - 只有 @ApiOperation 有效。
项目目录下npm ls的相关版本信息如下:
+-- @nestjs/swagger@2.5.1
| +-- @nestjs/common@5.3.6 deduped
| +-- @nestjs/core@5.3.6 deduped
| +-- lodash@4.17.10
| +-- path-to-regexp@2.2.1 deduped
| `-- swagger-ui-express@3.0.10
指示响应内容类型为text/plain的正确注释是什么?
【问题讨论】:
标签: node.js typescript swagger