apple / apple/swift-openapi-generator

Client configuration dateTranscoder: .iso8601WithFractionalSeconds is not used with asDecodedServerSentEventsWithJSONData

Open
#718 1 comment 0 reactions 0 assignees View on GitHub
kind/enhancement status/needs-design
Dominant language
Swift
Stars
2k
Forks
182
Avg merge
13h 28m
Merged PRs (30d)
5

Description

### Description

We do connect to a server api that sends dates with fractional seconds, so we set the dateTranscoder to .iso8601WithFractionalSeconds on the configuration struct we do pass into the Client.
This works perfectly for api calls that directly return a json result.

But some operations use server send events.
Here we use the stream.ok.body.text_event_hyphen_stream.asDecodedServerSentEventsWithJSONData(of: Components.Schemas.FooModel.self) function
which fails due to an decoding error of the date because of the fractional seconds. If I use a custom json decoder via the (of: Components.Schemas.FooModel.self, decoder: jsonDecoder) with a custom dateDecodingStrategy that uses formatOptions .withFractionalSeconds it also works here.

But shouldn't the asDecodedServerSentEventsWithJSONData function use the dateTranscoder configuration we set on the client by default?

### Reproduction

You need a server api that sends server send events with a return type that contains a date formatted with fractional seconds.

let stream = try await underlyingClient.GetMessageStream()
for try await event in try stream.ok.body.text_event_hyphen_stream.asDecodedServerSentEventsWithJSONData(of: Components.Schemas.FooModel.self) {
// event.data
}

### Package version(s)

.
├── swift-openapi-generator
│ ├── swift-algorithms
│ │ └── swift-numerics
│ ├── swift-collections
│ ├── openapikit
│ │ └── yams
│ ├── yams
│ └── swift-argument-parser
├── swift-openapi-runtime
│ └── swift-http-types
└── swift-openapi-urlsession
├── swift-openapi-runtime
│ └── swift-http-types
├── swift-http-types
└── swift-collections

### Expected behavior

asDecodedServerSentEventsWithJSONData function should use the dateTranscoder configuration of the client by default

### Environment

swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: arm64-apple-macosx15.0

### Additional information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start at asDecodedServerSentEventsWithJSONData and trace how its decoder is configured, comparing it with the direct JSON response path that already honors the client's dateTranscoder. Reproduce the issue with the provided server-sent event example and verify that fractional-second dates decode using the client's configuration by default.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.