Skip to content

Commit

Permalink
Merge pull request #28 from RedHatProductSecurity/underscore-keywords
Browse files Browse the repository at this point in the history
Fix double underscore query keywords
  • Loading branch information
JakubFrejlach authored Sep 5, 2023
2 parents 26239a8 + deac657 commit 242470e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
### Fixed
- fix usage of query parameters with double underscore

## [1.3.9] - 2023-08-25
### Changed
Expand Down
29 changes: 27 additions & 2 deletions component_registry_bindings/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,45 @@
)


def double_underscores_to_single_underscores(fn):
"""
Function decorator which changes all the keyword arguments which include
double underscore to use single underscore instead.
eg. affect__affectedness -> affect_affectedness
This change is needed because in OpenAPI schema query parameters might contain
double underscore, howerver OpenAPI Python Client package converts all these
double underscores into single ones and thus this creates a confusion as user
tries to use query parameter from the OpenAPI schema specification unaware of
the underscore change.
"""

def inner(*args, **kwargs):
new_kwargs = {name.replace("__", "_"): value for name, value in kwargs.items()}
return fn(*args, **new_kwargs)

return inner


def get_sync_function(api_module: ModuleType) -> Callable:
"""
Get 'sync' function from API module if available (response example is defined in schema)
or get basic 'sync_detailed' function (response example is not defined in schema)
"""
return getattr(api_module, "sync", getattr(api_module, "sync_detailed"))
return double_underscores_to_single_underscores(
getattr(api_module, "sync", getattr(api_module, "sync_detailed"))
)


def get_async_function(api_module: ModuleType) -> Callable:
"""
Get 'sync' function from API module if available (response example is defined in schema)
or get basic 'sync_detailed' function (response example is not defined in schema)
"""
return getattr(api_module, "async_", getattr(api_module, "async_detailed"))
return double_underscores_to_single_underscores(
getattr(api_module, "async_", getattr(api_module, "async_detailed"))
)


def new_session(
Expand Down

0 comments on commit 242470e

Please sign in to comment.