Title: Custom format for unmarshalling doesn't work · python-openapi/openapi-core · Discussion #778 · GitHub
Open Graph Title: Custom format for unmarshalling doesn't work · python-openapi/openapi-core · Discussion #778
X Title: Custom format for unmarshalling doesn't work · python-openapi/openapi-core · Discussion #778
Description: Custom format for unmarshalling doesn't work
Open Graph Description: Hello, Thanks for the openap-core project; it's very helpful. I'm using it to validate my api input. I'm trying to make sure that required values that are blank strings are not allowed. I've tried ...
X Description: Hello, Thanks for the openap-core project; it's very helpful. I'm using it to validate my api input. I'm trying to make sure that required values that are blank strings are not allowed....
Opengraph URL: https://github.com/python-openapi/openapi-core/discussions/778
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"QAPage","mainEntity":{"@type":"Question","name":"Custom format for unmarshalling doesn't work","text":"Hello, Thanks for the openap-core project; it's very helpful. I'm using it to validate my api input. I'm trying to make sure that required values that are blank strings are not allowed. I've tried using the documented YAML specs directly (https://swagger.io/docs/specification/data-models/data-types/#string):
\ntype: string\nminLength: 1\n\n
\nand
\n type: string\n pattern: '^.+$'\n\n
\nBut the unmarshaller ignores these specifications.
\nI upgraded to 0.19.0a1 to add a custom validator, per https://openapi-core.readthedocs.io/_/downloads/en/latest/pdf/ by @p1c2u Artur Maciag but his example doesn't seem to do anything:
\n from datetime import datetime\n\n def unmarshal_usdate(value):\n return datetime.strptime(value, \"%m/%d/%y\").date\n\n extra_format_unmarshallers = {\n \"usdate\": unmarshal_usdate,\n }\n\n def validate_usdate(value):\n return bool(re.match(r\"^\\d{1,2}/\\d{1,2}/\\d{4}$\", value))\n\n extra_format_validators = {\n \"usdate\": validate_usdate,\n }\n\n config = Config(\n extra_format_validators=extra_format_validators,\n extra_format_unmarshallers=extra_format_unmarshallers,\n )\n\n return OpenAPI.from_file_path(spec_file_path, config=config)\n\n
\nThe unmarshaller for the YAML:
\n test:\n type: string\n description: Test\n format: usdate\n\n
\nHappily returns:
\nRequestUnmarshalResult(errors=[], body={'test': 'not a date', 'description': 'A multiple choice activity focusing on synonyms', 'binary_result': True, 'directionality': 'passive', 'modality': 'text', 'interaction_type': 'match', 'activity_context': 'synonym', 'activity_visibility': 'public', 'activity_type_name': 'ok ok ok'}, parameters=Parameters(query={}, header={}, cookie={}, path={}), security={})\n
\ntldr; it would be nice to get this custom validator working, but can anyone give me a workaround in the meantime to make sure a string isn't blank?
\nThanks,
\nHeidi
","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"\nthanks for the report, I prepared fix for that. It's part of 0.19.0a2 version
","upvoteCount":2,"url":"https://github.com/python-openapi/openapi-core/discussions/778#discussioncomment-8431590"}}}
| route-pattern | /_view_fragments/Voltron::DiscussionsFragmentsController/show/:user_id/:repository/:discussion_number/discussion_layout(.:format) |
| route-controller | voltron_discussions_fragments |
| route-action | discussion_layout |
| fetch-nonce | v2:0323fc5b-bba1-8046-07b5-5189bc7892a0 |
| current-catalog-service-hash | 9f0abe34da433c9b6db74bffa2466494a717b579a96b30a5d252e5090baea7be |
| request-id | 918C:2E1B39:A0CDD0:E323CB:69779AF9 |
| html-safe-nonce | a2e8c845e15050f7ce7d7ad330c9ca0fc99f94b10c8c3ee6e2c730d5804df447 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MThDOjJFMUIzOTpBMENERDA6RTMyM0NCOjY5Nzc5QUY5IiwidmlzaXRvcl9pZCI6Ijg0ODAxNzc2NDk0MTI5NzEyNTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 4515cb9861ed6470a219a5f811288976d784317fea57735b86d63f9d7e9fa739 |
| hovercard-subject-tag | discussion:6201191 |
| github-keyboard-shortcuts | repository,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/Voltron::DiscussionsFragmentsController/show/python-openapi/openapi-core/778/discussion_layout |
| twitter:image | https://opengraph.githubassets.com/2d60f7b448d7325b8f264dbaa16b04981d06eb4c55c7f9082f65e566f67057b6/python-openapi/openapi-core/discussions/778 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2d60f7b448d7325b8f264dbaa16b04981d06eb4c55c7f9082f65e566f67057b6/python-openapi/openapi-core/discussions/778 |
| og:image:alt | Hello, Thanks for the openap-core project; it's very helpful. I'm using it to validate my api input. I'm trying to make sure that required values that are blank strings are not allowed. I've tried ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | fc421f20017e1c727052b30a42d36825c29cf12a25e3e3589a184309309fc08a |
| 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 | 82eac957e166000cbcf5a2f4595b013b0f5a51aa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width