[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.