Skip to content

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

Description

@ahjota

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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions