Skip to content

Commit

Permalink
Merge branch 'upstream_master' into feature/swift-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
4brunu committed Sep 26, 2024
2 parents 3a3b6a7 + 29c3b02 commit f72b9b0
Show file tree
Hide file tree
Showing 214 changed files with 15,888 additions and 6,265 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/samples-typescript-encode-decode.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: TypeScript Client (Encoding / Decoding Test)

on:
pull_request:
paths:
- samples/client/others/typescript/encode-decode/**
- .github/workflows/samples-typescript-encode-decode.yaml
jobs:
build:
name: Test TypeScript Encoding / Decoding
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sample:
# clients
- samples/client/others/typescript/encode-decode/test
node-version:
- 16
- 18
- 20
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Install
working-directory: ${{ matrix.sample }}
run: |
npm run preinstall
npm i
- name: Test
working-directory: ${{ matrix.sample }}
run: npm test
37 changes: 37 additions & 0 deletions .github/workflows/samples-typescript-node-encode-decode.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: TypeScript Node Client (Encoding / Decoding Test)

on:
pull_request:
paths:
- samples/client/others/typescript-node/encode-decode/**
- .github/workflows/samples-typescript-node-encode-decode.yaml
jobs:
build:
name: Test TypeScript Node Encoding / Decoding
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sample:
# clients
- samples/client/others/typescript-node/encode-decode/test
node-version:
- 16
- 18
- 20
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Install
working-directory: ${{ matrix.sample }}
run: |
npm run preinstall
npm i
- name: Test
working-directory: ${{ matrix.sample }}
run: npm test
11 changes: 11 additions & 0 deletions bin/configs/typescript-encode-decode.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
generatorName: typescript
outputDir: samples/client/others/typescript/encode-decode/build
inputSpec: modules/openapi-generator/src/test/resources/3_1/encode-decode.yaml
templateDir: modules/openapi-generator/src/main/resources/typescript
additionalProperties:
artifactId: encode-decode-typescript
hideGenerationTimestamp: "true"
npmVersion: 1.0.0
npmName: '@openapitools/typescript-encode-decode'
nullSafeAdditionalProps: true
platform: node
10 changes: 10 additions & 0 deletions bin/configs/typescript-node-encode-decode.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
generatorName: typescript-node
outputDir: samples/client/others/typescript-node/encode-decode/build
inputSpec: modules/openapi-generator/src/test/resources/3_1/encode-decode.yaml
templateDir: modules/openapi-generator/src/main/resources/typescript-node
additionalProperties:
artifactId: encode-decode-typescript-node
hideGenerationTimestamp: "true"
npmVersion: 1.0.0
npmName: '@openapitools/typescript-node-encode-decode'
nullSafeAdditionalProps: true
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ ApiResponse <- R6::R6Class(
status_code = NULL,
status_code_desc = NULL,
headers = NULL,
#' Initialize a new ApiResponse class.
#'

#' @description
#' Initialize a new ApiResponse class.
#'
Expand All @@ -27,7 +26,6 @@ ApiResponse <- R6::R6Class(
#' @param status_code The HTTP response status code.
#' @param status_code_desc The brief description of the HTTP response status code.
#' @param headers The HTTP response headers.
#' @export
initialize = function(content = NULL,
response = NULL,
status_code = NULL,
Expand All @@ -40,15 +38,13 @@ ApiResponse <- R6::R6Class(
self$headers <- headers
},

#' Return the response as text
#'

#' @description
#' The response is stored as a raw vector. Use this to access the response after
#' converting it to text. If the response is not coercible to text NA is returned.
#'
#' @param from_encoding The encoding of the raw response.
#' @param to_encoding The target encoding of the return value.
#' @export
response_as_text = function(from_encoding = "", to_encoding = "UTF-8") {
if (is.null(self$response)) {
self$response <- charToRaw(jsonlite::toJSON("NULL"))
Expand Down
87 changes: 5 additions & 82 deletions modules/openapi-generator/src/main/resources/r/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -6,79 +6,6 @@
#' @format An \code{R6Class} generator object
#' @field api_client Handles the client-server communication.
#'
#' @section Methods:
{{! Adding the below changes for generating documentation for the api methods. }}
#' \describe{
{{#operation}}
#' \strong{ {{operationId}} } \emph{ {{#lambdaRdocEscape}}{{summary}}{{/lambdaRdocEscape}} }
{{#notes}}
#' {{#lambdaRdocEscape}}{{{.}}}{{/lambdaRdocEscape}}
{{/notes}}
#'
#' \itemize{
{{#allParams}}
{{#isEnum}}
#' \item \emph{ @param } {{paramName}} Enum < {{#allowableValues}}{{values}}{{/allowableValues}} >
{{/isEnum}}
{{^isEnum}}
{{#isContainer}}
{{#isArray}}
{{#items}}
{{#isPrimitiveType}}
#' \item \emph{ @param } {{paramName}} list( {{dataType}} )
{{/isPrimitiveType}}
{{^isPrimitiveType}}
#' \item \emph{ @param } {{paramName}} list( \link{{=<% %>=}}{<%dataType%>}<%={{ }}=%> )
{{/isPrimitiveType}}
{{/items}}
{{/isArray}}
{{#isMap}}
{{#isPrimitiveType}}
#' \item \emph{ @param } {{paramName}} named list( {{dataType}} )
{{/isPrimitiveType}}
{{^isPrimitiveType}}
#' \item \emph{ @param } {{paramName}} named list( \link{{=<% %>=}}{<%dataType%>}<%={{ }}=%> )
{{/isPrimitiveType}}
{{/isMap}}
{{/isContainer}}
{{^isContainer}}
{{#isPrimitiveType}}
#' \item \emph{ @param } {{paramName}} {{dataType}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
#' \item \emph{ @param } {{paramName}} \link{{=<% %>=}}{<%dataType%>}<%={{ }}=%>
{{/isPrimitiveType}}
{{/isContainer}}
{{/isEnum}}
{{/allParams}}
{{#returnType}}
{{^returnTypeIsPrimitive}}
#' \item \emph{ @returnType } {{#returnContainer}}{{#isArray}}list( {{/isArray}}{{#isMap}}named list( {{/isMap}}{{/returnContainer}}\link{{=<% %>=}}{<%#returnContainer%><%={{ }}=%>{{returnBaseType}}{{/returnContainer}}{{^returnContainer}}{{returnType}}{{=<% %>=}}<%/returnContainer%>}<%={{ }}=%>{{#returnContainer}}{{#isArray}} ){{/isArray}}{{#isMap}} ){{/isMap}}{{/returnContainer}} \cr
{{/returnTypeIsPrimitive}}
{{/returnType}}
#'
{{#useRlangExceptionHandling}}
#' \item On encountering errors, an error of subclass ApiException will be thrown.
{{/useRlangExceptionHandling}}
#'
{{#responses}}
#' \item status code : {{code}} | {{{message}}}
#'
#'{{#dataType}} \item return type : {{{.}}}{{/dataType}}
#' \item response headers :
#'
#' \tabular{ll}{
{{#headers}}
#' {{name}} \tab {{{description}}} \cr
{{/headers}}
#' }
{{/responses}}
#' }
#'
{{/operation}}
#' }
#'
#'
#' @examples
#' \dontrun{
{{#operation}}
Expand Down Expand Up @@ -185,13 +112,11 @@
"{{classname}}",
public = list(
api_client = NULL,
#' Initialize a new {{{classname}}}.
#'
#' @description
#' Initialize a new {{{classname}}}.
#'
#' @param api_client An instance of API client.
#' @export
initialize = function(api_client) {
if (!missing(api_client)) {
self$api_client <- api_client
Expand All @@ -200,8 +125,7 @@
}
},
{{#operation}}
#' {{{summary}}}
#'
#' @description
#' {{{description}}}{{^description}}{{{summary}}}{{/description}}
#'
Expand All @@ -218,8 +142,8 @@
#' @param data_file (optional) name of the data file to save the result
{{/returnType}}
#' @param ... Other optional arguments
#'
#' @return {{{returnType}}}{{^returnType}}void{{/returnType}}
#' @export
{{{operationId}}} = function({{#requiredParams}}{{paramName}}, {{/requiredParams}}{{#optionalParams}}{{paramName}} = {{^defaultValue}}NULL{{/defaultValue}}{{{defaultValue}}}, {{/optionalParams}}{{#vendorExtensions.x-streaming}}stream_callback = NULL, {{/vendorExtensions.x-streaming}}{{#returnType}}data_file = NULL, {{/returnType}}...) {
local_var_response <- self${{{operationId}}}{{WithHttpInfo}}({{#allParams}}{{paramName}}, {{/allParams}}{{#vendorExtensions.x-streaming}}stream_callback = stream_callback, {{/vendorExtensions.x-streaming}}{{#returnType}}data_file = data_file, {{/returnType}}...)
{{#vendorExtensions.x-streaming}}
Expand All @@ -238,8 +162,7 @@
local_var_response
}
},
#' {{{summary}}}
#'
#' @description
#' {{{description}}}{{^description}}{{{summary}}}{{/description}}
#'
Expand All @@ -256,8 +179,8 @@
#' @param data_file (optional) name of the data file to save the result
{{/returnType}}
#' @param ... Other optional arguments
#'
#' @return API response ({{{returnType}}}{{^returnType}}void{{/returnType}}) with additional information such as HTTP status code, headers
#' @export
{{{operationId}}}{{WithHttpInfo}} = function({{#requiredParams}}{{paramName}}, {{/requiredParams}}{{#optionalParams}}{{paramName}} = {{^defaultValue}}NULL{{/defaultValue}}{{{defaultValue}}}, {{/optionalParams}}{{#vendorExtensions.x-streaming}}stream_callback = NULL, {{/vendorExtensions.x-streaming}}{{#returnType}}data_file = NULL, {{/returnType}}...) {
args <- list(...)
query_params <- list()
Expand Down
30 changes: 13 additions & 17 deletions modules/openapi-generator/src/main/resources/r/api_client.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ ApiClient <- R6::R6Class(
self$max_retry_attempts <- max_retry_attempts
}
},
#' Prepare to make an API call with the retry logic.
#'
#' @description
#' Prepare to make an API call with the retry logic.
#'
Expand All @@ -174,8 +173,8 @@ ApiClient <- R6::R6Class(
#' @param body The HTTP request body.
#' @param stream_callback Callback function to process the data stream
#' @param ... Other optional arguments.
#'
#' @return HTTP response
#' @export
CallApi = function(url, method, query_params, header_params, form_params,
file_params, accepts, content_types,
body, stream_callback = NULL, ...) {
Expand Down Expand Up @@ -205,8 +204,7 @@ ApiClient <- R6::R6Class(
resp
},
#' Make an API call
#'
#' @description
#' Make an API call
#'
Expand All @@ -221,8 +219,8 @@ ApiClient <- R6::R6Class(
#' @param body The HTTP request body.
#' @param stream_callback Callback function to process data stream
#' @param ... Other optional arguments.
#'
#' @return HTTP response
#' @export
Execute = function(url, method, query_params, header_params,
form_params, file_params,
accepts, content_types,
Expand Down Expand Up @@ -316,40 +314,39 @@ ApiClient <- R6::R6Class(
# return ApiResponse
api_response <- ApiResponse$new()
api_response$status_code <- httr::status_code(httr_response)
api_response$status_code <- httr::status_code(httr_response)
api_response$status_code_desc <- httr::http_status(httr_response)$reason
api_response$response <- httr::content(httr_response, "raw")
api_response$headers <- httr::headers(httr_response)
api_response
}
},
#' Deserialize the content of API response to the given type.
#'
#' @description
#' Deserialize the content of API response to the given type.
#'
#' @param raw_response Raw response.
#' @param return_type R return type.
#' @param pkg_env Package environment.
#'
#' @return Deserialized object.
#' @export
deserialize = function(raw_response, return_type, pkg_env) {
resp_obj <- jsonlite::fromJSON(raw_response)
self$deserializeObj(resp_obj, return_type, pkg_env)
},
#' Deserialize the response from jsonlite object based on the given type
#'
#' @description
#' Deserialize the response from jsonlite object based on the given type
#' by handling complex and nested types by iterating recursively
#' Example return_types will be like "array[integer]", "map(Pet)", "array[map(Tag)]", etc.,
#' Example return_types will be like "array[integer]", "map(Pet)",
#' "array[map(Tag)]", etc.,
#'
#' @param obj Response object.
#' @param return_type R return type.
#' @param pkg_env Package environment.
#'
#' @return Deserialized object.
#' @export
deserializeObj = function(obj, return_type, pkg_env) {
return_obj <- NULL
primitive_types <- c("character", "numeric", "integer", "logical", "complex")
Expand Down Expand Up @@ -411,15 +408,14 @@ ApiClient <- R6::R6Class(
}
return_obj
},
#' Return a property header (for accept or content-type).
#'

#' @description
#' Return a property header (for accept or content-type). If JSON-related MIME is found,
#' return it. Otherwise, return the first one, if any.
#'
#' @param headers A list of headers
#'
#' @return A header (e.g. 'application/json')
#' @export
select_header = function(headers) {
if (length(headers) == 0) {
return(invisible(NULL))
Expand Down
Loading

0 comments on commit f72b9b0

Please sign in to comment.