Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #1168
Closed
Open
Issue created Oct 04, 2018 by Administrator@rootContributor

[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 ... ?

Assignee
Assign to
Time tracking