[C++][Pistache-server] #include "json.hpp" is needed - Compilation failed
Created by: CyrilleBenard
Description
With a simple input YAML file, the generator omits to include the json.hpp file.
Usually, the generator seems to satisfy this include inside the ModelBase.h but in this case, there is no model that are generated, so ModelBase.h is not included inside the api file, and consequently the needed json.hpp is not included.
The compilation error looks like :
g++ -c -I./api -I./model -I./impl -Wall -g -std=c++11 -o obj/api/Stair1Api.o api/Stair1Api.cpp
api/Stair1Api.cpp: In member function ‘void com::bcom::amf::microservice::server::ms1::api::Stair1Api::check_generation_handler(const Pistache::Rest::Request&, Pistache::Http::ResponseWriter)’:
api/Stair1Api.cpp:64:7: error: ‘nlohmann’ has not been declared
nlohmann::json request_body = nlohmann::json::parse(request.body());
^
api/Stair1Api.cpp:67:14: error: ‘request_body’ was not declared in this scope
body = request_body;
^
openapi-generator version
Current master : 3.3.1-SNAPSHOT
OpenAPI declaration file content or url
openapi: 3.0.0
info:
version: 1.0.0
title: Check generation. json header file include is needed
description: Internal ref filename is check_json_include.yaml
servers:
- url: http://localhost:8080
paths:
/stair1:
post:
summary: blabla
operationId: check_generation
tags:
- Stair1
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Content'
responses:
'200':
description: Expected response to a valid request
content:
application/json:
schema:
type: string
default:
description: Unexpected error
components:
schemas:
Content:
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/Stair1Api.o api/Stair1Api.cpp
Steps to reproduce
Generate & compile
Related issues/PRs
N/A
Suggest a fix/enhancement
Add the #include "json.hpp" to the needed source(s) file(s) or Always generates at least one model that will be included inside the api sources files (?) or Always add #include "ModelBase.h" to the api files (not sure this is the best fix >_< ) or ... ?