processBodyAnnotation function
bool
processBodyAnnotation(
- List<
ParamExtractor> positionalArgumentsFunctions, - Map<
Symbol, ParamExtractor> namedArgumentsFunctions, - ParameterMirror singleParam,
- ObjectMapper om,
Implementation
bool processBodyAnnotation(
List<ParamExtractor> positionalArgumentsFunctions,
Map<Symbol, ParamExtractor> namedArgumentsFunctions,
ParameterMirror singleParam,
ObjectMapper om,
) {
Body? body = singleParam.metadata
.firstWhereOrNull(
(metadata) => metadata.reflectee is Body,
)
?.reflectee;
if (body != null) {
bool isRequired = !singleParam.isOptional;
var defaultValue = singleParam.hasDefaultValue
? singleParam.defaultValue?.reflectee
: null;
extractor(RequestEntity request) async {
String rawBody = await request.readAsString();
if (!isRequired && rawBody.isEmpty) {
return defaultValue;
}
Object parsedBody = body.parser(rawBody, om);
if (parsedBody is PlainBodyWrapper) {
return parsedBody.body;
}
return parsedBody;
}
if (singleParam.isNamed) {
namedArgumentsFunctions[singleParam.simpleName] = extractor;
} else {
positionalArgumentsFunctions.add(extractor);
}
}
return body != null;
}