OpenAPITools / OpenAPITools/openapi-generator

[BUG][R] Date and DateTime not parsed correctly

Open
#24,811 0 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?
  • 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

OpenAPI type: string, format: date and format: date-time fields to plain character in generated R models, not the proper classes. As a result, these arrive as a character string in the generated R client code, so callers cannot automatically use R's date/time API (as.Date, format, etc.) without explicit conversion. Even the schema default is emitted as a string literal.

No validation of dates or date times, so anything goes, e.g. "not-a-date". 🫢

openapi-generator version

7.26.0, but I know this is valid at least as far back as 6.1.0, maybe even 5.3.0.

OpenAPI declaration file content or url

Minimal reproduction (also attached as a full spec at https://gist.github.com/ajalon1/3ac3bdcb68fa7c5b9c66ad2625bf3ba4):

openapi: 3.0.1
components:
  schemas:
    DateTimeObject:
      type: object
      properties:
        requiredTime:
          type: string
          format: date-time
        optionalTime:
          type: string
          format: date-time
          nullable: true
          default: '2015-10-28T14:38:02Z'
        optionalDate:
          type: string
          format: date
          nullable: true
          default: '2015-10-28'
Generation Details
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
  -g r -i rproblems.yaml -o ./out/r-client \
  --additional-properties=packageName=rproblems
Steps to reproduce
  1. Generate the R client from the spec above.
  2. Open R/date_time_object.R:
    • @field requiredTime is documented as plain character.
    • initialize() accepts any string for the field without validation.
    • the optionalTime default is the literal string "2015-10-28T14:38:02Z", not a POSIXct.
  3. Round-trip: $fromJSON(toJSON(...)) and ApiClient$deserialize("POSIXct", "2015-10-28T14:38:02Z") both return the untouched string.
Related issues/PRs
Suggest a fix

Map date → R Date and date-time → R POSIXct and convert at the boundaries. I will open a PR shortly with the fix for this.

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

Generate the R client with the supplied OpenAPI YAML and inspect R/date_time_object.R, then trace ApiClient$deserialize and the $fromJSON(toJSON(...)) round trip. Done means date maps to Date and date-time to POSIXct, defaults use those types, and invalid date strings are no longer accepted as plain character values.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.