fix(cpp-httplib-server): serialize enums using spec values

Merged
KA
5mo ago
+176-112

Summary

Fixes enum serialization for the cpp-httplib-server generator.

Previously, convertNumericEnumValues() modified the original OpenAPI enum values during model processing. For example, a spec value like "available" was changed to "AVAILABLE" before enum serialization helpers were generated. As a result, generated EnumToString / EnumFromString code used the C++ enum identifier instead of the actual OpenAPI value.

This change keeps the two concepts separate:

  • C++ enum identifier: AVAILABLE
  • OpenAPI serialized value: "available"

Changes

  • Removed the destructive convertNumericEnumValues() mutation.
  • Moved C++ enum identifier derivation into setEnumVendorExtensions().
  • Preserved raw OpenAPI enum values for serialization and deserialization.
  • Fixed numeric enum default handling where a synthetic "0" default could incorrectly suppress std::optional.
  • Fixed array-of-enum identifier generation to use the enum values from items.
  • Added regression test coverage.
  • Regenerated the cpp-httplib-server-petstore and cpp-httplib-server-feature-test samples.

Verification

  • Generated code from the issue spec now serializes:

    • "available"
    • "pending"
    • "sold"

    instead of:

    • "AVAILABLE"
    • "PENDING"
    • "SOLD"
  • Ran cpp-httplib-server tests successfully.

  • Regenerated affected cpp-httplib-server samples.

Fixes #24052


Summary by cubic

Fixes enum serialization in cpp-httplib-server to use the OpenAPI value, not the derived C++ enum identifier. Restores correct wire values for strings and numerics (e.g., "available", "200"). Fixes #24052.

  • Bug Fixes
    • Removed destructive convertNumericEnumValues() and derive C++ identifiers in setEnumVendorExtensions(), preserving original spec values for EnumToString/EnumFromString.
    • Prevented synthetic "0" defaults for numeric enums so optional wrapping isn’t incorrectly suppressed.
    • For array-of-enum properties, declare enum members from items.allowableValues.values; updated model-header.mustache.
    • Added regression tests and regenerated cpp-httplib-server samples.