-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Description
Description
I am generating both client and server side code using a same API specification file (see sample file below).
My API spec defines a component of type 'object' that contains a single 'properties' of type: string, format: byte.
When I generate the cpp-qt5-qhttpengine-server code, the model generate contains a private member of type 'QByteArray', and the setter and getter method's parameters is called by reference (const QByteArray &). All good, code compiles.
When I generate the cpp-qt5 client code, the corresponding model generates a private member of type 'QByteArray*' (pointer), and the setter and getter method's parameter is called by address and reference (?) (const QByteArray* &). No good; this code does not compile.
I then compared the mustache files for the two generators. The 'model-body.mustache' and the 'model-header.mustache' in the two generator's template resources are the same.
I then looked into those two mustache files. It appears that the {{datatype}} variable is related to the problem. I think the value of the {{datatype}} variable gets instantiated differently by the two projects, resulting in different code generation.
If I hand-edit the cpp-qt5 generated code and remove the '*', then I can get the code to compile. Note: I also have to fix-up a reference to the m_blob_isSet private data member in the ::asJsonObject() and ::isSet() methods.
Version
I am using VERSION 3.3.4. I downloaded the jar file per instructions on your GitHub page.
The mustache files I am using have been downloaded from your GitHub page.
OpenAPI declaration file content or url
openapi: "3.0.0"
info:
version: 1.0.0
title: Check ByteArray
servers:
-
url: http://localhost:8080
paths:
CheckByteArray:
get:
summary: Check Byte Array generation
operationId: list
tags:
- Check
responses:
'200':
description: Every things gonna be alright
content:
application/json:
schema:
$ref: "#/components/schemas/Content"
components:
schemas:
Bytes:
format: byte
type: stringContent:
type: object
properties:
type:
$ref: '#/components/schemas/Bytes'
Command line used for generation
For generating the server:
java -jar ${SWCG_JAR}/swagger-codegen.jar generate --enable-post-process-file --input-spec $1 --generator-name cpp-qt5-qhttpengine-server --template-dir MustacheFiles/ForQHTTPEngine --output $2
For generating the client:
java -jar ${SWCG_JAR}/swagger-codegen.jar generate --enable-post-process-file --input-spec $1 --generator-name cpp-qt5 --template-dir MustacheFiles/ForQtClient --output $2
Steps to reproduce
-
Create the .yaml file from above.
-
Generate the code per the two different command line spec above.
-
Compare the generate code. For example:
From the server-side file 'OAIContent.h':
<---- cut ----->
QByteArray getType() const;
void setType(const QByteArray &type);virtual bool isSet() const override; virtual bool isValid() const override; private: QByteArray type;
<----- cut ---->
And from the client-side file 'OAIContent.h':
<----- cut ---->
QByteArray* getType() const;
void setType(const QByteArray* &type);
virtual bool isSet() const override;
virtual bool isValid() const override;
private:
QByteArray* type;
<----- cut ---->
Related issues/PRs
I think this issue: #407 may be closely related.
Suggest a fix
I think this has to do with the instantiation of the {{datatype}} value in the mustache code.