Title: validation(openapi-3.1.0) - nullable enums? · Issue #378 · python-openapi/openapi-spec-validator · GitHub
Open Graph Title: validation(openapi-3.1.0) - nullable enums? · Issue #378 · python-openapi/openapi-spec-validator
X Title: validation(openapi-3.1.0) - nullable enums? · Issue #378 · python-openapi/openapi-spec-validator
Description: I have in an external projects some problems with the openapi-spec-validator. In our project, we happen to generate an property that either has a value from an enum, or can be null. See: master...kazie:openapi-spec-validator:test/test-wi...
Open Graph Description: I have in an external projects some problems with the openapi-spec-validator. In our project, we happen to generate an property that either has a value from an enum, or can be null. See: master...k...
X Description: I have in an external projects some problems with the openapi-spec-validator. In our project, we happen to generate an property that either has a value from an enum, or can be null. See: master...k...
Opengraph URL: https://github.com/python-openapi/openapi-spec-validator/issues/378
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"validation(openapi-3.1.0) - nullable enums?","articleBody":"I have in an external projects some problems with the openapi-spec-validator.\r\n\r\nIn our project, we happen to generate an property that either has a value from an `enum`, or can be `null.`\r\n\r\nSee: https://github.com/python-openapi/openapi-spec-validator/compare/master...kazie:openapi-spec-validator:test/test-with-enum-string-or-null-property\r\n\r\nI would believe this is valid OpenAPI specification for a field, but the validation fails, as from this project fork when running test:\r\n\r\n```python\r\nopenapi_spec_validator/shortcuts.py:48: in validate\r\n return v.validate()\r\n base_uri = 'file:///home/kazie/src/github/openapi-spec-validator/tests/integration/data/v3.1/petstore.yaml'\r\n cls = \u003cclass 'openapi_spec_validator.validation.validators.OpenAPIV31SpecValidator'\u003e\r\n sp = SchemaPath('')\r\n spec = {'components': {'pathItems': {'PetPath': {'get': {'operationId': 'showPetById', 'parameters': [{...}], 'responses': {'...r'}}, 'summary': 'Create a pet', 'tags': ['pets']}}, '/pets/{petId}': {'$ref': '#/components/pathItems/PetPath'}}, ...}\r\n v = \u003copenapi_spec_validator.validation.validators.OpenAPIV31SpecValidator object at 0x782454500440\u003e\r\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \r\n\r\nself = \u003copenapi_spec_validator.validation.validators.OpenAPIV31SpecValidator object at 0x782454500440\u003e\r\n\r\n def validate(self) -\u003e None:\r\n for err in self.iter_errors():\r\n\u003e raise err\r\nE openapi_spec_validator.validation.exceptions.OpenAPIValidationError: None is not one of ['ALIVE', 'DEAD']\r\nE \r\nE Failed validating 'enum' in schema:\r\nE {'default': None,\r\nE 'description': 'The status of the pet. `null` if current status can '\r\nE 'not be confirmed.',\r\nE 'enum': ['ALIVE', 'DEAD'],\r\nE 'example': 'ALIVE',\r\nE 'type': ['string', 'null']}\r\nE \r\nE On instance:\r\nE None\r\n\r\nerr = \u003cOpenAPIValidationError: \"None is not one of ['ALIVE', 'DEAD']\"\u003e\r\nself = \u003copenapi_spec_validator.validation.validators.OpenAPIV31SpecValidator object at 0x782454500440\u003e\r\n\r\nopenapi_spec_validator/validation/validators.py:71: OpenAPIValidationError\r\n```\r\n\r\nIt is true that `None` is not in the enum `[ ALIVE, DEAD ]`, but it is in the type array as `['string', 'null']` \r\n\r\n---\r\n\r\nSo, do you believe that my specification is just invalid, or do we have a bug on our hands in the validation here? :sweat_smile: \r\n\r\nI came to this when migrating from `OpenAPI 3.0.3` where we migrate from having `nullable: true` into these type arrays.","author":{"url":"https://github.com/kazie","@type":"Person","name":"kazie"},"datePublished":"2024-11-19T16:10:37.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/378/openapi-spec-validator/issues/378"}
| 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:d621531f-7ec9-f10e-d43d-dd57c5fdd143 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CA00:21AC08:16E5F8:1FE61D:696A6C77 |
| html-safe-nonce | f351111ea6502d561cba74d0a77f87551d319b876708fa3ee41285b0056e4c7e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQTAwOjIxQUMwODoxNkU1Rjg6MUZFNjFEOjY5NkE2Qzc3IiwidmlzaXRvcl9pZCI6Ijc3MDExODU4ODg5MDQ3MDMwOTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 7206650018a275614c3af81264a739c27c1ef1a1dc15c05bac16d870b65be9cc |
| hovercard-subject-tag | issue:2672721890 |
| 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-spec-validator/378/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1ce40ebb56fd9196442769445e8ae73715e755170801929d6d51030322a7443c/python-openapi/openapi-spec-validator/issues/378 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1ce40ebb56fd9196442769445e8ae73715e755170801929d6d51030322a7443c/python-openapi/openapi-spec-validator/issues/378 |
| og:image:alt | I have in an external projects some problems with the openapi-spec-validator. In our project, we happen to generate an property that either has a value from an enum, or can be null. See: master...k... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kazie |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6fea32d5b7276b841b7a803796d9715bc6cfb31ed549fdf9de2948ac25d12ba6 |
| turbo-cache-control | no-preview |
| go-import | github.com/python-openapi/openapi-spec-validator git https://github.com/python-openapi/openapi-spec-validator.git |
| octolytics-dimension-user_id | 126442889 |
| octolytics-dimension-user_login | python-openapi |
| octolytics-dimension-repository_id | 102581313 |
| octolytics-dimension-repository_nwo | python-openapi/openapi-spec-validator |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 102581313 |
| octolytics-dimension-repository_network_root_nwo | python-openapi/openapi-spec-validator |
| 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 | f2d9f6432a5a115ec709295ae70623f33bb80aee |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width