Skip to content

Commit

Permalink
Fix auto-generated R doc (#8584)
Browse files Browse the repository at this point in the history
* fix auto-generated R doc

* better example for enum value
  • Loading branch information
wing328 committed Feb 1, 2021
1 parent d36ce12 commit 6dee987
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,11 @@ public String constructExampleCode(CodegenProperty codegenProperty, HashMap<Stri
if (StringUtils.isEmpty(codegenProperty.example)) {
return "\"" + codegenProperty.example + "\"";
} else {
return "\"" + codegenProperty.name + "_example\"";
if (Boolean.TRUE.equals(codegenProperty.isEnum)) { // enum
return "\"" + String.valueOf(((List<Object>) codegenProperty.allowableValues.get("values")).get(0)) + "\"";
} else {
return "\"" + codegenProperty.name + "_example\"";
}
}
} else { // numeric
if (StringUtils.isEmpty(codegenProperty.example)) {
Expand All @@ -756,9 +760,16 @@ public String constructExampleCode(CodegenModel codegenModel, HashMap<String, Co
String example;
example = codegenModel.name + "$new(";
List<String> propertyExamples = new ArrayList<>();
for (CodegenProperty codegenProperty : codegenModel.vars) {
// required properties first
for (CodegenProperty codegenProperty : codegenModel.requiredVars) {
propertyExamples.add(constructExampleCode(codegenProperty, modelMaps));
}

// optional properties second
for (CodegenProperty codegenProperty : codegenModel.optionalVars) {
propertyExamples.add(constructExampleCode(codegenProperty, modelMaps));
}

example += StringUtils.join(propertyExamples, ", ");
example += ")";
return example;
Expand Down
6 changes: 3 additions & 3 deletions samples/client/petstore/R/docs/PetApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Add a new pet to the store
```R
library(petstore)

var.body <- Pet$new(123, Category$new(123, "name_example"), "name_example", list("photoUrls_example"), list(Tag$new(123, "name_example")), "status_example") # Pet | Pet object that needs to be added to the store
var.body <- Pet$new("name_example", list("photoUrls_example"), 123, Category$new(123, "name_example"), list(Tag$new(123, "name_example")), "available") # Pet | Pet object that needs to be added to the store

#Add a new pet to the store
api.instance <- PetApi$new()
Expand Down Expand Up @@ -111,7 +111,7 @@ Multiple status values can be provided with comma separated strings
```R
library(petstore)

var.status <- list("status_example") # array[character] | Status values that need to be considered for filter
var.status <- list("available") # array[character] | Status values that need to be considered for filter

#Finds Pets by status
api.instance <- PetApi$new()
Expand Down Expand Up @@ -248,7 +248,7 @@ Update an existing pet
```R
library(petstore)

var.body <- Pet$new(123, Category$new(123, "name_example"), "name_example", list("photoUrls_example"), list(Tag$new(123, "name_example")), "status_example") # Pet | Pet object that needs to be added to the store
var.body <- Pet$new("name_example", list("photoUrls_example"), 123, Category$new(123, "name_example"), list(Tag$new(123, "name_example")), "available") # Pet | Pet object that needs to be added to the store

#Update an existing pet
api.instance <- PetApi$new()
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/R/docs/StoreApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Place an order for a pet
```R
library(petstore)

var.body <- Order$new(123, 123, 123, "shipDate_example", "status_example", "complete_example") # Order | order placed for purchasing the pet
var.body <- Order$new(123, 123, 123, "shipDate_example", "placed", "complete_example") # Order | order placed for purchasing the pet

#Place an order for a pet
api.instance <- StoreApi$new()
Expand Down

0 comments on commit 6dee987

Please sign in to comment.