smithy4s icon indicating copy to clipboard operation
smithy4s copied to clipboard

Should uniqueItems reject duplicates?

Open kubukoz opened this issue 1 year ago • 2 comments

According to the spec:

6.7. uniqueItems trait Summary Requires the items in a list to be unique based on Value equality.

Our implementation relies on scala's default Set behavior, which is to remove duplicates. The spec seems to be more strict than that.

Here's more precedent for rejecting lists that have duplicate entries:

kubukoz avatar Apr 02 '24 23:04 kubukoz

I think you are correct. uniqueItems should be treated as a validation constraint as opposed to a meta-hint dictating the generated type.

Baccata avatar Apr 03 '24 07:04 Baccata

thoughts/questions off the top of my head:

  • we could turn uniqueItems into a usual .validated / .refine call on Schema. If it's refine, it could turn the collection type into a Set.
    • should it actually change the collection type?
      • if not, do we give users the ability to do that (keep Set in the codegen), e.g. @smithy4s.meta#scalaSet?
    • does this remove the need for a SetTag to exist?

kubukoz avatar Apr 03 '24 17:04 kubukoz