You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit b02d00b
Browse filesBrowse the repository at this point in the historyBrowse files
* fix(cpp-httplib-server): generate top-level enum models
* fix(cpp-httplib-server): preserve enum string values
* fix(cpp-httplib-server): regenerate samples
* fix(cpp-httplib-server): serialize top-level string enums
* model-header.mustache fix namespace closure
* fix comments
* regenerate samples
* generate samples in codespace
* test(cpp-httplib-server): cover string-valued enums with non-string type
The isStringEnum fallback added in f368b5a had no test that
distinguished it from the previous ModelUtils.isStringSchema check.
ModelUtils.getType returns the first element of a 3.1 type set, so a
`type: [null, string]` enum reports its type as "null": isStringSchema is
false while isEnum is true, and model-header.mustache then emits
`j = available;` instead of `j = "available";`, which does not compile.
Reverting CppHttplibServerCodegen to the plain isStringSchema check makes
this test fail.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* test(cpp-httplib-server): assert rendered to_json/from_json for top-level enums
The existing enum tests only assert the isStringEnum vendor extension on
the fromModel result. That flag is just the input to model-header.mustache,
so a break in the template itself -- a renamed flag, an inverted section --
passed the whole suite unnoticed.
Add a test that builds a string-backed and an integer-backed top-level enum
schema, runs DefaultGenerator over them, and asserts on the rendered enum
headers: quoted values for the former, bare values for the latter, plus the
inverse via assertFileNotContains. Renaming vendorExtensions.isStringEnum
throughout model-header.mustache makes it fail.
Also add an integer-backed top-level enum to feature-test.json and
regenerate its sample. The template's `{{^vendorExtensions.isStringEnum}}`
branch had no checked-in sample output, since the spec carried a top-level
string enum but no integer one.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* add default branch to switch in to_json
* align exceptions also for nested enum definitions
* Revert nlohmann exceptions in cpp, as the corresponding methods are not directly related to nlohmann but are more general in nature.
---------
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
auto model = {{vendorExtensions.modelNamespace}}::{{vendorExtensions.modelClassName}}::{{#allowableValues}}{{#enumVars}}{{#-first}}{{name}}{{/-first}}{{/enumVars}}{{/allowableValues}};
103
+
104
+
// Serialize to JSON via the generated to_json free function
105
+
nlohmann::json json = model;
106
+
std::string jsonString = json.dump();
107
+
108
+
// Deserialize from JSON via the generated from_json free function
109
+
auto parsedModel = nlohmann::json::parse(jsonString).get<{{vendorExtensions.modelNamespace}}::{{vendorExtensions.modelClassName}}>();
110
+
{{/isEnum}}
111
+
{{^isEnum}}
100
112
// Create a model
101
113
auto model = {{vendorExtensions.modelNamespace}}::{{vendorExtensions.modelClassName}}();
if (j == {{#vendorExtensions.isStringEnum}}"{{{value}}}"{{/vendorExtensions.isStringEnum}}{{^vendorExtensions.isStringEnum}}{{value}}{{/vendorExtensions.isStringEnum}})
41
+
{
42
+
value = {{vendorExtensions.modelClassName}}::{{name}};
43
+
return;
44
+
}
45
+
{{/enumVars}}{{/allowableValues}}
46
+
throw nlohmann::json::type_error::create(302, "Invalid value for {{vendorExtensions.modelClassName}}", &j);
47
+
}
48
+
49
+
{{/isEnum}}
50
+
{{^isEnum}}
19
51
{{#vendorExtensions.isOneOfSchema}}
20
52
// oneOf schema - type alias for std::variant
21
53
using {{vendorExtensions.modelClassName}} = std::variant<
Copy file name to clipboardExpand all lines: modules/openapi-generator/src/test/java/org/openapitools/codegen/cpphttplibserver/CppHttplibServerCodegenModelTest.java
0 commit comments