toMap method
Converts the OpenApiObject to a map.
Implementation
@override
Map<String, dynamic> toMap() {
final dependenciesList = <String, dynamic>{};
if (dependencies != null && dependencies!.isNotEmpty) {
for (final entry in dependencies!.entries) {
if (entry.value is JsonSchema) {
dependenciesList[entry.key] = (entry.value as JsonSchema).toMap();
} else if (entry.value is List<String>) {
dependenciesList[entry.key] = entry.value;
}
}
}
return {
if (type != null) ...type!.toMap(),
if (title != null) 'title': title,
if (description != null) 'description': description,
if (multipleOf != null) 'multipleOf': multipleOf,
if (maximum != null) 'maximum': maximum,
if (exclusiveMaximum != null) 'exclusiveMaximum': exclusiveMaximum,
if (minimum != null) 'minimum': minimum,
if (exclusiveMinimum != null) 'exclusiveMinimum': exclusiveMinimum,
if (maxLength != null) 'maxLength': maxLength,
if (minLength != null) 'minLength': minLength,
if (pattern != null) 'pattern': pattern,
if (maxItems != null) 'maxItems': maxItems,
if (minItems != null) 'minItems': minItems,
if (uniqueItems != null) 'uniqueItems': uniqueItems,
if (maxProperties != null) 'maxProperties': maxProperties,
if (minProperties != null) 'minProperties': minProperties,
if (required != null) 'required': required,
if (additionalProperties != null && hasAdditionalProperties)
'additionalProperties': additionalProperties,
if (definitions != null && definitions!.isNotEmpty)
'definitions': definitions!.map(
(key, value) => MapEntry(key, value.toMap()),
),
if (properties != null && properties!.isNotEmpty)
'properties': properties!.map(
(key, value) => MapEntry(key, value.toMap()),
),
if (patternProperties != null && patternProperties!.isNotEmpty)
'patternProperties': patternProperties!.map(
(key, value) => MapEntry(key, value.toMap()),
),
if (dependencies != null && dependencies!.isNotEmpty)
'dependencies': dependenciesList,
if (enumValues != null) 'enum': enumValues,
if (items != null)
'items': items is OpenApiObject
? (items as OpenApiObject).toMap()
: items,
if (allOf != null) 'allOf': allOf!.map((e) => e.toMap()).toList(),
if (anyOf != null) 'anyOf': anyOf!.map((e) => e.toMap()).toList(),
if (oneOf != null) 'oneOf': oneOf!.map((e) => e.toMap()).toList(),
if (not != null) 'not': not!.toMap(),
if (ref != null) r'$ref': ref,
if (id != null) 'id': id,
if (schema != null) r'$schema': schema,
if (defaultValue != null) 'default': defaultValue,
};
}