-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[R] Added ApiClient and fixed other issues #6571
Merged
wing328
merged 10 commits into
swagger-api:master
from
brnleehng:fix/r-mustache-templates
Oct 4, 2017
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0feb55b
Added namespace mustache to be generated
brnleehng 9424d5c
Fixed syntax issues with package generation
brnleehng 5d06622
Added Response and Element mustache templates
brnleehng 3ac741a
Added ApiClient
brnleehng 2f5e03e
Fix: Only required parameters needed for api operations
brnleehng 20cc32c
Added documentation generated code
brnleehng 792386c
Regenerated petstore samples
brnleehng eccbe1b
Fixed url paths for operations
brnleehng d0e5399
Fixed based on comments in issues #6520
brnleehng 79025bd
Regenerated petstore samples
brnleehng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
110 changes: 74 additions & 36 deletions
110
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`.") | ||
} | ||
} | ||
) | ||
) |
2 changes: 1 addition & 1 deletion
2
modules/swagger-codegen/src/main/resources/r/description.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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brnleehng thanks for the PR. Does it mean developers (users of the SDK) can no longer use a different base path during runtime when constructing the class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah please ignore my question. You've moved "basePath" to apiClient.