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

Aberta
#115 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
42/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Estagnada
Stack de tecnologia
openapi, python
Domínio
api, testing

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
Python
Estrelas
409
Forks
73
Métricas de merge de PRs
Nenhum PR com merge em 30d

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de python-openapi/openapi-spec-validator

Todas as issues de python-openapi/openapi-spec-validator

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.