swagger-api / swagger-api/swagger-codegen
[R] enum definitions are not usable
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Defined enums generate an empty class. This type is then enforced for methods and other models, making it unusable.
Swagger-codegen version
swagger-codegen-cli-2.4.0-20180821.200234-311
Swagger declaration file content or url
swagger: "2.0"
info:
description: ""
title: "repro"
version: "1"
paths:
/pet:
post:
tags:
- "pet"
summary: "Add a new pet to the store"
description: ""
operationId: "addPet"
parameters:
- in: "body"
name: "body"
description: "Pet object that needs to be added to the store"
required: true
schema:
$ref: "#/definitions/Pet"
responses:
200:
description: ""
definitions:
Pet:
type: "object"
properties:
status:
$ref: "#/definitions/PetStatus"
PetStatus:
enum: [available, pending, sold]
Command line used for generation
java -jar swagger-codegen-cli-2.4.0-20180821.200234-311.jar generate --lang r -i swagger.yaml
Steps to reproduce
Try to create a new Pet using a PetStatus, cannot use enum values.
Pet$new("pending")
-> fails with wrong type
PetStatus is not usable as the generated class looks like this:
PetStatus <- R6::R6Class(
'PetStatus',
public = list(
initialize = function(){
},
toJSON = function() {
PetStatusObject <- list()
PetStatusObject
},
fromJSON = function(PetStatusJson) {
PetStatusObject <- jsonlite::fromJSON(PetStatusJson)
},
toJSONString = function() {
sprintf(
'{
}',
)
},
fromJSONString = function(PetStatusJson) {
PetStatusObject <- jsonlite::fromJSON(PetStatusJson)
}
)
)
Suggest a fix/enhancement
- Type enums (by reference) as strings.
- or, generate enum values in the enum definition models
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 reproducing the issue with the provided Swagger declaration and the java -jar swagger-codegen-cli-2.4.0-20180821.200234-311.jar generate --lang r command. Inspect the generated PetStatus and Pet R6 classes and the R generator templates; done means enum values can be passed to Pet$new and serialized correctly without the wrong-type failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100