refactor/(api): replace hardcoded technology strings with constants

Use TECHNOLOGY_LIFTWEB and TECHNOLOGY_HTTP4S constants from Constant object
instead of inline string literals "lift" and "http4s" across codebase.
This improves maintainability and reduces risk of typos.
This commit is contained in:
hongwei 2026-01-29 14:49:48 +01:00
parent 747d761c9b
commit 30f83680a6
6 changed files with 18 additions and 9 deletions

View File

@ -654,6 +654,11 @@ object Constant extends MdcLoggable {
CAN_GRANT_ACCESS_TO_VIEWS,
CAN_REVOKE_ACCESS_TO_VIEWS,
)
final val TECHNOLOGY_LIFTWEB = "liftweb"
final val TECHNOLOGY_HTTP4S = "http4s"
}

View File

@ -3,6 +3,7 @@ package code.api.v1_4_0
import code.api.Constant.{CREATE_LOCALISED_RESOURCE_DOC_JSON_TTL, LOCALISED_RESOURCE_DOC_PREFIX}
import code.api.berlin.group.v1_3.JvalueCaseClass
import code.api.cache.Caching
import code.api.Constant
import java.util.Date
import code.api.util.APIUtil.{EmptyBody, PrimaryDataBody, ResourceDoc}
import code.api.util.ApiTag.ResourceDocTag
@ -568,7 +569,7 @@ object JSONFactory1_4_0 extends MdcLoggable{
val technology =
if (includeTechnology) {
Some(if (resourceDocUpdatedTags.http4sPartialFunction.isDefined) "http4s" else "lift")
Some(if (resourceDocUpdatedTags.http4sPartialFunction.isDefined) Constant.TECHNOLOGY_HTTP4S else Constant.TECHNOLOGY_LIFTWEB)
} else {
None
}

View File

@ -1,5 +1,6 @@
package code.api.ResourceDocs1_4_0
import code.api.Constant
import code.setup.{PropsReset, ServerSetup}
import com.openbankproject.commons.util.ApiVersion
import net.liftweb.json.JsonAST.{JArray, JNothing, JNull, JString}
@ -20,7 +21,7 @@ class ResourceDocsTechnologyTest extends ServerSetup with PropsReset {
(response.body \ "resource_docs") match {
case JArray(docs) =>
val technology = docs.head \ "implemented_by" \ "technology"
technology should equal(JString("lift"))
technology should equal(JString(Constant.TECHNOLOGY_LIFTWEB))
case _ =>
fail("Expected resource_docs field to be an array")
}

View File

@ -1,5 +1,6 @@
package code.api.ResourceDocs1_4_0
import code.api.Constant
import code.api.ResourceDocs1_4_0.ResourceDocs140.ImplementationsResourceDocs
import code.api.berlin.group.ConstantsBG
import code.api.util.APIUtil.OAuth._
@ -104,7 +105,7 @@ class ResourceDocsTest extends ResourceDocsV140ServerSetup with PropsReset with
And("We should get 200 and the response can be extract to case classes")
val responseDocs = responseGetObp.body.extract[ResourceDocsJson]
responseGetObp.code should equal(200)
responseDocs.resource_docs.head.implemented_by.technology shouldBe Some("lift")
responseDocs.resource_docs.head.implemented_by.technology shouldBe Some(Constant.TECHNOLOGY_LIFTWEB)
//This should not throw any exceptions
responseDocs.resource_docs.map(responseDoc => stringToNodeSeq(responseDoc.description))
}

View File

@ -1,7 +1,7 @@
package code.api.v1_4_0
import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON.usersJsonV400
import code.api.Constant
import java.util.Date
import code.api.util.APIUtil.ResourceDoc
import code.api.util.{APIUtil, ExampleValue}
@ -131,13 +131,13 @@ class JSONFactory1_4_0Test extends code.setup.ServerSetup {
json1.implemented_by.technology shouldBe None
val json2 = JSONFactory1_4_0.createLocalisedResourceDocJson(liftDoc, false, None, includeTechnology = true, urlParameters, "JSON request body fields:", "JSON response body fields:")
json2.implemented_by.technology shouldBe Some("lift")
json2.implemented_by.technology shouldBe Some(Constant.TECHNOLOGY_LIFTWEB)
}
scenario("Technology field should be http4s when includeTechnology=true and doc is http4s") {
val http4sDoc: ResourceDoc = code.api.v7_0_0.Http4s700.resourceDocs.head
val json = JSONFactory1_4_0.createLocalisedResourceDocJson(http4sDoc, true, None, includeTechnology = true, urlParameters, "JSON request body fields:", "JSON response body fields:")
json.implemented_by.technology shouldBe Some("http4s")
json.implemented_by.technology shouldBe Some(Constant.TECHNOLOGY_HTTP4S)
}
scenario("createTypedBody should work well, no exception is good enough") {

View File

@ -1,5 +1,6 @@
package code.api.v7_0_0
import code.api.Constant
import cats.effect.IO
import cats.effect.unsafe.implicits.global
import code.api.util.ApiRole.{canGetCardsForBank, canReadResourceDoc}
@ -252,7 +253,7 @@ class Http4s700RoutesTest extends ServerSetupWithTestData {
toFieldMap(rdFields).get("implemented_by") match {
case Some(JObject(implFields)) =>
toFieldMap(implFields).get("technology") match {
case Some(JString(value)) => value == "http4s"
case Some(JString(value)) => value == Constant.TECHNOLOGY_HTTP4S
case _ => false
}
case _ => false
@ -289,7 +290,7 @@ class Http4s700RoutesTest extends ServerSetupWithTestData {
toFieldMap(rdFields).get("implemented_by") match {
case Some(JObject(implFields)) =>
toFieldMap(implFields).get("technology") match {
case Some(JString(value)) => value == "http4s"
case Some(JString(value)) => value == Constant.TECHNOLOGY_HTTP4S
case _ => false
}
case _ => false
@ -301,7 +302,7 @@ class Http4s700RoutesTest extends ServerSetupWithTestData {
toFieldMap(rdFields).get("implemented_by") match {
case Some(JObject(implFields)) =>
toFieldMap(implFields).get("technology") match {
case Some(JString(value)) => value == "lift"
case Some(JString(value)) => value == Constant.TECHNOLOGY_LIFTWEB
case _ => false
}
case _ => false