-
-
Notifications
You must be signed in to change notification settings - Fork 136
Add support for password
string format
#132
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
Conversation
`password` is a valid OpenAPIv3 string format, that is used as a UI hint for frontend clients to mask the input field. It was already present in the `SchemaFormat` enum, but it was not handled in `_unmarshal_string` that uses `STRING_FORMAT_CALLABLE_GETTER` to decide how to unmarshal a string, which would result in an error like this one: ``` Traceback (most recent call last): [... snip ...] File ".venv/lib/python3.7/site-packages/openapi_core/validation/request/validators.py", line 37, in validate body, body_errors = self._get_body(request, operation) File ".venv/lib/python3.7/site-packages/openapi_core/validation/request/validators.py", line 82, in _get_body body = media_type.unmarshal(raw_body, self.custom_formatters) File ".venv/lib/python3.7/site-packages/openapi_core/schema/media_types/models.py", line 45, in unmarshal unmarshalled = self.schema.unmarshal(deserialized, custom_formatters=custom_formatters) File ".venv/lib/python3.7/site-packages/openapi_core/schema/schemas/models.py", line 189, in unmarshal casted = self.cast(value, custom_formatters=custom_formatters, strict=strict) File ".venv/lib/python3.7/site-packages/openapi_core/schema/schemas/models.py", line 179, in cast return cast_callable(value) File ".venv/lib/python3.7/site-packages/openapi_core/schema/schemas/models.py", line 295, in _unmarshal_object value, custom_formatters=custom_formatters) File ".venv/lib/python3.7/site-packages/openapi_core/schema/schemas/models.py", line 335, in _unmarshal_properties prop_value, custom_formatters=custom_formatters) File ".venv/lib/python3.7/site-packages/openapi_core/schema/schemas/models.py", line 189, in unmarshal casted = self.cast(value, custom_formatters=custom_formatters, strict=strict) File ".venv/lib/python3.7/site-packages/openapi_core/schema/schemas/models.py", line 179, in cast return cast_callable(value) File ".venv/lib/python3.7/site-packages/openapi_core/schema/schemas/models.py", line 295, in _unmarshal_object value, custom_formatters=custom_formatters) File ".venv/lib/python3.7/site-packages/openapi_core/schema/schemas/models.py", line 335, in _unmarshal_properties prop_value, custom_formatters=custom_formatters) File ".venv/lib/python3.7/site-packages/openapi_core/schema/schemas/models.py", line 189, in unmarshal casted = self.cast(value, custom_formatters=custom_formatters, strict=strict) File ".venv/lib/python3.7/site-packages/openapi_core/schema/schemas/models.py", line 179, in cast return cast_callable(value) File ".venv/lib/python3.7/site-packages/openapi_core/schema/schemas/models.py", line 215, in _unmarshal_string formatstring = self.STRING_FORMAT_CALLABLE_GETTER[schema_format] KeyError: <SchemaFormat.PASSWORD: 'password'> ```
password
string format
Codecov Report
@@ Coverage Diff @@
## master #132 +/- ##
=======================================
Coverage 96.33% 96.33%
=======================================
Files 54 54
Lines 1474 1474
=======================================
Hits 1420 1420
Misses 54 54
Continue to review full report at Codecov.
|
1 similar comment
Codecov Report
@@ Coverage Diff @@
## master #132 +/- ##
=======================================
Coverage 96.33% 96.33%
=======================================
Files 54 54
Lines 1474 1474
=======================================
Hits 1420 1420
Misses 54 54
Continue to review full report at Codecov.
|
Several things needed to happen in order for this to work: * Add Passlib, Argon2 and pyramid_jwt to dependencies and configure them. * Add `jwt.secret` .ini setting. * Comment out `format: password` in `openapi.yaml` due to a bug in `openapi-core`: python-openapi/openapi-core#132 * Finally, some cleanup: * `pyramid.reload_templates` is not needed because we don't use templates * `pyramid.default_locale_name` is not needed because we don't support localizations * `pyramid_debugtoolbar` is not needed because we always render JSON. * Uncaught errors are logged instead of included in API response in order not to leak sensitive system information.
Several things needed to happen in order for this to work: * Add Passlib, Argon2 and pyramid_jwt to dependencies and configure them. * Add `jwt.secret` .ini setting. * Comment out `format: password` in `openapi.yaml` due to a bug in `openapi-core`: python-openapi/openapi-core#132 * Finally, some cleanup: * `pyramid.reload_templates` is not needed because we don't use templates * `pyramid.default_locale_name` is not needed because we don't support localizations * `pyramid_debugtoolbar` is not needed because we always render JSON. * Uncaught errors are logged instead of included in API response in order not to leak sensitive system information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zupo thank for the contribution. LGTM
Add support for `password` string format
password
is a valid OpenAPIv3 string format, that is used as a UI hintfor frontend clients to mask the input field.
It was already present in the
SchemaFormat
enum, but it was nothandled in
_unmarshal_string
that usesSTRING_FORMAT_CALLABLE_GETTER
to decide how to unmarshal a string, which would result in an error like
this one: