OpenAPITools / OpenAPITools/openapi-generator

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

Open
#6,767 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the generated R client's deserialize call shown in the report and review PR #5728, using openapi-v1.yaml as the reproduction specification. Reproduce the response where resp$content has class raw and compare it with the rawToChar() example. Done means the generated client can deparse this JSON response without the runtime error.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.