mirror of
				https://github.com/OpenAPITools/openapi-generator.git
				synced 2025-11-03 18:23:44 +00:00 
			
		
		
		
	* [r client] fix to-list and to-json functionality * fix type of json string * wip * refactor pr * regenerate samples * update to-dataframe example to use non-superceded tidyverse functions * fix typo
		
			
				
	
	
		
			310 lines
		
	
	
		
			9.8 KiB
		
	
	
	
		
			R
		
	
	
	
	
	
			
		
		
	
	
			310 lines
		
	
	
		
			9.8 KiB
		
	
	
	
		
			R
		
	
	
	
	
	
#' Create a new User
 | 
						|
#'
 | 
						|
#' @description
 | 
						|
#' A User who is purchasing from the pet store
 | 
						|
#'
 | 
						|
#' @docType class
 | 
						|
#' @title User
 | 
						|
#' @description User Class
 | 
						|
#' @format An \code{R6Class} generator object
 | 
						|
#' @field id  integer [optional]
 | 
						|
#' @field username  character [optional]
 | 
						|
#' @field firstName  character [optional]
 | 
						|
#' @field lastName  character [optional]
 | 
						|
#' @field email  character [optional]
 | 
						|
#' @field password  character [optional]
 | 
						|
#' @field phone  character [optional]
 | 
						|
#' @field userStatus User Status integer [optional]
 | 
						|
#' @field _field_list a list of fields list(character)
 | 
						|
#' @field additional_properties additional properties list(character) [optional]
 | 
						|
#' @importFrom R6 R6Class
 | 
						|
#' @importFrom jsonlite fromJSON toJSON
 | 
						|
#' @export
 | 
						|
User <- R6::R6Class(
 | 
						|
  "User",
 | 
						|
  public = list(
 | 
						|
    `id` = NULL,
 | 
						|
    `username` = NULL,
 | 
						|
    `firstName` = NULL,
 | 
						|
    `lastName` = NULL,
 | 
						|
    `email` = NULL,
 | 
						|
    `password` = NULL,
 | 
						|
    `phone` = NULL,
 | 
						|
    `userStatus` = NULL,
 | 
						|
    `_field_list` = c("id", "username", "firstName", "lastName", "email", "password", "phone", "userStatus"),
 | 
						|
    `additional_properties` = list(),
 | 
						|
 | 
						|
    #' @description
 | 
						|
    #' Initialize a new User class.
 | 
						|
    #'
 | 
						|
    #' @param id id
 | 
						|
    #' @param username username
 | 
						|
    #' @param firstName firstName
 | 
						|
    #' @param lastName lastName
 | 
						|
    #' @param email email
 | 
						|
    #' @param password password
 | 
						|
    #' @param phone phone
 | 
						|
    #' @param userStatus User Status
 | 
						|
    #' @param additional_properties additional properties (optional)
 | 
						|
    #' @param ... Other optional arguments.
 | 
						|
    initialize = function(`id` = NULL, `username` = NULL, `firstName` = NULL, `lastName` = NULL, `email` = NULL, `password` = NULL, `phone` = NULL, `userStatus` = NULL, additional_properties = NULL, ...) {
 | 
						|
      if (!is.null(`id`)) {
 | 
						|
        if (!(is.numeric(`id`) && length(`id`) == 1)) {
 | 
						|
          stop(paste("Error! Invalid data for `id`. Must be an integer:", `id`))
 | 
						|
        }
 | 
						|
        self$`id` <- `id`
 | 
						|
      }
 | 
						|
      if (!is.null(`username`)) {
 | 
						|
        if (!(is.character(`username`) && length(`username`) == 1)) {
 | 
						|
          stop(paste("Error! Invalid data for `username`. Must be a string:", `username`))
 | 
						|
        }
 | 
						|
        self$`username` <- `username`
 | 
						|
      }
 | 
						|
      if (!is.null(`firstName`)) {
 | 
						|
        if (!(is.character(`firstName`) && length(`firstName`) == 1)) {
 | 
						|
          stop(paste("Error! Invalid data for `firstName`. Must be a string:", `firstName`))
 | 
						|
        }
 | 
						|
        self$`firstName` <- `firstName`
 | 
						|
      }
 | 
						|
      if (!is.null(`lastName`)) {
 | 
						|
        if (!(is.character(`lastName`) && length(`lastName`) == 1)) {
 | 
						|
          stop(paste("Error! Invalid data for `lastName`. Must be a string:", `lastName`))
 | 
						|
        }
 | 
						|
        self$`lastName` <- `lastName`
 | 
						|
      }
 | 
						|
      if (!is.null(`email`)) {
 | 
						|
        if (!(is.character(`email`) && length(`email`) == 1)) {
 | 
						|
          stop(paste("Error! Invalid data for `email`. Must be a string:", `email`))
 | 
						|
        }
 | 
						|
        self$`email` <- `email`
 | 
						|
      }
 | 
						|
      if (!is.null(`password`)) {
 | 
						|
        if (!(is.character(`password`) && length(`password`) == 1)) {
 | 
						|
          stop(paste("Error! Invalid data for `password`. Must be a string:", `password`))
 | 
						|
        }
 | 
						|
        self$`password` <- `password`
 | 
						|
      }
 | 
						|
      if (!is.null(`phone`)) {
 | 
						|
        if (!(is.character(`phone`) && length(`phone`) == 1)) {
 | 
						|
          stop(paste("Error! Invalid data for `phone`. Must be a string:", `phone`))
 | 
						|
        }
 | 
						|
        self$`phone` <- `phone`
 | 
						|
      }
 | 
						|
      if (!is.null(`userStatus`)) {
 | 
						|
        if (!(is.numeric(`userStatus`) && length(`userStatus`) == 1)) {
 | 
						|
          stop(paste("Error! Invalid data for `userStatus`. Must be an integer:", `userStatus`))
 | 
						|
        }
 | 
						|
        self$`userStatus` <- `userStatus`
 | 
						|
      }
 | 
						|
      if (!is.null(additional_properties)) {
 | 
						|
        for (key in names(additional_properties)) {
 | 
						|
          self$additional_properties[[key]] <- additional_properties[[key]]
 | 
						|
        }
 | 
						|
      }
 | 
						|
    },
 | 
						|
 | 
						|
    #' @description
 | 
						|
    #' Convert to an R object. This method is deprecated. Use `toSimpleType()` instead.
 | 
						|
    toJSON = function() {
 | 
						|
      .Deprecated(new = "toSimpleType", msg = "Use the '$toSimpleType()' method instead since that is more clearly named. Use '$toJSONString()' to get a JSON string")
 | 
						|
      return(self$toSimpleType())
 | 
						|
    },
 | 
						|
 | 
						|
    #' @description
 | 
						|
    #' Convert to a List
 | 
						|
    #'
 | 
						|
    #' Convert the R6 object to a list to work more easily with other tooling.
 | 
						|
    #'
 | 
						|
    #' @return User as a base R list.
 | 
						|
    #' @examples
 | 
						|
    #' # convert array of User (x) to a data frame
 | 
						|
    #' \dontrun{
 | 
						|
    #' library(purrr)
 | 
						|
    #' library(tibble)
 | 
						|
    #' df <- x |> map(\(y)y$toList()) |> map(as_tibble) |> list_rbind()
 | 
						|
    #' df
 | 
						|
    #' }
 | 
						|
    toList = function() {
 | 
						|
      return(self$toSimpleType())
 | 
						|
    },
 | 
						|
 | 
						|
    #' @description
 | 
						|
    #' Convert User to a base R type
 | 
						|
    #'
 | 
						|
    #' @return A base R type, e.g. a list or numeric/character array.
 | 
						|
    toSimpleType = function() {
 | 
						|
      UserObject <- list()
 | 
						|
      if (!is.null(self$`id`)) {
 | 
						|
        UserObject[["id"]] <-
 | 
						|
          self$`id`
 | 
						|
      }
 | 
						|
      if (!is.null(self$`username`)) {
 | 
						|
        UserObject[["username"]] <-
 | 
						|
          self$`username`
 | 
						|
      }
 | 
						|
      if (!is.null(self$`firstName`)) {
 | 
						|
        UserObject[["firstName"]] <-
 | 
						|
          self$`firstName`
 | 
						|
      }
 | 
						|
      if (!is.null(self$`lastName`)) {
 | 
						|
        UserObject[["lastName"]] <-
 | 
						|
          self$`lastName`
 | 
						|
      }
 | 
						|
      if (!is.null(self$`email`)) {
 | 
						|
        UserObject[["email"]] <-
 | 
						|
          self$`email`
 | 
						|
      }
 | 
						|
      if (!is.null(self$`password`)) {
 | 
						|
        UserObject[["password"]] <-
 | 
						|
          self$`password`
 | 
						|
      }
 | 
						|
      if (!is.null(self$`phone`)) {
 | 
						|
        UserObject[["phone"]] <-
 | 
						|
          self$`phone`
 | 
						|
      }
 | 
						|
      if (!is.null(self$`userStatus`)) {
 | 
						|
        UserObject[["userStatus"]] <-
 | 
						|
          self$`userStatus`
 | 
						|
      }
 | 
						|
      for (key in names(self$additional_properties)) {
 | 
						|
        UserObject[[key]] <- self$additional_properties[[key]]
 | 
						|
      }
 | 
						|
 | 
						|
      return(UserObject)
 | 
						|
    },
 | 
						|
 | 
						|
    #' @description
 | 
						|
    #' Deserialize JSON string into an instance of User
 | 
						|
    #'
 | 
						|
    #' @param input_json the JSON input
 | 
						|
    #' @return the instance of User
 | 
						|
    fromJSON = function(input_json) {
 | 
						|
      this_object <- jsonlite::fromJSON(input_json)
 | 
						|
      if (!is.null(this_object$`id`)) {
 | 
						|
        self$`id` <- this_object$`id`
 | 
						|
      }
 | 
						|
      if (!is.null(this_object$`username`)) {
 | 
						|
        self$`username` <- this_object$`username`
 | 
						|
      }
 | 
						|
      if (!is.null(this_object$`firstName`)) {
 | 
						|
        self$`firstName` <- this_object$`firstName`
 | 
						|
      }
 | 
						|
      if (!is.null(this_object$`lastName`)) {
 | 
						|
        self$`lastName` <- this_object$`lastName`
 | 
						|
      }
 | 
						|
      if (!is.null(this_object$`email`)) {
 | 
						|
        self$`email` <- this_object$`email`
 | 
						|
      }
 | 
						|
      if (!is.null(this_object$`password`)) {
 | 
						|
        self$`password` <- this_object$`password`
 | 
						|
      }
 | 
						|
      if (!is.null(this_object$`phone`)) {
 | 
						|
        self$`phone` <- this_object$`phone`
 | 
						|
      }
 | 
						|
      if (!is.null(this_object$`userStatus`)) {
 | 
						|
        self$`userStatus` <- this_object$`userStatus`
 | 
						|
      }
 | 
						|
      # process additional properties/fields in the payload
 | 
						|
      for (key in names(this_object)) {
 | 
						|
        if (!(key %in% self$`_field_list`)) { # json key not in list of fields
 | 
						|
          self$additional_properties[[key]] <- this_object[[key]]
 | 
						|
        }
 | 
						|
      }
 | 
						|
 | 
						|
      self
 | 
						|
    },
 | 
						|
 | 
						|
    #' @description
 | 
						|
    #' To JSON String
 | 
						|
    #' 
 | 
						|
    #' @param ... Parameters passed to `jsonlite::toJSON`
 | 
						|
    #' @return User in JSON format
 | 
						|
    toJSONString = function(...) {
 | 
						|
      simple <- self$toSimpleType()
 | 
						|
      for (key in names(self$additional_properties)) {
 | 
						|
        simple[[key]] <- self$additional_properties[[key]]
 | 
						|
      }
 | 
						|
      json <- jsonlite::toJSON(simple, auto_unbox = TRUE, digits = NA, ...)
 | 
						|
      return(as.character(jsonlite::minify(json)))
 | 
						|
    },
 | 
						|
 | 
						|
    #' @description
 | 
						|
    #' Deserialize JSON string into an instance of User
 | 
						|
    #'
 | 
						|
    #' @param input_json the JSON input
 | 
						|
    #' @return the instance of User
 | 
						|
    fromJSONString = function(input_json) {
 | 
						|
      this_object <- jsonlite::fromJSON(input_json)
 | 
						|
      self$`id` <- this_object$`id`
 | 
						|
      self$`username` <- this_object$`username`
 | 
						|
      self$`firstName` <- this_object$`firstName`
 | 
						|
      self$`lastName` <- this_object$`lastName`
 | 
						|
      self$`email` <- this_object$`email`
 | 
						|
      self$`password` <- this_object$`password`
 | 
						|
      self$`phone` <- this_object$`phone`
 | 
						|
      self$`userStatus` <- this_object$`userStatus`
 | 
						|
      # process additional properties/fields in the payload
 | 
						|
      for (key in names(this_object)) {
 | 
						|
        if (!(key %in% self$`_field_list`)) { # json key not in list of fields
 | 
						|
          self$additional_properties[[key]] <- this_object[[key]]
 | 
						|
        }
 | 
						|
      }
 | 
						|
 | 
						|
      self
 | 
						|
    },
 | 
						|
 | 
						|
    #' @description
 | 
						|
    #' Validate JSON input with respect to User and throw an exception if invalid
 | 
						|
    #'
 | 
						|
    #' @param input the JSON input
 | 
						|
    validateJSON = function(input) {
 | 
						|
      input_json <- jsonlite::fromJSON(input)
 | 
						|
    },
 | 
						|
 | 
						|
    #' @description
 | 
						|
    #' To string (JSON format)
 | 
						|
    #'
 | 
						|
    #' @return String representation of User
 | 
						|
    toString = function() {
 | 
						|
      self$toJSONString()
 | 
						|
    },
 | 
						|
 | 
						|
    #' @description
 | 
						|
    #' Return true if the values in all fields are valid.
 | 
						|
    #'
 | 
						|
    #' @return true if the values in all fields are valid.
 | 
						|
    isValid = function() {
 | 
						|
      TRUE
 | 
						|
    },
 | 
						|
 | 
						|
    #' @description
 | 
						|
    #' Return a list of invalid fields (if any).
 | 
						|
    #'
 | 
						|
    #' @return A list of invalid fields (if any).
 | 
						|
    getInvalidFields = function() {
 | 
						|
      invalid_fields <- list()
 | 
						|
      invalid_fields
 | 
						|
    },
 | 
						|
 | 
						|
    #' @description
 | 
						|
    #' Print the object
 | 
						|
    print = function() {
 | 
						|
      print(jsonlite::prettify(self$toJSONString()))
 | 
						|
      invisible(self)
 | 
						|
    }
 | 
						|
  ),
 | 
						|
  # Lock the class to prevent modifications to the method or field
 | 
						|
  lock_class = TRUE
 | 
						|
)
 | 
						|
## Uncomment below to unlock the class to allow modifications of the method or field
 | 
						|
# User$unlock()
 | 
						|
#
 | 
						|
## Below is an example to define the print function
 | 
						|
# User$set("public", "print", function(...) {
 | 
						|
#   print(jsonlite::prettify(self$toJSONString()))
 | 
						|
#   invisible(self)
 | 
						|
# })
 | 
						|
## Uncomment below to lock the class to prevent modifications to the method or field
 | 
						|
# User$lock()
 | 
						|
 |