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

Serialize evaluation context to OFREP #5

Merged
merged 1 commit into from
Jan 26, 2025

Conversation

slashmo
Copy link
Member

@slashmo slashmo commented Jan 26, 2025

No description provided.

Copy link

codecov bot commented Jan 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Files with missing lines Coverage Δ
...ces/OFREP/OpenFeatureEvaluationContext+OFREP.swift 100.00% <100.00%> (ø)

case .object(let value):
let data = try Self.jsonEncoder.encode(value)
let container = try Self.jsonDecoder.decode(OpenAPIObjectContainer.self, from: data)
values[key] = container.value
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super happy about this approach to convert an any Codable & Sendable into a value to put inside an OpenAPIObjectContainer. @czechboy0 Do you have an idea how this could be improved?

Copy link

@czechboy0 czechboy0 Jan 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should be just able to use OpenAPIObjectContainer(unvalidatedValue: value instead of going through the Codable encoding/decoding.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fast reply 🏎️
unvalidatedValue expects a [String: any Sendable] dictionary, but value in this case is any Codable & Sendable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also tried OpenAPIValueContainer but that fails in the tryCast because value is neither an array nor a dictionary nor a supported primitive value: https://github.com/apple/swift-openapi-runtime/blob/23146bc8710ac5e57abb693113f02dc274cf39b6/Sources/OpenAPIRuntime/Base/OpenAPIValue.swift#L81

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, so what is the underlying type? Unless it's a native Swift container or primitive type then yeah, you'll need to run it through Codable.

I wonder why it's Codable though? Where does that requirement come from?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's part of the OpenFeature spec to allow for user-defined objects to be supported in the evaluation API. In the OFREP provider that maps to JSON-coded values but a different provider may encode/decode them differently. That's why I opted for Codable & Sendable as the requirement.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps OpenAPIRuntime could support "lazy encodable" values in OpenAPIValueContainer which would be encoded alongside the request. That way I could save the roundtrip.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's something you'd like to see, please open an issue on Swift OpenAPI Generator and we can discuss there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I'll think it through some more but will then likely create an issue. Thanks again for your input 🙏

@slashmo slashmo merged commit c78668a into main Jan 26, 2025
7 checks passed
@slashmo slashmo deleted the feature/evaluation-context-serialization branch January 26, 2025 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants