Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade tapir / openapiCirceYaml versions #7014

Merged
merged 6 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ val cronParserV = "9.1.6" // 9.1.7+ requires JDK 16+
val javaxValidationApiV = "2.0.1.Final"
val caffeineCacheV = "3.1.8"
val sttpV = "3.9.8"
val tapirV = "1.10.5"
val openapiCirceYamlV = "0.9.0"
val tapirV = "1.11.7"
val openapiCirceYamlV = "0.11.3"
//we use legacy version because this one supports Scala 2.12
val monocleV = "2.1.0"
val jmxPrometheusJavaagentV = "0.20.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import pl.touk.nussknacker.ui.security.api.SecurityError.{
ImpersonationNotSupportedError,
InsufficientPermission
}
import sttp.model.StatusCode.{Forbidden, NotFound, NotImplemented, Unauthorized}
import sttp.model.StatusCode.{Forbidden, NotImplemented, Unauthorized}
import sttp.tapir.EndpointIO.Example
import sttp.tapir._

Expand All @@ -29,7 +29,6 @@ trait BaseEndpointDefinitions {

object BaseEndpointDefinitions {

type EndpointError[ERROR] = Either[SecurityError, ERROR]
type SecuredEndpoint[INPUT, BUSINESS_ERROR, OUTPUT, -R] =
Endpoint[AuthCredentials, INPUT, Either[BUSINESS_ERROR, SecurityError], OUTPUT, R]

Expand Down Expand Up @@ -67,37 +66,20 @@ object BaseEndpointDefinitions {
)
)
),
oneOfVariantFromMatchType(
NotFound,
plainBody[ImpersonatedUserDataNotFoundError.type]
.description("Identity provided in the Nu-Impersonate-User-Identity header did not match any user")
.example(
Example.of(
summary = Some("No impersonated user's data found for provided identity"),
value = ImpersonatedUserDataNotFoundError
)
)
),
oneOfVariantFromMatchType(
Forbidden,
plainBody[ImpersonationMissingPermissionError.type]
.example(
Example.of(
summary = Some("Authorization failed, user does not have permission to impersonate"),
value = ImpersonationMissingPermissionError
oneOfBody[SecurityError](
plainBody[SecurityError]
.examples(
List(
Example.of(name = Some("InsufficientPermission"), value = InsufficientPermission),
Example
.of(name = Some("ImpersonationMissingPermission"), value = ImpersonationMissingPermissionError),
Example.of(name = Some("ImpersonatedUserDataNotFound"), value = ImpersonatedUserDataNotFoundError)
)
)
)
)
),
oneOfVariantFromMatchType(
Forbidden,
plainBody[InsufficientPermission.type]
.example(
Example.of(
summary = Some("Authorization failed"),
value = InsufficientPermission
)
)
)
)
)
}
Expand All @@ -106,36 +88,16 @@ object BaseEndpointDefinitions {

private object Codecs {

implicit val authenticationErrorCodec: Codec[String, CannotAuthenticateUser.type, CodecFormat.TextPlain] = {
Codec.string.map(
Mapping.from[String, CannotAuthenticateUser.type](_ => CannotAuthenticateUser)(_ =>
"The supplied authentication is invalid"
)
)
}

implicit val authorizationErrorCodec: Codec[String, InsufficientPermission.type, CodecFormat.TextPlain] = {
Codec.string.map(
Mapping.from[String, InsufficientPermission.type](_ => InsufficientPermission)(_ =>
"The supplied authentication is not authorized to access this resource"
)
)
}

implicit val impersonationPermissionErrorCodec
: Codec[String, ImpersonationMissingPermissionError.type, CodecFormat.TextPlain] = {
implicit val authorizationErrorCodec: Codec[String, SecurityError, CodecFormat.TextPlain] = {
Codec.string.map(
Mapping.from[String, ImpersonationMissingPermissionError.type](_ => ImpersonationMissingPermissionError)(_ =>
ImpersonationMissingPermissionError.errorMessage
)
Mapping.from[String, SecurityError](_ => InsufficientPermission)(s => s.errorMessage)
)
}

implicit val impersonatedDataNotFoundErrorCodec
: Codec[String, ImpersonatedUserDataNotFoundError.type, CodecFormat.TextPlain] = {
implicit val authenticationErrorCodec: Codec[String, CannotAuthenticateUser.type, CodecFormat.TextPlain] = {
Codec.string.map(
Mapping.from[String, ImpersonatedUserDataNotFoundError.type](_ => ImpersonatedUserDataNotFoundError)(_ =>
ImpersonatedUserDataNotFoundError.errorMessage
Mapping.from[String, CannotAuthenticateUser.type](_ => CannotAuthenticateUser)(_ =>
"The supplied authentication is invalid"
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,6 @@ object TestingApiHttpService {
)
)

val noProcessingTypeExample: EndpointOutput.OneOfVariant[NoProcessingType] =
oneOfVariantFromMatchType(
NotFound,
plainBody[NoProcessingType]
.example(
Example.of(
summary = Some("ProcessingType type: {processingType} not found"),
value = NoProcessingType("'processingType'")
)
)
)

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class TestingApiEndpoints(auth: EndpointInput[AuthCredentials]) extends BaseEndp
)
.errorOut(
oneOf[TestingError](
noScenarioExample // TODO
noScenarioExample
)
)
.withSecurity(auth)
Expand Down Expand Up @@ -205,7 +205,7 @@ class TestingApiEndpoints(auth: EndpointInput[AuthCredentials]) extends BaseEndp
.errorOut(
oneOf[TestingError](
testDataGenerationErrorExample,
noScenarioExample // TODO
noScenarioExample
)
)
.withSecurity(auth)
Expand Down
Loading
Loading