diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java index 1e24fc3ad52..dc8cc74432b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java @@ -17,6 +17,10 @@ package org.openapitools.codegen.languages; +import com.samskivert.mustache.Mustache.Lambda; +import com.samskivert.mustache.Mustache; +import com.samskivert.mustache.Template; + import io.swagger.v3.oas.models.examples.Example; import io.swagger.v3.oas.models.media.ArraySchema; import io.swagger.v3.oas.models.media.Schema; @@ -33,6 +37,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; +import java.io.IOException; +import java.io.Writer; import java.util.*; import java.util.regex.Pattern; @@ -232,6 +238,17 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig { supportingFiles.add(new SupportingFile("api_client.mustache", File.separator + "R", "api_client.R")); supportingFiles.add(new SupportingFile("NAMESPACE.mustache", "", "NAMESPACE")); supportingFiles.add(new SupportingFile("testthat.mustache", File.separator + "tests", "testthat.R")); + + // add lambda for mustache templates to fix license field + additionalProperties.put("lambdaLicense", new Mustache.Lambda() { + @Override + public void execute(Template.Fragment fragment, Writer writer) throws IOException { + String content = fragment.execute(); + content = content.trim().replace("Apache-2.0", "Apache License 2.0"); + writer.write(content); + } + }); + } @Override diff --git a/modules/openapi-generator/src/main/resources/r/description.mustache b/modules/openapi-generator/src/main/resources/r/description.mustache index d3ca9069c5f..2bafa3c15fe 100644 --- a/modules/openapi-generator/src/main/resources/r/description.mustache +++ b/modules/openapi-generator/src/main/resources/r/description.mustache @@ -1,13 +1,14 @@ Package: {{{packageName}}} Title: R Package Client for {{{appName}}} Version: {{packageVersion}} -Authors@R: person("{{infoName}}{{^infoName}}OpenAPI Generator community{{/infoName}}", email = "{{infoEmail}}{{^infoEmail}}team@openapitools.org{{/infoEmail}}", role = c("aut", "cre")) +Author: person("{{infoName}}{{^infoName}}OpenAPI Generator community{{/infoName}}", email = "{{infoEmail}}{{^infoEmail}}team@openapitools.org{{/infoEmail}}", role = c("aut", "cre")) +Maintainer: {{infoName}}{{^infoName}}OpenAPI Generator community{{/infoName}} <{{infoEmail}}{{^infoEmail}}team@openapitools.org{{/infoEmail}}> Description: {{{appDescription}}}{{^appDescription}}R Package Client for {{{appName}}}{{/appDescription}} URL: https://{{{gitHost}}}/{{{gitUserId}}}/{{{gitRepoId}}} BugReports: https://{{{gitHost}}}/{{{gitUserId}}}/{{{gitRepoId}}}/issues Depends: R (>= 3.3) Encoding: UTF-8 -License: {{licenseInfo}}{{^licenseInfo}}Unlicense{{/licenseInfo}} +License: {{#lambdaLicense}}{{licenseInfo}}{{/lambdaLicense}}{{^licenseInfo}}Unlicense{{/licenseInfo}} LazyData: true Suggests: testthat Imports: jsonlite, httr, R6, base64enc{{#useRlangExceptionHandling}}, rlang{{/useRlangExceptionHandling}} diff --git a/modules/openapi-generator/src/main/resources/r/testthat.mustache b/modules/openapi-generator/src/main/resources/r/testthat.mustache index 613dc9c4152..c6770a46d18 100644 --- a/modules/openapi-generator/src/main/resources/r/testthat.mustache +++ b/modules/openapi-generator/src/main/resources/r/testthat.mustache @@ -1,5 +1,4 @@ library(testthat) -library(rjson) library({{{packageName}}}) test_check("{{{packageName}}}") diff --git a/samples/client/petstore/R/DESCRIPTION b/samples/client/petstore/R/DESCRIPTION index 985a6e7b131..6293ab707f3 100644 --- a/samples/client/petstore/R/DESCRIPTION +++ b/samples/client/petstore/R/DESCRIPTION @@ -1,13 +1,14 @@ Package: petstore Title: R Package Client for OpenAPI Petstore Version: 1.0.0 -Authors@R: person("OpenAPI Generator community", email = "team@openapitools.org", role = c("aut", "cre")) +Author: person("OpenAPI Generator community", email = "team@openapitools.org", role = c("aut", "cre")) +Maintainer: OpenAPI Generator community Description: This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. URL: https://github.com/GIT_USER_ID/GIT_REPO_ID BugReports: https://github.com/GIT_USER_ID/GIT_REPO_ID/issues Depends: R (>= 3.3) Encoding: UTF-8 -License: Apache-2.0 +License: Apache License 2.0 LazyData: true Suggests: testthat Imports: jsonlite, httr, R6, base64enc diff --git a/samples/client/petstore/R/tests/testthat.R b/samples/client/petstore/R/tests/testthat.R index e27ee491ed1..d67bd9cf238 100644 --- a/samples/client/petstore/R/tests/testthat.R +++ b/samples/client/petstore/R/tests/testthat.R @@ -1,5 +1,4 @@ library(testthat) -library(rjson) library(petstore) test_check("petstore") diff --git a/samples/client/petstore/R/tests/testthat/test_petstore.R b/samples/client/petstore/R/tests/testthat/test_petstore.R index 4fed54b44ab..6e7cde566e1 100644 --- a/samples/client/petstore/R/tests/testthat/test_petstore.R +++ b/samples/client/petstore/R/tests/testthat/test_petstore.R @@ -94,7 +94,7 @@ test_that("GetPetById", { test_that("GetPetById with data_file", { # test to ensure json is saved to the file `get_pet_by_id.json` petResponse <- petApi$GetPetById(petId, data_file="get_pet_by_id.json") - response <- fromJSON(file = "get_pet_by_id.json") + response <- read_json("get_pet_by_id.json") expect_true(!is.null(response)) expect_equal(response$id, petId) expect_equal(response$name, "name_test")