diff --git a/CI/.drone.yml b/CI/.drone.yml
index 037fb654724c..a4c8c9b0e95e 100644
--- a/CI/.drone.yml
+++ b/CI/.drone.yml
@@ -1,6 +1,5 @@
kind: pipeline
name: default
-
steps:
# test Java 11 HTTP client
- name: java11-test
@@ -54,3 +53,10 @@ steps:
image: haskell:8.6.5
commands:
- (cd samples/client/petstore/haskell-http-client/ && stack --install-ghc --no-haddock-deps haddock --fast && stack test --fast)
+# test erlang client and server
+- name: erlang
+ image: erlang:alpine
+ commands:
+ - (cd samples/client/petstore/erlang-client && rebar3 compile)
+ - (cd samples/client/petstore/erlang-proper && rebar3 compile)
+ #- (cd samples/server/petstore/erlang-server && rebar3 compile)
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 30258ec9fd6c..0fe833163afa 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -48,6 +48,7 @@ Code change should conform to the programming style guide of the respective lang
- C#: https://msdn.microsoft.com/en-us/library/vstudio/ff926074.aspx
- C++: https://google.github.io/styleguide/cppguide.html
- C++ (Tizen): https://wiki.tizen.org/Native_Platform_Coding_Idiom_and_Style_Guide#C.2B.2B_Coding_Style
+- C++ (Unreal Engine 4): https://docs.unrealengine.com/en-US/ProductionPipelines/DevelopmentSetup/CodingStandard/index.html
- Clojure: https://github.com/bbatsov/clojure-style-guide
- Crystal: https://crystal-lang.org/reference/conventions/coding_style.html
- Dart: https://www.dartlang.org/guides/language/effective-dart/style
diff --git a/README.md b/README.md
index c27f86b1531d..c994f615fa62 100644
--- a/README.md
+++ b/README.md
@@ -562,7 +562,7 @@ When code is generated from this project, it shall be considered **AS IS** and o
### [3.5 - IDE Integration](#table-of-contents)
-Here is a list of community-conitributed IDE plug-ins that integrate with OpenAPI Generator:
+Here is a list of community-contributed IDE plug-ins that integrate with OpenAPI Generator:
- Eclipse: [Codewind OpenAPI Tools for Eclipse](https://www.eclipse.org/codewind/open-api-tools-for-eclipse.html) by [IBM](https://www.ibm.com)
- IntelliJ IDEA: [OpenAPI Generator](https://plugins.jetbrains.com/plugin/8433-openapi-generator) by [Jim Schubert](https://jimschubert.us/#/)
@@ -666,6 +666,7 @@ Here are some companies/projects (alphabetical order) using OpenAPI Generator in
- [Twitter](https://twitter.com)
- [unblu inc.](https://www.unblu.com/)
- [Veamly](https://www.veamly.com/)
+- [VMWare](https://www.vmware.com/)
- [wbt-solutions](https://www.wbt-solutions.de/)
- [Woleet](https://www.woleet.io/)
- [WSO2](https://wso2.com/)
diff --git a/bin/configs/other/cpp-pistache-server-cpp-pistache.yaml b/bin/configs/cpp-pistache-server-cpp-pistache.yaml
similarity index 100%
rename from bin/configs/other/cpp-pistache-server-cpp-pistache.yaml
rename to bin/configs/cpp-pistache-server-cpp-pistache.yaml
diff --git a/bin/configs/ktorm-schema.yaml b/bin/configs/ktorm-schema.yaml
index aff895cb279b..d3c5beb9a33b 100644
--- a/bin/configs/ktorm-schema.yaml
+++ b/bin/configs/ktorm-schema.yaml
@@ -1,7 +1,7 @@
generatorName: ktorm-schema
outputDir: samples/schema/petstore/ktorm
-inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
+inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/ktorm-schema
additionalProperties:
hideGenerationTimestamp: true
- importModelPackageName: org.openapitools.client.models
\ No newline at end of file
+ importModelPackageName: org.openapitools.client.models
diff --git a/bin/configs/nim.yaml b/bin/configs/nim.yaml
index 136a92764c3c..13a27a6b764c 100644
--- a/bin/configs/nim.yaml
+++ b/bin/configs/nim.yaml
@@ -1,6 +1,6 @@
generatorName: nim
outputDir: samples/client/petstore/nim
-inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
+inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/nim-client
additionalProperties:
packageName: petstore
diff --git a/docs/contributing.md b/docs/contributing.md
index a791b0d6f1ba..fe325ae17e16 100644
--- a/docs/contributing.md
+++ b/docs/contributing.md
@@ -52,6 +52,7 @@ Code change should conform to the programming style guide of the respective lang
- C#: https://msdn.microsoft.com/en-us/library/vstudio/ff926074.aspx
- C++: https://google.github.io/styleguide/cppguide.html
- C++ (Tizen): https://wiki.tizen.org/Native_Platform_Coding_Idiom_and_Style_Guide#C.2B.2B_Coding_Style
+- C++ (Unreal Engine 4): https://docs.unrealengine.com/en-US/ProductionPipelines/DevelopmentSetup/CodingStandard/index.html
- Clojure: https://github.com/bbatsov/clojure-style-guide
- Crystal: https://crystal-lang.org/reference/conventions/coding_style.html
- Dart: https://www.dartlang.org/guides/language/effective-dart/style
diff --git a/docs/generators/aspnetcore.md b/docs/generators/aspnetcore.md
index 0a30830099f5..99f0b789bdc3 100644
--- a/docs/generators/aspnetcore.md
+++ b/docs/generators/aspnetcore.md
@@ -7,9 +7,9 @@ These options may be applied as additional-properties (cli) or configOptions (pl
| Option | Description | Values | Default |
| ------ | ----------- | ------ | ------- |
-|aspnetCoreVersion|ASP.NET Core version: 5.0, 3.1, 3.0, 2.2, 2.1, 2.0 (deprecated)| |3.1|
-|buildTarget|Target to build an application or library| |program|
-|classModifier|Class Modifier for controller classes: Empty string or abstract.| ||
+|aspnetCoreVersion|ASP.NET Core version: 5.0, 3.1, 3.0, 2.2, 2.1, 2.0 (deprecated)|
- **2.0**
- ASP.NET Core 2.0
- **2.1**
- ASP.NET Core 2.1
- **2.2**
- ASP.NET Core 2.2
- **3.0**
- ASP.NET Core 3.0
- **3.1**
- ASP.NET Core 3.1
- **5.0**
- ASP.NET Core 5.0
|3.1|
+|buildTarget|Target to build an application or library|- **program**
- Generate code for a standalone server
- **library**
- Generate code for a server abstract class library
|program|
+|classModifier|Class Modifier for controller classes: Empty string or abstract.|- ****
- Keep class default with no modifier
- **abstract**
- Make class abstract
||
|compatibilityVersion|ASP.Net Core CompatibilityVersion| |Version_2_2|
|enumNameSuffix|Suffix that will be appended to all enum names.| |Enum|
|enumValueSuffix|Suffix that will be appended to all enum values.| |Enum|
@@ -17,10 +17,10 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|isLibrary|Is the build a library| |false|
|licenseName|The name of the license| |NoLicense|
|licenseUrl|The URL of the license| |http://localhost|
-|modelClassModifier|Model Class Modifier can be nothing or partial| |partial|
+|modelClassModifier|Model Class Modifier can be nothing or partial|- ****
- Keep model class default with no modifier
- **partial**
- Make model class partial
|partial|
|newtonsoftVersion|Version for Microsoft.AspNetCore.Mvc.NewtonsoftJson for ASP.NET Core 3.0+| |3.0.0|
|operationIsAsync|Set methods to async or sync (default).| |false|
-|operationModifier|Operation Modifier can be virtual or abstract| |virtual|
+|operationModifier|Operation Modifier can be virtual or abstract|- **virtual**
- Keep method virtual
- **abstract**
- Make method abstract
|virtual|
|operationResultTask|Set methods result to Task<>.| |false|
|packageAuthors|Specifies Authors property in the .NET Core project file.| |OpenAPI|
|packageCopyright|Specifies an AssemblyCopyright for the .NET Framework global assembly attributes stored in the AssemblyInfo file.| |No Copyright|
@@ -32,7 +32,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|returnICollection|Return ICollection<T> instead of the concrete type.| |false|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|sourceFolder|source folder for generated code| |src|
-|swashbuckleVersion|Swashbuckle version: 3.0.0, 4.0.0, 5.0.0| |3.0.0|
+|swashbuckleVersion|Swashbuckle version: 3.0.0, 4.0.0, 5.0.0|- **3.0.0**
- Swashbuckle 3.0.0
- **4.0.0**
- Swashbuckle 4.0.0
- **5.0.0**
- Swashbuckle 5.0.0
|3.0.0|
|useCollection|Deserialize array types to Collection<T> instead of List<T>.| |false|
|useDateTimeOffset|Use DateTimeOffset to model date-time properties| |false|
|useDefaultRouting|Use default routing for the ASP.NET Core version.| |true|
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AspNetCoreServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AspNetCoreServerCodegen.java
index a52fa88609a5..f7c24196331e 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AspNetCoreServerCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AspNetCoreServerCodegen.java
@@ -199,14 +199,14 @@ public AspNetCoreServerCodegen() {
aspnetCoreVersion.addEnum("5.0", "ASP.NET Core 5.0");
aspnetCoreVersion.setDefault("3.1");
aspnetCoreVersion.setOptValue(aspnetCoreVersion.getDefault());
- addOption(aspnetCoreVersion.getOpt(), aspnetCoreVersion.getDescription(), aspnetCoreVersion.getOptValue());
+ cliOptions.add(aspnetCoreVersion);
swashbuckleVersion.addEnum("3.0.0", "Swashbuckle 3.0.0");
swashbuckleVersion.addEnum("4.0.0", "Swashbuckle 4.0.0");
swashbuckleVersion.addEnum("5.0.0", "Swashbuckle 5.0.0");
swashbuckleVersion.setDefault("3.0.0");
swashbuckleVersion.setOptValue(swashbuckleVersion.getDefault());
- addOption(swashbuckleVersion.getOpt(), swashbuckleVersion.getDescription(), swashbuckleVersion.getOptValue());
+ cliOptions.add(swashbuckleVersion);
// CLI Switches
addSwitch(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG,
@@ -261,19 +261,19 @@ public AspNetCoreServerCodegen() {
classModifier.addEnum("abstract", "Make class abstract");
classModifier.setDefault("");
classModifier.setOptValue(classModifier.getDefault());
- addOption(classModifier.getOpt(), classModifier.getDescription(), classModifier.getOptValue());
+ cliOptions.add(classModifier);
operationModifier.addEnum("virtual", "Keep method virtual");
operationModifier.addEnum("abstract", "Make method abstract");
operationModifier.setDefault("virtual");
operationModifier.setOptValue(operationModifier.getDefault());
- addOption(operationModifier.getOpt(), operationModifier.getDescription(), operationModifier.getOptValue());
+ cliOptions.add(operationModifier);
buildTarget.addEnum("program", "Generate code for a standalone server");
buildTarget.addEnum("library", "Generate code for a server abstract class library");
buildTarget.setDefault("program");
buildTarget.setOptValue(buildTarget.getDefault());
- addOption(buildTarget.getOpt(), buildTarget.getDescription(), buildTarget.getOptValue());
+ cliOptions.add(buildTarget);
addSwitch(GENERATE_BODY,
"Generates method body.",
@@ -292,7 +292,7 @@ public AspNetCoreServerCodegen() {
modelClassModifier.addEnum("partial", "Make model class partial");
modelClassModifier.setDefault("partial");
modelClassModifier.setOptValue(modelClassModifier.getDefault());
- addOption(modelClassModifier.getOpt(), modelClassModifier.getDescription(), modelClassModifier.getOptValue());
+ cliOptions.add(modelClassModifier);
}
@Override
@@ -592,6 +592,7 @@ private void setModelClassModifier() {
private void setBuildTarget() {
setCliOption(buildTarget);
if ("library".equals(buildTarget.getOptValue())) {
+ LOGGER.warn("buildTarget is {} so changing default isLibrary to true", buildTarget.getOptValue());
isLibrary = true;
projectSdk = SDK_LIB;
additionalProperties.put(CLASS_MODIFIER, "abstract");
@@ -636,7 +637,7 @@ private String determineTemplateVersion(String frameworkVersion) {
private void setUseSwashbuckle() {
if (isLibrary) {
- LOGGER.warn("buildTarget is " + buildTarget.getOptValue() + " so changing default isLibrary to false ");
+ LOGGER.warn("isLibrary is true so changing default useSwashbuckle to false");
useSwashbuckle = false;
} else {
useSwashbuckle = true;
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java
index bf49fd425e05..3064af52c20d 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java
@@ -128,6 +128,7 @@ public CppPistacheServerCodegen() {
typeMapping.put("boolean", "bool");
typeMapping.put("array", "std::vector");
typeMapping.put("map", "std::map");
+ typeMapping.put("set", "std::vector");
typeMapping.put("file", "std::string");
typeMapping.put("object", "Object");
typeMapping.put("binary", "std::string");
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaAkkaClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaAkkaClientCodegen.java
index 138e9bf9c1d8..a5e293c9879d 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaAkkaClientCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaAkkaClientCodegen.java
@@ -166,8 +166,8 @@ public void processOpts() {
additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage);
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
- supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
supportingFiles.add(new SupportingFile("build.sbt.mustache", "", "build.sbt"));
+ supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
supportingFiles.add(new SupportingFile("reference.mustache", resourcesFolder, "reference.conf"));
final String invokerFolder = (sourceFolder + File.separator + invokerPackage).replace(".", File.separator);
supportingFiles.add(new SupportingFile("apiRequest.mustache", invokerFolder, "ApiRequest.scala"));
@@ -175,6 +175,7 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("requests.mustache", invokerFolder, "requests.scala"));
supportingFiles.add(new SupportingFile("apiSettings.mustache", invokerFolder, "ApiSettings.scala"));
final String apiFolder = (sourceFolder + File.separator + apiPackage).replace(".", File.separator);
+ supportingFiles.add(new SupportingFile("project/build.properties.mustache", "project", "build.properties"));
supportingFiles.add(new SupportingFile("enumsSerializers.mustache", apiFolder, "EnumsSerializers.scala"));
supportingFiles.add(new SupportingFile("serializers.mustache", invokerFolder, "Serializers.scala"));
}
diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/build.sbt.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/build.sbt.mustache
index a14047e79984..8979b10a7f8c 100644
--- a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/build.sbt.mustache
+++ b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/build.sbt.mustache
@@ -10,8 +10,8 @@ lazy val root = (project in file(".")).
resolvers += Resolver.mavenLocal,
libraryDependencies ++= Seq(
"io.swagger" % "swagger-annotations" % "1.5.24",
- "com.squareup.okhttp3" % "okhttp" % "3.14.7",
- "com.squareup.okhttp3" % "logging-interceptor" % "3.14.7",
+ "com.squareup.okhttp3" % "okhttp" % "4.9.1",
+ "com.squareup.okhttp3" % "logging-interceptor" % "4.9.1",
"com.google.code.gson" % "gson" % "2.8.6",
"org.apache.commons" % "commons-lang3" % "3.10",
{{#hasOAuthMethods}}
diff --git a/modules/openapi-generator/src/main/resources/Javascript-Flowtyped/api.mustache b/modules/openapi-generator/src/main/resources/Javascript-Flowtyped/api.mustache
index 35bff5b9687e..1afc22037510 100644
--- a/modules/openapi-generator/src/main/resources/Javascript-Flowtyped/api.mustache
+++ b/modules/openapi-generator/src/main/resources/Javascript-Flowtyped/api.mustache
@@ -104,16 +104,16 @@ export const {{classname}}FetchParamCreator = function (configuration?: Configur
{{#isKeyInHeader}}
if (configuration && configuration.apiKey) {
const localVarApiKeyValue = typeof configuration.apiKey === 'function'
- ? configuration.apiKey("{{keyParamName}}")
- : configuration.apiKey;
+ ? configuration.apiKey("{{keyParamName}}")
+ : configuration.apiKey;
localVarHeaderParameter["{{keyParamName}}"] = localVarApiKeyValue;
}
{{/isKeyInHeader}}
{{#isKeyInQuery}}
if (configuration && configuration.apiKey) {
const localVarApiKeyValue = typeof configuration.apiKey === 'function'
- ? configuration.apiKey("{{keyParamName}}")
- : configuration.apiKey;
+ ? configuration.apiKey("{{keyParamName}}")
+ : configuration.apiKey;
localVarQueryParameter["{{keyParamName}}"] = localVarApiKeyValue;
}
{{/isKeyInQuery}}
@@ -127,9 +127,9 @@ export const {{classname}}FetchParamCreator = function (configuration?: Configur
{{#isOAuth}}
// oauth required
if (configuration && configuration.accessToken) {
- const localVarAccessTokenValue = typeof configuration.accessToken === 'function'
- ? configuration.accessToken("{{name}}", [{{#scopes}}"{{{scope}}}"{{^-last}}, {{/-last}}{{/scopes}}])
- : configuration.accessToken;
+ const localVarAccessTokenValue = typeof configuration.accessToken === 'function'
+ ? configuration.accessToken("{{name}}", [{{#scopes}}"{{{scope}}}"{{^-last}}, {{/-last}}{{/scopes}}])
+ : configuration.accessToken;
localVarHeaderParameter["Authorization"] = "Bearer " + localVarAccessTokenValue;
}
{{/isOAuth}}
@@ -142,7 +142,7 @@ export const {{classname}}FetchParamCreator = function (configuration?: Configur
localVarQueryParameter['{{baseName}}'] = {{paramName}};
{{/isCollectionFormatMulti}}
{{^isCollectionFormatMulti}}
- localVarQueryParameter['{{baseName}}'] = {{paramName}}.join(COLLECTION_FORMATS["{{collectionFormat}}"]);
+ localVarQueryParameter['{{baseName}}'] = {{#uniqueItems}}Array.from({{/uniqueItems}}{{paramName}}{{#uniqueItems}}){{/uniqueItems}}.join(COLLECTION_FORMATS["{{collectionFormat}}"]);
{{/isCollectionFormatMulti}}
}
{{/isArray}}
@@ -166,7 +166,7 @@ export const {{classname}}FetchParamCreator = function (configuration?: Configur
{{#headerParams}}
{{#isArray}}
if ({{paramName}}) {
- localVarHeaderParameter['{{baseName}}'] = {{paramName}}.join(COLLECTION_FORMATS["{{collectionFormat}}"]);
+ localVarHeaderParameter['{{baseName}}'] = {{#uniqueItems}}Array.from({{/uniqueItems}}{{paramName}}{{#uniqueItems}}){{/uniqueItems}}.join(COLLECTION_FORMATS["{{collectionFormat}}"]);
}
{{/isArray}}
{{^isArray}}
@@ -185,7 +185,7 @@ export const {{classname}}FetchParamCreator = function (configuration?: Configur
})
{{/isCollectionFormatMulti}}
{{^isCollectionFormatMulti}}
- localVarFormParams.set('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS["{{collectionFormat}}"]));
+ localVarFormParams.set('{{baseName}}', {{#uniqueItems}}Array.from({{/uniqueItems}}{{paramName}}{{#uniqueItems}}){{/uniqueItems}}.join(COLLECTION_FORMATS["{{collectionFormat}}"]));
{{/isCollectionFormatMulti}}
}
{{/isArray}}
diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-header.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-header.mustache
index 7beb0990a960..f614d478e96c 100644
--- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-header.mustache
+++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-header.mustache
@@ -14,24 +14,21 @@
#include
#include
{{^hasModelImport}}#include {{/hasModelImport}}
+#include
{{#imports}}{{{import}}}
{{/imports}}
-{{#apiNamespaceDeclarations}}
-namespace {{this}} {
-{{/apiNamespaceDeclarations}}
-
-{{#hasModelImport}}
-using namespace {{modelNamespace}};{{/hasModelImport}}
+namespace {{apiNamespace}}
+{
class {{declspec}} {{classname}} {
public:
- {{classname}}(std::shared_ptr);
- virtual ~{{classname}}() {}
+ explicit {{classname}}(const std::shared_ptr& rtr);
+ virtual ~{{classname}}() = default;
void init();
- const std::string base = "{{basePathWithoutHost}}";
+ static const std::string base;
private:
void setupRoutes();
@@ -41,9 +38,21 @@ private:
{{/operation}}
void {{classnameSnakeLowerCase}}_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
- std::shared_ptr router;
- {{#operation}}
+ const std::shared_ptr router;
+
+ ///
+ /// Helper function to handle unexpected Exceptions during Parameter parsing and validation.
+ /// May be overriden to return custom error formats.
+ ///
+ virtual std::pair handleParsingException(const std::exception& ex) const noexcept;
+ ///
+ /// Helper function to handle unexpected Exceptions during processing of the request in handler functions.
+ /// May be overriden to return custom error formats.
+ ///
+ virtual std::pair handleOperationException(const std::exception& ex) const noexcept;
+
+ {{#operation}}
///
/// {{summary}}
///
@@ -54,7 +63,7 @@ private:
{{#allParams}}
/// {{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}
{{/allParams}}
- virtual void {{operationIdSnakeCase}}({{#allParams}}const {{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}Pistache::Http::ResponseWriter &response) = 0;
+ virtual void {{operationIdSnakeCase}}({{#allParams}}const {{#isModel}}{{modelNamespace}}::{{/isModel}}{{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}Pistache::Http::ResponseWriter &response) = 0;
{{/vendorExtensions.x-codegen-pistache-is-parsing-supported}}
{{^vendorExtensions.x-codegen-pistache-is-parsing-supported}}
virtual void {{operationIdSnakeCase}}(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response) = 0;
@@ -63,9 +72,7 @@ private:
};
-{{#apiNamespaceDeclarations}}
-}
-{{/apiNamespaceDeclarations}}
+} // namespace {{apiNamespace}}
#endif /* {{classname}}_H_ */
diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-header.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-header.mustache
index 18ff119ae208..bd20c1bdf5ab 100644
--- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-header.mustache
+++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-header.mustache
@@ -22,17 +22,16 @@
{{#imports}}{{{import}}}
{{/imports}}
-{{#apiNamespaceDeclarations}}
-namespace {{this}} {
-{{/apiNamespaceDeclarations}}
+namespace {{apiNamespace}}
+{
{{#hasModelImport}}
using namespace {{modelNamespace}};{{/hasModelImport}}
class {{classname}}Impl : public {{apiNamespace}}::{{classname}} {
public:
- {{classname}}Impl(std::shared_ptr);
- ~{{classname}}Impl() {}
+ explicit {{classname}}Impl(const std::shared_ptr& rtr);
+ ~{{classname}}Impl() override = default;
{{#operation}}
{{#vendorExtensions.x-codegen-pistache-is-parsing-supported}}
@@ -45,11 +44,9 @@ public:
};
-{{#apiNamespaceDeclarations}}
-}
-{{/apiNamespaceDeclarations}}
+} // namespace {{apiNamespace}}
{{/operations}}
-#endif
\ No newline at end of file
+#endif
diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache
index e5517bb487c1..2e25a8034b30 100644
--- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache
+++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache
@@ -10,9 +10,10 @@ namespace {{this}} {
{{#hasModelImport}}
using namespace {{modelNamespace}};{{/hasModelImport}}
-{{classname}}Impl::{{classname}}Impl(std::shared_ptr rtr)
+{{classname}}Impl::{{classname}}Impl(const std::shared_ptr& rtr)
: {{classname}}(rtr)
- { }
+{
+}
{{#operation}}
{{#vendorExtensions.x-codegen-pistache-is-parsing-supported}}
@@ -31,4 +32,4 @@ void {{classname}}Impl::{{operationIdSnakeCase}}(const Pistache::Rest::Request &
}
{{/apiNamespaceDeclarations}}
-{{/operations}}
\ No newline at end of file
+{{/operations}}
diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache
index 9225a5610c70..9814ba0cd626 100644
--- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache
+++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache
@@ -4,16 +4,18 @@
#include "{{classname}}.h"
#include "{{prefix}}Helpers.h"
-{{#apiNamespaceDeclarations}}
-namespace {{this}} {
-{{/apiNamespaceDeclarations}}
+namespace {{apiNamespace}}
+{
using namespace {{helpersNamespace}};
{{#hasModelImport}}
using namespace {{modelNamespace}};{{/hasModelImport}}
-{{classname}}::{{classname}}(std::shared_ptr rtr) {
- router = rtr;
+const std::string {{classname}}::base = "{{basePathWithoutHost}}";
+
+{{classname}}::{{classname}}(const std::shared_ptr& rtr)
+ : router(rtr)
+{
}
void {{classname}}::init() {
@@ -31,8 +33,26 @@ void {{classname}}::setupRoutes() {
router->addCustomHandler(Routes::bind(&{{classname}}::{{classnameSnakeLowerCase}}_default_handler, this));
}
+std::pair {{classname}}::handleParsingException(const std::exception& ex) const noexcept
+{
+ try {
+ throw ex;
+ } catch (nlohmann::detail::exception &e) {
+ return std::make_pair(Pistache::Http::Code::Bad_Request, e.what());
+ } catch ({{helpersNamespace}}::ValidationException &e) {
+ return std::make_pair(Pistache::Http::Code::Bad_Request, e.what());
+ }
+}
+
+std::pair {{classname}}::handleOperationException(const std::exception& ex) const noexcept
+{
+ return std::make_pair(Pistache::Http::Code::Internal_Server_Error, ex.what());
+}
+
{{#operation}}
void {{classname}}::{{operationIdSnakeCase}}_handler(const Pistache::Rest::Request &{{#hasParams}}request{{/hasParams}}, Pistache::Http::ResponseWriter response) {
+ try {
+
{{#vendorExtensions.x-codegen-pistache-is-parsing-supported}}
{{#hasPathParams}}
// Getting the path params
@@ -71,32 +91,40 @@ void {{classname}}::{{operationIdSnakeCase}}_handler(const Pistache::Rest::Reque
{{#hasBodyParam}}
{{#bodyParam}}
{{^isPrimitiveType}}
- nlohmann::json::parse(request.body()).get_to({{paramName}});
+ nlohmann::json::parse(request.body()).get_to({{paramName}});
+ {{paramName}}.validate();
{{/isPrimitiveType}}
{{#isPrimitiveType}}
- {{paramName}} = request.body();
+ {{paramName}} = request.body();
{{/isPrimitiveType}}
+ } catch (std::exception &e) {
+ const std::pair errorInfo = this->handleParsingException(e);
+ response.send(errorInfo.first, errorInfo.second);
+ return;
+ }
+
+ try {
{{/bodyParam}}
{{/hasBodyParam}}
- this->{{operationIdSnakeCase}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}response);
+ this->{{operationIdSnakeCase}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}response);
{{/vendorExtensions.x-codegen-pistache-is-parsing-supported}}
{{^vendorExtensions.x-codegen-pistache-is-parsing-supported}}
try {
this->{{operationIdSnakeCase}}(request, response);
{{/vendorExtensions.x-codegen-pistache-is-parsing-supported}}
- } catch (nlohmann::detail::exception &e) {
- //send a 400 error
- response.send(Pistache::Http::Code::Bad_Request, e.what());
- return;
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast(e.code()), e.what());
return;
} catch (std::exception &e) {
- //send a 500 error
- response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
+ const std::pair errorInfo = this->handleOperationException(e);
+ response.send(errorInfo.first, errorInfo.second);
return;
}
+ } catch (std::exception &e) {
+ response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
+ }
+
}
{{/operation}}
@@ -104,8 +132,6 @@ void {{classname}}::{{classnameSnakeLowerCase}}_default_handler(const Pistache::
response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist");
}
-{{#apiNamespaceDeclarations}}
-}
-{{/apiNamespaceDeclarations}}
+} // namespace {{apiNamespace}}
{{/operations}}
diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/helpers-header.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/helpers-header.mustache
index c39cca04fe10..d3489fad4026 100644
--- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/helpers-header.mustache
+++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/helpers-header.mustache
@@ -14,16 +14,80 @@
#include
#include