Skip to content

Commit 1703d94

Browse files
rajveshRajesh Vasireddy
authored andcommitted
Improvements from branch 3
Branch3: Resolved include names and generated file names. Adjusted mustache files and aligned properly. Added NLOHMANN_DEFINE_TYPE_INTRUSIVE for json serialization and deserialization. Branch4: CppHttplibServerCodegen: Support multiple success codes, void return types, and improve success/error type handling - Added support for multiple success response codes per operation. - Handled void return types for operations with no response schema. - Improved logic for collecting and exposing successTypes and errorTypes in vendor extensions. - Enhanced mapping and template support for distinguishing between primitive, model, and void responses. - Handled Enums from specification. Further improvements (branch4)
1 parent 4ea1f2a commit 1703d94

45 files changed

Lines changed: 2255 additions & 2806 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bin/configs/cpp-httplib-petstore.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
generatorName: cpp-httplib-server
22
outputDir: samples/server/petstore/cpp-httplib-server
3-
inputSpec: modules/openapi-generator/src/test/resources/3_0/cpp-httplib-server/petstore.yaml
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/cpp-httplib-server/petstore.json
44
templateDir: modules/openapi-generator/src/main/resources/cpp-httplib-server
55
additionalProperties:
66
apiNamespace: "petstore::openapi::api"

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppHttplibServerCodegen.java

Lines changed: 270 additions & 172 deletions
Large diffs are not rendered by default.

modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ org.openapitools.codegen.languages.CrystalClientCodegen
1212
org.openapitools.codegen.languages.CLibcurlClientCodegen
1313
org.openapitools.codegen.languages.ClojureClientCodegen
1414
org.openapitools.codegen.languages.ConfluenceWikiCodegen
15+
org.openapitools.codegen.languages.CppHttplibServerCodegen
1516
org.openapitools.codegen.languages.CppOatppClientCodegen
1617
org.openapitools.codegen.languages.CppQtClientCodegen
1718
org.openapitools.codegen.languages.CppQtQHttpEngineServerCodegen

modules/openapi-generator/src/main/resources/cpp-httplib-server/api-header.mustache

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
#pragma once
44

5+
#include <httplib.h>
6+
{{#includeVariantHeader}}{{{includeVariantHeader}}}{{/includeVariantHeader}}
7+
{{#includeOptionalHeader}}{{{includeOptionalHeader}}}{{/includeOptionalHeader}}
8+
59
{{#modelsUsed}}
610
#include "models/{{{.}}}.h"
711
{{/modelsUsed}}
812

9-
#include <httplib.h>
10-
{{#includeVariantHeader}}{{{includeVariantHeader}}}{{/includeVariantHeader}}
11-
{{#includeOptionalHeader}}{{{includeOptionalHeader}}}{{/includeOptionalHeader}}
1213
namespace {{apiNamespace}} {
1314
class {{apiClassnameInPascalCase}} {
1415
public:
@@ -30,11 +31,13 @@ public:
3031
*/
3132
struct {{requestType}}
3233
{
33-
{{#requestModel}}std::optional<{{requestModelNamespace}}::{{requestModel}}> m_request;{{/requestModel}}{{^requestModel}}// No Schema Types defined{{/requestModel}}
34-
{{#queryParams}}{{{dataType}}} m_{{paramName}};{{/queryParams}}{{^queryParams}}// Query Params not available{{/queryParams}}
35-
{{#headerParams}}{{{dataType}}} m_{{paramName}};{{/headerParams}}{{^headerParams}}// Header Params not available{{/headerParams}}
34+
{{#requestModel}}
35+
std::optional<{{requestModelNamespace}}::{{requestModel}}> m_request; //Request Body{{/requestModel}}{{#queryParams}}
36+
{{{dataType}}} m_{{paramName}}; //Query Params{{/queryParams}}{{#headerParams}}
37+
{{{dataType}}} m_{{paramName}}; //HeaderParams{{/headerParams}}{{#pathParams}}
38+
{{{dataType}}} m_{{paramName}}; //PathParams{{/pathParams}}{{#cookieParams}}
39+
{{{dataType}}} m_{{paramName}}; //Cookies{{/cookieParams}}
3640
};
37-
3841
{{/hasAnyRequestSchema}}
3942
{{/vendorExtensions}}
4043
{{/operation}}
@@ -49,14 +52,13 @@ public:
4952
// ===== Response types =====
5053
// ==========================
5154
{{/-first}}
55+
5256
/**
5357
* @brief Response type for {{handlerFunctionName}}.
5458
*/
55-
using {{responseType}} = std::variant<
56-
{{#successType}}{{successType}}{{/successType}}{{^errorTypes}}>;{{/errorTypes}}
57-
{{#errorTypes}} , {{{.}}}{{#-last}}>;{{/-last}}
58-
{{/errorTypes}}
59-
59+
using {{responseType}} = std::variant<{{#successCodeToTypes}}{{#successType}}
60+
{{successType}}{{/successType}}{{#errorCodeToTypes}}{{#-first}} ,{{/-first}}{{/errorCodeToTypes}}{{/successCodeToTypes}}{{^errorCodeToTypes}}>;{{/errorCodeToTypes}}{{#errorCodeToTypes}}
61+
{{#errorType}}{{errorType}}{{/errorType}}{{^-last}} ,{{/-last}}{{#-last}} >;{{/-last}}{{/errorCodeToTypes}}
6062
{{/hasAnyResponseSchema}}
6163
{{/vendorExtensions}}
6264
{{/operation}}

0 commit comments

Comments
 (0)