Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close #278 - [refined4s-tapir] Add Schema type-class instances with a…
…uto deriving
- Loading branch information
Showing
2 changed files
with
690 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...fined4s-tapir/shared/src/main/scala/refined4s/modules/tapir/derivation/generic/auto.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package refined4s.modules.tapir.derivation.generic | ||
|
||
import refined4s.* | ||
import sttp.tapir.Schema | ||
|
||
/** @author Kevin Lee | ||
* @since 2024-04-03 | ||
*/ | ||
trait auto { | ||
inline given derivedNewtypeSchema[A, B]( | ||
using coercibleA2B: Coercible[A, B], | ||
coercibleB2A: Coercible[B, A], | ||
schemaB: Schema[B], | ||
): Schema[A] = auto.derivedNewtypeSchema | ||
|
||
inline given derivedRefinedSchema[A, B]( | ||
using refinedCtor: RefinedCtor[A, B], | ||
coercibleA2B: Coercible[A, B], | ||
schemaB: Schema[B], | ||
): Schema[A] = auto.derivedRefinedSchema | ||
|
||
} | ||
object auto { | ||
|
||
inline given derivedNewtypeSchema[A, B]( | ||
using coercibleA2B: Coercible[A, B], | ||
coercibleB2A: Coercible[B, A], | ||
schemaB: Schema[B], | ||
): Schema[A] = | ||
schemaB.map(b => Some(coercibleB2A(b)))(coercibleA2B(_)) | ||
|
||
inline given derivedRefinedSchema[A, B]( | ||
using refinedCtor: RefinedCtor[A, B], | ||
coercibleA2B: Coercible[A, B], | ||
schemaB: Schema[B], | ||
): Schema[A] = | ||
schemaB.map(refinedCtor.create(_).toOption)(coercibleA2B(_)) | ||
|
||
} |
Oops, something went wrong.