• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hyperledger / identus-cloud-agent / 10833924030

12 Sep 2024 03:25PM CUT coverage: 48.864% (+0.07%) from 48.793%
10833924030

Pull #1351

CryptoKnightIOG
ATL-7660: Credential Schema as List

Signed-off-by: Bassam Riman <bassam.riman@iohk.io>
Pull Request #1351: feat: Support Array Of Credential Schema

15 of 28 new or added lines in 3 files covered. (53.57%)

222 existing lines in 68 files now uncovered.

7530 of 15410 relevant lines covered (48.86%)

0.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.92
/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/api/http/ErrorResponse.scala
1
package org.hyperledger.identus.api.http
2

3
import org.hyperledger.identus.api.http.ErrorResponse.annotations
4
import org.hyperledger.identus.shared.models.Failure
5
import sttp.model.StatusCode
6
import sttp.tapir.generic.auto.*
7
import sttp.tapir.Schema
8
import sttp.tapir.Schema.annotations.{description, encodedExample}
9
import zio.json.{DeriveJsonDecoder, DeriveJsonEncoder}
10
import zio.ZIO
11

12
import java.util.UUID
13
import scala.language.implicitConversions
14
import scala.util.matching.Regex
15

16
private val INSTANCE_URI_PREFIX = "error:instance:"
17

18
case class ErrorResponse(
19
    @description(annotations.status.description)
1✔
20
    @encodedExample(annotations.status.example)
1✔
21
    status: Int,
22
    @description(annotations.`type`.description)
1✔
23
    @encodedExample(annotations.`type`.example)
1✔
24
    `type`: String,
25
    @description(annotations.title.description)
1✔
26
    @encodedExample(annotations.title.example)
1✔
27
    title: String,
28
    @description(annotations.detail.description)
1✔
29
    @encodedExample(annotations.detail.example)
1✔
30
    detail: Option[String] = None,
1✔
31
    @description(annotations.instance.description)
1✔
32
    @encodedExample(annotations.instance.example)
1✔
33
    instance: String = INSTANCE_URI_PREFIX + UUID.randomUUID().toString
1✔
34
)
35

36
object ErrorResponse {
37
  given encoder: zio.json.JsonEncoder[ErrorResponse] = DeriveJsonEncoder.gen[ErrorResponse]
1✔
38

UNCOV
39
  given decoder: zio.json.JsonDecoder[ErrorResponse] = DeriveJsonDecoder.gen[ErrorResponse]
×
40

UNCOV
41
  given schema: Schema[ErrorResponse] = Schema.derived
×
42

43
  private val CamelCaseSplitRegex: Regex = "(([A-Z]?[a-z]+)|([A-Z]))".r
1✔
44
  given failureToErrorResponseConversionZIO[R, A]
1✔
45
      : Conversion[ZIO[R, Failure | ErrorResponse, A], ZIO[R, ErrorResponse, A]] = { effect =>
46
    effect.mapError {
1✔
47
      case failure: Failure => failure
1✔
48
      case e: ErrorResponse => e
1✔
49
    }
50
  }
51

52
  given failureToErrorResponseConversion[R, A]: Conversion[Failure, ErrorResponse] = { failure =>
1✔
53
    val simpleName = failure.getClass.getSimpleName
1✔
54
    ErrorResponse(
1✔
55
      failure.statusCode.code,
1✔
56
      s"error:${failure.namespace}:$simpleName",
1✔
57
      CamelCaseSplitRegex.findAllIn(simpleName).mkString(" "),
1✔
58
      Some(failure.userFacingMessage)
1✔
59
    )
60
  }
61

62
  object annotations {
63
    object status
64
        extends Annotation[Int](
1✔
65
          description = "The HTTP status code for this occurrence of the problem.",
66
          example = 200
67
        )
68
    object `type`
69
        extends Annotation[String](
1✔
70
          description = "A URI reference that identifies the problem type.",
×
71
          example = "https://example.org/doc/#model-MalformedEmail/"
72
        )
73

74
    object title
75
        extends Annotation[String](
1✔
76
          description =
1✔
77
            "A short, human-readable summary of the problem type. It does not change from occurrence to occurrence of the problem.",
78
          example = "Malformed email"
1✔
79
        )
80

81
    object detail
82
        extends Annotation[Option[String]](
1✔
83
          description = "A human-readable explanation specific to this occurrence of the problem.",
84
          example = Option("The received '{}à!è@!.b}' email does not conform to the email format")
1✔
UNCOV
85
        )
×
86

87
    object instance
88
        extends Annotation[String](
1✔
89
          description =
90
            "A URI reference that identifies the specific occurrence of the problem. It may or may not yield further information if dereferenced.",
91
          example = "The received '{}à!è@!.b}' email does not conform to the email format"
92
        )
93
  }
94

95
  def notFound(title: String = "NotFound", detail: Option[String] = None) =
×
96
    ErrorResponse(StatusCode.NotFound.code, `type` = "NotFound", title = title, detail = detail)
×
97

98
  def internalServerError(title: String = "InternalServerError", detail: Option[String] = None) =
×
99
    ErrorResponse(
×
100
      StatusCode.InternalServerError.code,
101
      `type` = "InternalServerError",
102
      title = title,
103
      detail = detail
104
    )
105

106
  def badRequest(title: String = "BadRequest", detail: Option[String] = None) =
1✔
107
    ErrorResponse(
1✔
108
      StatusCode.BadRequest.code,
×
109
      `type` = title,
110
      title = title,
111
      detail = detail
112
    )
113

114
  def unprocessableEntity(title: String = "UnprocessableEntity", detail: Option[String] = None) =
×
115
    ErrorResponse(
×
116
      StatusCode.UnprocessableEntity.code,
117
      `type` = title,
118
      title = title,
119
      detail = detail
120
    )
121

122
  def conflict(title: String = "Conflict", detail: Option[String] = None) =
×
123
    ErrorResponse(
×
124
      StatusCode.Conflict.code,
125
      `type` = title,
126
      title = title,
127
      detail = detail
128
    )
129
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc