OpenAPITools / OpenAPITools/openapi-generator

[BUG] [R] Initialize validation/check of an enum parameter

Open
#17,976 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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

Summary: Initialize validation/check of an enum parameter in the outer R6 class against an empty vector.

In the example below:

  • The outer component contains a kind property of type my_enum
  • The my_enum component has two enum cases x and y
  • The initialize function of outer checks kind with respect to the empty vector c(), hence this condition is always false:
  initialize = function(`kind`, ...) {
      if (!missing(`kind`)) {
        if (!(`kind` %in% c())) {
          stop(paste("Error! \"", `kind`, "\" cannot be assigned to `kind`. Must be .", sep = ""))
        }
        stopifnot(R6::is.R6(`kind`))
        self$`kind` <- `kind`
      }
    },
openapi-generator version

7.4.0-SNAPSHOT (via docker openapitools/openapi-generator-cli:latest)

OpenAPI declaration file content or url
{
  "openapi": "3.0.3",
  "info": {
    "title": "test",
    "version": "1.0.0"
  },
  "paths":{
  },
  "components": {
    "schemas": {
      "outer": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "kind"
        ],
        "properties": {
          "kind": {
            "$ref": "#/components/schemas/my_enum"
          }
        }
      },
      "my_enum": {
        "type": "string",
        "enum": [
          "x",
          "y"
        ]
      }
    }
  }
}
Generation Details
Steps to reproduce
docker run --user 1000:1000 --rm -v /tmp/test:/test openapitools/openapi-generator-cli:latest generate --global-property models -i /test/test.json -g r -o /test
Related issues/PRs

Possibly related to (but not sure):

Suggest a fix

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the generated R models with the provided OpenAPI declaration and Docker command, focusing on the outer R6 class's initialize function. Compare its enum validation for the referenced my_enum property with the declared x and y cases; done means the generated validation no longer checks against an empty vector and accepts valid enum values while rejecting invalid ones.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.