Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for scientific notation #146

Open
redparham opened this issue Nov 8, 2023 · 3 comments
Open

Support for scientific notation #146

redparham opened this issue Nov 8, 2023 · 3 comments

Comments

@redparham
Copy link

This schema with scientific notation maximum: 1e2

openapi: 3.0.3
info:
  title: scientific notation
  description: ...
  version: 1.0.0
paths:
  /pet:
    put:
      tags:
        - pet
      summary: ...
      description: ...
      operationId: updatePet
      requestBody:
        description: ...
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Pet'
      responses:
        '200':
          description: Successful operation
components:
  schemas:
    Pet:
      type: object
      properties:
        id:
          type: integer
          format: int64
          maximum: 1e2
          example: 10

results in this unexpected failure

# Validation Error

{'description': '...', 'content': {'application/json': {'schema': {'type': 'object', 'properties': {'id': {'type': 'integer', 'format': 'int64', 'maximum': '1e2', 'example': 10}}}}}} is not valid under any of the given schemas

Failed validating 'oneOf' in schema['properties']['paths']['patternProperties']['^\\/']['patternProperties']['^(get|put|post|delete|options|head|patch|trace)$']['properties']['requestBody']:
    {'oneOf': [{'$ref': '#/definitions/RequestBody'},
               {'$ref': '#/definitions/Reference'}]}

On instance['paths']['/pet']['put']['requestBody']:
    {'content': {'application/json': {'schema': {'properties': {'id': {'example': 10,
                                                                       'format': 'int64',
                                                                       'maximum': '1e2',
                                                                       'type': 'integer'}},
                                                 'type': 'object'}}},
     'description': '...'}


# Due to one of those errors

## {'type': 'object', 'properties': {'id': {'type': 'integer', 'format': 'int64', 'maximum': '1e2', 'example': 10}}} is not valid under any of the given schemas

Failed validating 'oneOf' in schema[0]['properties']['content']['additionalProperties']['properties']['schema']:
    {'oneOf': [{'$ref': '#/definitions/Schema'},
               {'$ref': '#/definitions/Reference'}]}

On instance['content']['application/json']['schema']:
    {'properties': {'id': {'example': 10,
                           'format': 'int64',
                           'maximum': '1e2',
                           'type': 'integer'}},
     'type': 'object'}


## '$ref' is a required property

Failed validating 'required' in schema[1]:
    {'patternProperties': {'^\\$ref$': {'format': 'uri-reference',
                                        'type': 'string'}},
     'required': ['$ref'],
     'type': 'object'}

On instance:
    {'content': {'application/json': {'schema': {'properties': {'id': {'example': 10,
                                                                       'format': 'int64',
                                                                       'maximum': '1e2',
                                                                       'type': 'integer'}},
                                                 'type': 'object'}}},
     'description': '...'}
...

If I change maximum: 1e2 to maximum: 100, it validates without error.

@p1c2u
Copy link
Collaborator

p1c2u commented Nov 9, 2023

Hi @redparham

you use OpenAPI 3.0.3 (Wright Draft 00 schema) which doesn't support integers as floats. Switch to OpenAPI 3.1 (Draft 2020-12 schema) and it should work for you.

@redparham
Copy link
Author

Hi @p1c2u.

I see this in the 3.0.1 and 3.1.0 spec:

Note that integer as a type is also supported and is defined as a JSON number without a fraction or exponent part.
https://spec.openapis.org/oas/v3.1.0#data-types

@p1c2u
Copy link
Collaborator

p1c2u commented Nov 10, 2023

Hmm , that's true. I will investigate this more.

@p1c2u p1c2u transferred this issue from python-openapi/openapi-spec-validator Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants