Function sanitizePayload

  • Normalize a form payload into the shape the API expects.

    Recursively walks data against fields and:

    • resolves FK fields without an x-fk.value (id -> object), mapping null/ "" to null (or resolving each element for FK arrays);
    • recurses into inline (refSchema) objects using the referenced schema's fields, mapping empty values to {} or [];
    • maps empty array fields to [] and empty object fields to {}.

    Fields not present in fields are copied through untouched.

    Parameters

    • data: any

      The raw form value (object or array).

    • fields: FieldConfig[]

      Field metadata for the current level.

    • schemas: Record<string, any>

      The spec's components.schemas (for inline-ref recursion).

    • OptionalresolveFk: FkResolver

      Resolves FK values to objects (defaults to identity).

    Returns Promise<any>

    A new, normalized payload.

    const body = await sanitizePayload(form, resource.fields, schemas, resolveFk);