toJson method
Implementation
Map<String, dynamic> toJson() {
if (data is FormData) {
final _properties = <String, dynamic>{};
for (final e in (data as FormData).fields) {
_properties.putIfAbsent(
e.key,
() => SwaggerUtils().toPrimativeType(e.value),
);
}
for (final e in (data as FormData).files) {
_properties.putIfAbsent(
e.key,
() => {
'type': 'string',
'format': 'binary',
},
);
}
return {
'multipart/form-data': {
'schema': {
'type': 'object',
'properties': _properties,
}
},
};
}
if (data is List) {
final _element = data.isNotEmpty ? data.first : null;
if (_element is Map<dynamic, dynamic>) {
return {
'application/json': {
'schema': {
'type': 'array',
'items': {
'type': 'object',
'properties': mapProperties(_element),
},
}
}
};
}
return {
'application/json': {
'schema': {
'type': 'array',
'items': {
'type': 'string',
},
}
}
};
}
if (data is Map<dynamic, dynamic>) {
return {
'application/json': {
'schema': {
'type': 'object',
'properties': mapProperties(data),
}
}
};
}
try {
return {
'application/json': {
'schema': {
'type': 'object',
'properties': mapProperties(jsonDecode(data)),
}
}
};
} catch (e) {
return {
'text/plain': {
'schema': SwaggerUtils().toPrimativeType(data),
}
};
}
}