Skip to content

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

Merged
wing328 merged 45 commits into
OpenAPITools:masterfrom
bold84:cpp-boost-beast-fixes
Jul 18, 2026
Merged

C++ Boost.Beast client generator with OpenAPI 3.1 support#24335
wing328 merged 45 commits into
OpenAPITools:masterfrom
bold84:cpp-boost-beast-fixes

Conversation

@bold84

@bold84 bold84 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

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

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.

Written for commit 2c2dac4. Summary will update on new commits.

Review in cubic

LukasWoodtli and others added 30 commits March 25, 2025 20:37
* Fixed names of the approval files for ApiTests.
* Silence warnings due to boost/property_tree/json_parser.hpp
* ApprovalTests only works when not using header-only boost::test
* More clean shutdown of imposter when test(s) fail
* Update petstore-config.yaml test config to add explicit values
  for all tested enpoints, rather than relying on imposter-provided
  default values. As of v4.5.2, imposter's defaults have changed.
* Fixed CppBoostBeastClientCodegen compilation error triggered by
  refactoring of getAdditionalProperties(Schema) -> ModelUtils.
…enSSL

- Remove boost_system COMPONENT from find_package (header-only in Boost 1.73+)
- Add find_package(OpenSSL REQUIRED) and use OpenSSL::SSL OpenSSL::Crypto
- Fix C++11 narrowing warnings in test files with static_cast
- Update approval test files to match new JSON formatting from modern Boost
- Handle JsonSchema type without casting to ArraySchema
- Use p.getItems() directly instead of casting to ArraySchema
- Support OpenAPI 3.1 type arrays (e.g., type: ["string", "null"])
- Gracefully handle complex composed schemas with JsonSchema
- Fix ClassCastException when processing OpenAPI 3.1 specs

The generator now successfully processes OpenAPI 3.1 specifications
with full JSON Schema 2020-12 compatibility.
- Remove unsafe instanceof JsonSchema checks that bypassed proper type handling
- Use ModelUtils.getType() which properly handles OpenAPI 3.1 types array
- Use p.getItems() instead of casting to ArraySchema
- Add support for OpenAPI 3.1 null type
- Leverage existing ModelUtils infrastructure for spec-version-agnostic processing

This follows the same pattern used in DefaultCodegen.getSchemaType() and
ModelUtils.getType() which check schema.getTypes() for JsonSchema (OAS 3.1)
and schema.getType() for regular Schema (OAS 3.0).

Fixes ClassCastException when processing OpenAPI 3.1 specs with type arrays
(e.g., type: ["string", "null"]) and complex composed schemas.
- Map 'object' type to boost::property_tree::ptree (not custom AnyType class)
- Follows pattern from cpp-pistache-server (nlohmann::json) and cpp-restsdk (json::value)
- ptree is already used in AnyType.h for JSON serialization
- Eliminates need for missing Object.h and AnyType.h files
- Properly handles OpenAPI 3.1 JsonSchema free-form objects

This is the correct approach for C++ Boost.Beast as ptree can hold any JSON value
(string, number, object, array, null) and is already part of the codebase.
bold84 added 4 commits March 26, 2026 17:26
- Use hardcoded BOOST_BEAST_OPENAPI_CLIENT_ANYTYPE_H guard
- Use nested namespace to match other generated files
- Fixes include guard with dots issue
…ionIds, and non-JSON responses

- DefaultCodegen: Populate _enum, isEnum, isInnerEnum for referenced enum
  schemas so enumName is computed, fixing 'Could not compute datatypeWithEnum'
  warnings for array items referencing enum schemas (e.g. TranscriptionInclude)

- DefaultCodegen: Replace spurious 'Could not compute datatypeWithEnum' warning
  with silent fallback for non-enum array items and enum items without enumName

- 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. audio/octet-stream)

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 93 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread samples/client/petstore/cpp-boost-beast/tests/model/CMakeLists.txt Outdated
Comment thread samples/client/petstore/cpp-boost-beast/tests/api/run_imposter_for_tests.sh Outdated
@bold84
bold84 marked this pull request as draft July 17, 2026 13:35
@bold84

bold84 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

Addressed all 21 Cubic review findings in bfd48fb9545.

Highlights:

  • added verified HTTPS transport with SNI, hostname/certificate validation, TLS 1.2+, bounded resolve/connect/handshake/write/read/shutdown operations, and portable OpenSSL/Threads CMake targets
  • fixed request/response conversion for free-form, map, nested container, primitive, raw, multipart, and default-response cases
  • fixed allOf parent inheritance/JSON forwarding, null container preservation, query/header wire names and encoding, sample approvals, CMake paths, and Imposter startup bounds
  • added generator regression specs plus executable TLS, timeout, multipart, query, and header behavior tests

Verification:

  • focused generator tests: 3 passed
  • CLI package and canonical Petstore regeneration: passed
  • fresh CMake build with -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_CXX_FLAGS=-Werror: passed
  • generated Petstore tests: 40 API and 42 model cases passed

openai-cpp-sdk/ remains a local-only generation workspace and was not included.

@bold84
bold84 marked this pull request as ready for review July 18, 2026 00:18

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 96 files

Tip: cubic used a learning from your PR history. Let your coding agent read cubic learnings directly with the cubic MCP.

Re-trigger cubic

Comment thread samples/client/petstore/cpp-boost-beast/tests/api/run_imposter_for_tests.sh Outdated
@bold84
bold84 marked this pull request as draft July 18, 2026 00:41
@bold84
bold84 marked this pull request as ready for review July 18, 2026 00:45

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 96 files

Re-trigger cubic

@bold84

bold84 commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the 20 follow-up review findings in fee75e8c8b2 and resolved the corresponding threads.

Highlights:

  • corrected query/path/header serialization, optional query omission, XML fail-closed handling, response ranges/defaults, and extracted the shared operation partial
  • serialized shared-client execution, skipped SNI for IP literals, bracketed IPv6 Host values, and added configurable HTTP/HTTPS body limits
  • added requiredness-aware model presence, setter-based enum validation, assignment-safe typed enum tables, package-specific CMake targets, and installed public headers
  • made Imposter cleanup graceful and removed the post-readiness delay

Verification:

  • focused Maven generator tests: 4 passed
  • CLI reactor package: passed
  • generated API/model regression builds with -Werror: passed
  • dual generated-client CMake build: passed
  • regenerated Petstore build with -Werror: passed
  • Petstore CTest: 45 API + 45 model cases passed
  • install-tree downstream header compile: passed
  • independent final review: PASS

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 53 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@bold84

bold84 commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the three latest review findings in 6928015244f and resolved their threads.

  • replaced positional boost::format path substitution with named placeholder replacement, preserving parameter associations regardless of declaration order
  • preserved literal percent-encoded path segments such as %20
  • honored the default explode: true for explicit style: form query arrays while retaining OpenAPI 2 CSV and multi behavior

Verification: focused generator tests passed; CLI package passed; focused generated client and regenerated Petstore built with -Werror; Petstore CTest passed 45 API + 45 model cases; sequential independent review passed.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 9 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

@bold84

bold84 commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the latest query serialization finding in aadb82ee4d0 and resolved the thread. Style-less query arrays now treat explicit explode: true as form-style repeated keys. The regression matrix covers omitted/omitted, omitted/true, omitted/false, explicit form/omitted, and explicit form/false, while existing OpenAPI 2 CSV/multi coverage remains green.

Verification: focused generator tests passed; generated regression client built with -Werror; CLI package passed; canonical regeneration produced no sample drift; sequential independent review passed.

@bold84

bold84 commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

Completed the complex OpenAPI schema follow-up in e16269b2e2e.

  • fixed shared-pointer defaults for referenced enums
  • added recursive enum validation for arrays, maps, and nested containers
  • added OpenAPI form/deepObject query-map serialization
  • added focused OAS 3.0/3.1 regression coverage

Verification:

  • focused generator tests: 4 passed
  • generated OpenAI C++ SDK built completely with -Werror using 12 parallel jobs
  • git diff --check: passed
  • CircleCI: all 4 nodes passed
  • Cubic incremental review: 0 issues found across 8 files; no unresolved threads

openai-cpp-sdk/ and temporary generated output remain local-only and were not committed.

@wing328

wing328 commented Jul 18, 2026

Copy link
Copy Markdown
Member

Thanks for the contribution.

Let's give it a try and see if there is any feedback from our users.

@wing328
wing328 merged commit b8f10df into OpenAPITools:master Jul 18, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants