openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG][Java][native] Regression: DateTime in deepObjects is no longer serialized correctly

Open marcel-huber-ptv opened this issue 1 year ago • 0 comments

Bug Report Checklist

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

When serializing an Object of type OffsetDateTime within a query deepObject, it is no longer formatted following the ISO-8601 standard.

openapi-generator version

7.6.0, introduced in 6.3.0

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: title
  version: 0.0.1
paths:
  /test:
    get:
      parameters:
        - name: deepObject
          in: query
          schema:
            $ref: '#/components/schemas/DeepObject'
          explode: true
          style: deepObject
      responses:
        204:
          description: no content
components:
  schemas:
    DeepObject:
      type: object
      properties:
        dateTime:
          type: string
          format: date-time
Generation Details

All values in the deepObject are currently serialized with String.valueOf(). Before v6.3.0 this was done with ApiClient.valueToString(), which has a special handling for objects of type OffsetDateTime to ensure dateTime is serialized following RFC 3339 / ISO-8601.

v7.6.0 generates

    // add `dateTime` to the URL query string
    if (getDateTime() != null) {
      joiner.add(String.format("%sdateTime%s=%s", prefix, suffix, URLEncoder.encode(String.valueOf(getDateTime()), StandardCharsets.UTF_8).replaceAll("\\+", "%20")));
    }

I'd propose to instead generate

    // add `dateTime` to the URL query string
    if (getDateTime() != null) {
      joiner.add(String.format("%sdateTime%s=%s", prefix, suffix, URLEncoder.encode(ApiClient.valueToString(getDateTime()), StandardCharsets.UTF_8).replaceAll("\\+", "%20")));
    }

reusing the existing valueToString() method.

Steps to reproduce

Generate the clients for the above openapi.yaml: java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i openapi.yaml -g java --library native -o out

Related issues/PRs

I couldn't find similar issure, but it seems to have been introduced with d269a2a09d86c461c1e586122980a5ba347dff83

Suggest a fix

Use the existing valueToString() method.

marcel-huber-ptv avatar May 23 '24 08:05 marcel-huber-ptv