MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / validateBatchOps

Function validateBatchOps

app/src/API/Handlers/ProjectHandler.cpp:5354–5388  ·  view source on GitHub ↗

* @brief Validate the `ops` array against the batch handler's preconditions; returns an error * response when invalid. */

Source from the content-addressed store, hash-verified

5352 * response when invalid.
5353 */
5354static std::optional<API::CommandResponse> validateBatchOps(const QString& id,
5355 const QJsonObject& params,
5356 QJsonArray& outOps)
5357{
5358 constexpr int kMaxBatchOps = 1024;
5359
5360 if (!params.contains(QStringLiteral("ops")))
5361 return API::CommandResponse::makeError(id,
5362 API::ErrorCode::MissingParam,
5363 QStringLiteral("Missing required parameter: ops"),
5364 buildBatchSchemaHint());
5365
5366 if (!params.value(QStringLiteral("ops")).isArray())
5367 return API::CommandResponse::makeError(id,
5368 API::ErrorCode::InvalidParam,
5369 QStringLiteral("ops must be an array"),
5370 buildBatchSchemaHint());
5371
5372 outOps = params.value(QStringLiteral("ops")).toArray();
5373 if (outOps.isEmpty())
5374 return API::CommandResponse::makeError(id,
5375 API::ErrorCode::InvalidParam,
5376 QStringLiteral("ops array must not be empty"),
5377 buildBatchSchemaHint());
5378
5379 if (outOps.size() > kMaxBatchOps)
5380 return API::CommandResponse::makeError(
5381 id,
5382 API::ErrorCode::InvalidParam,
5383 QStringLiteral("ops array exceeds limit of %1 (got %2)")
5384 .arg(QString::number(kMaxBatchOps), QString::number(outOps.size())),
5385 buildBatchSchemaHint());
5386
5387 return std::nullopt;
5388}
5389
5390/**
5391 * @brief When dryRun is set, ensure every op supports dryRun; returns an error response if any does

Callers 1

projectBatchMethod · 0.85

Calls 5

buildBatchSchemaHintFunction · 0.85
isEmptyMethod · 0.80
containsMethod · 0.45
valueMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected