OpenAPITools / OpenAPITools/openapi-generator
[BUG][R] model properties cannot use reserved words self, super, private, initialize as names
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Generating the R client for a spec that has a model with property named one of self, private, or super creates code with runtime errors.
> devtools::load_all(".")
ℹ Loading openapi
Error in R6::R6Class("MyObject", public = list(public = NULL, private = NULL, :
Items cannot use reserved names 'self', 'private', and 'super'.
11. stop("Items cannot use reserved names 'self', 'private', and 'super'.")
10. R6::R6Class("MyObject", public = list(public = NULL, private = NULL,
self = NULL, initialize = function(public = NULL, private = NULL,
self = NULL, ...) {
local.optional.var <- list(...) ... at my_object.R#25
9. eval(exprs[i], envir)
8. eval(exprs[i], envir)
7. source_one(file, encoding, envir = envir)
6. source_many(paths, encoding, env)
5. force(code)
4. withr_with_dir(path, source_many(paths, encoding, env))
3. load_code(path)
2. pkgload::load_all(path = path, reset = reset, recompile = recompile,
export_all = export_all, helpers = helpers, quiet = quiet,
...)
1. devtools::load_all(".")
Additionally, using initialize will cause a different error:
Error in R6::R6Class("MyObject", public = list(initialize = NULL, initialize = function(initialize = NULL, :
All items in public, private, and active must have unique names.
In the R6 OO system, self, private, and super are used to access public members / private members / superclass methods. initialize is the class initializer.
https://r6.r-lib.org/articles/Introduction.html#fields-containing-reference-objects-1
openapi-generator version
I am using openapi-generator 5.1.1.
OpenAPI declaration file content or url
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
Generation Details
openapi-generator generate -i spec.yaml -g r -o rtest
Steps to reproduce
Prereq: R and RStudio installed
- Open RStudio
- Open project, navigate to
rtestoutput directory. This will create an .Rproj file inrtest. - In the RStudio Console, run
devtools::load_all()to load the library.
Related issues/PRs
Suggest a fix
- adding
initialize,super,private, andselfas reserved keywords - using the reserved keywords mapping specifically when generating R6 class item names from OAS model properties.
I've created a gist with a generated model file that is broken as well as what I think the expected file should look like.
I'm guessing this means changes to all of the model* templates.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by generating the R client with the supplied spec.yaml and the openapi-generator generate -i spec.yaml -g r -o rtest command, then inspect the generated model file and the model* templates mentioned in the issue. The work is done when models with self, private, super, and initialize properties load without R6 runtime errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100