R/category.R

# OpenAPI Petstore
#
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
#
# The version of the OpenAPI document: 1.0.0
# Generated by: https://openapi-generator.tech

#' @docType class
#' @title Category
#'
#' @description Category Class
#'
#' @format An \code{R6Class} generator object
#'
#' @field id  integer [optional]
#'
#' @field name  character [optional]
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
Category <- R6::R6Class(
  'Category',
  public = list(
    `id` = NULL,
    `name` = NULL,
    initialize = function(
        `id`=NULL, `name`=NULL, ...
    ) {
      local.optional.var <- list(...)
      if (!is.null(`id`)) {
        stopifnot(is.numeric(`id`), length(`id`) == 1)
        self$`id` <- `id`
      }
      if (!is.null(`name`)) {
        stopifnot(is.character(`name`), length(`name`) == 1)
        self$`name` <- `name`
      }
    },
    toJSON = function() {
      CategoryObject <- list()
      if (!is.null(self$`id`)) {
        CategoryObject[['id']] <-
          self$`id`
      }
      if (!is.null(self$`name`)) {
        CategoryObject[['name']] <-
          self$`name`
      }

      CategoryObject
    },
    fromJSON = function(CategoryJson) {
      CategoryObject <- jsonlite::fromJSON(CategoryJson)
      if (!is.null(CategoryObject$`id`)) {
        self$`id` <- CategoryObject$`id`
      }
      if (!is.null(CategoryObject$`name`)) {
        self$`name` <- CategoryObject$`name`
      }
      self
    },
    toJSONString = function() {
      jsoncontent <- c(
        if (!is.null(self$`id`)) {
        sprintf(
        '"id":
          %d
                ',
        self$`id`
        )},
        if (!is.null(self$`name`)) {
        sprintf(
        '"name":
          "%s"
                ',
        self$`name`
        )}
      )
      jsoncontent <- paste(jsoncontent, collapse = ",")
      paste('{', jsoncontent, '}', sep = "")
    },
    fromJSONString = function(CategoryJson) {
      CategoryObject <- jsonlite::fromJSON(CategoryJson)
      self$`id` <- CategoryObject$`id`
      self$`name` <- CategoryObject$`name`
      self
    }
  )
)
wing328/petstore-r-client documentation built on June 2, 2022, 10:24 a.m.