Skip to content

Commit

Permalink
fix file type in qt5cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 committed Apr 5, 2018
1 parent a4bcb3b commit 4090154
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
Expand All @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions samples/client/petstore/qt5cpp/client/SWGBody_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

}

Expand All @@ -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;
Expand All @@ -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;
}
Expand Down
7 changes: 4 additions & 3 deletions samples/client/petstore/qt5cpp/client/SWGBody_1.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <QJsonObject>


#include "SWGHttpRequest.h"
#include <QString>

#include "SWGObject.h"
Expand All @@ -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;
Expand All @@ -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;

};
Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/qt5cpp/client/SWGPetApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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);
}


Expand Down
3 changes: 2 additions & 1 deletion samples/client/petstore/qt5cpp/client/SWGPetApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <QString>
#include "SWGApiResponse.h"
#include "SWGHttpRequest.h"
#include "SWGPet.h"

#include <QObject>
Expand All @@ -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);
Expand Down

0 comments on commit 4090154

Please sign in to comment.