Skip to content

Instantly share code, notes, and snippets.

@ahjota
Last active June 15, 2021 18:46
Show Gist options
  • Save ahjota/e0451393cf469a2aef06350db7ee29be to your computer and use it in GitHub Desktop.
Save ahjota/e0451393cf469a2aef06350db7ee29be to your computer and use it in GitHub Desktop.
OpenAPI-generated R client with errors related to self as a model property name
# R reserved words bug example
#
# No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
#
# The version of the OpenAPI document: 0.0.1
#
# Generated by: https://openapi-generator.tech
#' @docType class
#' @title MyObject
#'
#' @description MyObject Class
#'
#' @format An \code{R6Class} generator object
#'
#' @field self character [optional]
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
MyObject <- R6::R6Class(
'MyObject',
public = list(
`self` = NULL,
initialize = function(
`self`=NULL, ...
) {
local.optional.var <- list(...)
if (!is.null(`self`)) {
stopifnot(is.character(`self`), length(`self`) == 1)
self$`self` <- `self`
}
},
toJSON = function() {
MyObjectObject <- list()
if (!is.null(self$`self`)) {
MyObjectObject[['self']] <-
self$`self`
}
MyObjectObject
},
fromJSON = function(MyObjectJson) {
MyObjectObject <- jsonlite::fromJSON(MyObjectJson)
if (!is.null(MyObjectObject$`self`)) {
self$`self` <- MyObjectObject$`self`
}
self
},
toJSONString = function() {
jsoncontent <- c(
if (!is.null(self$`self`)) {
sprintf(
'"self":
"%s"
',
self$`self`
)}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
paste('{', jsoncontent, '}', sep = "")
},
fromJSONString = function(MyObjectJson) {
MyObjectObject <- jsonlite::fromJSON(MyObjectJson)
self$`self` <- MyObjectObject$`self`
self
}
)
)
# R reserved words bug example
#
# No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
#
# The version of the OpenAPI document: 0.0.1
#
# Generated by: https://openapi-generator.tech
#' @docType class
#' @title MyObject
#'
#' @description MyObject Class
#'
#' @format An \code{R6Class} generator object
#'
#' @field self_ character [optional]
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
MyObject <- R6::R6Class(
'MyObject',
public = list(
`self_` = NULL,
initialize = function(
`self_`=NULL, ...
) {
local.optional.var <- list(...)
if (!is.null(`self_`)) {
stopifnot(is.character(`self_`), length(`self_`) == 1)
self$`self_` <- `self_`
}
},
toJSON = function() {
MyObjectObject <- list()
if (!is.null(self$`self_`)) {
MyObjectObject[['self']] <-
self$`self_`
}
MyObjectObject
},
fromJSON = function(MyObjectJson) {
MyObjectObject <- jsonlite::fromJSON(MyObjectJson)
if (!is.null(MyObjectObject$`self`)) {
self$`self_` <- MyObjectObject$`self`
}
self
},
toJSONString = function() {
jsoncontent <- c(
if (!is.null(self$`self_`)) {
sprintf(
'"self":
"%s"
',
self$`self_`
)}
)
jsoncontent <- paste(jsoncontent, collapse = ",")
paste('{', jsoncontent, '}', sep = "")
},
fromJSONString = function(MyObjectJson) {
MyObjectObject <- jsonlite::fromJSON(MyObjectJson)
self$`self_` <- MyObjectObject$`self`
self
}
)
)
openapi: 3.0.3
info:
title: R reserved words bug example
version: 0.0.1
paths:
/example:
post:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/MyObject'
responses:
'200':
description: OK
components:
schemas:
MyObject:
properties:
self:
type: string
type: object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment