fix(cpp-httplib-server): handle missing optional JSON properties

Closed
DH
1mo ago
+21-3

Fixes #23991

This fixes a crash in cpp-httplib-server generator when optional JSON properties
are missing in the request payload.

Previously, NLOHMANN_DEFINE_TYPE_INTRUSIVE was used which does not safely handle
missing fields.

Now replaced with custom to_json/from_json using:

  • j.at() for required fields
  • j.contains() check for optional fields

Summary by cubic

Prevents crashes in the cpp-httplib-server generator when request JSON omits optional fields by switching to explicit to_json/from_json handling. Generated servers now safely ignore missing optional properties.

  • Bug Fixes
    • Replaced NLOHMANN_DEFINE_TYPE_INTRUSIVE with friend to_json/from_json in model headers.
    • Required fields use j.at(...).get_to(...).
    • Optional fields use j.contains(...) and null check before get_to(...).