-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
fix(cpp-httplib-server): generate top-level enum models #24795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
f186960
c877a32
67be047
ffbc0fa
d80db91
facbbb0
24a7af8
f368b5a
753093e
385e1c2
d20ead3
a2a938d
501451d
be62cce
47dd09b
21cfca0
969fd96
112e3e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,38 @@ | |
|
|
||
| namespace {{vendorExtensions.modelNamespace}} { | ||
|
|
||
| {{#isEnum}} | ||
| enum class {{vendorExtensions.modelClassName}} { | ||
| {{#allowableValues}}{{#enumVars}} | ||
| {{name}}{{^-last}},{{/-last}} | ||
| {{/enumVars}}{{/allowableValues}} | ||
| }; | ||
|
|
||
| inline void to_json(nlohmann::json& j, const {{vendorExtensions.modelClassName}}& value) | ||
| { | ||
| switch (value) | ||
| { | ||
| {{#allowableValues}}{{#enumVars}} | ||
| case {{vendorExtensions.modelClassName}}::{{name}}: j = {{#vendorExtensions.isStringEnum}}"{{{value}}}"{{/vendorExtensions.isStringEnum}}{{^vendorExtensions.isStringEnum}}{{value}}{{/vendorExtensions.isStringEnum}}; break; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: When a top-level string enum contains a quote, backslash, or control character, this raw interpolation generates an invalid or changed C++ literal in both Prompt for AI agents |
||
| {{/enumVars}}{{/allowableValues}} | ||
| default: throw nlohmann::json::type_error::create(302, "Invalid value for {{vendorExtensions.modelClassName}}", &j); | ||
| } | ||
| } | ||
|
|
||
| inline void from_json(const nlohmann::json& j, {{vendorExtensions.modelClassName}}& value) | ||
| { | ||
| {{#allowableValues}}{{#enumVars}} | ||
| if (j == {{#vendorExtensions.isStringEnum}}"{{{value}}}"{{/vendorExtensions.isStringEnum}}{{^vendorExtensions.isStringEnum}}{{value}}{{/vendorExtensions.isStringEnum}}) | ||
| { | ||
| value = {{vendorExtensions.modelClassName}}::{{name}}; | ||
| return; | ||
| } | ||
| {{/enumVars}}{{/allowableValues}} | ||
| throw nlohmann::json::type_error::create(302, "Invalid value for {{vendorExtensions.modelClassName}}", &j); | ||
| } | ||
|
|
||
| {{/isEnum}} | ||
| {{^isEnum}} | ||
| {{#vendorExtensions.isOneOfSchema}} | ||
| // oneOf schema - type alias for std::variant | ||
| using {{vendorExtensions.modelClassName}} = std::variant< | ||
|
|
@@ -250,6 +282,7 @@ private: | |
| {{/vendorExtensions.isAnyOfSchema}} | ||
| {{/vendorExtensions.isOneOfSchema}} | ||
|
|
||
| {{/isEnum}} | ||
| } // namespace {{vendorExtensions.modelNamespace}} | ||
|
|
||
| {{/model}} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.