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
  • #258
Closed
Open
Issue created Jun 08, 2018 by Administrator@rootContributor

[pistache-server](C++ stub) - POST not handled correctly - compile failed

Created by: CyrilleBenard

Description

I'm still trying to use the openAPI v3 Tutorial and I notice the openapi-generator tool seems to generate a wrong C++ code when handling a POST.

The compile command line and its stdout is :

g++ -c  -I./api -I./model -I./impl -Wall -g -std=c++11 -o obj/api/DefaultApi.o api/DefaultApi.cpp
api/DefaultApi.cpp: In member function ‘void com::bcom::amf::microservice::server::ms1::api::DefaultApi::artists_post_handler(const Pistache::Rest::Request&, Pistache::Http::ResponseWriter)’:
api/DefaultApi.cpp:63:40: error: no matching function for call to ‘com::bcom::amf::microservice::server::ms1::api::DefaultApi::artists_post(com::bcom::amf::microservice::server::ms1::model::Body&, Pistache::Http::ResponseWriter&)’
       this->artists_post(body, response);
                                        ^
In file included from api/DefaultApi.cpp:13:0:
api/DefaultApi.h:67:18: note: candidate: virtual void com::bcom::amf::microservice::server::ms1::api::DefaultApi::artists_post(const std::shared_ptr<com::bcom::amf::microservice::server::ms1::model::Body>&, Pistache::Http::ResponseWriter&)
     virtual void artists_post(const std::shared_ptr<Body> &body, Pistache::Http::ResponseWriter &respons
                  ^
api/DefaultApi.h:67:18: note:   no known conversion for argument 1 from ‘com::bcom::amf::microservice::server::ms1::model::Body’ to ‘const std::shared_ptr<com::bcom::amf::microservice::server::ms1::model::Body>&’

Indeed, after having a look into the two generated files DefaultApi.h and DefaultApi.cpp I can notice that one method is called passing wrong arguments. See below.

The DefaultApi.cpp describes this ( see the line ==> this->artists_post(body, response); )

void DefaultApi::artists_post_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {

    // Getting the body param
    Body body;
    
    try {
      nlohmann::json request_body = nlohmann::json::parse(request.body());
      body.fromJson(request_body);
      this->artists_post(body, response);
    } catch (std::runtime_error & e) {
      //send a 400 error
      response.send(Pistache::Http::Code::Bad_Request, e.what());
      return;
    }
}

whereas the DefaultApi.h describes the prototype :

virtual void artists_post(const std::shared_ptr<Body> &body, Pistache::Http::ResponseWriter &response) = 0;

In other words, the method artists_post is called with the first argument as a Body type, whereas it should be called with a shared_ptr<Body> type. Or the opposite, I mean, may be the method call is correct and the prototype should be modified.

NOTE: The second solution is used by the swagger-codegen tool

openapi-generator version

v3.0.0

OpenAPI declaration file content or url

Based on the published openAPI V3 tutorial, I extract the short lines that generate the wrong behavior

openapi: 3.0.0
info:
  version: 1.0.0
  title: Simple API
  description: A simple API to illustrate OpenAPI concepts

servers:
  - url: https://example.io/v1

components:
  securitySchemes:
    BasicAuth:
      type: http
      scheme: basic
security:
  - BasicAuth: []

paths:
  /artists:
    post:
      description: Lets a user post a new artist
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object 
              required:
                - username
              properties:
                artist_name:
                  type: string
                artist_genre:
                  type: string
                albums_recorded:
                  type: integer
                username:
                  type: string

      responses:
        '200':
          description: Successfully created a new artist

        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                type: object
                properties:   
                  message:
                    type: string
Command line used for generation

openapi-generator-cli.sh generate -i ../../api-ms1/openapi.yaml -g cpp-pistache-server -c ./config.json -o .

Steps to reproduce

config.json content is :

{
    "modelPackage"   : "com.bcom.amf.microservice.server.ms1.model",
    "apiPackage"     : "com.bcom.amf.microservice.server.ms1.api"
}

Call the openapi-generator-cli as shown previously and then compile the code, for example :

g++ -c  -I./api -I./model -I./impl -Wall -g -std=c++11 -o obj/api/DefaultApi.o api/DefaultApi.cpp
Related issues/PRs

n/a

Suggest a fix/enhancement

Described above

Assignee
Assign to
Time tracking