swagger-api / swagger-api/swagger-codegen
[QT5][QT5CPP] Bug in methods writing model data into JSON
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
The generated model classes contain methods to read data from and write data back to JSON. I'm expecting that I'd receive the same JSON object when:
auto model = new SWGMyModel();
auto jsonOutput = model->fromJson()->asJson();
Instead on the output most of the fields are not defined anymore.
The reason for that is that the m_*_isSet member variables do not get updated when loading data from a JSON string / object
Swagger-codegen version
Version 2.4.14
Swagger declaration file content or url
swagger: "2.0"
info:
version: "1.0.0"
title: "Bug in qt5cpp"
schemes:
- "http"
paths:
/echo:
post:
parameters:
- name: "body"
in: "body"
schema:
$ref: "#/definitions/Example"
responses:
"200":
description: "successful operation"
definitions:
Example:
type: "object"
properties:
int64_type:
type: "integer"
format: "int64"
int32_type:
type: "integer"
format: "int32"
boolean_type:
type: "boolean"
float_type:
type: "number"
format: "float"
double_type:
type: "number"
format: "double"
string_type:
type: "string"
enum_type:
type: "string"
enum:
- "a"
- "b"
object_type:
type: "object"
properties:
double_type:
type: "number"
format: "double"
string_type:
type: "string"
number_array_type:
type: "array"
items:
type: "string"
string_array_type:
type: "array"
items:
type: "string"
Command line used for generation
java -jar swagger-codegen-cli.jar generate -l qt5cpp -i swagger.json
Steps to reproduce
- generate code using provided interface description
- use these files to create a Qt project using the generated client
- run
qmake && make - check the output and compare to the JSON used as input
Related issues/PRs
Suggest a fix/enhancement
I don't know the purpose of m_*_isSet member variables. Either they are used to track if the user modified the model (like the use in the isSet() function suggests). Then the check for these members when writing to JSON can be removed.
Or the members are to check if the value is set at all (not undefined) then we could set the member to true if the corresponding field in the JSON document is present and add lines like the following in the fromJsonObject() method:
m_propertyName_isSet = pJson.contains("propertyName");
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the qt5cpp generator templates that produce model fromJsonObject() and asJson(), then compare how m_*_isSet is handled during deserialization and serialization. Reproduce the issue with the supplied Swagger declaration and generation command; it is done when fields present in the input JSON are preserved in the generated model's output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100