openapi-generator
openapi-generator copied to clipboard
[BUG] [R] Initialize validation/check of an enum parameter
Bug Report Checklist
- [x] Have you provided a full/minimal spec to reproduce the issue?
- [x] Have you validated the input using an OpenAPI validator (example)?
- [x] Have you tested with the latest master to confirm the issue still exists?
- [x] Have you searched for related issues/PRs?
- [x] 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
outercomponent contains akindproperty of typemy_enum - The my_enum component has two enum cases
xandy - The initialize function of
outercheckskindwith respect to the empty vectorc(), 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):
- https://github.com/OpenAPITools/openapi-generator/issues/13469
Suggest a fix
Hi, from the first looks of it, shouldn`t your enum be defined as
"my_enum": {
"type": "array",
"enum": [
"x",
"y"
]
}
instead of having type "string"?
@joXemMx
Looking at this, for example, we see, at the bottom of the page, that the enum Color is of type string:
components:
schemas:
Color:
type: string
enum:
- black
- white
- red
- green
- blue