Skip to content

fix(cpp-httplib-server): generate compilable models for uuid/uri/set and free-form properties - #25607

Open
stefanwitkowskiwmb wants to merge 2 commits into
OpenAPITools:masterfrom
stefanwitkowskiwmb:fix/cpp-httplib-server-uuid-mapping
Open

stefanwitkowskiwmb wants to merge 2 commits into
OpenAPITools:masterfrom
stefanwitkowskiwmb:fix/cpp-httplib-server-uuid-mapping

Conversation

@stefanwitkowskiwmb

@stefanwitkowskiwmb stefanwitkowskiwmb commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Several schema shapes made cpp-httplib-server emit model code that does not compile.

Type mappings

  • format: uuid, format: uri and type: string, format: decimal were emitted as the Java type names UUID, URI and BigDecimal inherited from DefaultCodegen ('UUID' does not name a type). They now map to std::string, like the other std::-based C++ generators.
  • uniqueItems: true arrays were already declared as std::vector, but the Set import produced #include "Set.h". set now maps to std::vector (→ #include <vector>).

Member initialization

  • The constructor initializer was derived from isNullable, so every nullable member got std::nullopt, although nullable members are declared unwrapped. This broke free-form {} properties (nlohmann::json optAny(std::nullopt); DefaultCodegen marks AnyType as nullable) and nullable model references (Child c(std::nullopt)). The initializer is now derived from the declared member type; nlohmann::json and model members default-construct (JSON null / default object).
  • Optional nullable enums: dataType was already wrapped by the nullable handling, so the std::optional wrap for optional enums was skipped and the member stayed Enum while being initialized with std::nullopt. They now take the same std::optional<Enum> path as other optional enums.
  • The constructor initializer list is built in Java (memberInitializers), so the leading : is emitted even when the first member has no initializer (previously Foo::Foo() , x("")).

Spec to reproduce (any of these properties fails to compile on master):

components:
  schemas:
    Child:
      type: object
      properties:
        a: { type: string }
    Repro:
      type: object
      properties:
        id:       { type: string, format: uuid }
        link:     { type: string, format: uri }
        amount:   { type: string, format: decimal }
        tags:     { type: array, uniqueItems: true, items: { type: string } }
        anything: {}
        child:    { allOf: [ { $ref: '#/components/schemas/Child' } ], nullable: true }
        state:    { type: string, enum: [a, b], nullable: true }

Testing

  • Added unit tests in CppHttplibServerCodegenModelTest; all CppHttplibServer* tests pass.
  • Regenerated bin/configs/cpp-httplib-server-*.yaml: no changes to the existing samples (only this generator is touched).
  • export_docs_generators.sh: no change to docs/generators/cpp-httplib-server.md.
  • Compiled the generated models for the spec above (plus all nullable primitive/container variants and an allOf inheritance 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 enum null → empty optional).

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    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.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

C++ technical committee: @ravinikam @stkrwork @etherealjoy @MartinDelille @muttleyxd @aminya

🤖 Generated with Claude Code


Summary by cubic

Fixes cpp-httplib-server so schema shapes that previously generated uncompilable model code now produce valid C++.

Bug fixes

  • uuid, uri, and decimal string formats now map to std::string instead of the Java type names UUID, URI, and BigDecimal inherited from DefaultCodegen.
  • uniqueItems: true arrays resolve the set mapping to std::vector, so the generated include is <vector> instead of "Set.h".
  • Constructor initializers are now derived from the declared C++ member type rather than isNullable, so nullable members no longer get std::nullopt on unwrapped declarations such as nlohmann::json and model references.
  • Optional nullable enums now take the same std::optional<Enum> path as other optional enums instead of being initialized with std::nullopt while declared unwrapped.
  • The constructor initializer list is now built in Java, so the leading : is emitted even when the first member has no initializer.

Unit tests were added, and regenerating the cpp-httplib-server samples produced no changes.

Written for commit f51d8b8. Summary will update on new commits.

View guided diff

…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>

@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 3 files

View guided diff | Re-trigger cubic

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant