Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client configuration dateTranscoder: .iso8601WithFractionalSeconds is not used with asDecodedServerSentEventsWithJSONData #718

Open
ChristophM2000 opened this issue Jan 24, 2025 · 1 comment
Labels
kind/enhancement Improvements to existing feature. status/needs-design Needs further discussion and a concrete proposal.

Comments

@ChristophM2000
Copy link

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-generatorhttps://github.com/apple/[email protected]
│ ├── swift-algorithmshttps://github.com/apple/[email protected]
│ │ └── swift-numericshttps://github.com/apple/[email protected]
│ ├── swift-collectionshttps://github.com/apple/[email protected]
│ ├── openapikithttps://github.com/mattpolzin/[email protected]
│ │ └── yamshttps://github.com/jpsim/[email protected]
│ ├── yamshttps://github.com/jpsim/[email protected]
│ └── swift-argument-parserhttps://github.com/apple/[email protected]
├── swift-openapi-runtimehttps://github.com/apple/[email protected]
│ └── swift-http-typeshttps://github.com/apple/[email protected]
└── swift-openapi-urlsessionhttps://github.com/apple/[email protected]
├── swift-openapi-runtimehttps://github.com/apple/[email protected]
│ └── swift-http-typeshttps://github.com/apple/[email protected]
├── swift-http-typeshttps://github.com/apple/[email protected]
└── swift-collectionshttps://github.com/apple/[email protected]

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

@ChristophM2000 ChristophM2000 added kind/bug Feature doesn't work as expected. status/triage Collecting information required to triage the issue. labels Jan 24, 2025
@czechboy0
Copy link
Contributor

The configuration on the client/server isn't available in these helper extensions on AsyncSequence. So the way to customize the decoding is what you found: pass a custom decoder.

I'm open to ideas how to improve this. Some half-baked ones that come to mind:

  1. offer this utility as a method on the configuration struct, and require the input async sequence to be provided as a parameter
  2. attach a copy of the configuration on the HTTPBody somehow
  3. put the current configuration in some task local, unclear what the scope would be
  4. ?

@czechboy0 czechboy0 added status/needs-design Needs further discussion and a concrete proposal. kind/enhancement Improvements to existing feature. and removed kind/bug Feature doesn't work as expected. status/triage Collecting information required to triage the issue. labels Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Improvements to existing feature. status/needs-design Needs further discussion and a concrete proposal.
Projects
None yet
Development

No branches or pull requests

2 participants