transformRequestToRest static method
Implementation
static Map? transformRequestToRest(NodeSpec action, ActionContext context) {
NodeSpec? requestSpec;
final restSpec = {}..addAll(action.props);
final requestValue = restSpec["request"];
if (requestValue is String) {
requestSpec = Schema.getRequest(requestValue);
} else if (requestValue is Map) {
requestSpec = Schema.getRequest(requestValue["_type"] ?? "");
}
if (requestSpec == null) {
return null;
}
restSpec.remove("request");
Lowder.widgets.mergeMaps(restSpec, requestSpec.props);
if (requestValue is Map) {
var path = requestSpec.props["path"] as String?;
if (path != null) {
final pathParameters = requestValue["pathParameters"];
if (pathParameters != null && pathParameters is Map) {
for (var propKey in pathParameters.keys) {
path = path!
.replaceAll("{$propKey}", "${pathParameters[propKey] ?? ""}");
}
}
}
restSpec["path"] = path;
Lowder.widgets.mergeMaps(restSpec, requestValue);
}
final evaluatorContext = Lowder.actions.getEvaluatorContext(
context.actionValue, context.state, context.actionContext);
Lowder.properties.evaluateMap(restSpec, evaluatorContext);
return restSpec;
}