OpenAPITools / OpenAPITools/openapi-generator
[C++][Pistache-server] Object in a query generates code that do not compile
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
If a query owns an object in a parameter, the generator makes code that do not compile. It seems that the corresponding method is not generated.
The compilation error looks like :
g++ -c -I./api -I./model -I./impl -Wall -g -std=c++11 -o obj/api/CheckApi.o api/CheckApi.cpp
api/CheckApi.cpp: In member function ‘void com::bcom::amf::microservice::server::ms1::api::CheckApi::list_handler(const Pistache::Rest::Request&, Pistache::Http::ResponseWriter)’:
api/CheckApi.cpp:51:55: error: no matching function for call to ‘fromStringValue(std::__cxx11::basic_string<char>, com::bcom::amf::microservice::server::ms1::model::PresenceState&)’
if(fromStringValue(infoClassQuery.get(), value)){
^
In file included from api/CheckApi.cpp:14:0:
./model/Helpers.h:39:10: note: candidate: bool org::openapitools::server::helpers::fromStringValue(const string&, std::__cxx11::string&)
bool fromStringValue(const std::string &inStr, std::string &value);
... etc
openapi-generator version
Current master : 3.3.2-SNAPSHOT
OpenAPI declaration file content or url
openapi: "3.0.0"
info:
version: 1.0.0
title: Check generation of a structured object in the query (Pistache)
description: Internal ref filename is check_object_in_query.yaml
servers:
- url: http://localhost:8080
paths:
/Check:
get:
summary: Check object in the query
operationId: list
tags:
- Check
parameters:
- name: info-class
in: query
description: UE Context Information Class
schema:
$ref: '#/components/schemas/PresenceState'
responses:
'200':
description: Everythings gonna be alright
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
content:
application/json:
schema:
type: string
default:
description: unexpected error
content:
application/json:
schema:
type: string
components:
schemas:
PresenceState:
type: object
properties:
prop1:
type: string
Command line used for generation
Generate :
openapi-generator-cli.sh generate -i ./openapi.yaml -g cpp-pistache-server -c ./config.json -o .
Compile :
g++ -c -I./api -I./model -I./impl -Wall -g -std=c++11 -o obj/api/CheckApi.o api/CheckApi.cpp
Steps to reproduce
Generate & compile
Related issues/PRs
N/A
Suggest a fix/enhancement
Each property of the query object should be considered separately, one by one, and for each of them, call the fromStringValue method to assign the corresponding member of the instantiated model.
Or
The model should implement its own 'fromStringValue" method that will assign all the values of its members from the query string.
Second suggestion is probably much more elegant. I don't know how it is solved in others languages but I trust in @etherealjoy or @stkrwork to make the best choice 👓
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 check_object_in_query.yaml fixture and the generated api/CheckApi.cpp and model/Helpers.h shown in the report. Run the openapi-generator-cli.sh generation command, then compile CheckApi.cpp to reproduce the failure. Done means the generated C++ Pistache server compiles and the object-valued query parameter is handled without the reported fromStringValue mismatch.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, openapi
- Domain
- backend-api-design, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100