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

Convert bool values from a .ini file #245

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hiromu
Copy link

@hiromu hiromu commented Jun 14, 2020

When I use a .ini file for configuration, some variables are passed to bravado-core in the form of str and always treated as True.
Since all variables except formats are boolean, they should be converted using asbool(): https://bravado-core.readthedocs.io/en/stable/config.html

The same thing happens for enable_api_doc_views in __init__.py, and thus I fixed.

@coveralls
Copy link

Coverage Status

Coverage decreased (-99.6%) to 0.0% when pulling cbe5f57 on hiromu:convert-bool-values-in-ini-file into 2c8d37f on striglia:master.

Copy link
Contributor

@sjaensch sjaensch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution @hiromu! As mentioned we need to make sure this is forwards-compatible. Also, how were you specifying config values that you ran into this issue? bravado-core itself doesn't use asbool.

@@ -217,12 +218,13 @@ def create_bravado_core_config(settings):
'use_models': False,
}
configs.update({
bravado_core_key: settings[pyramid_swagger_key]
bravado_core_key: (settings[pyramid_swagger_key] if bravado_core_key == 'formats'
else asbool(settings[pyramid_swagger_key]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is dangerous, as any new bravado-core config key which doesn't have a boolean value would break this. We should instead list the bravado-core keys we know of and the function we should use for each key to get the value. Ideally we'd provide an API to do this within bravado-core.

for pyramid_swagger_key, bravado_core_key in iteritems(config_keys)
if pyramid_swagger_key in settings
})
configs.update({
key.replace(BRAVADO_CORE_CONFIG_PREFIX, ''): value
key.replace(BRAVADO_CORE_CONFIG_PREFIX, ''): asbool(value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't handle formats.

@hiromu
Copy link
Author

hiromu commented Jun 18, 2020

I understand your concerns on the forward compatibility.

Are you considering to implement an API within bravado-core? Otherwise, I'll update this pull request so as to use a hard-coded allowlist to determine whether to apply asbool.

how were you specifying config values that you ran into this issue?

In my implementation, I'm specifying bravado_core.internally_dereference_refs = false in environment.ini and just calling config = Configurator(settings=settings); config.include('pyramid_swagger') in main(global_config, **settings) of Pyramid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants