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
  • #482
Closed
Open
Issue created Jul 06, 2018 by Administrator@rootContributor

[C++][Pistache-server] Wrong code generation : prototype does not exist

Created by: CyrilleBenard

Description

With the example I submitted below, the code generator produces a call to a constructor that does not exist

The compile error looks like :

model/ProblemDetails.cpp: In member function ‘virtual void com::bcom::amf::microservice::server::ms1::model::ProblemDetails::fromJson(nlohmann::json&)’:
model/ProblemDetails.cpp:126:64: error: no matching function for call to ‘com::bcom::amf::microservice::server::ms1::model::InvalidParam::InvalidParam(std::nullptr_t)’
                 m_InvalidParams.push_back( InvalidParam(nullptr) );
                                                                ^
In file included from model/ProblemDetails.h:25:0,
                 from model/ProblemDetails.cpp:14:
model/InvalidParam.h:41:5: note: candidate: com::bcom::amf::microservice::server::ms1::model::InvalidParam::InvalidParam()
     InvalidParam();
     ^
model/InvalidParam.h:41:5: note:   candidate expects 0 arguments, 1 provided

Indeed, the InvalidParam::InvalidParam(std::nullptr_t) method does not exist and should it ?

Extract of the code :

void ProblemDetails::fromJson(nlohmann::json& val)
{
   // ... previous code we don't care in this example

    {
        m_InvalidParams.clear();
        nlohmann::json jsonArray;
        if(val.find("invalidParams") != val.end())
        {
        for( auto& item : val["invalidParams"] )
        {
            if(item.is_null())
            {
                m_InvalidParams.push_back( InvalidParam(nullptr) );
            }
            else
            {
                InvalidParam newItem(InvalidParam());
                newItem.fromJson(item);
                m_InvalidParams.push_back( newItem );
            }
            
        }
        }
    } 
}

Why does the condition if(item.is_null()) should push a "null" object ? Another generation code (that looks looks like this one) does not consider this kind of condition in the same way (see #446 (closed)) : null object ? => does not push / save it

openapi-generator version

3.1.0-SNAPSHOT

OpenAPI declaration file content or url
openapi: "3.0.0"
info:
  version: 1.0.0
  title: Check InvalidParam instanciation
servers:
  - url: http://localhost:8080
paths:
  /Check:
    get:
      summary: Check call to an unkown constructor
      operationId: doit
      tags:
        - Check
      responses:
        '200':
          description: Everythings gonna be alright
          headers:
            x-next:
              description: A link to the next page of responses
              schema:
                type: string
          content:
            application/json:    
              schema:
                type: object
                properties:   
                  message:
                    type: string
      default:
        description: unexpected error
        content:
          application/json:
            schema:
              type: object
              properties:   
                message:
                  type: string

components:
  schemas:
    Report:
      type: object
      properties:
        location:
          $ref: 'https://raw.githubusercontent.com/jdegre/5GC_APIs/master/TS29571_CommonData.yaml#/components/schemas/ProblemDetails'
{
  "openapi": "3.0.0",
  "info": {
    "version": "1.0.0",
    "title": "Check InvalidParam instanciation"
  },
  "servers": [
    {
      "url": "http://localhost:8080"
    }
  ],
  "paths": {
    "/Check": {
      "get": {
        "summary": "Check call to an unkown constructor",
        "operationId": "doit",
        "tags": [
          "Check"
        ],
        "responses": {
          "200": {
            "description": "Everythings gonna be alright",
            "headers": {
              "x-next": {
                "description": "A link to the next page of responses",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "default": {
          "description": "unexpected error",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "message": {
                    "type": "string"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Report": {
        "type": "object",
        "properties": {
          "location": {
            "$ref": "https://raw.githubusercontent.com/jdegre/5GC_APIs/master/TS29571_CommonData.yaml#/components/schemas/ProblemDetails"
          }
        }
      }
    }
  }
}
Command line used for generation

Generation :

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

Compilation :

g++ -c  -I./api -I./model -I./impl -Wall -g -std=c++11 -o obj/model/ProblemDetails.o model/ProblemDetails.cpp
Steps to reproduce

Just generate and compile

Related issues/PRs

Not exactly the same issue but the code generation should take into account the proposal described in issue #446 (closed) (see std::shared_ptr usage)

Suggest a fix/enhancement

Do not push_back a "null object" and generalize the std::shared_ptr usage (?)

Assignee
Assign to
Time tracking