Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #9468
Closed
Open
Issue created May 12, 2021 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][R] Boolean values garbled in toJSONString() as quoted Strings and uppercase

Created by: sneumann

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

The generated code seems to not treat boolean values correctly in toJSON() serialisation. It is currently turned into "use_datacite":"TRUE", causing a 400 Bad Request with "detail": "'TRUE' is not of type 'boolean'" . Just lower-casing "use_datacite":"true"also causes "detail": "'true' is not of type 'boolean' ".

=> The client has to send the boolean values as "use_datacite":true

openapi-generator version

Using 5.2.0-SNAPSHOT, unsure if that ever worked and is a regression now.

OpenAPI declaration file content or url

The OpenAPI in question is available from https://raw.githubusercontent.com/sneumann/fuji/patch-1/fuji_server/yaml/swagger.yaml

Generation Details

I created an R package with docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate -i https://raw.githubusercontent.com/sneumann/fuji/patch-1/fuji_server/yaml/swagger.yaml -g r --package-name rfuji -o /local/rfuji (5.2.0-SNAPSHOT, with docker hash 0656cdcfe71e)

Steps to reproduce

After R CMD INSTALL /tmp/rfuji I do

library(rfuji)
Body <- rfuji::Body$new()
Body$use_datacite <- T
cat(Body$toJSONString())
# {"test_debug": "FALSE", "use_datacite": "TRUE" }

In a patched version of the package I get the correct:

{"test_debug": false, "use_datacite": true }
Related issues/PRs

None close enough I could find.

Suggest a fix

The generated file rfuji/R/body.R corresponds to the parameter body in https://github.com/pangaea-data-publisher/fuji/blob/master/fuji_server/yaml/swagger.yaml#L560

and has a boolean called use_datacite: https://github.com/pangaea-data-publisher/fuji/blob/master/fuji_server/yaml/swagger.yaml#L578

The generated code turns this boolean into a character string, which the REST service does not like, returning 400 Bad Request with "detail": "'TRUE' is not of type 'boolean'"

Body <- R6::R6Class( 'Body', public = list(
    toJSONString = function() {
      jsoncontent <- c(
...
        if (!is.null(self$`test_debug`)) {
             sprintf( ' "test_debug": "%s" ', self$`test_debug` )
        },
        if (!is.null(self$`use_datacite`)) {
        sprintf(' "use_datacite": "%s" ', self$`use_datacite` )}
...

My locally fixed package has instead removed the quotes in "%s" and added tolower():

       if (!is.null(self$`use_datacite`)) {
           sprintf('"use_datacite": %s', tolower(self$`use_datacite`)
        )}

This must probably be handled in the templates such as https://github.com/OpenAPITools/openapi-generator/blob/60dcf8613f6b75b606757c4a991fe018ad10ee99/modules/openapi-generator/src/main/resources/r/model.mustache#L172 by testing for boolean and then emitting the above corrected code.

Hope that helped, yours, Steffen

Assignee
Assign to
Time tracking