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
  • #5148
Closed
Open
Issue created Jan 29, 2020 by Administrator@rootContributor

[C++] openapi-generator does not handle additional properties type map

Created by: anandgbhat

Description

C++ openapi generated code has an issue wherein additional properties of the type map are converted to array with {key, value} due to which from_json() fails in the generated code.

openapi-generator version

4.2.2. Same issue is seen in 4.1.3 too.

OpenAPI declaration file content or url

Model generated for the below JSON snippet

"definitions": {
    "Network": {
      "description": "User defined network",
      "properties": {
        "metadata": {
          "additionalProperties": {
            "type": "string"
          },
          "description": "Metadata about this network",
          "type": "object"
        },
        "name": {
          "description": "name of the network",
          "minLength": 1,
          "type": "string",
          "x-go-name": "Name"
        },
      },
      "required": [
        "name"
      ],
      "title": "Network"
    },
  }

C++ code generated:

This is part of from_json()

{ m_Metadata.clear(); std::vectorweb::json::value jsonArray; if(val.has_field(utility::conversions::to_string_t("metadata"))) { for( const auto& item : val.at(utility::conversions::to_string_t("metadata")).as_array() ) {
if(item.has_field(utility::conversions::to_string_t("key"))) { utility::string_t key = ModelBase::stringFromJson(item.at(utility::conversions::to_string_t("key"))); m_Metadata.insert(std::pairutility::string_t,utility::string_t( key, ModelBase::stringFromJson(item.at(utility::conversions::to_string_t("value"))))); } } } } }

Command line used for generation

openapi-generator-cli generate -g cpp-restsdk -i <json_file> -o <output_dir> --enable-post-process-file --model-package=openapi_package

Steps to reproduce

Run the above command with the sample JSON provided above. Use the API generated in the client. Client complains with "not an array" error when any of the API is issued.

Related issues/PRs
Suggest a fix/enhancement
Assignee
Assign to
Time tracking