Skip to content

Incorporate validation of version together with other  #246

@Aeilert

Description

@Aeilert

It would be beneficial to move all the API input argument checks to the same location in endpoints.R.

Incorporate

if (!is.null(req$argsQuery$version)) {
if (!req$argsQuery$version %in% lkups$versions) {
res$status <- 404
out <- list(
error = "Invalid query arguments have been submitted.",
details = list(msg = "You supplied an invalid value for version. Please use one of the valid values.",
valid = lkups$versions))
return(out)
#return("Invalid version has been submitted. Please check valid versions with /versions")
}
}

together with

if (req$QUERY_STRING != "" & !grepl("swagger", req$PATH_INFO)) {
# STEP 1: Assign required parameters
# Non-provided parameters are typically assigned the underlying function
# arguments' default values. There is an exception to that however:
# The `country` & `year` parameters cannot be NULL in order for to pass
# the if condition that will decide whether or no the request should be
# treated asynchronously.
req <- pipapi:::assign_required_params(req)
# STEP 2: Validate individual query parameters
are_valid <- pipapi:::check_parameters(req, query_controls)
if (any(are_valid == FALSE)) {
res$status <- 404
invalid_params <- names(req$argsQuery)[!are_valid]
out <- pipapi:::format_error(invalid_params, query_controls)
return(out)
}
# STEP 3: Check for invalid combinations of query parameter values
# Break if bad request
endpoint <- pipapi:::extract_endpoint(req$PATH_INFO)
if (endpoint == "pip-grp") {
if (req$argsQuery$group_by != "none" && req$argsQuery$country != "all") {
res$status <- 400
out <- list(
error = "Invalid query arguments have been submitted.",
details = list(msg = "You cannot query individual countries when specifying a predefined sub-group. Please use country=all")
)
return(out)
}
}
}

Metadata

Metadata

Assignees

Labels

BacklogPlaceholder for issues moved to backlog

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions