C++ Boost.Beast client generator with OpenAPI 3.1 support#24335
Conversation
Fix maven pom
* 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.
- 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)
There was a problem hiding this comment.
All reported issues were addressed across 93 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
|
Addressed all 21 Cubic review findings in Highlights:
Verification:
|
There was a problem hiding this comment.
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
|
Addressed the 20 follow-up review findings in Highlights:
Verification:
|
There was a problem hiding this comment.
All reported issues were addressed across 53 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
|
Addressed the three latest review findings in
Verification: focused generator tests passed; CLI package passed; focused generated client and regenerated Petstore built with |
There was a problem hiding this comment.
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
|
Addressed the latest query serialization finding in Verification: focused generator tests passed; generated regression client built with |
|
Completed the complex OpenAPI schema follow-up in
Verification:
|
|
Thanks for the contribution. Let's give it a try and see if there is any feedback from our users. |
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):
ModelUtils.getType()for proper OpenAPI 3.1 type detection (includingtype: "null")boost::property_tree::ptreeboost::property_tree::ptreepropertiesAnyType.hsupporting file for OpenAPI 3.1 any-type schemascpp-boost-beast-clientinCodegenConfigservice loaderModern Boost/OpenSSL fixes:
CMakeLists.txttemplate for modern Boost/OpenSSL find patternsAnyType.htemplate with proper include guard and namespaceCore 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:
Build and test
PR checklist
./mvnw clean packagemasterbranch@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-backedimposterintegration tests. Docs refreshed and the new generator is documented and linked.New Features
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.null), free-form/any schemas viaAnyType.h(boost::json::value), and composed schemas (allOf/oneOf).HttpClient/HttpClientImpl) with Accept/Content-Type negotiation andx-www-form-urlencoded. Petstore sample includes CMake/CTest, approval tests, andimposter-driven API tests.Bug Fixes
collectionFormat: multi, explicitexplode); fix response parsing (incl. arrays).operationIdand tag untagged webhooks asWebhooks.Written for commit 2c2dac4. Summary will update on new commits.