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

Use io-ts's strict utility type to ignore excess fields #156156

Closed
cnasikas opened this issue Apr 28, 2023 · 5 comments · Fixed by #156813
Closed

Use io-ts's strict utility type to ignore excess fields #156156

cnasikas opened this issue Apr 28, 2023 · 5 comments · Fixed by #156813
Assignees
Labels
Feature:Cases Cases feature Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams)

Comments

@cnasikas
Copy link
Member

cnasikas commented Apr 28, 2023

In Cases, we use a custom function called excess (io-ts) to throw an error when a request contains excess fields. In the Serverless world where different nodes can be on different versions (thus with different data schemas), we cannot throw errors as it will break Cases. io-ts supports the strict type where it omits unsupported fields by default. We should use this type.

@cnasikas cnasikas changed the title Use io-ts's strict utility type to ignore excess fields (@js-jankisalvi) Use io-ts's strict utility type to ignore excess fields Apr 28, 2023
@botelastic botelastic bot added the needs-team Issues missing a team label label Apr 28, 2023
@cnasikas cnasikas added Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Feature:Cases Cases feature labels Apr 28, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops-cases (Feature:Cases)

@botelastic botelastic bot removed the needs-team Issues missing a team label label Apr 28, 2023
@jonathan-buttner
Copy link
Contributor

For most things we should be able to use exact()

@cnasikas
Copy link
Member Author

cnasikas commented May 2, 2023

@jonathan-buttner Does exact removes excess fields? What is the difference between strict and exact?

@jonathan-buttner
Copy link
Contributor

Actually sorry I have it wrong. We want strict. strict is an alias for exact(type())

t.strict({ name: A }) (an alias of t.exact(t.type({ name: A })))

jonathan-buttner added a commit that referenced this issue May 24, 2023
## Summary

This PR fixes #156156

It uses` io-ts strict` type to remove unnecessary attributes.


### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### For maintainers

- [x] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Jonathan Buttner <jonathan.buttner@elastic.co>
Co-authored-by: Christos Nasikas <christos.nasikas@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Cases Cases feature Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants