Skip to content

Serialization using $ref returns arrays #77

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

Open
AlexAxthelm opened this issue Jan 15, 2024 · 0 comments
Open

Serialization using $ref returns arrays #77

AlexAxthelm opened this issue Jan 15, 2024 · 0 comments

Comments

@AlexAxthelm
Copy link

Hi,

I've been working with json_schema$serialise() recently, and I'm seeing that when I attempt to serialise an object using a composed/cobined schema (anything using $ref), the returned values are always arrays.

schema <- '{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "definitions": {
        "city": { "type": "string" }
    },
    "type": "object",
    "properties": {
        "city": { "$ref": "#/definitions/city" }
    }
}'
                        
validator <- jsonvalidate::json_schema$new(schema)

out <- validator$serialise(list(city = "Firenze"))

print(out)
#> {"city":["Firenze"]}

validator$validate(out, verbose = TRUE)
#> [1] FALSE
#> attr(,"errors")
#>   instancePath              schemaPath keyword   type        message schema
#> 1        /city #/definitions/city/type    type string must be string string
#>     type    data dataPath
#> 1 string Firenze    /city

Created on 2024-01-15 with reprex v2.0.2

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.3.2 (2023-10-31)
#>  os       macOS Sonoma 14.2
#>  system   aarch64, darwin23.0.0
#>  ui       unknown
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       Europe/Belgrade
#>  date     2024-01-15
#>  pandoc   3.1.7 @ /opt/homebrew/bin/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package      * version date (UTC) lib source
#>  cli            3.6.2   2023-12-11 [1] CRAN (R 4.3.1)
#>  curl           5.1.0   2023-10-02 [1] CRAN (R 4.3.1)
#>  digest         0.6.33  2023-07-07 [1] CRAN (R 4.3.1)
#>  evaluate       0.21    2023-05-05 [1] CRAN (R 4.3.1)
#>  fastmap        1.1.1   2023-02-24 [1] CRAN (R 4.3.1)
#>  fs             1.6.3   2023-07-20 [1] CRAN (R 4.3.1)
#>  glue           1.6.2   2022-02-24 [1] CRAN (R 4.3.1)
#>  htmltools      0.5.6   2023-08-10 [1] CRAN (R 4.3.1)
#>  jsonlite       1.8.7   2023-06-29 [1] CRAN (R 4.3.1)
#>  jsonvalidate   1.4.2   2023-11-07 [1] Github (ropensci/jsonvalidate@53600f3)
#>  knitr          1.43    2023-05-25 [1] CRAN (R 4.3.1)
#>  lifecycle      1.0.4   2023-11-07 [1] CRAN (R 4.3.1)
#>  magrittr       2.0.3   2022-03-30 [1] CRAN (R 4.3.1)
#>  purrr          1.0.2   2023-08-10 [1] CRAN (R 4.3.1)
#>  R.cache        0.16.0  2022-07-21 [1] CRAN (R 4.3.1)
#>  R.methodsS3    1.8.2   2022-06-13 [1] CRAN (R 4.3.1)
#>  R.oo           1.25.0  2022-06-12 [1] CRAN (R 4.3.1)
#>  R.utils        2.12.2  2022-11-11 [1] CRAN (R 4.3.1)
#>  R6             2.5.1   2021-08-19 [1] CRAN (R 4.3.1)
#>  Rcpp           1.0.11  2023-07-06 [1] CRAN (R 4.3.1)
#>  reprex         2.0.2   2022-08-17 [1] CRAN (R 4.3.1)
#>  rlang          1.1.2   2023-11-04 [1] CRAN (R 4.3.1)
#>  rmarkdown      2.25    2023-09-18 [1] CRAN (R 4.3.1)
#>  sessioninfo    1.2.2   2021-12-06 [1] CRAN (R 4.3.1)
#>  styler         1.10.2  2023-08-29 [1] CRAN (R 4.3.1)
#>  V8             4.4.0   2023-10-09 [1] CRAN (R 4.3.1)
#>  vctrs          0.6.5   2023-12-01 [1] CRAN (R 4.3.1)
#>  withr          2.5.2   2023-10-30 [1] CRAN (R 4.3.1)
#>  xfun           0.40    2023-08-09 [1] CRAN (R 4.3.1)
#>  yaml           2.3.7   2023-01-23 [1] CRAN (R 4.3.1)
#> 
#>  [1] /opt/homebrew/lib/R/4.3/site-library
#>  [2] /opt/homebrew/Cellar/r/4.3.2/lib/R/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

The example above is a reprex, but I see the same behavior for definitions defined in separate files ("$ref": "x.json") as well. at a first guess, this seems like the sub-schemas aren't propagating auto_unbox, but I'm out of my depth on JS/V8.

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

No branches or pull requests

1 participant