Title: [Bug]: Can’t validate numerical string as `type`: `integer`/`number`/`boolean` wrapped in `allOf`/`anyOf`/`oneOf` · Issue #698 · python-openapi/openapi-core · GitHub
Open Graph Title: [Bug]: Can’t validate numerical string as `type`: `integer`/`number`/`boolean` wrapped in `allOf`/`anyOf`/`oneOf` · Issue #698 · python-openapi/openapi-core
X Title: [Bug]: Can’t validate numerical string as `type`: `integer`/`number`/`boolean` wrapped in `allOf`/`anyOf`/`oneOf` · Issue #698 · python-openapi/openapi-core
Description: Actual Behavior The string 123 from a path or query parameter validates as {"type": "integer"}, but unexpectedly fails to validate as {"allOf": [{"type": "integer"}]}. The same problem occurs with number or boolean in place of integer, o...
Open Graph Description: Actual Behavior The string 123 from a path or query parameter validates as {"type": "integer"}, but unexpectedly fails to validate as {"allOf": [{"type": "integer"}]}. The same problem occurs with ...
X Description: Actual Behavior The string 123 from a path or query parameter validates as {"type": "integer"}, but unexpectedly fails to validate as {"allOf": [{"type": &qu...
Opengraph URL: https://github.com/python-openapi/openapi-core/issues/698
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Can’t validate numerical string as `type`: `integer`/`number`/`boolean` wrapped in `allOf`/`anyOf`/`oneOf`","articleBody":"### Actual Behavior\n\nThe string `123` from a path or query parameter validates as `{\"type\": \"integer\"}`, but unexpectedly fails to validate as `{\"allOf\": [{\"type\": \"integer\"}]}`. The same problem occurs with `number` or `boolean` in place of `integer`, or `anyOf` or `oneOf` in place of `allOf`.\r\n\r\n(My [actual use case](https://github.com/zulip/zulip/blob/1839eb023977107699e2368ccdb0f20a496f6fcf/zerver/openapi/zulip.yaml#L17561-L17568) involves `{\"oneOf\": [{\"type\": \"string\", \"enum\": [\"newest\", \"oldest\", \"first_unread\"]}, {\"type\": \"integer\"}]}`.)\r\n\r\n```pytb\r\nTraceback (most recent call last):\r\n File \"/home/anders/python/openapi-core/openapi_core/validation/decorators.py\", line 31, in wrapper\r\n return f(*args, **kwds)\r\n File \"/home/anders/python/openapi-core/openapi_core/validation/request/validators.py\", line 200, in _get_parameter\r\n value, _ = self._get_param_or_header_and_schema(param, location)\r\n File \"/home/anders/python/openapi-core/openapi_core/validation/validators.py\", line 166, in _get_param_or_header_and_schema\r\n self._validate_schema(schema, casted)\r\n File \"/home/anders/python/openapi-core/openapi_core/validation/validators.py\", line 144, in _validate_schema\r\n validator.validate(value)\r\n File \"/home/anders/python/openapi-core/openapi_core/validation/schemas/validators.py\", line 36, in validate\r\n raise InvalidSchemaValue(value, schema_type, schema_errors=errors)\r\nopenapi_core.validation.schemas.exceptions.InvalidSchemaValue: Value 123 not valid for schema of type any: (\u003cValidationError: \"'123' is not of type 'integer'\"\u003e,)\r\n\r\nThe above exception was the direct cause of the following exception:\r\n\r\nTraceback (most recent call last):\r\n File \"/home/anders/python/openapi-core/test.py\", line 41, in \u003cmodule\u003e\r\n validate_request(request, spec=spec) # error\r\n File \"/home/anders/python/openapi-core/openapi_core/shortcuts.py\", line 321, in validate_request\r\n validate_apicall_request(\r\n File \"/home/anders/python/openapi-core/openapi_core/shortcuts.py\", line 396, in validate_apicall_request\r\n return v.validate(request)\r\n File \"/home/anders/python/openapi-core/openapi_core/validation/request/validators.py\", line 279, in validate\r\n raise err\r\n File \"/home/anders/python/openapi-core/openapi_core/validation/request/validators.py\", line 164, in _get_parameters\r\n value = self._get_parameter(parameters, param)\r\n File \"/home/anders/python/openapi-core/openapi_core/validation/decorators.py\", line 33, in wrapper\r\n self._raise_error(exc, self.err_validate_cls, f, *args, **kwds)\r\n File \"/home/anders/python/openapi-core/openapi_core/validation/decorators.py\", line 58, in _raise_error\r\n raise init(**kw) from exc\r\nopenapi_core.validation.request.exceptions.InvalidParameter: Invalid path parameter: bar_id\r\n```\n\n### Expected Behavior\n\nNo error. A string that validates as `{\"type\": \"integer\"}` should also validate as `{\"allOf\": [{\"type\": \"integer\"}]}`.\n\n### Steps to Reproduce\n\n```python\r\nfrom openapi_core import Spec, validate_request\r\nfrom openapi_core.testing import MockRequest\r\n\r\nspec = Spec.from_dict(\r\n {\r\n \"openapi\": \"3.1.0\",\r\n \"info\": {\"title\": \"test\", \"version\": \"0\"},\r\n \"paths\": {\r\n \"/foo/{foo_id}\": {\r\n \"get\": {\r\n \"parameters\": [\r\n {\r\n \"name\": \"foo_id\",\r\n \"in\": \"path\",\r\n \"required\": True,\r\n \"schema\": {\"type\": \"integer\"},\r\n },\r\n ],\r\n },\r\n },\r\n \"/bar/{bar_id}\": {\r\n \"get\": {\r\n \"parameters\": [\r\n {\r\n \"name\": \"bar_id\",\r\n \"in\": \"path\",\r\n \"required\": True,\r\n \"schema\": {\"allOf\": [{\"type\": \"integer\"}]},\r\n },\r\n ],\r\n },\r\n },\r\n },\r\n }\r\n)\r\n\r\nrequest = MockRequest(\"http://localhost\", \"get\", \"/foo/123\")\r\nvalidate_request(request, spec=spec) # ok\r\n\r\nrequest = MockRequest(\"http://localhost\", \"get\", \"/bar/123\")\r\nvalidate_request(request, spec=spec) # error\r\n```\n\n### OpenAPI Core Version\n\n0.18.1 or current Git (0838a84e7c23d9f0691e0e7d496550d12513476e)\n\n### OpenAPI Core Integration\n\nnone\n\n### Affected Area(s)\n\n_No response_\n\n### References\n\n_No response_\n\n### Anything else we need to know?\n\n_No response_\n\n### Would you like to implement a fix?\n\nNone","author":{"url":"https://github.com/andersk","@type":"Person","name":"andersk"},"datePublished":"2023-10-21T00:10:31.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/698/openapi-core/issues/698"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:1f2a6b6c-3995-d70d-d57d-55050f58d706 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C138:18807F:4915227:644C6F1:6978009A |
| html-safe-nonce | 74f89292c5ac96492fa4b958fd9be5a7461d42bd1368788872305ad21422d27d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMTM4OjE4ODA3Rjo0OTE1MjI3OjY0NEM2RjE6Njk3ODAwOUEiLCJ2aXNpdG9yX2lkIjoiNTM0Njc1MzAyMTMxOTA1MzQ2NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a60e5095ac1fb92fc9ffe57d766107d45e3746cbd2c866198e5bf2fe06dc9a75 |
| hovercard-subject-tag | issue:1955150028 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-openapi/openapi-core/698/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4b7d91eaf139563aeaf46b5f53972a9b8b0bda0a390ad0b352aae72be064d581/python-openapi/openapi-core/issues/698 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4b7d91eaf139563aeaf46b5f53972a9b8b0bda0a390ad0b352aae72be064d581/python-openapi/openapi-core/issues/698 |
| og:image:alt | Actual Behavior The string 123 from a path or query parameter validates as {"type": "integer"}, but unexpectedly fails to validate as {"allOf": [{"type": "integer"}]}. The same problem occurs with ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | andersk |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9306bf4a8c8a88a5945f83e25033fc5e6fb7a05f40c5fca300ac67db7fee56ae |
| turbo-cache-control | no-preview |
| go-import | github.com/python-openapi/openapi-core git https://github.com/python-openapi/openapi-core.git |
| octolytics-dimension-user_id | 126442889 |
| octolytics-dimension-user_login | python-openapi |
| octolytics-dimension-repository_id | 104200746 |
| octolytics-dimension-repository_nwo | python-openapi/openapi-core |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 104200746 |
| octolytics-dimension-repository_network_root_nwo | python-openapi/openapi-core |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ebcec36a0fcd90aa18ad42cdc7e8952475890ee5 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width