Repository navigation
fix(cpp-httplib-server): generate compilable models for uuid/uri/set and free-form properties - #25607
Open
stefanwitkowskiwmb wants to merge 2 commits into
Conversation
…and free-form properties
Type mappings:
- Map UUID, URI and decimal to std::string. DefaultCodegen's Java type
names (UUID, URI, BigDecimal) were emitted as undefined C++ types.
- Map set (uniqueItems arrays) to std::vector. The member was already
std::vector, but the "Set" import produced #include "Set.h".
Member initialization:
- Derive the constructor initializer from the declared member type
instead of isNullable. Nullable members are declared unwrapped, so
std::nullopt did not compile for free-form {} properties
(nlohmann::json) and nullable model references; these now
default-construct.
- Wrap optional nullable enums in std::optional like other optional
enums; previously dataType was pre-wrapped so the enum member stayed
unwrapped but was initialized with std::nullopt.
- Build the constructor initializer list in Java (memberInitializers) so
the leading ':' is emitted even when the first member has no
initializer.
Generated samples are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Several schema shapes made
cpp-httplib-serveremit model code that does not compile.Type mappings
format: uuid,format: uriandtype: string, format: decimalwere emitted as the Java type namesUUID,URIandBigDecimalinherited fromDefaultCodegen('UUID' does not name a type). They now map tostd::string, like the otherstd::-based C++ generators.uniqueItems: truearrays were already declared asstd::vector, but theSetimport produced#include "Set.h".setnow maps tostd::vector(→#include <vector>).Member initialization
isNullable, so every nullable member gotstd::nullopt, although nullable members are declared unwrapped. This broke free-form{}properties (nlohmann::json optAny(std::nullopt);DefaultCodegenmarks AnyType as nullable) and nullable model references (Child c(std::nullopt)). The initializer is now derived from the declared member type;nlohmann::jsonand model members default-construct (JSONnull/ default object).dataTypewas already wrapped by the nullable handling, so thestd::optionalwrap for optional enums was skipped and the member stayedEnumwhile being initialized withstd::nullopt. They now take the samestd::optional<Enum>path as other optional enums.memberInitializers), so the leading:is emitted even when the first member has no initializer (previouslyFoo::Foo() , x("")).Spec to reproduce (any of these properties fails to compile on master):
Testing
CppHttplibServerCodegenModelTest; allCppHttplibServer*tests pass.bin/configs/cpp-httplib-server-*.yaml: no changes to the existing samples (only this generator is touched).export_docs_generators.sh: no change todocs/generators/cpp-httplib-server.md.allOfinheritance case) with gcc 13-std=c++17 -Wall -Wextra: no errors or warnings; JSON round-trips behave as expected (free-form values incl.null, nullable enumnull→ empty optional).PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
C++ technical committee: @ravinikam @stkrwork @etherealjoy @MartinDelille @muttleyxd @aminya
🤖 Generated with Claude Code
Summary by cubic
Fixes
cpp-httplib-serverso schema shapes that previously generated uncompilable model code now produce valid C++.Bug fixes
uuid,uri, anddecimalstring formats now map tostd::stringinstead of the Java type namesUUID,URI, andBigDecimalinherited fromDefaultCodegen.uniqueItems: truearrays resolve thesetmapping tostd::vector, so the generated include is<vector>instead of"Set.h".isNullable, so nullable members no longer getstd::nullopton unwrapped declarations such asnlohmann::jsonand model references.std::optional<Enum>path as other optional enums instead of being initialized withstd::nulloptwhile declared unwrapped.:is emitted even when the first member has no initializer.Unit tests were added, and regenerating the
cpp-httplib-serversamples produced no changes.Written for commit f51d8b8. Summary will update on new commits.