Bug Report Checklist
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
- Generate the R client from the spec above.
- 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.
- 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.
Bug Report Checklist
Description
OpenAPI
type: string, format: dateandformat: date-timefields to plaincharacterin 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):
Generation Details
Steps to reproduce
R/date_time_object.R:@field requiredTimeis documented as plaincharacter.initialize()accepts any string for the field without validation.optionalTimedefault is the literal string"2015-10-28T14:38:02Z", not aPOSIXct.$fromJSON(toJSON(...))andApiClient$deserialize("POSIXct", "2015-10-28T14:38:02Z")both return the untouched string.Related issues/PRs
Suggest a fix
Map
date→ RDateanddate-time→ RPOSIXctand convert at the boundaries. I will open a PR shortly with the fix for this.