Skip to content
Permalink
Browse files

[C++] minor improvements (#5319)

* minor code format, make sure cpp samples updated

* add new files
  • Loading branch information
wing328 committed Feb 14, 2020
1 parent 3f490ea commit 118b5e77473c80eb0e3cbea1413ecf27075c19e3
Showing with 101 additions and 71 deletions.
  1. +2 −0 bin/utils/ensure-up-to-date
  2. +4 −5 modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCppCodegen.java
  3. +19 −22 ...les/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5AbstractCodegen.java
  4. +1 −6 ...pi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5QHttpEngineServerCodegen.java
  5. +2 −2 ...s/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestSdkClientCodegen.java
  6. +1 −1 samples/client/petstore/cpp-restsdk/client/.openapi-generator/VERSION
  7. +1 −1 samples/client/petstore/cpp-restsdk/client/ApiClient.cpp
  8. +1 −1 samples/client/petstore/cpp-restsdk/client/ApiClient.h
  9. +1 −1 samples/client/petstore/cpp-restsdk/client/ApiConfiguration.cpp
  10. +1 −1 samples/client/petstore/cpp-restsdk/client/ApiConfiguration.h
  11. +1 −1 samples/client/petstore/cpp-restsdk/client/ApiException.cpp
  12. +1 −1 samples/client/petstore/cpp-restsdk/client/ApiException.h
  13. +1 −1 samples/client/petstore/cpp-restsdk/client/HttpContent.cpp
  14. +1 −1 samples/client/petstore/cpp-restsdk/client/HttpContent.h
  15. +1 −1 samples/client/petstore/cpp-restsdk/client/IHttpBody.h
  16. +1 −1 samples/client/petstore/cpp-restsdk/client/JsonBody.cpp
  17. +1 −1 samples/client/petstore/cpp-restsdk/client/JsonBody.h
  18. +1 −1 samples/client/petstore/cpp-restsdk/client/ModelBase.cpp
  19. +1 −1 samples/client/petstore/cpp-restsdk/client/ModelBase.h
  20. +1 −1 samples/client/petstore/cpp-restsdk/client/MultipartFormData.cpp
  21. +1 −1 samples/client/petstore/cpp-restsdk/client/MultipartFormData.h
  22. +1 −1 samples/client/petstore/cpp-restsdk/client/Object.cpp
  23. +1 −1 samples/client/petstore/cpp-restsdk/client/Object.h
  24. +1 −1 samples/client/petstore/cpp-restsdk/client/api/PetApi.cpp
  25. +1 −1 samples/client/petstore/cpp-restsdk/client/api/PetApi.h
  26. +1 −1 samples/client/petstore/cpp-restsdk/client/api/StoreApi.cpp
  27. +1 −1 samples/client/petstore/cpp-restsdk/client/api/StoreApi.h
  28. +1 −1 samples/client/petstore/cpp-restsdk/client/api/UserApi.cpp
  29. +1 −1 samples/client/petstore/cpp-restsdk/client/api/UserApi.h
  30. +1 −1 samples/client/petstore/cpp-restsdk/client/model/ApiResponse.cpp
  31. +1 −1 samples/client/petstore/cpp-restsdk/client/model/ApiResponse.h
  32. +1 −1 samples/client/petstore/cpp-restsdk/client/model/Category.cpp
  33. +1 −1 samples/client/petstore/cpp-restsdk/client/model/Category.h
  34. +1 −1 samples/client/petstore/cpp-restsdk/client/model/Order.cpp
  35. +1 −1 samples/client/petstore/cpp-restsdk/client/model/Order.h
  36. +1 −1 samples/client/petstore/cpp-restsdk/client/model/Pet.cpp
  37. +1 −1 samples/client/petstore/cpp-restsdk/client/model/Pet.h
  38. +1 −1 samples/client/petstore/cpp-restsdk/client/model/Tag.cpp
  39. +1 −1 samples/client/petstore/cpp-restsdk/client/model/Tag.h
  40. +1 −1 samples/client/petstore/cpp-restsdk/client/model/User.cpp
  41. +1 −1 samples/client/petstore/cpp-restsdk/client/model/User.h
  42. +23 −0 samples/server/petstore/cpp-qt5-qhttpengine-server/.openapi-generator-ignore
  43. +1 −0 samples/server/petstore/cpp-qt5-qhttpengine-server/.openapi-generator/VERSION
  44. +13 −0 samples/server/petstore/cpp-qt5-qhttpengine-server/server/src/models/OAIHelpers.cpp
@@ -82,6 +82,8 @@ declare -a samples=(
"${root}/bin/java-play-framework-petstore-server-all.sh"
#"${root}/bin/elm-petstore-all.sh"
"${root}/bin/typescript-redux-query-petstore-with-npm-version.sh"
"${root}/bin/cpp-restsdk-petstore.sh"
"${root}/bin/cpp-qt5-qhttpengine-server-petstore.sh"
)

# Some special case generators may expect to be run as a stanalone process (e.g. modifying classpath)
@@ -19,7 +19,6 @@

import com.google.common.collect.ImmutableMap.Builder;
import com.samskivert.mustache.Mustache.Lambda;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.media.Schema;
import org.apache.commons.io.FilenameUtils;
@@ -302,17 +301,17 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
String host = url.getHost();
String scheme = url.getProtocol();

if(!port.isEmpty()) {
if (!port.isEmpty()) {
this.additionalProperties.put("serverPort", port);
}
if(!host.isEmpty()) {
if (!host.isEmpty()) {
this.additionalProperties.put("serverHost", host);
}
if(!scheme.isEmpty()) {
if (!scheme.isEmpty()) {
this.additionalProperties.put("scheme", scheme);
}
}

@Override
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
return postProcessModelsEnum(objs);
@@ -4,11 +4,7 @@
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.parser.util.SchemaTypeUtil;
import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.CodegenConfig;
import org.openapitools.codegen.CodegenConstants;
import org.openapitools.codegen.CodegenModel;
import org.openapitools.codegen.CodegenOperation;
import org.openapitools.codegen.CodegenParameter;
import org.openapitools.codegen.*;
import org.openapitools.codegen.meta.features.*;
import org.openapitools.codegen.utils.ModelUtils;
import org.slf4j.Logger;
@@ -130,6 +126,7 @@ public CppQt5AbstractCodegen() {
systemIncludes.add("QDateTime");
systemIncludes.add("QByteArray");
}

@Override
public void processOpts() {
super.processOpts();
@@ -154,15 +151,15 @@ public void processOpts() {

@Override
public String toModelImport(String name) {
if( name.isEmpty() ) {
if (name.isEmpty()) {
return null;
}

if (namespaces.containsKey(name)) {
return "using " + namespaces.get(name) + ";";
} else if (systemIncludes.contains(name)) {
return "#include <" + name + ">";
} else if(importMapping.containsKey(name)){
} else if (importMapping.containsKey(name)) {
return importMapping.get(name);
}

@@ -317,53 +314,53 @@ protected boolean needToImport(String type) {
List<CodegenOperation> operations = (List<CodegenOperation>) objectMap.get("operation");

List<Map<String, String>> imports = (List<Map<String, String>>) objs.get("imports");
Map<String, CodegenModel> codegenModels = new HashMap<String, CodegenModel> ();
Map<String, CodegenModel> codegenModels = new HashMap<String, CodegenModel>();

// TODO: 5.0: Remove the camelCased vendorExtension below and ensure templates use the newer property naming.
once(LOGGER).warn("4.3.0 has deprecated the use of vendor extensions which don't follow lower-kebab casing standards with x- prefix.");

for(Object moObj : allModels) {
for (Object moObj : allModels) {
CodegenModel mo = ((Map<String, CodegenModel>) moObj).get("model");
if(mo.isEnum) {
if (mo.isEnum) {
codegenModels.put(mo.classname, mo);
}
}
for (CodegenOperation operation : operations) {
if(operation.returnType != null) {
if(codegenModels.containsKey(operation.returnType)){
if (operation.returnType != null) {
if (codegenModels.containsKey(operation.returnType)) {
operation.vendorExtensions.put("returnsEnum", true); // TODO: 5.0 Remove
operation.vendorExtensions.put("x-returns-enum", true);
}
}
// Check all return parameter baseType if there is a necessity to include, include it if not
// already done
if (operation.returnBaseType != null && needToImport(operation.returnBaseType)) {
if(!isIncluded(operation.returnBaseType, imports)) {
if (!isIncluded(operation.returnBaseType, imports)) {
imports.add(createMapping("import", operation.returnBaseType));
}
}
List<CodegenParameter> params = new ArrayList<CodegenParameter>();
if (operation.allParams != null)params.addAll(operation.allParams);
if (operation.allParams != null) params.addAll(operation.allParams);

// Check all parameter baseType if there is a necessity to include, include it if not
// already done
for(CodegenParameter param : params) {
if(param.isPrimitiveType && needToImport(param.baseType)) {
if(!isIncluded(param.baseType, imports)) {
for (CodegenParameter param : params) {
if (param.isPrimitiveType && needToImport(param.baseType)) {
if (!isIncluded(param.baseType, imports)) {
imports.add(createMapping("import", param.baseType));
}
}
}
if (operation.pathParams != null) {
// We use QString to pass path params, add it to include
if(!isIncluded("QString", imports)) {
if (!isIncluded("QString", imports)) {
imports.add(createMapping("import", "QString"));
}
}
}
if(isIncluded("QMap", imports)) {
if (isIncluded("QMap", imports)) {
// Maps uses QString as key
if(!isIncluded("QString", imports)) {
if (!isIncluded("QString", imports)) {
imports.add(createMapping("import", "QString"));
}
}
@@ -390,14 +387,14 @@ private boolean isIncluded(String type, List<Map<String, String>> imports) {
boolean included = false;
String inclStr = toModelImport(type);
for (Map<String, String> importItem : imports) {
if(importItem.containsValue(inclStr)) {
if (importItem.containsValue(inclStr)) {
included = true;
break;
}
}
return included;
}

public void setContentCompressionEnabled(boolean flag) {
this.isContentCompressionEnabled = flag;
}
@@ -17,19 +17,14 @@

package org.openapitools.codegen.languages;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.servers.Server;

import org.openapitools.codegen.CodegenConfig;
import org.openapitools.codegen.CodegenType;
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.meta.features.DocumentationFeature;
import org.openapitools.codegen.utils.URLPathUtils;

import java.io.File;
import java.net.URL;

import static org.openapitools.codegen.utils.StringUtils.*;
import static org.openapitools.codegen.utils.StringUtils.camelize;

public class CppQt5QHttpEngineServerCodegen extends CppQt5AbstractCodegen implements CodegenConfig {

@@ -265,7 +265,7 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
if (response != null) {
CodegenProperty cm = fromProperty("response", response);
op.vendorExtensions.put("x-codegen-response", cm);
if ("std::shared_ptr<HttpContent>".equals(cm.dataType)) {
if ("std::shared_ptr<HttpContent>".equals(cm.dataType)) {
op.vendorExtensions.put("x-codegen-response-ishttpcontent", true);
}
}
@@ -385,7 +385,7 @@ public String toDefaultValue(Schema p) {
} else if (ModelUtils.isFreeFormObject(p)) {
return "new Object()";
}

return "nullptr";
}

@@ -1 +1 @@
4.2.3-SNAPSHOT
4.3.0-SNAPSHOT
@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 4.2.3-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 4.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 4.2.3-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 4.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 4.2.3-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 4.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 4.2.3-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 4.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 4.2.3-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 4.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 4.2.3-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 4.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 4.2.3-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 4.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 4.2.3-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 4.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 4.2.3-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 4.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 4.2.3-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 4.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 4.2.3-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 4.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 4.2.3-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 4.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 4.2.3-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 4.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 4.2.3-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 4.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 4.2.3-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 4.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 4.2.3-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 4.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 4.2.3-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 4.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 4.2.3-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 4.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 4.2.3-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 4.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 4.2.3-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 4.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
@@ -4,7 +4,7 @@
*
* The version of the OpenAPI document: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 4.2.3-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 4.3.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

0 comments on commit 118b5e7

Please sign in to comment.
You can’t perform that action at this time.