The base {{prefix}}Object should not be an abstract
- there are real situations in REST APIs where the body of a request
or response is an empty object rather than `null` or no body at all.
Some endpoints use POST or PUT to trigger actions rather than send
data. In such a case, an empty JSON object can be sent instead of an
empty body to satisfy JSON parsing. See an example:
"http"
"POST /logout"
"Content-Type: application/json"
Which sends: {}
Typed OpenAPI generators (Java, C#, or previous Qt5) usually generate
an Empty body object `{}` for such cases, even if no properties exist.
It avoids potential interpretation issues with `null` or “no body”
mapping to types.
Another reason is sometimes APIs may define a request as an object
for allowing it to be extended it in the future without breaking
clients.
Initially empty: `{}`. Later fields like
`"priority": "high"` or `"tags": []` can be added
(though this approach can sometimes have some security issues
I think, see links in comments of yaml file).
To continue supporting both approaches (even if the second one has
weak sides, still it exists and is being used), I suggest making all
pure virtual methods of {{prefix}}Object back just virtual.
Note:
Working on QString {{prefix}}Object::asJson() const, I noticed that
using `return QString(bytes);` leads to the warning:
'QString' is deprecated: Use fromUtf8, QStringLiteral, or
QLatin1StringView.
So I updated model-body.mustache, which uses a similar block.
Task-number: QTBUG-143176
Pick-to: 6.11
Change-Id: I8bf073750fdc12e54dd9bbb8346e2529bac114d8
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>