Giving an integer value as default for a double, causes the validation to fail

未关闭
#115 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
42/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
openapi, python
领域
api, testing

调研方向

Reproduce the failure with the provided openapi.yaml using openapi_spec_validator.readers.read_from_filename and validate_spec. Compare validation of integer and floating-point defaults for a number with format double; done means the intended behavior is established and covered by a regression test, while preserving the valid 15.0 case.

由索引模型根据 Issue 内容生成。

描述

Hi,
I noticed that there is a breaking change from 0.2.9 to 0.3.0, but I am not sure if it is intentional or not.

tl;dr: an integer is no longer considered a valid (default) value for a double. In the example below, 15 fails the validation, but 15.0 is fine.

PS: I am using openapi-spec-validator through the connexion library.

Steps to reproduce
python -m venv .venv
source .venv/bin/activate
pip install "openapi-spec-validator@0.3.0"
>>> from openapi_spec_validator import validate_spec
>>> from openapi_spec_validator.readers import read_from_filename
>>>
>>> spec_dict, spec_url = read_from_filename('./openapi.yaml')
>>> validate_spec(spec_dict)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<current working directory>/.venv/lib/python3.9/site-packages/openapi_spec_validator/shortcuts.py", line 7, in validate
    return validator_callable(spec, spec_url=spec_url)
  File "<current working directory>/__app__/.venv/lib/python3.9/site-packages/openapi_spec_validator/validators.py", line 48, in validate
    raise err
openapi_spec_validator.exceptions.OpenAPIValidationError: 15 is not a 'double'

Failed validating 'format' in schema:
    {'default': 15,
     'format': 'double',
     'maximum': 60,
     'minimum': 15,
     'nullable': False,
     'type': 'number'}

On instance:
    15

where openapi.yaml is defined as

openapi: "3.0.3"
info:
  title: API
  version: "1.0.0"

servers:
  - url: http://localhost/api
    description: Used for local development.
paths:
  /foo:
    get:
      parameters:
        - in: query
          name: duration
          required: false
          schema:
            type: number
            format: double
            default: 15
            maximum: 60
            minimum: 15
          example: 53

      responses:
        200:
          description: ""
          content:
            text/plain: {}

Changing default: 15 to default: 15.0 works as expected.

In version 0.2.9, the OpenAPI specification above was considered valid.

主要语言
Python
星标
409
派生
73
PR 合并指标
30 天内没有已合并 PR

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

python-openapi/openapi-spec-validator 的其他 Issue

查看 python-openapi/openapi-spec-validator 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。