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
  • #1163
Closed
Open
Issue created Oct 03, 2018 by Administrator@rootContributor

[C++][cpp-restsdk] Simple request / response (string) is not well handled. Compilation failed

Created by: CyrilleBenard

Description

A simple query with a simple response (string) does not compile. The generated code shows a miscalled method that does not exist (std::string::fromJson)

The compilation error looks like :

/home/xxxx/dev/amf/impl-ms1/src/client/client-ms2/gen-cpp/api/Stair1Api.cpp: In lambda function:
/home/xxxx/dev/amf/impl-ms1/src/client/client-ms2/gen-cpp/api/Stair1Api.cpp:161:27: error: base operand of ‘->’ has non-pointer type ‘utility::string_t {aka std::__cxx11::basic_string<char>}’
             localVarResult->fromJson(localVarJson);
                           ^
CMakeFiles/client-ms2.dir/build.make:254: recipe for target 'CMakeFiles/client-ms2.dir/api/Stair1Api.cpp.o' failed
make[3]: *** [CMakeFiles/client-ms2.dir/api/Stair1Api.cpp.o] Error 1
openapi-generator version

Current master 3.3.0-SNAPSHOT

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  version: 1.0.0
  title: Check generation of  (cpp-restsdk)
  description: Internal ref filename is check_cpprest_simple_response.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'
        required: true
      responses:
        '200':
          description: Expected response to a valid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Gpsi'
        default:
          description: Unexpected error

components:
  schemas:
    Content:
      type: object
      properties:
        data:
          $ref: '#/components/schemas/Gpsi'

    Gpsi:
      type: string
Command line used for generation

Generate :

openapi-generator-cli.sh generate -i ./openapi.yaml -g cpp-restsdk -c ./config.json -o gen-cpp

Compile :

mkdir -p obj ; cd obj ; cmake -D CPPREST_ROOT=/usr/ ../gen-cpp ; make ; cd ..
Steps to reproduce

Generate & Compile

Related issues/PRs
Suggest a fix/enhancement

Wrong code is located in Stair1Api::checkGeneration method :

../..
    .then([=](utility::string_t localVarResponse)
    {
        utility::string_t localVarResult(utility::conversions::to_string_t(""));

        if(localVarResponseHttpContentType == utility::conversions::to_string_t("application/json"))
        {
            web::json::value localVarJson = web::json::value::parse(localVarResponse);

            // WRONG CALL BELOW
            localVarResult->fromJson(localVarJson);
        }
        // else if(localVarResponseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
        // {
        // TODO multipart response parsing
        // }
        else
        {
            throw ApiException(500
                , utility::conversions::to_string_t("error calling checkGeneration: unsupported response type"));
        }

        return localVarResult;
    });
../..

The called method should probably be :

    localVarResult = ModelBase::stringFromJson(localVarJson);
Assignee
Assign to
Time tracking