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

204 as error #120

Merged
merged 5 commits into from
Apr 29, 2024
Merged
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
27 changes: 17 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
cmake_minimum_required(VERSION 3.24)
cmake_minimum_required(VERSION 3.22.3) # to build without conan

include(FetchContent)

if(NOT CONAN_PROVIDER_INCLUDED)
set(CONAN_PROVIDER_INCLUDED true)
FetchContent_Declare(
conan_provider
GIT_REPOSITORY https://github.com/Klebert-Engineering/cmake-conan
GIT_TAG zswag)
FetchContent_MakeAvailable(conan_provider)
set(CMAKE_PROJECT_TOP_LEVEL_INCLUDES "${conan_provider_SOURCE_DIR}/conan_provider.cmake")
# Provide an option to disable Conan, defaulting to using Conan
option(ZSWAG_WITH_CONAN "Build with Conan dependency management" ON)

if(ZSWAG_WITH_CONAN)
# Upgrade the required CMake version for Conan
cmake_minimum_required(VERSION 3.24)
if(NOT CONAN_PROVIDER_INCLUDED)
set(CONAN_PROVIDER_INCLUDED true)
FetchContent_Declare(
conan_provider
GIT_REPOSITORY https://github.com/Klebert-Engineering/cmake-conan
GIT_TAG zswag)
FetchContent_MakeAvailable(conan_provider)
set(CMAKE_PROJECT_TOP_LEVEL_INCLUDES "${conan_provider_SOURCE_DIR}/conan_provider.cmake")
endif()
endif()

project(zswag)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(ZSWAG_VERSION 1.6.4)
set(ZSWAG_VERSION 1.6.7)

option(ZSWAG_BUILD_WHEELS "Enable zswag whl-output to WHEEL_DEPLOY_DIRECTORY." ON)
option(ZSWAG_KEYCHAIN_SUPPORT "Enable zswag keychain support." ON)
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ zswag is a set of libraries for using/hosting zserio services through OpenAPI.
* [Client Environment Settings](#client-environment-settings)
* [HTTP Proxies and Authentication](#persistent-http-headers-proxy-cookie-and-authentication)
* [Swagger User Interface](#swagger-user-interface)
* [Client Result Code Handling](#client-result-code-handling)
* [OpenAPI Options Interoperability](#openapi-options-interoperability)
+ [HTTP method](#http-method)
+ [Request Body](#request-body)
Expand Down Expand Up @@ -467,12 +468,17 @@ project(myapp)
# libsecret, the following switch will disable keychain integration:
# set(ZSWAG_KEYCHAIN_SUPPORT OFF)

# In case you want to build zswag without using conan
# make sure to provide targets for OpenSSL and spdlog
# and set the following switch to OFF:
# set(ZSWAG_WITH_CONAN OFF)

# This is how C++ will know about the zswag lib
# and its dependencies, such as zserio.
if (NOT TARGET zswag)
FetchContent_Declare(zswag
GIT_REPOSITORY "https://github.com/ndsev/zswag.git"
GIT_TAG "v1.5.0"
GIT_TAG "v1.6.7"
GIT_SHALLOW ON)
FetchContent_MakeAvailable(zswag)
endif()
Expand All @@ -498,6 +504,8 @@ target_link_libraries(${PROJECT_NAME}
${PROJECT_NAME}-zserio-cpp zswagcl)
```

**Note:** OpenSSL is assumed to be installed or built using the `lib` (not `lib64`) directory name.

The `add_executable` command above references the file `myapp/client.cpp`,
which contains the code to actually use the zswag C++ client.

Expand Down Expand Up @@ -609,6 +617,12 @@ on each platform:
* [macOS `add-generic-password`](https://www.netmeister.org/blog/keychain-passwords.html)
* [Windows `cmdkey`](https://www.scriptinglibrary.com/languages/powershell/how-to-manage-secrets-and-passwords-with-credentialmanager-and-powershell/)

## Client Result Code Handling

Both clients (Python and C++) will treat any HTTP response code other than `200` as an error since zserio services are expected to return a parsable response object. The client will throw an exception with a descriptive message if the response code is not `200`.

In case applications want to utilize for example the `204 (No Content)` response code, they have to catch the exception and handle it accordingly.

## Swagger User Interface

If you have installed `pip install "connexion[swagger-ui]"`, you can view
Expand Down
2 changes: 1 addition & 1 deletion libs/zswagcl/src/openapi-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ std::string OpenAPIClient::call(const std::string& methodIdent,
auto result = resultFuture.get();
httpcl::log().debug("{} Response received (code {}, content length {} bytes).", debugContext, result.status, result.content.size());

if (result.status >= 200 && result.status < 300) {
if (result.status == 200) {
return std::move(result.content);
}

Expand Down
Loading