C++ Boost.Beast client generator with OpenAPI 3.1 support

Merged
BO
4mo ago
+19308-0

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 (including type: "null")
  • Map free-form objects to boost::property_tree::ptree
  • Set correct default values for boost::property_tree::ptree properties
  • Add AnyType.h supporting file for OpenAPI 3.1 any-type schemas
  • Register cpp-boost-beast-client in CodegenConfig service loader

Modern Boost/OpenSSL fixes:

  • Update CMakeLists.txt template for modern Boost/OpenSSL find patterns
  • Fix map serialization in model templates
  • Fix AnyType.h template with proper include guard and namespace

Core generator warning fixes:

  • DefaultCodegen: Populate _enum, isEnum, isInnerEnum for referenced enum schemas so enumName is properly computed, fixing Could not compute datatypeWithEnum warnings for array items referencing enum schemas
  • DefaultCodegen: Replace spurious Could not compute datatypeWithEnum warning with silent fallback for non-enum array items
  • DefaultGenerator: Set operationId from webhook key for webhook operations missing operationId, fixing Empty operationId found for path warnings
  • DefaultGenerator: Tag untagged webhook operations with Webhooks instead of default, fixing Duplicate file path detected collision with DefaultApi
  • ExamplesUtils: Downgrade No application/json content media type from 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 master branch
  • @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-client generator registered and documented (docs/generators.md, docs/generators/cpp-boost-beast-client.md); Petstore config added at bin/configs/cpp-boost-beast-client-petstore.yaml.
    • OpenAPI 3.1: proper type detection (incl. null), free-form/any schemas via AnyType.h (boost::json::value), and composed schemas (allOf/oneOf).
    • HTTP client abstraction (HttpClient/HttpClientImpl) with Accept/Content-Type negotiation and x-www-form-urlencoded. Petstore sample includes CMake/CTest, approval tests, and imposter-driven API tests.
  • Bug Fixes

    • Correct path templating and query serialization (lists, collectionFormat: multi, explicit explode); fix response parsing (incl. arrays).
    • Sanitize model names; fix map (de)serialization and include guards; correct enum metadata; reduce noisy core warnings; set webhook operationId and tag untagged webhooks as Webhooks.
    • Safer default-response handling with compatibility checks in generated APIs.