Skip to content

Internal helper that validates the structure of list_sections used in Whapi LIST messages. Each section must provide a non-empty title and a non-empty rows list. Each row must provide non-empty id and title. The description field is optional.

Usage

whapi_validate_list_sections(list_sections, verbose = TRUE, trim = TRUE)

Arguments

list_sections

A list of sections; each section is a named list with title (character) and rows (list of row objects).

verbose

Logical (default TRUE). If TRUE, prints progress messages via cli.

trim

Logical (default TRUE). If TRUE, trims whitespace from section$title, row$title, and row$id before validating.

Value

The (possibly trimmed) list_sections object, invisibly unchanged in shape.

Details

Expected structure:

list_sections <- list(
  list(
    title = "Section title",
    rows = list(
      list(id = "r1", title = "Row title", description = "Optional"),
      ...
    )
  ),
  ...
)

This function performs lightweight validation and (optionally) trims whitespace from titles and ids to avoid subtle formatting issues.

See also

Examples

sections <- list(
  list(
    title = "Burgers",
    rows = list(
      list(id = "r1", title = "Plain",  description = "No cheese, no sauce"),
      list(id = "r2", title = "Cheese", description = "With melted cheese")
    )
  )
)
whapi_validate_list_sections(sections)
#>  Validating 1 section(s) for LIST message...
#>  LIST sections validated successfully.
#> [[1]]
#> [[1]]$title
#> [1] "Burgers"
#> 
#> [[1]]$rows
#> [[1]]$rows[[1]]
#> [[1]]$rows[[1]]$id
#> [1] "r1"
#> 
#> [[1]]$rows[[1]]$title
#> [1] "Plain"
#> 
#> [[1]]$rows[[1]]$description
#> [1] "No cheese, no sauce"
#> 
#> 
#> [[1]]$rows[[2]]
#> [[1]]$rows[[2]]$id
#> [1] "r2"
#> 
#> [[1]]$rows[[2]]$title
#> [1] "Cheese"
#> 
#> [[1]]$rows[[2]]$description
#> [1] "With melted cheese"
#> 
#> 
#> 
#>