Skip to content

Commit

Permalink
feat(r): saving changes for reference
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramanth committed Jun 10, 2019
1 parent 75189aa commit 0d091b5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bin/windows/r-petstore.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ If Not Exist %executable% (
)

REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g r -o samples\client\petstore\R --additional-properties packageName=petstore
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g r -o samples\client\petstore\R --additional-properties=packageName=petstore,backwardCompatible=true

java %JAVA_OPTS% -jar %executable% %ags%
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
protected String modelDocPath = "docs/";
protected String testFolder = "tests/testthat";

protected boolean backwardCompatible = Boolean.TRUE;
public static final String BACKWARD_COMPATIBLE = "backwardCompatible";

public CodegenType getTag() {
return CodegenType.CLIENT;
}
Expand Down Expand Up @@ -115,6 +118,9 @@ public RClientCodegen() {
cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP, CodegenConstants.HIDE_GENERATION_TIMESTAMP_DESC)
.defaultValue(Boolean.TRUE.toString()));

cliOptions.add(new CliOption(BACKWARD_COMPATIBLE, "Set to true if backward compatibility is required, which doesn't provide some new features.")
.defaultValue(Boolean.TRUE.toString()));

}

@Override
Expand All @@ -132,9 +138,16 @@ public void processOpts() {
} else {
setPackageVersion("1.0.0");
}

if (additionalProperties.containsKey(BACKWARD_COMPATIBLE)) {
this.backwardCompatible = convertPropertyToBooleanAndWriteBack(BACKWARD_COMPATIBLE);
} else {
additionalProperties.put(BACKWARD_COMPATIBLE, backwardCompatible);
}

additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
additionalProperties.put(CodegenConstants.PACKAGE_VERSION, packageVersion);


additionalProperties.put("apiDocPath", apiDocPath);
additionalProperties.put("modelDocPath", modelDocPath);
Expand All @@ -159,6 +172,7 @@ public void processOpts() {
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"));
supportingFiles.add(new SupportingFile("test.mustache","","test.R"));
}

@Override
Expand Down
7 changes: 6 additions & 1 deletion modules/openapi-generator/src/main/resources/r/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,19 @@
{{{operationId}}} = function({{#requiredParams}}{{paramName}}, {{/requiredParams}}{{#optionalParams}}{{paramName}}={{^defaultValue}}NULL{{/defaultValue}}{{#defaultValue}}{{{.}}}{{/defaultValue}}, {{/optionalParams}}...){
apiResponse <- self${{{operationId}}}WithHttpInfo({{#requiredParams}}{{paramName}}, {{/requiredParams}}{{#optionalParams}}{{paramName}}={{^defaultValue}}NULL{{/defaultValue}}{{#defaultValue}}{{{.}}}{{/defaultValue}}, {{/optionalParams}}...)
resp <- apiResponse$response
{{#backwardCompatible}}
resp <- apiResponse$response
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
apiResponse$content
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
apiResponse
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
apiResponse
}
{{/backwardCompatible}}
{{^backwardCompatible}}
apiResponse
{{/backwardCompatible}}
}{{#hasMore}},{{/hasMore}}
{{/operation}}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{backwardCompatible}}
Empty file.

0 comments on commit 0d091b5

Please sign in to comment.