Skip to content

Commit 6d753d2

Browse files
author
alex-omophub
committed
Enhance input validation in SearchResource class
- Added checks for `page` and `page_size` parameters to ensure they are positive integers within specified limits. - Introduced validation for `max_suggestions` parameter to confirm it is a positive integer. - Included validation for `concept_id` if provided, ensuring it is a single positive integer.
1 parent f162b20 commit 6d753d2

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

R/search.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ SearchResource <- R6::R6Class(
161161
page = 1,
162162
page_size = 20) {
163163
checkmate::assert_string(query, min.chars = 1)
164+
checkmate::assert_integerish(page, lower = 1, len = 1, any.missing = FALSE)
165+
checkmate::assert_integerish(page_size, lower = 1, upper = 1000, len = 1, any.missing = FALSE)
164166

165167
body <- list(query = query)
166168

@@ -206,6 +208,7 @@ SearchResource <- R6::R6Class(
206208
domains = NULL,
207209
max_suggestions = 10) {
208210
checkmate::assert_string(query, min.chars = 1)
211+
checkmate::assert_integerish(max_suggestions, lower = 1, len = 1, any.missing = FALSE)
209212

210213
params <- list(
211214
query = query,
@@ -368,6 +371,9 @@ SearchResource <- R6::R6Class(
368371
checkmate::assert_choice(algorithm, c("semantic", "lexical", "hybrid"))
369372
checkmate::assert_number(similarity_threshold, lower = 0, upper = 1)
370373
checkmate::assert_integerish(page_size, lower = 1, upper = 1000)
374+
if (!is.null(concept_id)) {
375+
checkmate::assert_integerish(concept_id, len = 1, any.missing = FALSE)
376+
}
371377

372378
body <- list(
373379
algorithm = algorithm,

0 commit comments

Comments
 (0)