Skip to content

Conversation

@roomote
Copy link

@roomote roomote bot commented Nov 27, 2025

This PR adds comprehensive improvements to the cpp-httplib-server generator to address the following requirements:

Changes Made

1. ✅ Enum Support

  • Added enum type definitions in model headers with enum class
  • Implemented enum-to-string and string-to-enum helper functions
  • Added enum support in path, query, and header parameters
  • Enums are properly serialized/deserialized in JSON

2. ✅ Nullable/Optional Support

  • Added support for nullable parameters using std::optional<T>
  • Non-required parameters are automatically wrapped in std::optional
  • Proper handling of nullable types in request parsing

3. ✅ Number Type Mapping

  • Kept number type mapped to double (standard for JSON precision)
  • Added explicit support for float type in parameters
  • Both float and double are properly handled in path, query, and header parameters

4. ✅ Fixed Comma Issue in std::variant

  • Fixed the bug where an extra comma appeared in std::variant when no success type was defined
  • Improved template logic to handle all combinations of success/error types

5. ✅ Void Return Type Support

  • Handler functions now properly handle void return types
  • When no response schema is defined, handlers return void and set HTTP 200 status automatically

6. ✅ Server URL and Port Utilities

  • Added getServerUrl(host, port) static method to generate server URLs
  • Added getPort(svr) static method to retrieve the server port
  • These utilities are available in all API classes

7. ✅ Path Parameter Support

  • Full support for path parameters in request parsing
  • Path parameters are extracted from req.path_params
  • Support for all primitive types (string, int, long, float, double, bool) and enums in path parameters

Files Modified

  • CppHttplibServerCodegen.java - Enhanced codegen logic for enums, nullable types, and path parameters
  • api-header.mustache - Added utility methods, fixed variant comma issue, added path params to request struct
  • api-source.mustache - Added path parameter parsing, enum conversion, void return handling, utility implementations
  • model-header.mustache - Added enum definitions and helper function declarations
  • model-source.mustache - Added enum helper function implementations

Testing

The changes have been implemented following C++ best practices and the existing codebase patterns. The generator will now properly handle:

  • Enums in models and all parameter types
  • Nullable/optional values
  • Path parameters alongside query and header parameters
  • Void return types
  • Float and double numeric types

All changes maintain backward compatibility with existing generated code.

wing328 and others added 30 commits September 9, 2025 09:21
* fix default value when enum is ref (python)

* update spec
* java-client: fix some javadoc comments

* update samples
…t with poetry1 fallback (OpenAPITools#21931)

* Add support for both string and object license formats in `pyproject.toml` for Python and Python-Pydantic generators. (OpenAPITools#21619)

* Generate the samples (OpenAPITools#21698)

* Generate the samples (OpenAPITools#21698)

* Remove Python-Pydantic-v1 license format tests (OpenAPITools#21619)

* Revert license format to string in Python-Pydantic-v1 samples (OpenAPITools#21619)
* python: feature flag for lazy imports

* python: update samples

* python: add python-lazyImports to test job

* python: reuse tests in lazyImports sample

* python: avoid using non-imported submodules

* add normalizer option

---------

Co-authored-by: Pascal Bachor <[email protected]>
Co-authored-by: William Cheng <[email protected]>
…PITools#21943)

Changes the logic of parsing of OneOf/AnyOf to fix incorrect type coercion
in OneOf/AnyOf contexts. The guard which checks whether typed_data is true-ish
fails for booleans. If the oneOf includes a boolean type and the data is false then
it will correctly parse this value as a boolean. However, the guard class will determine
that false is not true-ish and therefore returns nil. So the result of the type coercion
of false will be nil. This can result in problems when dealing with default true.

For example how a false can turn into a true with defaults:
1. The API returns false
2. The type coercion determines false becomes nil
3. When storing this retrieved record with a default of true for this column the stored value is suddenly true
while the API specifically returned false

This fix removes this guard and will rely on the exception raised to return nil when type coercion fails.
* fix: parameter appending for number types

Updated string and number parameter handling to ensure proper conversion to string before appending.

* Update api.mustache
* add tests for numeric form data (kotlin)

* remove null check as its done already
Unfortunately i have not had time to engage in this project in recent years, and as such feel its best for myself and the community if i remove myself from the Kotlin technical committe. 

Thanks for all the great work done by all contributors.
…ls#21961)

* update rest-assured dep to newer versions

* update build
…le, required Map (OpenAPITools#21953)

* Issue 21890: Fixed flag to use for check of required, non-nullable map

* Issue 21890: added test (first draft)

* Issue 21890: Added Test

---------

Co-authored-by: Marco <[email protected]>
…in validation (OpenAPITools#21957)

* Correctly apply Gradle task input & output annotations to accessors

Gradle's task input and output annotations should be applied to the accessors instead of the properties. No adhering to this can cause funky behavior in the generated stubs. Examples of this can be found in the docs: https://docs.gradle.org/current/userguide/implementing_custom_tasks.html

Also adds missing annotations so that validation passes

* Enable strict Gradle plugin validation
…reactive.RestResponse" (OpenAPITools#21877)

* replace Response by RestResponse

* fix rest response for Async

* update documentation

* Add option "returnJBossResponse"

* Add tests + fixes

* Polish

* Add dependency "io.quarkus.resteasy.reactive:resteasy-reactive" when returnJBossResponse=true

* fix JavaJAXRSSpecServerCodegenTest

* generate samples & docs
…he reqwest library (OpenAPITools#21925)

* feat(rust): add the native-tls (default) and rustls Cargo features for `reqwest`

* refactor(rust): rename the `rustls` Cargo feature to follow the ecosystem naming convention
…penAPITools#21968)

* feat: add Apache Dubbo code generator with multi-registry support

- Add comprehensive Dubbo microservice code generator
- Support Zookeeper and Nacos registries with auto-dependency selection
- Implement version-aware dependency management (Dubbo 3.2 vs 3.3+)
- Generate service interfaces, implementations, and Spring Boot REST controllers
- Include complete Spring Boot application structure with configuration
- Add detailed documentation and usage examples
- Support async operations and generic response wrappers
- Provide flexible configuration options for packages, versions, and features

* feat: Add dubbo sample with CI validation

Adds a new sample generator configuration for dubbo.

The existing GitHub workflow for Java samples is updated to build and test this new sample automatically.

* fix: fix Dubbo protocol extension issue in test environment

- Set registry address to N/A to avoid ZooKeeper dependency
- Change protocol from 'triple' to 'tri' to resolve extension loading error

* various fix to java dubbo server generator

* update doc

* update readme

---------

Co-authored-by: redoom <[email protected]>
…face in DTOs (similar to x-implements from java-spring) (OpenAPITools#21950)

* add basic implementation and tests

* improve test a bit

* modify kotlin-spring.md

* add x-kotlin-implements also to enum

* update samples & properly define implemented vendor extension

* use enum.getName() instead of hardcoded string as key in vendor extension map

* fix docs

* fix test openapi spec and test

* add samples for x-kotlin-implements

* add samples for x-kotlin-implements to proper output folder

* fix

* revert unwanted changes

* move to correct place

* fix mustache template

* add to samples-kotlin-server.yaml

* reuse 1 open api schema for everything. Add also case where interface extends interface.

* add warn logs when x-kotlin-implements-fields is used without x-kotlin-implements to improve usability

* remove unnecessary generated files

* remove unnecessary generated files

* remove "status" inner enum from Pet as it fails to properly import as Pet.Status in implementations. This is a separate bug - not caused by x-kotlin-implements
… of local_date_serialize (OpenAPITools#21974)

* Bugfix: saving offset_date_serializer instead of local_date_serializer.dart

* New config for dart-dio (timemachine)

* test samples in github workflow

* update workflow, samples

* rename

---------

Co-authored-by: Enric Pou <[email protected]>
* more dart dio tests, update samples

* update

* update

* more tests

* update

* update
* mark scala-lagom-server as deprecated

* update workflow
* add workflow for powershell client

* update

* fix container

* import, test

* combine

* use localhost

* update tests

* remove powershell tests from appveyor.yml
* migrate tests from appveyor to github workflow

* test with dotnet 7

* test on windows

* set dotnet version

* Revert "set dotnet version"

This reverts commit 87af6a6.

* use localhost

* update

* update

* update tets

* update

* remove appveyor
wing328 and others added 20 commits November 8, 2025 23:12
…enAPITools#22285)

* fix(c): Remove duplicate code generation for UUID path parameters

The C generator was generating duplicate path parameter handling code
when a parameter had format: uuid. This occurred because UUID parameters
have both isString=true and isUuid=true flags set, causing both the
{{#isString}} and {{#isUuid}} template blocks to execute.

The duplicate {{#isUuid}} block has been removed since it generated
identical code to the {{#isString}} block. This makes UUID parameters
consistent with email parameters, which already work this way
(isEmail=true and isString=true, but only use the {{#isString}} block).

The generated code now compiles successfully without duplicate variable
declarations.

* test(c): Add UUID path parameter test case to petstore

Adds endpoint with UUID path parameter to verify C generator produces compilable code without duplicate variable declarations.

* chore(samples): Regenerate all C samples with template fix

Regenerated all C sample variants to include the UUID path parameter example.
OpenAPITools#22300)

* feat: add support for Swagger v3 annotations to jaxrs-spec

* test added unittest for jaxrs-spec with swagger3Annotations

* test added integrationtest for jaxrs-spec with swagger3Annotations

* test added integrationtest for jaxrs-spec with swaggerV2Annotations

* documentation update for new option useSwaggerV3Annotations in the jaxrs-spec.md

* test added integrationtest for jaxrs-spec with swaggerV3Annotations icm use JakartaEE

* update documentation by executing:  ./bin/utils/export_docs_generators.sh

* ran on wsl: ./bin/generate-samples.sh ./bin/configs/*.yaml
* add new jaxrs samples to github workflow

* trigger ci
…penAPITools#22279 (OpenAPITools#22316)

* Partial revert changing path generation if interface

This reverts commit 65703ff.

* update samples and docs
…22312)

* [Java] Annotate Deprecated `enum`-classes with `@Deprecated`

* Update Generated 'samples'-files

Signed-off-by: Chrimle <[email protected]>

* Update `modelEnum.mustache` According to Review Comment

Signed-off-by: Chrimle <[email protected]>

* Update Generated 'sample'-files

Signed-off-by: Chrimle <[email protected]>

* Update Java Native `modelEnum.mustache` File

Signed-off-by: Chrimle <[email protected]>

* Update Java JaxRS `modelEnum.mustache` File

Signed-off-by: Chrimle <[email protected]>

* Update Java Okhttp-gson `modelEnum.mustache` File

Signed-off-by: Chrimle <[email protected]>

* Update Java Micronaut `modelEnum.mustache` File

Signed-off-by: Chrimle <[email protected]>

* Update Java Helidon `modelEnum.mustache` File

Signed-off-by: Chrimle <[email protected]>

---------

Signed-off-by: Chrimle <[email protected]>
* clean up java jersey3 smaples

* clean up jersey3 samples

* update tests
…22332)

allow trait mocking

See merge request tools.core/swagger-codegen!379

Co-authored-by: Richard Whitehouse <[email protected]>
* cherry pick the change from 22299

* fix accept headers
- Add enum support in models and parameters with helper functions
- Add nullable/optional support for parameters using std::optional
- Keep number type mapped to double (standard for JSON precision)
- Fix comma issue in std::variant when no success type is defined
- Handle void return types in handler functions
- Add utility methods getServerUrl() and getPort() to API class
- Add full support for path parameters in request parsing
- Add support for float type in parameters and models
- Improve type flag detection for enums in parameters

These changes address all the requirements for better OpenAPI spec support
in the cpp-httplib-server generator.
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

The pull request #1 has too many files changed.

The GitHub API will only let us fetch up to 300 changed files, and this pull request has 12144.

@roomote
Copy link
Author

roomote bot commented Nov 27, 2025

Rooviewer Clock   See task on Roo Cloud

Review completed. Found 4 issues that need attention:

  • Undefined variable modelClassName - Line 320, 328, 336: Variable used but never declared
  • Invalid C++ namespace syntax - Lines 380, 419: Leading :: when namespace is empty causes compilation errors
  • Missing path parameters check - Line 465-467: Path parameters not included in hasRequestSchema condition

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

// Add type flags for query and header params for template type conversion
if (op.queryParams != null) {
for (CodegenParameter qp : op.queryParams) {
setCppTypeFlags(qp, modelClassName, hasPrimitiveParams);
Copy link
Author

Choose a reason for hiding this comment

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

Undefined variable modelClassName is used here. This variable is never declared or initialized in the postProcessOperationsWithModels method, which will cause a compilation error. The variable should either be defined from the operation context or removed if not needed.

Fix it with Roo Code or mention @roomote and request a fix.

if (!typeMapping.containsKey(resp.baseType)) {
// String className = stripPathFromClassName(resp.baseType).get("className");
String className = toPascalCase(resp.baseType);
successType = namespaceFiltered + "::" + className;
Copy link
Author

Choose a reason for hiding this comment

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

Invalid C++ syntax when namespaceFiltered is empty. The expression namespaceFiltered + "::" + className produces a leading :: (e.g., ::ClassName) when the namespace is empty, which is invalid C++ syntax and will cause compilation errors. The code should check if namespaceFiltered is empty before adding the :: separator.

Fix it with Roo Code or mention @roomote and request a fix.

if (!typeMapping.containsKey(errorBaseType)) {
// String className = stripPathFromClassName(errorBaseType).get("className");
String className = toPascalCase(errorBaseType);
errorType = namespaceFiltered + "::" + className;
Copy link
Author

Choose a reason for hiding this comment

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

Same namespace issue as line 380. The expression namespaceFiltered + "::" + className produces invalid C++ syntax with a leading :: when namespaceFiltered is empty. This will cause compilation errors in generated code for error response types.

Fix it with Roo Code or mention @roomote and request a fix.

Comment on lines +465 to +467
boolean hasRequestSchema = (op.queryParams != null && !op.queryParams.isEmpty()) ||
(op.headerParams != null && !op.headerParams.isEmpty()) ||
(op.bodyParams != null && !op.bodyParams.isEmpty());
Copy link
Author

Choose a reason for hiding this comment

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

Path parameters are not included in the hasRequestSchema check. Since path parameters are now supported (as stated in the PR description) and are added to the request struct (line 38 in api-header.mustache), they should be included in this condition. Without this, operations with only path parameters will incorrectly have hasAnyRequestSchema set to false, potentially causing the request struct to not be generated or parsed correctly.

Suggested change
boolean hasRequestSchema = (op.queryParams != null && !op.queryParams.isEmpty()) ||
(op.headerParams != null && !op.headerParams.isEmpty()) ||
(op.bodyParams != null && !op.bodyParams.isEmpty());
boolean hasRequestSchema = (op.queryParams != null && !op.queryParams.isEmpty()) ||
(op.headerParams != null && !op.headerParams.isEmpty()) ||
(op.pathParams != null && !op.pathParams.isEmpty()) ||
(op.bodyParams != null && !op.bodyParams.isEmpty());

Fix it with Roo Code or mention @roomote and request a fix.

rajvesh pushed a commit that referenced this pull request Jan 29, 2026
…streaming (OpenAPITools#22673)

* Update isomorphic-fetch file to allow for response streaming (#1)

* Update samples/openapi3/client/petstore/typescript/builds/inversify/http/http.ts

Co-authored-by: Copilot <[email protected]>

* Update samples/client/echo_api/typescript/build/http/http.ts

Co-authored-by: Copilot <[email protected]>

* Update samples/openapi3/client/petstore/typescript/builds/object_params/http/http.ts

Co-authored-by: Copilot <[email protected]>

* update samples

* fix tests

---------

Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
@rajvesh rajvesh closed this Feb 9, 2026
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.