-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[R] Added ApiClient and fixed other issues (#6571)
* Added namespace mustache to be generated * Fixed syntax issues with package generation * Added Response and Element mustache templates * Added ApiClient * Fix: Only required parameters needed for api operations * Added documentation generated code * Regenerated petstore samples * Fixed url paths for operations * Fixed based on comments in issues #6520 * Regenerated petstore samples
- Loading branch information
Showing
19 changed files
with
1,207 additions
and
551 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 85 additions & 36 deletions
121
modules/swagger-codegen/src/main/resources/r/api.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
modules/swagger-codegen/src/main/resources/r/api_client.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{{>partial_header}} | ||
|
||
#' ApiClient Class | ||
#' | ||
#' Generic API client for Swagger client library builds. | ||
#' Swagger generic API client. This client handles the client- | ||
#' server communication, and is invariant across implementations. Specifics of | ||
#' the methods and models for each application are generated from the Swagger | ||
#' templates. | ||
#' | ||
#' NOTE: This class is auto generated by the swagger code generator program. | ||
#' Ref: https://github.com/swagger-api/swagger-codegen | ||
#' Do not edit the class manually. | ||
#' | ||
#' @export | ||
ApiClient <- R6::R6Class( | ||
'ApiClient', | ||
public = list( | ||
basePath = "{{{basePath}}}", | ||
configuration = NULL, | ||
userAgent = NULL, | ||
defaultHeaders = NULL, | ||
initialize = function(basePath, configuration, defaultHeaders){ | ||
if (!missing(basePath)) { | ||
self$basePath <- basePath | ||
} | ||
|
||
if (!missing(configuration)) { | ||
self$configuration <- configuration | ||
} | ||
|
||
if (!missing(defaultHeaders)) { | ||
self$defaultHeaders <- defaultHeaders | ||
} | ||
|
||
self$`userAgent` <- '{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}Swagger-Codegen/{{{packageVersion}}}/r{{/httpUserAgent}}' | ||
}, | ||
callApi = function(url, method, queryParams, headerParams, body, ...){ | ||
headers <- httr::add_headers(headerParams) | ||
|
||
if (method == "GET") { | ||
httr::GET(url, queryParams, headers, ...) | ||
} | ||
else if (method == "POST") { | ||
httr::POST(url, queryParams, headers, body = body, ...) | ||
} | ||
else if (method == "PUT") { | ||
httr::PUT(url, queryParams, headers, body = body, ...) | ||
} | ||
else if (method == "PATCH") { | ||
httr::PATCH(url, queryParams, headers, body = body, ...) | ||
} | ||
else if (method == "HEAD") { | ||
httr::HEAD(url, queryParams, headers, ...) | ||
} | ||
else if (method == "DELETE") { | ||
httr::DELETE(url, queryParams, headers, ...) | ||
} | ||
else { | ||
stop("http method must be `GET`, `HEAD`, `OPTIONS`, `POST`, `PATCH`, `PUT` or `DELETE`.") | ||
} | ||
} | ||
) | ||
) |
24 changes: 24 additions & 0 deletions
24
modules/swagger-codegen/src/main/resources/r/element.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#' Element Class | ||
#' | ||
#' Element Class | ||
#' @export | ||
Element <- R6::R6Class( | ||
'Element', | ||
public = list( | ||
id = NULL, | ||
name = NULL, | ||
initialize = function(id,name){ | ||
if (!missing(id)) { | ||
stopifnot(is.numeric(id), length(id) == 1) | ||
self$id <- id | ||
} | ||
if (!missing(name)) { | ||
stopifnot(is.character(name), length(name) == 1) | ||
self$name <- name | ||
} | ||
}, | ||
toJSON = function() { | ||
sprintf('{"id":%d,"name":"%s"}', self$id, self$name) | ||
} | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.