@@ -28,48 +28,55 @@ import scala.reflect.ClassTag
28
28
*
29
29
* A concise description of an endpoint can be generated using the [[EndpointMetaOps.show ]] method.
30
30
*
31
- * @tparam A
32
- * Security input parameter types.
33
- * @tparam I
34
- * Input parameter types.
35
- * @tparam E
36
- * Error output parameter types.
37
- * @tparam O
38
- * Output parameter types.
31
+ * @tparam SECURITY_INPUT
32
+ * Security input parameter types, abbreviated as `A` .
33
+ * @tparam INPUT
34
+ * Input parameter types, abbreviated as `I` .
35
+ * @tparam ERROR_OUTPUT
36
+ * Error output parameter types, abbreviated as `E` .
37
+ * @tparam OUTPUT
38
+ * Output parameter types, abbreviated as `O` .
39
39
* @tparam R
40
40
* The capabilities that are required by this endpoint's inputs/outputs. This might be `Any` (no requirements),
41
41
* [[sttp.capabilities.Effect ]] (the interpreter must support the given effect type), [[sttp.capabilities.Streams ]] (the ability to send
42
42
* and receive streaming bodies) or [[sttp.capabilities.WebSockets ]] (the ability to handle websocket requests).
43
43
*/
44
- case class Endpoint [A , I , E , O , - R ](
45
- securityInput : EndpointInput [A ],
46
- input : EndpointInput [I ],
47
- errorOutput : EndpointOutput [E ],
48
- output : EndpointOutput [O ],
44
+ case class Endpoint [SECURITY_INPUT , INPUT , ERROR_OUTPUT , OUTPUT , - R ](
45
+ securityInput : EndpointInput [SECURITY_INPUT ],
46
+ input : EndpointInput [INPUT ],
47
+ errorOutput : EndpointOutput [ERROR_OUTPUT ],
48
+ output : EndpointOutput [OUTPUT ],
49
49
info : EndpointInfo
50
- ) extends EndpointSecurityInputsOps [A , I , E , O , R ]
51
- with EndpointInputsOps [A , I , E , O , R ]
52
- with EndpointErrorOutputsOps [A , I , E , O , R ]
53
- with EndpointErrorOutputVariantsOps [A , I , E , O , R ]
54
- with EndpointOutputsOps [A , I , E , O , R ]
50
+ ) extends EndpointSecurityInputsOps [SECURITY_INPUT , INPUT , ERROR_OUTPUT , OUTPUT , R ]
51
+ with EndpointInputsOps [SECURITY_INPUT , INPUT , ERROR_OUTPUT , OUTPUT , R ]
52
+ with EndpointErrorOutputsOps [SECURITY_INPUT , INPUT , ERROR_OUTPUT , OUTPUT , R ]
53
+ with EndpointErrorOutputVariantsOps [SECURITY_INPUT , INPUT , ERROR_OUTPUT , OUTPUT , R ]
54
+ with EndpointOutputsOps [SECURITY_INPUT , INPUT , ERROR_OUTPUT , OUTPUT , R ]
55
55
with EndpointInfoOps [R ]
56
56
with EndpointMetaOps
57
- with EndpointServerLogicOps [A , I , E , O , R ] { outer =>
57
+ with EndpointServerLogicOps [SECURITY_INPUT , INPUT , ERROR_OUTPUT , OUTPUT , R ] { outer =>
58
58
59
59
override type EndpointType [_A, _I, _E, _O, - _R] = Endpoint [_A, _I, _E, _O, _R]
60
- override type ThisType [- _R] = Endpoint [A , I , E , O , _R]
61
- override private [tapir] def withSecurityInput [A2 , R2 ](securityInput : EndpointInput [A2 ]): Endpoint [A2 , I , E , O , R with R2 ] =
60
+ override type ThisType [- _R] = Endpoint [SECURITY_INPUT , INPUT , ERROR_OUTPUT , OUTPUT , _R]
61
+ override private [tapir] def withSecurityInput [A2 , R2 ](
62
+ securityInput : EndpointInput [A2 ]
63
+ ): Endpoint [A2 , INPUT , ERROR_OUTPUT , OUTPUT , R with R2 ] =
62
64
this .copy(securityInput = securityInput)
63
- override private [tapir] def withInput [I2 , R2 ](input : EndpointInput [I2 ]): Endpoint [A , I2 , E , O , R with R2 ] = this .copy(input = input)
64
- override private [tapir] def withErrorOutput [E2 , R2 ](errorOutput : EndpointOutput [E2 ]): Endpoint [A , I , E2 , O , R with R2 ] =
65
+ override private [tapir] def withInput [I2 , R2 ](input : EndpointInput [I2 ]): Endpoint [SECURITY_INPUT , I2 , ERROR_OUTPUT , OUTPUT , R with R2 ] =
66
+ this .copy(input = input)
67
+ override private [tapir] def withErrorOutput [E2 , R2 ](
68
+ errorOutput : EndpointOutput [E2 ]
69
+ ): Endpoint [SECURITY_INPUT , INPUT , E2 , OUTPUT , R with R2 ] =
65
70
this .copy(errorOutput = errorOutput)
66
71
override private [tapir] def withErrorOutputVariant [E2 , R2 ](
67
72
errorOutput : EndpointOutput [E2 ],
68
- embedE : E => E2
69
- ): Endpoint [A , I , E2 , O , R with R2 ] =
73
+ embedE : ERROR_OUTPUT => E2
74
+ ): Endpoint [SECURITY_INPUT , INPUT , E2 , OUTPUT , R with R2 ] =
70
75
this .copy(errorOutput = errorOutput)
71
- override private [tapir] def withOutput [O2 , R2 ](output : EndpointOutput [O2 ]): Endpoint [A , I , E , O2 , R with R2 ] = this .copy(output = output)
72
- override private [tapir] def withInfo (info : EndpointInfo ): Endpoint [A , I , E , O , R ] = this .copy(info = info)
76
+ override private [tapir] def withOutput [O2 , R2 ](output : EndpointOutput [O2 ]): Endpoint [SECURITY_INPUT , INPUT , ERROR_OUTPUT , O2 , R with R2 ] =
77
+ this .copy(output = output)
78
+ override private [tapir] def withInfo (info : EndpointInfo ): Endpoint [SECURITY_INPUT , INPUT , ERROR_OUTPUT , OUTPUT , R ] =
79
+ this .copy(info = info)
73
80
override protected def showType : String = " Endpoint"
74
81
}
75
82
@@ -420,41 +427,41 @@ trait EndpointServerLogicOps[A, I, E, O, -R] { outer: Endpoint[A, I, E, O, R] =>
420
427
* An example use-case is defining an endpoint with fully-defined errors, and with security logic built-in. Such an endpoint can be then
421
428
* extended by multiple other endpoints, by specifying different inputs, outputs and the main logic.
422
429
*/
423
- def serverSecurityLogic [U , F [_]](f : A => F [Either [E , U ]]): PartialServerEndpoint [A , U , I , E , O , R , F ] =
430
+ def serverSecurityLogic [PRINCIPAL , F [_]](f : A => F [Either [E , PRINCIPAL ]]): PartialServerEndpoint [A , PRINCIPAL , I , E , O , R , F ] =
424
431
PartialServerEndpoint (this , _ => f)
425
432
426
433
/** Like [[serverSecurityLogic ]], but specialised to the case when the result is always a success (`Right`), hence when the logic type can
427
- * be simplified to `A => F[U ]`.
434
+ * be simplified to `A => F[PRINCIPAL ]`.
428
435
*/
429
- def serverSecurityLogicSuccess [U , F [_]](
430
- f : A => F [U ]
431
- ): PartialServerEndpoint [A , U , I , E , O , R , F ] =
436
+ def serverSecurityLogicSuccess [PRINCIPAL , F [_]](
437
+ f : A => F [PRINCIPAL ]
438
+ ): PartialServerEndpoint [A , PRINCIPAL , I , E , O , R , F ] =
432
439
PartialServerEndpoint (this , implicit m => a => f(a).map(Right (_)))
433
440
434
441
/** Like [[serverSecurityLogic ]], but specialised to the case when the result is always an error (`Left`), hence when the logic type can
435
442
* be simplified to `A => F[E]`.
436
443
*/
437
- def serverSecurityLogicError [U , F [_]](
444
+ def serverSecurityLogicError [PRINCIPAL , F [_]](
438
445
f : A => F [E ]
439
- ): PartialServerEndpoint [A , U , I , E , O , R , F ] =
446
+ ): PartialServerEndpoint [A , PRINCIPAL , I , E , O , R , F ] =
440
447
PartialServerEndpoint (this , implicit m => a => f(a).map(Left (_)))
441
448
442
449
/** Like [[serverSecurityLogic ]], but specialised to the case when the logic function is pure, that is doesn't have any side effects. */
443
- def serverSecurityLogicPure [U , F [_]](f : A => Either [E , U ]): PartialServerEndpoint [A , U , I , E , O , R , F ] =
450
+ def serverSecurityLogicPure [PRINCIPAL , F [_]](f : A => Either [E , PRINCIPAL ]): PartialServerEndpoint [A , PRINCIPAL , I , E , O , R , F ] =
444
451
PartialServerEndpoint (this , implicit m => a => f(a).unit)
445
452
446
453
/** Same as [[serverSecurityLogic ]], but requires `E` to be a throwable, and coverts failed effects of type `E` to endpoint errors. */
447
- def serverSecurityLogicRecoverErrors [U , F [_]](
448
- f : A => F [U ]
449
- )(implicit eIsThrowable : E <:< Throwable , eClassTag : ClassTag [E ]): PartialServerEndpoint [A , U , I , E , O , R , F ] =
450
- PartialServerEndpoint (this , recoverErrors1[A , E , U , F ](f))
454
+ def serverSecurityLogicRecoverErrors [PRINCIPAL , F [_]](
455
+ f : A => F [PRINCIPAL ]
456
+ )(implicit eIsThrowable : E <:< Throwable , eClassTag : ClassTag [E ]): PartialServerEndpoint [A , PRINCIPAL , I , E , O , R , F ] =
457
+ PartialServerEndpoint (this , recoverErrors1[A , E , PRINCIPAL , F ](f))
451
458
452
459
/** Like [[serverSecurityLogic ]], but specialised to the case when the error type is `Unit` (e.g. a fixed status code), and the result of
453
460
* the logic function is an option. A `None` is then treated as an error response.
454
461
*/
455
- def serverSecurityLogicOption [U , F [_]](
456
- f : A => F [Option [U ]]
457
- )(implicit eIsUnit : E =:= Unit ): PartialServerEndpoint [A , U , I , Unit , O , R , F ] = {
462
+ def serverSecurityLogicOption [PRINCIPAL , F [_]](
463
+ f : A => F [Option [PRINCIPAL ]]
464
+ )(implicit eIsUnit : E =:= Unit ): PartialServerEndpoint [A , PRINCIPAL , I , Unit , O , R , F ] = {
458
465
import sttp .monad .syntax ._
459
466
PartialServerEndpoint (
460
467
this .asInstanceOf [Endpoint [A , I , Unit , O , R ]],
@@ -470,43 +477,46 @@ trait EndpointServerLogicOps[A, I, E, O, -R] { outer: Endpoint[A, I, E, O, R] =>
470
477
//
471
478
472
479
/** Like [[serverSecurityLogic ]], but allows the security function to contribute to the overall output of the endpoint. A value for the
473
- * complete output `O` defined so far has to be provided. The value `U ` will be propagated as an input to the regular logic.
480
+ * complete output `O` defined so far has to be provided. The value `PRINCIPAL ` will be propagated as an input to the regular logic.
474
481
*/
475
- def serverSecurityLogicWithOutput [U , F [_]](
476
- f : A => F [Either [E , (O , U )]]
477
- ): PartialServerEndpointWithSecurityOutput [A , U , I , E , O , Unit , R , F ] =
482
+ def serverSecurityLogicWithOutput [PRINCIPAL , F [_]](
483
+ f : A => F [Either [E , (O , PRINCIPAL )]]
484
+ ): PartialServerEndpointWithSecurityOutput [A , PRINCIPAL , I , E , O , Unit , R , F ] =
478
485
PartialServerEndpointWithSecurityOutput (this .output, this .copy(output = emptyOutput), _ => f)
479
486
480
487
/** Like [[serverSecurityLogicWithOutput ]], but specialised to the case when the result is always a success (`Right`), hence when the
481
- * logic type can be simplified to `A => F[(O, U )]`.
488
+ * logic type can be simplified to `A => F[(O, PRINCIPAL )]`.
482
489
*/
483
- def serverSecurityLogicSuccessWithOutput [U , F [_]](
484
- f : A => F [(O , U )]
485
- ): PartialServerEndpointWithSecurityOutput [A , U , I , E , O , Unit , R , F ] =
490
+ def serverSecurityLogicSuccessWithOutput [PRINCIPAL , F [_]](
491
+ f : A => F [(O , PRINCIPAL )]
492
+ ): PartialServerEndpointWithSecurityOutput [A , PRINCIPAL , I , E , O , Unit , R , F ] =
486
493
PartialServerEndpointWithSecurityOutput (this .output, this .copy(output = emptyOutput), implicit m => a => f(a).map(Right (_)))
487
494
488
495
/** Like [[serverSecurityLogicWithOutput ]], but specialised to the case when the logic function is pure, that is doesn't have any side
489
496
* effects.
490
497
*/
491
- def serverSecurityLogicPureWithOutput [U , F [_]](
492
- f : A => Either [E , (O , U )]
493
- ): PartialServerEndpointWithSecurityOutput [A , U , I , E , O , Unit , R , F ] =
498
+ def serverSecurityLogicPureWithOutput [PRINCIPAL , F [_]](
499
+ f : A => Either [E , (O , PRINCIPAL )]
500
+ ): PartialServerEndpointWithSecurityOutput [A , PRINCIPAL , I , E , O , Unit , R , F ] =
494
501
PartialServerEndpointWithSecurityOutput (this .output, this .copy(output = emptyOutput), implicit m => a => f(a).unit)
495
502
496
503
/** Same as [[serverSecurityLogicWithOutput ]], but requires `E` to be a throwable, and coverts failed effects of type `E` to endpoint
497
504
* errors.
498
505
*/
499
- def serverSecurityLogicRecoverErrorsWithOutput [U , F [_]](
500
- f : A => F [(O , U )]
501
- )(implicit eIsThrowable : E <:< Throwable , eClassTag : ClassTag [E ]): PartialServerEndpointWithSecurityOutput [A , U , I , E , O , Unit , R , F ] =
502
- PartialServerEndpointWithSecurityOutput (this .output, this .copy(output = emptyOutput), recoverErrors1[A , E , (O , U ), F ](f))
506
+ def serverSecurityLogicRecoverErrorsWithOutput [PRINCIPAL , F [_]](
507
+ f : A => F [(O , PRINCIPAL )]
508
+ )(implicit
509
+ eIsThrowable : E <:< Throwable ,
510
+ eClassTag : ClassTag [E ]
511
+ ): PartialServerEndpointWithSecurityOutput [A , PRINCIPAL , I , E , O , Unit , R , F ] =
512
+ PartialServerEndpointWithSecurityOutput (this .output, this .copy(output = emptyOutput), recoverErrors1[A , E , (O , PRINCIPAL ), F ](f))
503
513
504
514
/** Like [[serverSecurityLogicWithOutput ]], but specialised to the case when the error type is `Unit` (e.g. a fixed status code), and the
505
515
* result of the logic function is an option. A `None` is then treated as an error response.
506
516
*/
507
- def serverSecurityLogicOptionWithOutput [U , F [_]](
508
- f : A => F [Option [(O , U )]]
509
- )(implicit eIsUnit : E =:= Unit ): PartialServerEndpointWithSecurityOutput [A , U , I , Unit , O , Unit , R , F ] = {
517
+ def serverSecurityLogicOptionWithOutput [PRINCIPAL , F [_]](
518
+ f : A => F [Option [(O , PRINCIPAL )]]
519
+ )(implicit eIsUnit : E =:= Unit ): PartialServerEndpointWithSecurityOutput [A , PRINCIPAL , I , Unit , O , Unit , R , F ] = {
510
520
import sttp .monad .syntax ._
511
521
PartialServerEndpointWithSecurityOutput (
512
522
this .output,
0 commit comments