【问题标题】:Validate OpenAPI response with dredd使用 dredd 验证 OpenAPI 响应
【发布时间】:2019-03-19 12:13:13
【问题描述】:

我有一个 OpenAPI v3 规范文件,其中包含以下内容(仅显示片段):

paths:
  /global/name:
    get:
    description: Some description
    tags:
      - Global settings
    operationId: getGlobalSettingsName
    responses:
      # Response code
      '200':
        description: Successful response
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/globalSettingsName'

components:
  schemas:
    globalSettingsName:
      type: object
      properties:
        name:
          type: integer
          description: 'ID'
          example: 1
      required:
        - name

但服务器响应是:

{
  "name": "somestring"
}

注意名称属性类型是integer,在服务器响应中,它是string(故意)但dredd请求通过(成功)。

dredd 不检查响应属性类型吗?

我将响应重新定义为string(不是 JSON):

responses:
    # Response code
    '200':
      description: Successful response
      content:
        application/json:
          schema:
            type: string

dredd 也没有抱怨。

我什至改变了模式的属性:

    globalSettingsName:
      type: object
      properties:
        www:
          type: string
          description: 'some description'
          example: 'somestring'
      required:
        - www

当预期失败时,结果相同(成功)。

dredd 不支持这些验证吗?我是不是用错了规范?

【问题讨论】:

  • 这可能不相关 - 但 example: 1 应该在 name 属性定义内,而不是在对象级别。

标签: openapi dredd


【解决方案1】:

导致当前版本(8.0.5)只支持内容中的示例值:https://github.com/apiaryio/dredd/issues/1281

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2021-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多