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

feat: playground api returns removed context values under a new warnings property #6784

Merged

Conversation

thomasheartman
Copy link
Contributor

@thomasheartman thomasheartman commented Apr 5, 2024

This PR expands upon #6773 by returning the list of removed properties in the API response. To achieve this, I added a new top-level warnings key to the API response and added an invalidContextProperties property under it. This is a list with the keys that were removed.

Discussion points

Should we return the type of each removed key's value? We could expand upon this by also returning the type that was considered invalid for the property, e.g. invalidProp: 'object'. This would give us more information that we could display to the user. However, I'm not sure it's useful? We already return the input as-is, so you can always cross-check. And the only type we allow for non-properties top-level properties is string. Does it give any useful info? I think if we want to display this in the UI, we might be better off cross-referencing with the input?

Can properties be invalid for any other reason? As far as I can tell, that's the only reason properties can be invalid for the context. OpenAPI will prevent you from using a type other than string for the context fields we have defined and does not let you add non-string properties to the properties object. So all we have to deal with are top-level properties. And as long as they are strings, then they should be valid.

Should we instead infer the diff when creating the model? In this first approach, I've amended the clean-context function to also return the list of context fields it has removed. The downside to this approach is that we need to thread it through a few more hoops. Another approach would be to compare the input context with the context used to evaluate one of the features when we create the view model and derive the missing keys from that. This would probably work in 98 percent of cases. However, if your result contains no flags, then we can't calculate the diff. But maybe that's alright? It would likely be fewer lines of code (but might require additional testing), although picking an environment from feels hacky.

Copy link

vercel bot commented Apr 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
unleash-docs ⬜️ Ignored (Inspect) Visit Preview Apr 5, 2024 8:28am
unleash-monorepo-frontend ⬜️ Ignored (Inspect) Visit Preview Apr 5, 2024 8:28am

@thomasheartman thomasheartman changed the title feat: return removed context values as warnings feat: playground api returns removed context values under a new warnings property Apr 5, 2024

// verify that the two lists contain all the same elements
expect(removedProperties).toEqual(
expect.arrayContaining(invalidProperties),
Copy link
Contributor

Choose a reason for hiding this comment

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

is it because the order is not predictable? for predictable order I'd do simple equal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't checked the order, to be honest. I could, but it's not something that I think we can intrinsically rely on; we might want to sort it alphabetically or something later 🤷🏼 I don't think that should cause the tests to fail. So this just seemed like a more robust way to check it.

Copy link
Contributor

@kwasniew kwasniew left a comment

Choose a reason for hiding this comment

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

do you plan to use the warnings in the UI?

@thomasheartman
Copy link
Contributor Author

Yes, that's the plan. Create a follow-up PR that exposes this data in the UI if it's present.

@thomasheartman thomasheartman merged commit c59d28a into main Apr 8, 2024
5 of 6 checks passed
@thomasheartman thomasheartman deleted the feat/return-removed-properties-in-playground-response branch April 8, 2024 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants