Skip to content
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

[BUG] [R] Code generated needs a 'raw2Char' translation before JSON deparsing #6767

Open
4 of 6 tasks
eddelbuettel opened this issue Jun 24, 2020 · 4 comments
Open
4 of 6 tasks

Comments

@eddelbuettel
Copy link
Contributor

eddelbuettel commented Jun 24, 2020

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

This is a follow-up to #6714 which (most helpfully, thanks again!) directed us to PR #5728 with which we can generate working R code from our YAML spec. But running the code ends in a runtime error e.g. from here for the access I tried:

        deserializedRespObj <- tryCatch(
          self$apiClient$deserialize(resp, "ArraySchema", loadNamespace("openapi")),
          error = function(e){
             stop("Failed to deserialize response")
          }
          # more code here...

because resp$content is a raw character vector which needs rawToChar(). I injected a step to save the (R-serialized) response object for the simple call.

R> res <- readRDS("~/git/tiledb-cloud-r-prototyping/rest-client-r-openapi-pr5728/quickstart_dense_reponse.rds")
R> names(res)
 [1] "url"         "status_code" "headers"     "all_headers" "cookies"     "content"     "date"        "times"       "request"     "handle"     
R> class(res$content)
[1] "raw"
R> jsonlite::fromJSON(res$content)
Error: Argument 'txt' must be a JSON string, URL or file.
R> str(jsonlite::fromJSON( rawToChar(res$content) ))
List of 11
 $ arrayType           : chr "dense"
 $ attributes          :'data.frame':	1 obs. of  4 variables:
  ..$ cellValNum    : int 1
  ..$ name          : chr "a"
  ..$ type          : chr "INT32"
  ..$ filterPipeline:'data.frame':	1 obs. of  0 variables
 $ capacity            : chr "10000"
 $ cellOrder           : chr "row-major"
 $ coordsFilterPipeline:List of 1
  ..$ filters:'data.frame':	1 obs. of  2 variables:
  .. ..$ type: chr "ZSTD"
  .. ..$ data:'data.frame':	1 obs. of  1 variable:
  .. .. ..$ int32: int -1
 $ domain              :List of 4
  ..$ cellOrder : chr "row-major"
  ..$ dimensions:'data.frame':	2 obs. of  6 variables:
  .. ..$ name          : chr [1:2] "rows" "cols"
  .. ..$ nullTileExtent: logi [1:2] FALSE FALSE
  .. ..$ type          : chr [1:2] "INT32" "INT32"
  .. ..$ tileExtent    :'data.frame':	2 obs. of  1 variable:
  .. .. ..$ int32: int [1:2] 4 4
  .. ..$ domain        :'data.frame':	2 obs. of  1 variable:
  .. .. ..$ int32:List of 2
  .. .. .. ..$ : int [1:2] 1 4
  .. .. .. ..$ : int [1:2] 1 4
  .. ..$ filterPipeline:'data.frame':	2 obs. of  0 variables
  ..$ tileOrder : chr "row-major"
  ..$ type      : chr "INT32"
 $ offsetFilterPipeline:List of 1
  ..$ filters:'data.frame':	1 obs. of  2 variables:
  .. ..$ type: chr "ZSTD"
  .. ..$ data:'data.frame':	1 obs. of  1 variable:
  .. .. ..$ int32: int -1
 $ tileOrder           : chr "row-major"
 $ uri                 : chr "s3://tiledb-inc-demo-data/tiledb-arrays/1.6/quickstart_dense"
 $ version             : int 3
 $ allowsDuplicates    : logi FALSE
R> 

Our service generally wants a username/password handshake; I will try to take a look at a possible password-less transaction.

openapi-generator version

See PR #5728

OpenAPI declaration file content or url

The YAML file is given above in the snippet and from here:

Command line used for generation

See above. We used your PR to generate an R package from the YAML spec listed above. No further changes.

Steps to reproduce

See above, I followed your recommended invocation.

Related issues/PRs

N/A

Suggest a fix

N/A

@eddelbuettel eddelbuettel changed the title [BUG] [R] Code generated needs a 'raw2char' translation before JSON deparsing [BUG] [R] Code generated needs a 'raw2Char' translation before JSON deparsing Jun 24, 2020
@eddelbuettel
Copy link
Contributor Author

As a follow-up I since learned that the related / simpler rapiclient package for R and OpenAPI has a hook for a 'handler' function. In a test case I used that to rawToChar() convert the result$content object. We could like do the same here and you may already offer such a hook which I could well have missed....

@rmoff
Copy link

rmoff commented Jul 10, 2023

I'm hitting this same error using code generated against this YAML.

I can see that this issue is quite old; should I add my report to it, or log a new one?

@eddelbuettel
Copy link
Contributor Author

@rmoff It's been a while since I filed this. I think we just ended up with a small set of patches we locally apply after the code generation.

@rmoff
Copy link

rmoff commented Jul 12, 2023

FWIW I got around this error by using openapitools/openapi-generator-cli:latest instead of openapitools/openapi-generator-cli:v5.3.0. The generated code then ran fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants