ThingDescription.fromJson constructor
Creates a ThingDescription from a json
object.
Throws a FormatException if the Thing Description should not be valid.
Implementation
factory ThingDescription.fromJson(Map<String, dynamic> json) {
final Set<String> parsedFields = {};
final context = json.parseContext(parsedFields);
final prefixMapping = context.prefixMapping;
final atType =
json.parseArrayField<String>("@type", parsedFields: parsedFields);
final title = json.parseRequiredField<String>("title", parsedFields);
final titles = json.parseMapField<String>("titles", parsedFields);
final description = json.parseField<String>("description", parsedFields);
final descriptions =
json.parseMapField<String>("descriptions", parsedFields);
final version = json.parseVersionInfo(prefixMapping, parsedFields);
final created = json.parseDateTime("created", parsedFields);
final modified = json.parseDateTime("modified", parsedFields);
final support = json.parseUriField("support", parsedFields);
final base = json.parseUriField("base", parsedFields);
final id = json.parseField<String>("id", parsedFields);
final security = json.parseRequiredArrayField<String>(
"security",
parsedFields: parsedFields,
minimalSize: 1,
);
final securityDefinitions =
json.parseSecurityDefinitions(prefixMapping, parsedFields);
final forms = json.parseForms(prefixMapping, parsedFields);
// TODO: Move somewhere else
// TODO: Validate correct use of op-values
forms?.forEach((form) {
if (form.op == null) {
throw const FormatException('Missing "op" field in thing-level form.');
}
});
final properties = json.parseProperties(prefixMapping, parsedFields);
final actions = json.parseActions(prefixMapping, parsedFields);
final events = json.parseEvents(prefixMapping, parsedFields);
final links = json.parseLinks(prefixMapping, parsedFields);
final profile = json.parseUriArrayField(
"profile",
parsedFields: parsedFields,
minimalSize: 1,
);
final schemaDefinitions = json.parseDataSchemaMapField(
"schemaDefinitions",
prefixMapping,
parsedFields,
);
final uriVariables = json.parseDataSchemaMapField(
"uriVariables",
prefixMapping,
parsedFields,
);
final additionalFields =
json.parseAdditionalFields(prefixMapping, parsedFields);
return ThingDescription(
context: context,
title: title,
titles: titles,
description: description,
descriptions: descriptions,
version: version,
created: created,
modified: modified,
support: support,
base: base,
id: id,
forms: forms,
properties: properties,
actions: actions,
events: events,
links: links,
profile: profile,
schemaDefinitions: schemaDefinitions,
uriVariables: uriVariables,
additionalFields: additionalFields,
security: security,
securityDefinitions: securityDefinitions,
atType: atType,
);
}