Skip to content

Commit

Permalink
Merge pull request #95 from ndsev/issue/94-python-expansion
Browse files Browse the repository at this point in the history
Release 1.5.0: Additional Python versions, pre-set OpenAPI controller.
  • Loading branch information
josephbirkner committed Feb 9, 2023
2 parents 4d71bbc + 2ffe78b commit 1df8fca
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 19 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ jobs:
build-manylinux:
strategy:
matrix:
python-version: [3.8, 3.9]
python-version: ["3.8", "3.9", "3.10", "3.11"]
runs-on: ubuntu-latest
container: ghcr.io/klebert-engineering/manylinux-cpp17-py${{ matrix.python-version }}:2021.3
container: ghcr.io/klebert-engineering/manylinux-cpp17-py${{ matrix.python-version }}:2023.1
steps:
- uses: actions/checkout@v2
with:
Expand Down Expand Up @@ -41,7 +41,7 @@ jobs:
strategy:
matrix:
os: [macos-10.15, macos-latest, windows-latest]
python-version: [3.8, 3.9]
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
deploy:
strategy:
matrix:
python-version: [3.8, 3.9]
python-version: ["3.8", "3.9", "3.10", "3.11"]
os: [macos-10.15, macos-latest, ubuntu-latest, windows-latest]
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ include(FetchContent)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(ZSWAG_VERSION 1.4.0)
set(ZSWAG_VERSION 1.5.0)

option(ZSWAG_BUILD_WHEELS "Enable zswag whl-output to WHEEL_DEPLOY_DIRECTORY." ON)
option(ZSWAG_KEYCHAIN_SUPPORT "Enable zswag keychain support." ON)
Expand Down
2 changes: 1 addition & 1 deletion deps/keychain
2 changes: 1 addition & 1 deletion deps/pybind11
Submodule pybind11 updated 224 files
2 changes: 1 addition & 1 deletion deps/zserio
Submodule zserio updated 666 files
16 changes: 11 additions & 5 deletions libs/zswag/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
# to hold the service instance.
CONTROLLER_SERVICE_INSTANCE = "_service"

# Name of OpenApi extension field from which connexion
# reads the target wsgi function.
CONTROLLER_OPENAPI_FIELD = "x-openapi-router-controller"

# Utility function for slash conversion in format strings
def to_slashes(s: str):
Expand Down Expand Up @@ -69,7 +72,7 @@ def __init__(self, *,
# In swagger yaml, the path specs reference `my.app.controller._service.myApi`
_service = Service()
_service.myApi = lambda request: _service._myApiMethod(request)
_service._myApiImpl = my.app.controller.myApiImpl
_service._myApiImpl = my.app.controller.my_api
# Written by user
def my_api(request):
Expand All @@ -81,7 +84,7 @@ def my_api(request):
Zserio Server instance injected method (ns.service.service(base64): blob), which calls
ns.service._serviceMethod(blob), which calls
ns.service._serviceImpl(value) which is remapped to
Runtime-generated user function (ns.serviceImpl(value): value).
User function (ns.serviceImpl(value): value).
"""
if not yaml_path:
Expand Down Expand Up @@ -173,9 +176,12 @@ def method_impl(request, ctx=None, fun=user_function):
print(f"Loading spec from {yaml_path} ...")
with open(yaml_path, 'r') as swagger_file:
openapi = yaml.load(swagger_file, Loader=yaml.FullLoader)
for _, path_spec in openapi["paths"].items():
for _, method_spec in path_spec.items():
method_spec["x-openapi-router-controller"] = self.service_instance_path
for path_name, path_spec in openapi["paths"].items():
for meth_name, method_spec in path_spec.items():
if CONTROLLER_OPENAPI_FIELD not in method_spec:
method_spec[CONTROLLER_OPENAPI_FIELD] = self.service_instance_path
else:
print(f"{meth_name} {path_name}: Using pre-set {CONTROLLER_OPENAPI_FIELD}.")

# Initialise connexion app
super(OAServer, self).__init__(
Expand Down
12 changes: 11 additions & 1 deletion libs/zswagcl/src/oaclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ParameterValue reflectableArrayToParameterValue(std::function<void(std::vector<a
return helper.array(values);
}

ParameterValue reflectableToParameterValue(std::string const& fieldName, zserio::IReflectablePtr const& ref, zserio::ITypeInfo const& refType, ParameterValueHelper& helper)
ParameterValue reflectableToParameterValue(std::string const& fieldName, zserio::IReflectableConstPtr const& ref, zserio::ITypeInfo const& refType, ParameterValueHelper& helper)
{
switch (refType.getCppType())
{
Expand Down Expand Up @@ -70,6 +70,16 @@ ParameterValue reflectableToParameterValue(std::string const& fieldName, zserio:
}
return helper.value(ref->toString());
case zserio::CppType::BIT_BUFFER: {
if (ref->isArray()) {
return reflectableArrayToParameterValue<std::string>([&](auto& arr, auto i) {
auto const& buffer = ref->at(i)->getBytes();
arr.emplace_back(buffer.begin(), buffer.end());
}, ref->size(), helper);
}
auto const& buffer = ref->getBytes();
return helper.binary(std::vector<uint8_t>(buffer.begin(), buffer.end()));
}
case zserio::CppType::BYTES: {
if (ref->isArray()) {
return reflectableArrayToParameterValue<std::string>([&](auto& arr, auto i) {
auto const& buffer = ref->at(i)->getBitBuffer();
Expand Down
8 changes: 4 additions & 4 deletions libs/zswagcl/test/src/oaclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ TEST_CASE("HTTP-Service", "[oaclient]") {
)json");

auto service = OAClient(config, std::move(client));
auto response = service.callMethod("multi", zserio::ServiceData(request.reflectable()), nullptr);
auto response = service.callMethod("multi", zserio::ReflectableServiceData(request.reflectable()), nullptr);

/* Check result */
REQUIRE(getCalled);
Expand Down Expand Up @@ -171,7 +171,7 @@ TEST_CASE("HTTP-Service", "[oaclient]") {
)json");

auto service = OAClient(config, std::move(client));
auto response = service.callMethod("q", zserio::BasicServiceData(request.reflectable()), nullptr);
auto response = service.callMethod("q", zserio::ReflectableServiceData(request.reflectable()), nullptr);

/* Check result */
REQUIRE(getCalled);
Expand Down Expand Up @@ -226,7 +226,7 @@ TEST_CASE("HTTP-Service", "[oaclient]") {
}
)json");
auto service = OAClient(config, std::move(client));
auto response = service.callMethod("post", zserio::BasicServiceData(request.reflectable()), nullptr);
auto response = service.callMethod("post", zserio::ReflectableServiceData(request.reflectable()), nullptr);

/* Check result */
REQUIRE(postCalled);
Expand All @@ -247,7 +247,7 @@ TEST_CASE("HTTP-Service", "[oaclient]") {
auto request = service_client_test::Request(
"hello", 0, std::vector<std::string>{},
service_client_test::Flat("", ""));
zserio::BasicServiceData requestData{request.reflectable()};
zserio::ReflectableServiceData requestData{request.reflectable()};

/* Make config, client, service */
auto config = makeConfig("", TESTDATA "/config-with-auth.json");
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ connexion
requests
zserio>=2.4.2
pyyaml
pyzswagcl>=1.4.0
pyzswagcl>=1.5.0
openapi-spec-validator

0 comments on commit 1df8fca

Please sign in to comment.