From 409015461c50546f3db01fa059ece1be0926f2a2 Mon Sep 17 00:00:00 2001 From: wing328 Date: Thu, 5 Apr 2018 15:56:30 +0800 Subject: [PATCH] fix file type in qt5cpp --- .../java/org/openapitools/codegen/DefaultCodegen.java | 10 +++++++--- .../codegen/languages/CppQt5ClientCodegen.java | 4 ++-- samples/client/petstore/qt5cpp/client/SWGBody_1.cpp | 8 ++++---- samples/client/petstore/qt5cpp/client/SWGBody_1.h | 7 ++++--- samples/client/petstore/qt5cpp/client/SWGPetApi.cpp | 4 ++-- samples/client/petstore/qt5cpp/client/SWGPetApi.h | 3 ++- 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 296bce15c313..fafe588a9030 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -1665,6 +1665,7 @@ public CodegenProperty fromProperty(String name, Schema p) { } if (p instanceof ByteArraySchema || SchemaTypeUtil.BYTE_FORMAT.equals(p.getFormat())) { property.isByteArray = true; + property.isFile = true; // in OAS3.0 "file" is 'byte' (format) } if (p instanceof NumberSchema || SchemaTypeUtil.NUMBER_TYPE.equals(p.getType())) { @@ -2313,6 +2314,7 @@ public CodegenResponse fromResponse(String responseCode, ApiResponse response) { r.isUuid = true; } else if (Boolean.TRUE.equals(cp.isByteArray)) { r.isByteArray = true; + r.isFile = true; // in OAS3.0 "file" is 'byte' (format) } else if (Boolean.TRUE.equals(cp.isString)) { r.isString = true; } else if (Boolean.TRUE.equals(cp.isBoolean)) { @@ -3552,6 +3554,11 @@ public void setParameterBooleanFlagWithCodegenProperty(CodegenParameter paramete } else if (Boolean.TRUE.equals(property.isByteArray)) { parameter.isByteArray = true; parameter.isPrimitiveType = true; + parameter.isFile = true; // in OAS3.0 "file" is 'byte' (format) + } else if (Boolean.TRUE.equals(property.isBinary)) { + parameter.isByteArray = true; + parameter.isPrimitiveType = true; + parameter.isFile = true; // in OAS3.0 "file" is 'byte' (format) } else if (Boolean.TRUE.equals(property.isString)) { parameter.isString = true; parameter.isPrimitiveType = true; @@ -3573,9 +3580,6 @@ public void setParameterBooleanFlagWithCodegenProperty(CodegenParameter paramete } else if (Boolean.TRUE.equals(property.isNumber)) { parameter.isNumber = true; parameter.isPrimitiveType = true; - } else if (Boolean.TRUE.equals(property.isBinary)) { - parameter.isByteArray = true; - parameter.isPrimitiveType = true; } else if (Boolean.TRUE.equals(property.isFile)) { parameter.isFile = true; } else if (Boolean.TRUE.equals(property.isDate)) { diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5ClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5ClientCodegen.java index f2dbc94f7496..b7116b04b2f0 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5ClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5ClientCodegen.java @@ -127,8 +127,8 @@ public CppQt5ClientCodegen() { typeMapping.put("file", "SWGHttpRequestInputFileElement"); typeMapping.put("object", PREFIX + "Object"); //TODO binary should be mapped to byte array - // mapped to String as a workaround - typeMapping.put("binary", "QString"); + // mapped as "file" type for OAS 3.0 + typeMapping.put("binary", "SWGHttpRequestInputFileElement"); typeMapping.put("ByteArray", "QByteArray"); // UUID support - possible enhancement : use QUuid instead of QString. // beware though that Serialisation/deserialisation of QUuid does not diff --git a/samples/client/petstore/qt5cpp/client/SWGBody_1.cpp b/samples/client/petstore/qt5cpp/client/SWGBody_1.cpp index 6f169af90bf8..41125130a236 100644 --- a/samples/client/petstore/qt5cpp/client/SWGBody_1.cpp +++ b/samples/client/petstore/qt5cpp/client/SWGBody_1.cpp @@ -66,7 +66,7 @@ void SWGBody_1::fromJsonObject(QJsonObject pJson) { ::Swagger::setValue(&additional_metadata, pJson["additionalMetadata"], "QString", "QString"); - ::Swagger::setValue(&file, pJson["file"], "QString", "QString"); + ::Swagger::setValue(&file, pJson["file"], "SWGHttpRequestInputFileElement", "SWGHttpRequestInputFileElement"); } @@ -86,7 +86,7 @@ SWGBody_1::asJsonObject() { toJsonValue(QString("additionalMetadata"), additional_metadata, obj, QString("QString")); } if((file != nullptr) && (file->isSet())){ - toJsonValue(QString("file"), file, obj, QString("QString")); + toJsonValue(QString("file"), file, obj, QString("SWGHttpRequestInputFileElement")); } return obj; @@ -102,12 +102,12 @@ SWGBody_1::setAdditionalMetadata(QString* additional_metadata) { this->m_additional_metadata_isSet = true; } -QString* +SWGHttpRequestInputFileElement* SWGBody_1::getFile() { return file; } void -SWGBody_1::setFile(QString* file) { +SWGBody_1::setFile(SWGHttpRequestInputFileElement* file) { this->file = file; this->m_file_isSet = true; } diff --git a/samples/client/petstore/qt5cpp/client/SWGBody_1.h b/samples/client/petstore/qt5cpp/client/SWGBody_1.h index dda618666f73..fbb41ddc4ade 100644 --- a/samples/client/petstore/qt5cpp/client/SWGBody_1.h +++ b/samples/client/petstore/qt5cpp/client/SWGBody_1.h @@ -22,6 +22,7 @@ #include +#include "SWGHttpRequest.h" #include #include "SWGObject.h" @@ -44,8 +45,8 @@ class SWGBody_1: public SWGObject { QString* getAdditionalMetadata(); void setAdditionalMetadata(QString* additional_metadata); - QString* getFile(); - void setFile(QString* file); + SWGHttpRequestInputFileElement* getFile(); + void setFile(SWGHttpRequestInputFileElement* file); virtual bool isSet() override; @@ -54,7 +55,7 @@ class SWGBody_1: public SWGObject { QString* additional_metadata; bool m_additional_metadata_isSet; - QString* file; + SWGHttpRequestInputFileElement* file; bool m_file_isSet; }; diff --git a/samples/client/petstore/qt5cpp/client/SWGPetApi.cpp b/samples/client/petstore/qt5cpp/client/SWGPetApi.cpp index 4a1f37e99ddf..fbb410c4ff2c 100644 --- a/samples/client/petstore/qt5cpp/client/SWGPetApi.cpp +++ b/samples/client/petstore/qt5cpp/client/SWGPetApi.cpp @@ -514,7 +514,7 @@ SWGPetApi::updatePetWithFormCallback(SWGHttpRequestWorker * worker) { } void -SWGPetApi::uploadFile(qint64 pet_id, QString* additional_metadata, QString* file) { +SWGPetApi::uploadFile(qint64 pet_id, QString* additional_metadata, SWGHttpRequestInputFileElement* file) { QString fullPath; fullPath.append(this->host).append(this->basePath).append("/pet/{petId}/uploadImage"); @@ -529,7 +529,7 @@ SWGPetApi::uploadFile(qint64 pet_id, QString* additional_metadata, QString* file input.add_var("additionalMetadata", *additional_metadata); } if (file != nullptr) { - input.add_var("file", *file); + input.add_file("file", (*file).local_filename, (*file).request_filename, (*file).mime_type); } diff --git a/samples/client/petstore/qt5cpp/client/SWGPetApi.h b/samples/client/petstore/qt5cpp/client/SWGPetApi.h index a718ad014c72..c1da383fa19e 100644 --- a/samples/client/petstore/qt5cpp/client/SWGPetApi.h +++ b/samples/client/petstore/qt5cpp/client/SWGPetApi.h @@ -17,6 +17,7 @@ #include #include "SWGApiResponse.h" +#include "SWGHttpRequest.h" #include "SWGPet.h" #include @@ -42,7 +43,7 @@ class SWGPetApi: public QObject { void getPetById(qint64 pet_id); void updatePet(SWGPet& pet); void updatePetWithForm(qint64 pet_id, QString* name, QString* status); - void uploadFile(qint64 pet_id, QString* additional_metadata, QString* file); + void uploadFile(qint64 pet_id, QString* additional_metadata, SWGHttpRequestInputFileElement* file); private: void addPetCallback (SWGHttpRequestWorker * worker);