feat: srcgen for unknown/empty json objects

This commit is contained in:
Mingwei Samuel 2024-04-19 13:19:32 -07:00
parent d13ab723c2
commit 6ee5687437

View file

@ -91,6 +91,9 @@ function stringifyType(prop, { endpoint = null, optional = false, fullpath = tru
return (owned ? (fullpath ? 'std::vec::' : '') + `Vec<${subprop}>` : `&[${subprop}]`); return (owned ? (fullpath ? 'std::vec::' : '') + `Vec<${subprop}>` : `&[${subprop}]`);
case 'string': return (owned ? 'String' : '&str'); case 'string': return (owned ? 'String' : '&str');
case 'object': case 'object':
if (1 === Object.keys(prop).length) { // Only `{ "type": "object" }`.
return 'serde_json::Map<String, serde_json::Value>'
}
return 'std::collections::HashMap<' + stringifyType(prop['x-key'], { endpoint, optional, fullpath, owned }) + ', ' + return 'std::collections::HashMap<' + stringifyType(prop['x-key'], { endpoint, optional, fullpath, owned }) + ', ' +
stringifyType(prop.additionalProperties, { endpoint, optional, fullpath, owned }) + '>'; stringifyType(prop.additionalProperties, { endpoint, optional, fullpath, owned }) + '>';
default: return prop.type; default: return prop.type;