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

[C++][Pistache-server] Query parameter Type is not well handled (if not string)

Created by: CyrilleBenard

Description

When the OpenApi file describes a parameter inside the query, the generator produces the corresponding code with a wrong type handled (if the current type is not string, for example integer).

The generated handler for the query looks like :

void Stair1Api::check_query_param_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {

    // **** limit is a Optional<std::string> ****
    auto limit = request.query().get("limit");
    
    try {
      // **** API method is called but the first param should be  Optional<int32_t> ****
      this->check_query_param(limit, response);

    } catch (std::runtime_error & e) {
      //send a 400 error
      response.send(Pistache::Http::Code::Bad_Request, e.what());
      return;
    }
}

The generated check_query_param method prototype looks like :

virtual void check_query_param(const Pistache::Optional<int32_t> &limit, Pistache::Http::ResponseWriter &response) = 0;

But the handler described above call this method with a wrong argument (string instead of int32_t)

The 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_query_param_handler(const Pistache::Rest::Request&, Pistache::Http::ResponseWriter)’:
api/Stair1Api.cpp:61:46: error: no matching function for call to ‘com::bcom::amf::microservice::server::ms1::api::Stair1Api::check_query_param(Pistache::Optional<std::__cxx11::basic_string<char> >&, Pistache::Http::ResponseWriter&)’
       this->check_query_param(limit, response);
                                              ^
In file included from api/Stair1Api.cpp:13:0:
api/Stair1Api.h:68:18: note: candidate: virtual void com::bcom::amf::microservice::server::ms1::api::Stair1Api::check_query_param(const Pistache::Optional<int>&, Pistache::Http::ResponseWriter&)
     virtual void check_query_param(const Pistache::Optional<int32_t> &limit, Pistache::Http::ResponseWr
                  ^
api/Stair1Api.h:68:18: note:   no known conversion for argument 1 from ‘Pistache::Optional<std::__cxx11::basic_string<char> >’ to ‘const Pistache::Optional<int>&’
../rules.mk:55: recipe for target 'obj/api/Stair1Api.o' failed
openapi-generator version

Current master : 3.2.1-SNAPSHOT

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  version: 1.0.0
  title: Check query parameter
  description: A simple API to illustrate OpenAPI concepts

servers:
  - url: http://localhost:8080

paths:
  /stair1:
    get:
      description: blabla
      operationId: check_query_param
      tags:
        - Stair1
      parameters:
        - name: limit
          in: query
          description: Limits the number of items on a page
          schema:
            type: integer
      
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: string
        default:
          description: unexpected error
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

#257 (closed)

Suggest a fix/enhancement

The handler method should convert the string read into the appropriate type before calling the API method

Assignee
Assign to
Time tracking