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

[Bug]: Numerical strings are accepted as integers #819

Open
Alopalao opened this issue Mar 26, 2024 · 0 comments
Open

[Bug]: Numerical strings are accepted as integers #819

Alopalao opened this issue Mar 26, 2024 · 0 comments
Labels
kind/bug Indicates an issue

Comments

@Alopalao
Copy link

Actual Behavior

String numerical values ("10") are accepted as integers.

Expected Behavior

Unmarshal request should return an error.

Steps to Reproduce

api.yml

openapi: 3.0.0
info:
  title: test
  version: '0.1'
servers:
  - url: /test
paths:
  /sending:
    put:
      summary: Send integer
      requestBody:
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              properties:
                my_integer:
                  type: integer
      responses:
        200:
          description: Ok.

test_request.py

import json
from openapi_core import OpenAPI
from openapi_core.contrib.starlette import StarletteOpenAPIRequest
from starlette.requests import Request


def starlette_request(path: str):
    return Request({
        "type": "http",
        "method": "PUT",
        "path": path,
        "headers": [(b"content-type", b"application/json; charset=utf-8")],
        "query_string": "",
    })

body = json.dumps({"my_integer": "10"})
spec = OpenAPI.from_file_path("api.yml")
request = StarletteOpenAPIRequest(starlette_request("/test/sending"), body=body)
result = spec.unmarshal_request(request)
print(result.errors)

OpenAPI Core Version

0.19.0

OpenAPI Core Integration

starlette

Affected Area(s)

Unmarshaling

References

Reading the guide for OpenAPI 3.0.0 from swagger, it states that numbers in strings are not accepted as integers.

Anything else we need to know?

Is this a feature? Previously this was not the case and I found out about this change because I updated from 0.16.6 to 0.19.0.

Would you like to implement a fix?

None

@Alopalao Alopalao added the kind/bug Indicates an issue label Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Indicates an issue
Projects
None yet
Development

No branches or pull requests

1 participant