[R] fix warnings in DESCRIPTION (#12380)

* fix warnings in description

* fix maintainer

* update test with jsonlite method instead
This commit is contained in:
William Cheng 2022-05-17 13:25:16 +08:00 committed by GitHub
parent 3e3a527fc2
commit 1b7b4ede44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 7 deletions

View File

@ -17,6 +17,10 @@
package org.openapitools.codegen.languages; 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.examples.Example;
import io.swagger.v3.oas.models.media.ArraySchema; import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.media.Schema; import io.swagger.v3.oas.models.media.Schema;
@ -33,6 +37,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.util.*; import java.util.*;
import java.util.regex.Pattern; 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("api_client.mustache", File.separator + "R", "api_client.R"));
supportingFiles.add(new SupportingFile("NAMESPACE.mustache", "", "NAMESPACE")); supportingFiles.add(new SupportingFile("NAMESPACE.mustache", "", "NAMESPACE"));
supportingFiles.add(new SupportingFile("testthat.mustache", File.separator + "tests", "testthat.R")); 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 @Override

View File

@ -1,13 +1,14 @@
Package: {{{packageName}}} Package: {{{packageName}}}
Title: R Package Client for {{{appName}}} Title: R Package Client for {{{appName}}}
Version: {{packageVersion}} 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}} Description: {{{appDescription}}}{{^appDescription}}R Package Client for {{{appName}}}{{/appDescription}}
URL: https://{{{gitHost}}}/{{{gitUserId}}}/{{{gitRepoId}}} URL: https://{{{gitHost}}}/{{{gitUserId}}}/{{{gitRepoId}}}
BugReports: https://{{{gitHost}}}/{{{gitUserId}}}/{{{gitRepoId}}}/issues BugReports: https://{{{gitHost}}}/{{{gitUserId}}}/{{{gitRepoId}}}/issues
Depends: R (>= 3.3) Depends: R (>= 3.3)
Encoding: UTF-8 Encoding: UTF-8
License: {{licenseInfo}}{{^licenseInfo}}Unlicense{{/licenseInfo}} License: {{#lambdaLicense}}{{licenseInfo}}{{/lambdaLicense}}{{^licenseInfo}}Unlicense{{/licenseInfo}}
LazyData: true LazyData: true
Suggests: testthat Suggests: testthat
Imports: jsonlite, httr, R6, base64enc{{#useRlangExceptionHandling}}, rlang{{/useRlangExceptionHandling}} Imports: jsonlite, httr, R6, base64enc{{#useRlangExceptionHandling}}, rlang{{/useRlangExceptionHandling}}

View File

@ -1,5 +1,4 @@
library(testthat) library(testthat)
library(rjson)
library({{{packageName}}}) library({{{packageName}}})
test_check("{{{packageName}}}") test_check("{{{packageName}}}")

View File

@ -1,13 +1,14 @@
Package: petstore Package: petstore
Title: R Package Client for OpenAPI Petstore Title: R Package Client for OpenAPI Petstore
Version: 1.0.0 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 <team@openapitools.org>
Description: This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. 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 URL: https://github.com/GIT_USER_ID/GIT_REPO_ID
BugReports: https://github.com/GIT_USER_ID/GIT_REPO_ID/issues BugReports: https://github.com/GIT_USER_ID/GIT_REPO_ID/issues
Depends: R (>= 3.3) Depends: R (>= 3.3)
Encoding: UTF-8 Encoding: UTF-8
License: Apache-2.0 License: Apache License 2.0
LazyData: true LazyData: true
Suggests: testthat Suggests: testthat
Imports: jsonlite, httr, R6, base64enc Imports: jsonlite, httr, R6, base64enc

View File

@ -1,5 +1,4 @@
library(testthat) library(testthat)
library(rjson)
library(petstore) library(petstore)
test_check("petstore") test_check("petstore")

View File

@ -94,7 +94,7 @@ test_that("GetPetById", {
test_that("GetPetById with data_file", { test_that("GetPetById with data_file", {
# test to ensure json is saved to the file `get_pet_by_id.json` # 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") 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_true(!is.null(response))
expect_equal(response$id, petId) expect_equal(response$id, petId)
expect_equal(response$name, "name_test") expect_equal(response$name, "name_test")