Skip to content

Conversation

@cwaldren-ld
Copy link
Contributor

@cwaldren-ld cwaldren-ld commented Jun 27, 2023

This PR builds on #153, extending the deserialization to flag data.

I've added to the PARSE_FIELD macro to handle the following cases:

  1. Parse a field where the zero-value is a valid part of the domain: PARSE_FIELD. In other words, if the field is omitted or null, it will be filled in with a default value. Most common scenario.
  2. Like (1), but supply a default value in case the field is null or omitted: PARSE_FIELD_DEFAULT.
  3. Parse a field that doesn't have a valid default value, and so is represented as an optional: PARSE_CONDITIONAL_FIELD. For example, the value "" wouldn't be a valid default for a unique key.
  4. Parse a field that must be present in the JSON data: PARSE_REQUIRED_FIELD. Usage of this should be rare; the test would be if the SDK is totally unable to function without this.

To achieve this, I've made the tag_invokes operate on expected<optional<T>, JsonError's, instead of expected<T, JsonError.

We could potentially revert that (and instead add a new enum case to JsonError), but I figure optional is a good representation of null/omitted. I think I need to actually try removing it to determine if it results in a better API.

One thing lacking is better error messages - we use kSchemaFailure everywhere but we now have the ability to report exactly what was missing/wrong type, etc.

@shortcut-integration
Copy link

This pull request has been linked to Shortcut Story #207650: Flag data model.

@cwaldren-ld cwaldren-ld force-pushed the cw/sc-207650/flag-data-model branch from 5a36e4b to 0158bf0 Compare June 27, 2023 02:06
@cwaldren-ld cwaldren-ld force-pushed the cw/sc-207650/flag-data-model branch from 0158bf0 to a0fbc31 Compare June 27, 2023 20:17
@cwaldren-ld cwaldren-ld requested a review from kinyoklion June 30, 2023 17:48
@cwaldren-ld cwaldren-ld marked this pull request as ready for review June 30, 2023 17:48

TEST(SDKDataSetTests, DeserializesZeroSegments) {
auto result =
boost::json::value_to<tl::expected<data_model::SDKDataSet, JsonError>>(
Copy link
Contributor Author

@cwaldren-ld cwaldren-ld Jun 30, 2023

Choose a reason for hiding this comment

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

Some of these tests change in the (not yet issued) evaluator PR, due to slight changes in the data model. So if you notice some field that should be required (or the other way around), it might be fixed there.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I am depending a bit on testing for that. Mainly checked conditions matched manes.

Base automatically changed from cw/sc-207649/segment-data-model to server-side June 30, 2023 22:00
@cwaldren-ld cwaldren-ld requested a review from a team June 30, 2023 22:00
@cwaldren-ld cwaldren-ld merged commit 4954f88 into server-side Jun 30, 2023
@cwaldren-ld cwaldren-ld deleted the cw/sc-207650/flag-data-model branch June 30, 2023 22:29
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.

3 participants