OpenTool.fromJson constructor
OpenTool.fromJson(
- Map<String, dynamic> json
)
Implementation
factory OpenTool.fromJson(Map<String, dynamic> json) {
final rawSchemas = json['schemas'];
if (rawSchemas != null && rawSchemas is! Map<String, dynamic>) {
throw const FormatException('schemas: expected an object.');
}
final schemaResolver = SchemaResolver(rawSchemas as Map<String, dynamic>?);
final parsedSchemas = rawSchemas == null
? null
: schemaResolver.resolveAll();
final rawFunctions = json['functions'];
if (rawFunctions is! List) {
throw const FormatException('functions: expected an array.');
}
final functions = <FunctionModel>[];
for (var i = 0; i < rawFunctions.length; i++) {
final rawFunction = rawFunctions[i];
if (rawFunction is! Map<String, dynamic>) {
throw FormatException('functions[$i]: expected an object.');
}
functions.add(
FunctionModel.fromJson(
rawFunction,
schemaResolver: schemaResolver,
path: 'functions[$i]',
),
);
}
return OpenTool(
opentool: json['opentool'] as String,
info: Info.fromJson(json['info'] as Map<String, dynamic>),
server: json['server'] == null
? null
: ServerConfig.fromJson(json['server'] as Map<String, dynamic>),
functions: functions,
schemas: parsedSchemas,
);
}