feat: srcgen for unknown/empty json objects

val_queue
Mingwei Samuel 2024-04-19 13:19:32 -07:00
parent d13ab723c2
commit 6ee5687437
1 changed files with 3 additions and 0 deletions

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;