SwaggerJS 验证失败:无效的内容类型(应用程序/json)

Com*_*mum 0 swagger

我正在尝试使用swagger-node设置模拟 API 。我已经收到了.yaml包含所有声明的文件,所以它应该是开箱即用的。但是,当我在模拟模式下运行它时,它会构建,但是当我访问任何路由时,我收到一个错误:Error: Response validation failed: invalid content type (application/json). These are valid: */*

我认为问题是在每条路径中都有 aconsumes和 a produces,但是我真的不知道它们指的是什么,因为我在文档 () 中找不到它们。下面是我得到的路径示例,我只添加了x-swagger-router-controller一点。谁能帮我弄清楚为什么这不会立即运行?

示例路径

'/**/C/{categoryCode}/getSearchPageData':
get:
  tags:
    - category-search-results-rest-controller
  summary: Get Search Page Data
  operationId: getSearchPageDataUsingGET
  consumes:
    - application/json
  produces:
    - '*/*'
  parameters:
    - name: categoryCode
      in: path
      description: category code
      required: true
      type: string
    - name: q
      in: query
      description: search query
      required: false
      type: string
    - name: sort
      in: query
      description: sort
      required: false
      type: string
    - name: pageSize
      in: query
      description: page size
      required: false
      type: integer
      default: 20
      format: int32
    - name: pageNumber
      in: query
      description: page number
      required: false
      type: integer
      format: int32
  responses:
    '200':
      description: OK
      schema:
        $ref: '#/definitions/ProductCategorySearchPageData'
    '401':
      description: Unauthorized
    '403':
      description: Forbidden
    '404':
      description: Not Found
  x-swagger-router-controller: 'getSearchPageData'
Run Code Online (Sandbox Code Playgroud)

Hel*_*len 6

通配符( */*)通常对应于application/octet-stream,不同于application/json。尝试更改produces以列出您的实际响应媒体类型,例如

produces:
  - application/json
  - application/xml
Run Code Online (Sandbox Code Playgroud)

您可能还应该删除consumes,因为它仅适用于具有请求正文的请求,例如 POST/PUT/PATCH。