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

[C++][Pistache-server] (Type string - format binary) are not well handled - compilation failed

Created by: CyrilleBenard

Description

The use of a [type string, format binary] inside a body generates a miscalled method <string>::fromJson().

The method generated is as below (see the call to newItem.fromJson)

void Body::fromJson(nlohmann::json& val)
{
    if(val.find("binaryDataN2Information") != val.end())
    {
        if(!val["binaryDataN2Information"].is_null())
        {
            std::string newItem;
            newItem.fromJson(val["binaryDataN2Information"]);
            setBinaryDataN2Information( newItem );
        }
    }  
}

The compilation error looks like :

model/Body.cpp: In member function ‘virtual void com::bcom::amf::microservice::server::ms1::model::Body::fromJson(nlohmann::json&)’:
model/Body.cpp:59:21: error: ‘std::__cxx11::string {aka class std::__cxx11::basic_string<char>}’ has no member named ‘fromJson’
             newItem.fromJson(val["binaryDataN2Information"]);
                     ^
openapi-generator version

3.1.2-SNAPSHOT

OpenAPI declaration file content or url
openapi: "3.0.0"
info:
  version: 1.0.0
  title: Check wrong generation of a body containing string/binary type
servers:
  - url: http://localhost:8080
paths:
  /check:
    post:
      summary: see title
      tags:
        - Non UE N2 Message Transfer
      operationId: NonUeN2MessageTransfer
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties: # Request parts
                binaryDataN2Information:
                  type: string
                  format: binary
        required: true
      responses:
        '200':
          description: Non UE N2 Message Transfer successfully initiated.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/content'
        default:
          description: Unexpected error


components:
  schemas:
    Bytes:
      format: byte
      type: string

    Content:
      type: object
      properties:
        type:
          $ref: '#/components/schemas/Bytes'
{
  "openapi": "3.0.0",
  "info": {
    "version": "1.0.0",
    "title": "Check wrong generation of a body containing string/binary type"
  },
  "servers": [
    {
      "url": "http://localhost:8080"
    }
  ],
  "paths": {
    "/check": {
      "post": {
        "summary": "see title",
        "tags": [
          "Non UE N2 Message Transfer"
        ],
        "operationId": "NonUeN2MessageTransfer",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "binaryDataN2Information": {
                    "type": "string",
                    "format": "binary"
                  }
                }
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Non UE N2 Message Transfer successfully initiated.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/content"
                }
              }
            }
          },
          "default": {
            "description": "Unexpected error"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Bytes": {
        "format": "byte",
        "type": "string"
      },
      "Content": {
        "type": "object",
        "properties": {
          "type": {
            "$ref": "#/components/schemas/Bytes"
          }
        }
      }
    }
  }
}
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/Body.o model/Body.cpp
Steps to reproduce

Generate & compile

Related issues/PRs

N/A

Suggest a fix/enhancement

Not sure what we are supposed to do :/

Assignee
Assign to
Time tracking