C++ Boost.Beast client generator with OpenAPI 3.1 support
Merged
BO
4mo ago+19308+19308+01234567890123456789012345678901234567890123456789-0-0-0123456789
C++ Boost.Beast Client Code Generator (with OpenAPI 3.1 support)
This continues the work from PR #20971 by @cwilson1776, which itself was a resurrection of the original PR #12197 by @LukasWoodtli.
Credits
- @LukasWoodtli did the original work creating the Boost.Beast client generator in PR #12197
- @cwilson1776 resurrected it in PR #20971, fixing bitrot, updating for modern Boost/OpenSSL, and adding integration tests with imposter mock server
- This PR builds on their work with the additions below
What this PR adds on top of #20971
OpenAPI 3.1 support (needed to generate clients from modern specs like the OpenAI API):
- Use
ModelUtils.getType()for proper OpenAPI 3.1 type detection (includingtype: "null") - Map free-form objects to
boost::property_tree::ptree - Set correct default values for
boost::property_tree::ptreeproperties - Add
AnyType.hsupporting file for OpenAPI 3.1 any-type schemas - Register
cpp-boost-beast-clientinCodegenConfigservice loader
Modern Boost/OpenSSL fixes:
- Update
CMakeLists.txttemplate for modern Boost/OpenSSL find patterns - Fix map serialization in model templates
- Fix
AnyType.htemplate with proper include guard and namespace
Core generator warning fixes:
DefaultCodegen: Populate_enum,isEnum,isInnerEnumfor referenced enum schemas soenumNameis properly computed, fixingCould not compute datatypeWithEnumwarnings for array items referencing enum schemasDefaultCodegen: Replace spuriousCould not compute datatypeWithEnumwarning with silent fallback for non-enum array itemsDefaultGenerator: SetoperationIdfrom webhook key for webhook operations missingoperationId, fixingEmpty operationId found for pathwarningsDefaultGenerator: Tag untagged webhook operations withWebhooksinstead ofdefault, fixingDuplicate file path detectedcollision withDefaultApiExamplesUtils: DowngradeNo application/json content media typefrom warn to debug for valid non-JSON responses (e.g.application/octet-stream)
Motivation
A C++ client generator that:
- Does not depend on the now-retired cpprestsdk
- Does not require an X server (unlike the Qt client generator)
- Supports OpenAPI 3.1 specs (needed for modern APIs like OpenAI)
Build and test
sudo apt update && sudo apt install libboost-all-dev cmake
curl -L https://raw.githubusercontent.com/imposter-project/imposter-cli/main/install/install_imposter.sh | sudo bash -
cd samples/client/petstore/cpp-boost-beast/
./build-and-test.bash
PR checklist
- Read the contribution guidelines
- Pull Request title clearly describes the work
- Built the project:
./mvnw clean package - File the PR against the
masterbranch - @mention the technical committee members
@ravinikam
@stkrwork
@etherealjoy
@martindelille
@muttleyxd
Summary by cubic
Adds cpp-boost-beast-client, a C++ client generator built on Boost.Beast with full OpenAPI 3.1 support, modern Boost/OpenSSL integration, and a working Petstore sample with CTest-backed imposter integration tests. Docs refreshed and the new generator is documented and linked.
-
New Features
- New
cpp-boost-beast-clientgenerator registered and documented (docs/generators.md,docs/generators/cpp-boost-beast-client.md); Petstore config added atbin/configs/cpp-boost-beast-client-petstore.yaml. - OpenAPI 3.1: proper type detection (incl.
null), free-form/any schemas viaAnyType.h(boost::json::value), and composed schemas (allOf/oneOf). - HTTP client abstraction (
HttpClient/HttpClientImpl) with Accept/Content-Type negotiation andx-www-form-urlencoded. Petstore sample includes CMake/CTest, approval tests, andimposter-driven API tests.
- New
-
Bug Fixes
- Correct path templating and query serialization (lists,
collectionFormat: multi, explicitexplode); fix response parsing (incl. arrays). - Sanitize model names; fix map (de)serialization and include guards; correct enum metadata; reduce noisy core warnings; set webhook
operationIdand tag untagged webhooks asWebhooks. - Safer default-response handling with compatibility checks in generated APIs.
- Correct path templating and query serialization (lists,