mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-21 19:51:14 +00:00
490902c80a
Adds the per-endpoint child of AZ-795 ("Strict Input Validation Epic")
for the UAV upload multipart endpoint. Three new validators land under
SatelliteProvider.Api/Validators/:
- UavTileBatchMetadataPayloadValidator: items NotNull + NotEmpty +
count <= MaxBatchSize + RuleForEach dispatching to the per-item
validator.
- UavTileMetadataValidator: lat / lon / tileZoom range, tileSizeMeters
> 0, capturedAt within [now - MaxAgeDays, now + future-skew]; uses an
injectable TimeProvider so unit tests can drive a fixed clock.
- UavUploadValidationFilter: IEndpointFilter that reads the multipart
`metadata` form field, deserializes it with the strict global
JsonSerializerOptions (so UnmappedMemberHandling.Disallow +
[JsonRequired] from AZ-795 are honored), runs the FluentValidation
chain, and enforces the cross-field `items.Count == files.Count`
envelope rule. FluentValidation errors are prefixed with `metadata.`
so wire keys look like `errors["metadata.items[0].latitude"]`.
[JsonRequired] is added to every non-optional axis on
UavTileMetadata and UavTileBatchMetadataPayload; FlightId stays
nullable per AZ-503 anonymous-flight semantics.
Coverage: 13 unit tests + 16 integration tests + 1 curl probe script
exercise the happy path and every failure mode. All 9 ACs covered;
no regression in AZ-488 UavUploadTests payloads (traced against the
new rules).
Documentation: uav-tile-upload.md bumped v1.1.0 -> v1.2.0 with the
new validation rules section + 400-shape examples + changelog entry.
api_program.md updated to describe the three new validators + filter
+ the AddTransient<UavUploadValidationFilter>() DI registration.
Reports: batch_04_cycle8_report.md + reviews/batch_04_cycle8_review.md
record the PASS_WITH_WARNINGS verdict (2 Low DRY-in-tests findings:
FixedTimeProvider duplication crossed the cycle-2 "promote to shared"
threshold; PostBatch helper duplicated between two integration
suites). Both deferred to follow-up PBIs.
Task spec archived: _docs/02_tasks/todo/AZ-810... -> done/.
Jira: AZ-810 transitioned In Progress -> In Testing.
Co-authored-by: Cursor <cursoragent@cursor.com>
34 lines
1.5 KiB
C#
34 lines
1.5 KiB
C#
using FluentValidation;
|
|
using Microsoft.Extensions.Options;
|
|
using SatelliteProvider.Common.Configs;
|
|
using SatelliteProvider.Common.DTO;
|
|
|
|
namespace SatelliteProvider.Api.Validators;
|
|
|
|
// AZ-810: root validator for the UAV upload metadata envelope. Runs from
|
|
// inside the custom `UavUploadValidationFilter` (the endpoint takes a
|
|
// multipart form, so the standard `WithValidation<T>()` JSON-body filter
|
|
// doesn't apply). Error keys come out as `errors.items[…]` from this
|
|
// validator and are prefixed with `metadata.` by the filter, producing
|
|
// `errors.metadata.items[…]` in the final ValidationProblemDetails per
|
|
// `_docs/02_document/contracts/api/error-shape.md` v1.0.0.
|
|
public sealed class UavTileBatchMetadataPayloadValidator : AbstractValidator<UavTileBatchMetadataPayload>
|
|
{
|
|
public UavTileBatchMetadataPayloadValidator(
|
|
IOptions<UavQualityConfig> qualityConfig,
|
|
TimeProvider? timeProvider = null)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(qualityConfig);
|
|
var maxBatchSize = qualityConfig.Value.MaxBatchSize;
|
|
|
|
RuleFor(p => p.Items)
|
|
.NotNull().WithMessage("`items` is required.")
|
|
.NotEmpty().WithMessage("`items` must contain at least one entry.")
|
|
.Must(items => items is null || items.Count <= maxBatchSize)
|
|
.WithMessage($"`items` must contain at most {maxBatchSize} entries.");
|
|
|
|
RuleForEach(p => p.Items)
|
|
.SetValidator(new UavTileMetadataValidator(qualityConfig, timeProvider));
|
|
}
|
|
}
|