[C++] minor improvements (#5319)

* minor code format, make sure cpp samples updated

* add new files
This commit is contained in:
William Cheng 2020-02-14 17:58:15 +08:00 committed by GitHub
parent 3f490ea7ee
commit 118b5e7747
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
44 changed files with 101 additions and 71 deletions

View File

@ -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)

View File

@ -19,7 +19,6 @@ package org.openapitools.codegen.languages;
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,13 +301,13 @@ abstract public class AbstractCppCodegen extends DefaultCodegen implements Codeg
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);
}
}

View File

@ -4,11 +4,7 @@ import io.swagger.v3.oas.models.media.ArraySchema;
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 class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
systemIncludes.add("QDateTime");
systemIncludes.add("QByteArray");
}
@Override
public void processOpts() {
super.processOpts();
@ -154,7 +151,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
@Override
public String toModelImport(String name) {
if( name.isEmpty() ) {
if (name.isEmpty()) {
return null;
}
@ -162,7 +159,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
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,20 +314,20 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
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);
}
@ -338,32 +335,32 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
// 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,7 +387,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
boolean included = false;
String inclStr = toModelImport(type);
for (Map<String, String> importItem : imports) {
if(importItem.containsValue(inclStr)) {
if (importItem.containsValue(inclStr)) {
included = true;
break;
}

View File

@ -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 {

View File

@ -1 +1 @@
4.2.3-SNAPSHOT
4.3.0-SNAPSHOT

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -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.
*/

View File

@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.
# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md

View File

@ -0,0 +1 @@
4.3.0-SNAPSHOT

View File

@ -11,6 +11,7 @@
*/
#include <QDebug>
#include <QJsonParseError>
#include "OAIHelpers.h"
@ -230,6 +231,18 @@ fromStringValue(const QString &inStr, double &value){
return ok;
}
bool
fromStringValue(const QString &inStr, OAIObject &value)
{
QJsonParseError err;
QJsonDocument::fromJson(inStr.toUtf8(),&err);
if ( err.error == QJsonParseError::NoError ){
value.fromJson(inStr);
return true;
}
return false;
}
bool
fromStringValue(const QString &inStr, OAIEnum &value){
value.fromJson(inStr);