softwaremill / tapir

Rapid development of self-documenting APIs
https://tapir.softwaremill.com
Apache License 2.0
1.34k stars 405 forks source link

Define schemas for maps #62

Closed adamw closed 5 years ago

adamw commented 5 years ago

The default schema for Map should be an object without arbitrary fields. Alternatively: only for Map[String, V] for any V.

Such a schema should also be properly generated in the docs.

guersam commented 5 years ago

Circe has KeyEncoder and KeyDecoder for that use case. Maybe we can use it in circe modules or define something similar in the core module and add a derivation to/from corresponding circe typeclasses. https://circe.github.io/circe/codecs/custom-codecs.html#custom-key-types

ghostbuster91 commented 5 years ago

I did a first version of this generation which is to generate schemas for Map[String, _]

Regarding other types of keys support and keyEncoder approach. We already have similar situation with oneOf macro where we are forcing users to provide asString: A => String converting method. If we decide to implement something like keyEncoder, we should apply this pattern to both places.

adamw commented 5 years ago

@guersam generating circe encoders/decoders from a schema is a whole other story, but definitely worth investigating at some point :) Or event better - replacing the whole thing with sth like https://github.com/scalaz/scalaz-schema