Skip to content

[C++][cpp-restsdk] (Type string - format binary) are not well handled - compilation failed #934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
CyrilleBenard opened this issue Aug 30, 2018 · 2 comments · Fixed by #5222

Comments

@CyrilleBenard
Copy link

Description

This bug issue is almost the same than the one I identified for Pistache server, see #638
For convenience, I decided to create a dedicated cpp-restsdk bug issue.

The compilation error looks like :

./client-ms2/gen-cpp/model/Body.cpp: In member function ‘virtual web::json::value com::bcom::amf::microservice::client::ms2::model::Body::toJson() const’:
./client-ms2/gen-cpp/model/Body.cpp:44:120: error: no matching function for call to ‘com::bcom::amf::microservice::client::ms2::model::Body::toJson(const com::bcom::amf::microservice::client::ms2::model::HttpContent&) const’
 ty::conversions::to_string_t("binaryDataN2Information")] = ModelBase::toJson(m_BinaryDataN2Information);
                                                                                                       ^
openapi-generator version

Current master 3.2.3-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
  description: Internal ref filename is check_binary_property.yaml
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",
    "description": "Internal ref filename is check_binary_property.yaml"
  },
  "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-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

#638

Suggest a fix/enhancement

Maybe a similar code than suggested (for the same method) in #638

@etherealjoy
Copy link
Contributor

etherealjoy commented Oct 14, 2018

@CyrilleBenard
In cpprest this is a file stream. It is not a string.

@wing328
Is it normal to have the type below

           type: string
           format: binary

mapped to file ?
If mapped to string type then it is much easier.

@grmcdorman
Copy link

type: string and format: binary is mapped to files in other languages. However, it seems this is not common; aspdotnetcore server and csharp client generation create code that compiles but does not work. Issue #1327 fixes this for aspdotnetcore, among other things. See issue #1381 just submitted for the same problem in the csharp client generation code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants