Codec equality considerations


Since codec instantiation happens like this:

we have e.g. (new Tapir{}.emptyIO == new Tapir{}.emptyIO) == false

This is obviously a synthetic example but a more general question is IMO valid: given that EndpointIOs are case classes, EndpointIO.Info is a case class, Schema is a case class, CodecFormats are case classes, do you think an e.g. (which is a product of a Schema and a CodecFormat) could be structurally comparable as well?

Since encoding/decoding functions are involved, any equality would be accidental anyway. That is, you can always create an “identical” codec but with a different instance of the e.g. id function. So this might be misleading. Even in the schema, there are functions: validators, coproduct projections etc.

Ok, but would you say 2 emptyInputs should be equal to each other?

I don’t think they should be comparable, so equality wouldn’t make sense for them.

What would you say is the right way to check for empty input then? If there’s a better way then == which I used until now, I’ll just do that

Maybe you can share your use-case?

The simplest way would be to check if the input is of type EndpointIO.Empty

My use-case was basically doing some endpoint analysis where i was filtering with sth along the lines of

.filterNot(_.securityInput == emptyInput)

which unexpectedly (for me) failed when i started declaring endpoints in a class that did extends Tapir (regardless of how smart is that, i mean… it’s public so why not :D)

So basically was just looking to get only endpoints that were declaring securityInput and stumbled over universal equality.

... extends Tapir is definitely valid, also part of the docs :slight_smile:

But for your use-case, I guess the isInstanceOf-check for EndpointIO.Empty should work just tine.