Hello!
I’m hitting a problem with CPPREST SDK when defining an API with a
dictionary (map). The SDK generates and compile, but I when core when I try
to de-stream using fromJson(). The message is below and indicates the
object is “not an array” (but the CPPREST generated code is an array). I’ve
listed the Swagger snippet along with the error message and the generated
code snippet. I’m running on Centos7 with CPPREST 1.54 and using swagger
codegen 2.3.0.
Any help would be appreciated!
Thanks
Frank
*Swagger:*
definitions:
serviceAvailableIndV1:
type: object
properties:
ServiceName:
type: string
ServiceID:
type: string
ServiceUdsPath:
type: string
ServiceIpAddr:
type: string
ServiceIpPort:
type: string
*ServiceAttributes:*
* type: object*
* additionalProperties:*
* type: string*
* format: kvattrs*
required:
- ServiceName
- ServiceID
- ServiceUdsPath
- ServiceIpAddr
- ServiceIpPort
- ServiceAttributes
*Error message:*
[2018-03-28T1:0:31][Worker] serviceAvailableIndCallback: Message: URI :
/srClient/v1/serviceAvailableInd, Data : {"Status": "Available",
"ServiceName": "hello_world_worker", "ServiceIpPort": "8499",
"ServiceUdsPath": "worker", "ServiceID":
"hello-dep-785dff66b-h6lrp-worker-worker", "ServiceAttributes":
{"ContainerName": "infra", "ServiceUdsPath": "worker", "PodName":
"hello-dep-785dff66b-h6lrp"}, "ServiceIpAddr": "192.168.141.246",
"ServiceScope": "ClusterWide"},Cookie : 0 : /ramdisk/uds.srClient
*[2018-03-28T1:0:31][SWERRlogger] exception_swerr_v: Uncaught Exception:
'web::json::json_exception'; 'not an array'*
terminate called after throwing an instance of 'web::json::json_exception'
what(): not an array
*Generated code:*
void ServiceAvailableIndV1::fromJson(web::json::value& val)
{
setServiceName(ModelBase::stringFromJson(val[utility::conversions::to_string_t("ServiceName")]));
setServiceID(ModelBase::stringFromJson(val[utility::conversions::to_string_t("ServiceID")]));
setServiceUdsPath(ModelBase::stringFromJson(val[utility::conversions::to_string_t("ServiceUdsPath")]));
if(val.has_field(utility::conversions::to_string_t("ServiceIpAddr")))
{
setServiceIpAddr(ModelBase::stringFromJson(val[utility::conversions::to_string_t("ServiceIpAddr")]));
}
if(val.has_field(utility::conversions::to_string_t("ServiceIpPort")))
{
setServiceIpPort(ModelBase::stringFromJson(val[utility::conversions::to_string_t("ServiceIpPort")]));
}
{
m_ServiceAttributes.clear();
std::vector<web::json::value> jsonArray;
for( auto& item :
val[utility::conversions::to_string_t("ServiceAttributes")].as_array() )
{
utility::string_t key;
if(item.has_field(utility::conversions::to_string_t("key")))
{
key =
ModelBase::stringFromJson(item[utility::conversions::to_string_t("key")]);
}
m_ServiceAttributes.insert(std::pair<utility::string_t,utility::string_t>(
key,
ModelBase::stringFromJson(item[utility::conversions::to_string_t("value")])));
}
}
}
--
You received this message because you are subscribed to the Google Groups
"Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.