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
  • #1572
Closed
Open
Issue created Nov 29, 2018 by Administrator@rootContributor

[C++][Pistache-server] Object containing an Array - model file (.h) is not included and generated code is wrong - Compilation failed

Created by: CyrilleBenard

Description

When the YAML file describes the use of an array inside an object there are two issues :

  • One model file is not included (whereas it as been well generated) In the current example see the lack of #include "EpsBearerId.h" inside the file AssignEbi.h

  • The generated code below is wrong because the ::push_back method can't handle an json object

void AssignEbi::fromJson(const nlohmann::json& val)
{
    {
        m_ReleasedEbiList.clear();
        if(val.find("releasedEbiList") != val.end())
        {
            for( auto& item : val["releasedEbiList"] )
            {
                m_ReleasedEbiList.push_back(item);
                
            }
        }
    }
}

It should generate something like this :

void AssignEbi::fromJson(const nlohmann::json& val)
{
    {
        m_ReleasedEbiList.clear();
        if(val.find("releasedEbiList") != val.end())
        {
            for( auto& item : val["releasedEbiList"] )
            {
                if(item.is_null())
                {
                    m_ReleasedEbiList.push_back(EpsBearerId());
                }
                else
                {
                    EpsBearerId newItem ;
                    newItem.fromJson(item);
                    m_ReleasedEbiList.push_back(newItem);
                }
            }
        }
    }
}
openapi-generator version

Current master 3.3.4-SNAPSHOT

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  version: 1.0.0
  title: Check generation of array inside object
  description: Internal ref filename is check_object_containing_array.yaml 

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

paths:
  /ue-contexts/{ueContextId}/assignEbi:
    post:
      summary: Namf_Communication EBI Assignment service Operation
      tags:
        - EBI Assignment
      operationId: EBIAssignment
      parameters:
        - name: ueContextId
          in: path
          description: UE Context Identifier
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AssignEbi'
        required: true
      responses:
        '200':
          description: EBI Assignment successfully performed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Content'
        default:
          description: Unexpected error

components:
  schemas:
    Content:
      type: string

    AssignEbi:
      type: object
      properties:
        releasedEbiList:
          type: array
          items:
            $ref: '#/components/schemas/EpsBearerId'
          minItems: 0

#
# Generated code is also wrong with this below definition
#
#    AssignEbi:
#      type: array
#      items:
#        $ref: '#/components/schemas/EpsBearerId'
#      minItems: 0


    EpsBearerId:
      $ref: '#/components/schemas/Uinteger'


    Uinteger:
      type: integer
      minimum: 0
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/model/AssignEbi.o model/AssignEbi.cpp
Steps to reproduce

Generate & compile

Related issues/PRs

N/A

Suggest a fix/enhancement

I wrote a proposal of generated code above.

Assignee
Assign to
Time tracking