-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* wip: fix documentation tags * update model.mustache * update template for documentation * update mustache templates * update mustache templates * run ./bin/r-petstore and update R pkg docs * use loadNamespace instead of package:pkgName string * update R package code * wip: enum * update enum function * use httr::content to unwrap response * update enum table and functions * include simplifyVector and auto_unbox arguments * remove mapping and return strings * use triple stash values and update enum class methods * remove extra comma * minor: formatting * update and run ./bin/r-petstore.sh * move helper for template - export tag does not coincide with original model function - move helper down so it does * update tests based on generator * Revert "update tests based on generator" This reverts commit b6314c8. * Update tests with engine - preserve test_petstore.R * restore apiResponse * restore simplifyVector to TRUE value * update api.mustache templates * fix and add tests to package Co-authored-by: William Cheng <[email protected]>
- Loading branch information
Showing
20 changed files
with
254 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
modules/openapi-generator/src/main/resources/r/modelEnum.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#' @export | ||
{{#allowableValues}} | ||
{{classname}} <- R6::R6Class( | ||
"{{classname}}", | ||
public = list( | ||
initialize = function(...) { | ||
local.optional.var <- list(...) | ||
val <- unlist(local.optional.var) | ||
enumvec <- .parse_{{name}}() | ||
stopifnot(length(val) == 1L) | ||
if (!val %in% enumvec) | ||
stop("Use one of the valid values: ", | ||
paste0(enumvec, collapse = ", ")) | ||
private$value <- val | ||
}, | ||
toJSON = function() { | ||
jsonlite::toJSON(private$value, auto_unbox = TRUE) | ||
}, | ||
fromJSON = function({{classname}}Json) { | ||
private$value <- jsonlite::fromJSON({{classname}}Json, | ||
simplifyVector = FALSE) | ||
self | ||
}, | ||
toJSONString = function() { | ||
as.character(jsonlite::toJSON(private$value, | ||
auto_unbox = TRUE)) | ||
}, | ||
fromJSONString = function({{classname}}Json) { | ||
private$value <- jsonlite::fromJSON({{classname}}Json, | ||
simplifyVector = FALSE) | ||
self | ||
} | ||
), | ||
private = list( | ||
value = NULL | ||
) | ||
) | ||
|
||
# add to utils.R | ||
.parse_{{name}} <- function(vals) { | ||
res <- gsub("^\\[|\\]$", "", | ||
"{{{values}}}" | ||
) | ||
unlist(strsplit(res, ", ")) | ||
} | ||
{{/allowableValues}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.