Skip to main content

validate_fields

Function validate_fields 

Source
pub fn validate_fields(
    requested: Option<&HashSet<String>>,
    sample: &Map<String, Value>,
) -> Result<(), String>
Expand description

Refuse a ?fields= name the serializer never emits.

Same defect, different parameter: an unknown name was dropped, so ?fields=titel returned {"id":…,"meta":{…}} — every object stripped to nothing, with no hint that the client had misspelled the one field it asked for.

Validated against the keys of a serialized sample rather than a hand-written list, so it cannot drift from what the endpoint actually returns. id and meta are always permitted: they are always kept in the output, so naming one is harmless even where a serializer omits it.

A caller with no rows to sample skips validation — there is nothing to filter, and guessing an allowlist from an empty page would mean inventing the very list this avoids.

§Errors

A message naming the offending field and listing the valid ones.