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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyramid_swagger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import absolute_import

import pyramid
from pyramid.settings import asbool

from pyramid_swagger.api import build_swagger_20_swagger_schema_views
from pyramid_swagger.api import register_api_doc_endpoints
Expand Down Expand Up @@ -47,7 +48,7 @@ def includeme(config):

config.add_renderer('pyramid_swagger', PyramidSwaggerRendererFactory())

if settings.get('pyramid_swagger.enable_api_doc_views', True):
if asbool(settings.get('pyramid_swagger.enable_api_doc_views', True)):
if SWAGGER_12 in swagger_versions:
register_api_doc_endpoints(
config,
Expand Down
6 changes: 4 additions & 2 deletions pyramid_swagger/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import simplejson
from bravado_core.spec import build_http_handlers
from bravado_core.spec import Spec
from pyramid.settings import asbool
from six import iteritems
from six.moves.urllib import parse as urlparse
from six.moves.urllib.request import pathname2url
Expand Down Expand Up @@ -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.

for key, value in iteritems(settings)
if key.startswith(BRAVADO_CORE_CONFIG_PREFIX)
})
Expand Down