diff --git a/modules/openapi-generator/src/main/resources/r/modelGeneric.mustache b/modules/openapi-generator/src/main/resources/r/modelGeneric.mustache index a47824208ae..7fd625caf3c 100644 --- a/modules/openapi-generator/src/main/resources/r/modelGeneric.mustache +++ b/modules/openapi-generator/src/main/resources/r/modelGeneric.mustache @@ -86,8 +86,8 @@ stopifnot(is.character(`{{name}}`), length(`{{name}}`) == 1) {{/isDateTime}} {{#isUri}} - # validate URL using https://github.com/cran/librarian/blob/master/R/internal_functions.R#L131 credit: Desi Quintans - if (!any(grepl("(https?|ftp)://[^\\s/$.?#].[^\\s]*", `{{name}}`))) { + # to validate URL. ref: https://stackoverflow.com/questions/73952024/url-validation-in-r + if (!stringr::str_detect(`{{name}}`, "(https?|ftp)://[^ /$.?#].[^\\s]*")) { stop(paste("Error! Invalid URL:", `{{name}}`)) } {{/isUri}} @@ -142,8 +142,8 @@ stopifnot(is.character(`{{name}}`), length(`{{name}}`) == 1) {{/isDateTime}} {{#isUri}} - # validate URL using https://github.com/cran/librarian/blob/master/R/internal_functions.R#L131 credit: Desi Quintans - if (!any(grepl("(https?|ftp)://[^\\s/$.?#].[^\\s]*", `{{name}}`))) { + # to validate URL. ref: https://stackoverflow.com/questions/73952024/url-validation-in-r + if (!stringr::str_detect(`{{name}}`, "(https?|ftp)://[^ /$.?#].[^\\s]*")) { stop(paste("Error! Invalid URL:", `{{name}}`)) } {{/isUri}} @@ -251,8 +251,8 @@ } {{/isEnum}} {{#isUri}} - # validate URL using https://github.com/cran/librarian/blob/master/R/internal_functions.R#L131 credit: Desi Quintans - if (!any(grepl("(https?|ftp)://[^\\s/$.?#].[^\\s]*", this_object$`{{baseName}}`))) { + # to validate URL. ref: https://stackoverflow.com/questions/73952024/url-validation-in-r + if (!stringr::str_detect(this_object$`{{baseName}}`, "(https?|ftp)://[^ /$.?#].[^\\s]*")) { stop(paste("Error! Invalid URL:", this_object$`{{baseName}}`)) } {{/isUri}} @@ -383,8 +383,8 @@ } {{/isEnum}} {{#isUri}} - # validate URL using https://github.com/cran/librarian/blob/master/R/internal_functions.R#L131 credit: Desi Quintans - if (!any(grepl("(https?|ftp)://[^\\s/$.?#].[^\\s]*", this_object$`{{name}}`))) { + # to validate URL. ref: https://stackoverflow.com/questions/73952024/url-validation-in-r + if (!stringr::str_detect(this_object$`{{name}}`, "(https?|ftp)://[^ /$.?#].[^\\s]*")) { stop(paste("Error! Invalid URL:", this_object$`{{name}}`)) } {{/isUri}} @@ -444,8 +444,8 @@ stopifnot(is.character(input_json$`{{name}}`), length(input_json$`{{name}}`) == 1) {{/isDateTime}} {{#isUri}} - # validate URL using https://github.com/cran/librarian/blob/master/R/internal_functions.R#L131 credit: Desi Quintans - if (!any(grepl("(https?|ftp)://[^\\s/$.?#].[^\\s]*", input_json$`{{name}}`))) { + # to validate URL. ref: https://stackoverflow.com/questions/73952024/url-validation-in-r + if (!stringr::str_detect(input_json$`{{name}}`, "(https?|ftp)://[^ /$.?#].[^\\s]*")) { stop(paste("Error! Invalid URL:", input_json$`{{name}}`)) } {{/isUri}} @@ -524,8 +524,8 @@ } {{/pattern}} {{#isUri}} - # validate URL using https://github.com/cran/librarian/blob/master/R/internal_functions.R#L131 credit: Desi Quintans - if (!any(grepl("(https?|ftp)://[^\\s/$.?#].[^\\s]*", self$`{{{name}}}`))) { + # to validate URL. ref: https://stackoverflow.com/questions/73952024/url-validation-in-r + if (!stringr::str_detect(self$`{{name}}`, "(https?|ftp)://[^ /$.?#].[^\\s]*")) { return(FALSE) } {{/isUri}} @@ -590,8 +590,8 @@ } {{/pattern}} {{#isUri}} - # validate URL using https://github.com/cran/librarian/blob/master/R/internal_functions.R#L131 credit: Desi Quintans - if (!any(grepl("(https?|ftp)://[^\\s/$.?#].[^\\s]*", self$`{{name}}`))) { + # to validate URL. ref: https://stackoverflow.com/questions/73952024/url-validation-in-r + if (!stringr::str_detect(self$`{{name}}`, "(https?|ftp)://[^ /$.?#].[^\\s]*")) { invalid_fields["{{{name}}}"] <- "Invalid value for `{{{name}}}`, must be URL." } {{/isUri}} diff --git a/samples/client/petstore/R-httr2-wrapper/R/date.R b/samples/client/petstore/R-httr2-wrapper/R/date.R index 1797a087aa4..cab55abeaf6 100644 --- a/samples/client/petstore/R-httr2-wrapper/R/date.R +++ b/samples/client/petstore/R-httr2-wrapper/R/date.R @@ -43,8 +43,8 @@ Date <- R6::R6Class( } if (!missing(`url_property`)) { stopifnot(is.character(`url_property`), length(`url_property`) == 1) - # validate URL using https://github.com/cran/librarian/blob/master/R/internal_functions.R#L131 credit: Desi Quintans - if (!any(grepl("(https?|ftp)://[^\\s/$.?#].[^\\s]*", `url_property`))) { + # to validate URL. ref: https://stackoverflow.com/questions/73952024/url-validation-in-r + if (!stringr::str_detect(`url_property`, "(https?|ftp)://[^ /$.?#].[^\\s]*")) { stop(paste("Error! Invalid URL:", `url_property`)) } self$`url_property` <- `url_property` @@ -103,8 +103,8 @@ Date <- R6::R6Class( self$`percent_description` <- this_object$`percent_description` } if (!is.null(this_object$`url_property`)) { - # validate URL using https://github.com/cran/librarian/blob/master/R/internal_functions.R#L131 credit: Desi Quintans - if (!any(grepl("(https?|ftp)://[^\\s/$.?#].[^\\s]*", this_object$`url_property`))) { + # to validate URL. ref: https://stackoverflow.com/questions/73952024/url-validation-in-r + if (!stringr::str_detect(this_object$`url_property`, "(https?|ftp)://[^ /$.?#].[^\\s]*")) { stop(paste("Error! Invalid URL:", this_object$`url_property`)) } self$`url_property` <- this_object$`url_property` @@ -172,8 +172,8 @@ Date <- R6::R6Class( this_object <- jsonlite::fromJSON(input_json) self$`className` <- this_object$`className` self$`percent_description` <- this_object$`percent_description` - # validate URL using https://github.com/cran/librarian/blob/master/R/internal_functions.R#L131 credit: Desi Quintans - if (!any(grepl("(https?|ftp)://[^\\s/$.?#].[^\\s]*", this_object$`url_property`))) { + # to validate URL. ref: https://stackoverflow.com/questions/73952024/url-validation-in-r + if (!stringr::str_detect(this_object$`url_property`, "(https?|ftp)://[^ /$.?#].[^\\s]*")) { stop(paste("Error! Invalid URL:", this_object$`url_property`)) } self$`url_property` <- this_object$`url_property` @@ -204,8 +204,8 @@ Date <- R6::R6Class( # check the required field `url_property` if (!is.null(input_json$`url_property`)) { stopifnot(is.character(input_json$`url_property`), length(input_json$`url_property`) == 1) - # validate URL using https://github.com/cran/librarian/blob/master/R/internal_functions.R#L131 credit: Desi Quintans - if (!any(grepl("(https?|ftp)://[^\\s/$.?#].[^\\s]*", input_json$`url_property`))) { + # to validate URL. ref: https://stackoverflow.com/questions/73952024/url-validation-in-r + if (!stringr::str_detect(input_json$`url_property`, "(https?|ftp)://[^ /$.?#].[^\\s]*")) { stop(paste("Error! Invalid URL:", input_json$`url_property`)) } } else { diff --git a/samples/client/petstore/R-httr2-wrapper/tests/testthat/test_petstore.R b/samples/client/petstore/R-httr2-wrapper/tests/testthat/test_petstore.R index fb7ee7d0a51..7c19739714f 100644 --- a/samples/client/petstore/R-httr2-wrapper/tests/testthat/test_petstore.R +++ b/samples/client/petstore/R-httr2-wrapper/tests/testthat/test_petstore.R @@ -593,6 +593,9 @@ test_that("Tests anyOf", { }) test_that("Tests URL validation", { + valid_json <- '{"className":"date","percent_description":"abc","url_property":"https://stackoverflow.com/a/1/b/2"}' + Date$public_methods$validateJSON(valid_json) # shouldn't throw exception + valid_json <- '{"className":"date","percent_description":"abc","url_property":"https://abc.com/a/1/b/2"}' Date$public_methods$validateJSON(valid_json) # shouldn't throw exception diff --git a/samples/client/petstore/R-httr2/R/date.R b/samples/client/petstore/R-httr2/R/date.R index f8387d1de08..ffbad1cd46b 100644 --- a/samples/client/petstore/R-httr2/R/date.R +++ b/samples/client/petstore/R-httr2/R/date.R @@ -38,8 +38,8 @@ Date <- R6::R6Class( } if (!missing(`url_property`)) { stopifnot(is.character(`url_property`), length(`url_property`) == 1) - # validate URL using https://github.com/cran/librarian/blob/master/R/internal_functions.R#L131 credit: Desi Quintans - if (!any(grepl("(https?|ftp)://[^\\s/$.?#].[^\\s]*", `url_property`))) { + # to validate URL. ref: https://stackoverflow.com/questions/73952024/url-validation-in-r + if (!stringr::str_detect(`url_property`, "(https?|ftp)://[^ /$.?#].[^\\s]*")) { stop(paste("Error! Invalid URL:", `url_property`)) } self$`url_property` <- `url_property` @@ -89,8 +89,8 @@ Date <- R6::R6Class( self$`percent_description` <- this_object$`percent_description` } if (!is.null(this_object$`url_property`)) { - # validate URL using https://github.com/cran/librarian/blob/master/R/internal_functions.R#L131 credit: Desi Quintans - if (!any(grepl("(https?|ftp)://[^\\s/$.?#].[^\\s]*", this_object$`url_property`))) { + # to validate URL. ref: https://stackoverflow.com/questions/73952024/url-validation-in-r + if (!stringr::str_detect(this_object$`url_property`, "(https?|ftp)://[^ /$.?#].[^\\s]*")) { stop(paste("Error! Invalid URL:", this_object$`url_property`)) } self$`url_property` <- this_object$`url_property` @@ -146,8 +146,8 @@ Date <- R6::R6Class( this_object <- jsonlite::fromJSON(input_json) self$`className` <- this_object$`className` self$`percent_description` <- this_object$`percent_description` - # validate URL using https://github.com/cran/librarian/blob/master/R/internal_functions.R#L131 credit: Desi Quintans - if (!any(grepl("(https?|ftp)://[^\\s/$.?#].[^\\s]*", this_object$`url_property`))) { + # to validate URL. ref: https://stackoverflow.com/questions/73952024/url-validation-in-r + if (!stringr::str_detect(this_object$`url_property`, "(https?|ftp)://[^ /$.?#].[^\\s]*")) { stop(paste("Error! Invalid URL:", this_object$`url_property`)) } self$`url_property` <- this_object$`url_property` @@ -171,8 +171,8 @@ Date <- R6::R6Class( # check the required field `url_property` if (!is.null(input_json$`url_property`)) { stopifnot(is.character(input_json$`url_property`), length(input_json$`url_property`) == 1) - # validate URL using https://github.com/cran/librarian/blob/master/R/internal_functions.R#L131 credit: Desi Quintans - if (!any(grepl("(https?|ftp)://[^\\s/$.?#].[^\\s]*", input_json$`url_property`))) { + # to validate URL. ref: https://stackoverflow.com/questions/73952024/url-validation-in-r + if (!stringr::str_detect(input_json$`url_property`, "(https?|ftp)://[^ /$.?#].[^\\s]*")) { stop(paste("Error! Invalid URL:", input_json$`url_property`)) } } else { diff --git a/samples/client/petstore/R/R/date.R b/samples/client/petstore/R/R/date.R index 1797a087aa4..cab55abeaf6 100644 --- a/samples/client/petstore/R/R/date.R +++ b/samples/client/petstore/R/R/date.R @@ -43,8 +43,8 @@ Date <- R6::R6Class( } if (!missing(`url_property`)) { stopifnot(is.character(`url_property`), length(`url_property`) == 1) - # validate URL using https://github.com/cran/librarian/blob/master/R/internal_functions.R#L131 credit: Desi Quintans - if (!any(grepl("(https?|ftp)://[^\\s/$.?#].[^\\s]*", `url_property`))) { + # to validate URL. ref: https://stackoverflow.com/questions/73952024/url-validation-in-r + if (!stringr::str_detect(`url_property`, "(https?|ftp)://[^ /$.?#].[^\\s]*")) { stop(paste("Error! Invalid URL:", `url_property`)) } self$`url_property` <- `url_property` @@ -103,8 +103,8 @@ Date <- R6::R6Class( self$`percent_description` <- this_object$`percent_description` } if (!is.null(this_object$`url_property`)) { - # validate URL using https://github.com/cran/librarian/blob/master/R/internal_functions.R#L131 credit: Desi Quintans - if (!any(grepl("(https?|ftp)://[^\\s/$.?#].[^\\s]*", this_object$`url_property`))) { + # to validate URL. ref: https://stackoverflow.com/questions/73952024/url-validation-in-r + if (!stringr::str_detect(this_object$`url_property`, "(https?|ftp)://[^ /$.?#].[^\\s]*")) { stop(paste("Error! Invalid URL:", this_object$`url_property`)) } self$`url_property` <- this_object$`url_property` @@ -172,8 +172,8 @@ Date <- R6::R6Class( this_object <- jsonlite::fromJSON(input_json) self$`className` <- this_object$`className` self$`percent_description` <- this_object$`percent_description` - # validate URL using https://github.com/cran/librarian/blob/master/R/internal_functions.R#L131 credit: Desi Quintans - if (!any(grepl("(https?|ftp)://[^\\s/$.?#].[^\\s]*", this_object$`url_property`))) { + # to validate URL. ref: https://stackoverflow.com/questions/73952024/url-validation-in-r + if (!stringr::str_detect(this_object$`url_property`, "(https?|ftp)://[^ /$.?#].[^\\s]*")) { stop(paste("Error! Invalid URL:", this_object$`url_property`)) } self$`url_property` <- this_object$`url_property` @@ -204,8 +204,8 @@ Date <- R6::R6Class( # check the required field `url_property` if (!is.null(input_json$`url_property`)) { stopifnot(is.character(input_json$`url_property`), length(input_json$`url_property`) == 1) - # validate URL using https://github.com/cran/librarian/blob/master/R/internal_functions.R#L131 credit: Desi Quintans - if (!any(grepl("(https?|ftp)://[^\\s/$.?#].[^\\s]*", input_json$`url_property`))) { + # to validate URL. ref: https://stackoverflow.com/questions/73952024/url-validation-in-r + if (!stringr::str_detect(input_json$`url_property`, "(https?|ftp)://[^ /$.?#].[^\\s]*")) { stop(paste("Error! Invalid URL:", input_json$`url_property`)) } } else {