Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ trait ResourceDocsAPIMethods extends MdcLoggable with APIMethods220 with APIMeth
case ApiVersion.v1_2_1 => resourceDocs
case ApiVersion.v6_0_0 => resourceDocs // fully on http4s — no Lift route filter
case ApiVersion.v5_1_0 => resourceDocs // fully on http4s — no Lift route filter
case ApiVersion.v5_0_0 => resourceDocs // fully on http4s — no Lift route filter
case _ => resourceDocs.filter(rd => versionRoutesClasses.contains(rd.partialFunction.getClass))
}

Expand Down
5,054 changes: 2,534 additions & 2,520 deletions obp-api/src/main/scala/code/api/v5_0_0/APIMethods500.scala

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions obp-api/src/main/scala/code/api/v5_0_0/Http4s500.scala
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ object Http4s500 {
}

resourceDocs += ResourceDoc(
null, implementedInApiVersion, "createBank", "POST",
null, implementedInApiVersion, nameOf(createBank), "POST",
"/banks", "Create Bank",
s"""Create a new bank (Authenticated access).
|
Expand Down Expand Up @@ -535,7 +535,7 @@ object Http4s500 {
}

resourceDocs += ResourceDoc(
null, implementedInApiVersion, "updateBank", "PUT",
null, implementedInApiVersion, nameOf(updateBank), "PUT",
"/banks", "Update Bank",
"Update an existing bank (Authenticated access).",
postBankJson500, bankJson500,
Expand Down Expand Up @@ -615,7 +615,7 @@ object Http4s500 {
}

resourceDocs += ResourceDoc(
null, implementedInApiVersion, "createAccount", "PUT",
null, implementedInApiVersion, nameOf(createAccount), "PUT",
"/banks/BANK_ID/accounts/NEW_ACCOUNT_ID", "Create Account (PUT)",
"""Create Account at bank specified by BANK_ID with Id specified by ACCOUNT_ID.
|
Expand Down
80 changes: 17 additions & 63 deletions obp-api/src/main/scala/code/api/v5_0_0/OBPAPI5_0_0.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,83 +28,37 @@ package code.api.v5_0_0

import scala.language.reflectiveCalls
import code.api.OBPRestHelper
import code.api.util.APIUtil.{OBPEndpoint, getAllowedEndpoints}
import code.api.util.{APIUtil, VersionedOBPApis}
import code.api.v1_3_0.APIMethods130
import code.api.v1_4_0.APIMethods140
import code.api.v2_0_0.APIMethods200
import code.api.v2_1_0.APIMethods210
import code.api.v2_2_0.APIMethods220
import code.api.v3_0_0.APIMethods300
import code.api.v3_0_0.custom.CustomAPIMethods300
import code.api.v3_1_0.{APIMethods310, OBPAPI3_1_0}
import code.api.v4_0_0.{APIMethods400, OBPAPI4_0_0}
import code.api.v4_0_0.OBPAPI4_0_0.{Implementations4_0_0, endpointsOf4_0_0}
import code.api.util.APIUtil.OBPEndpoint
import code.api.util.VersionedOBPApis
import code.api.v4_0_0.OBPAPI4_0_0
import code.util.Helper.MdcLoggable
import com.github.dwickern.macros.NameOf.nameOf
import com.openbankproject.commons.util.{ApiVersion, ApiVersionStatus}
import net.liftweb.common.{Box, Full}
import net.liftweb.http.{LiftResponse, PlainTextResponse}
import org.apache.http.HttpStatus

/*
This file defines which endpoints from all the versions are available in v5.0.0
This file defines which endpoints from all the versions are available in v5.0.0.
All v5.0.0 endpoints have been migrated to Http4s500 — this object is retained
only for resource-doc aggregation and the Lift dispatch registry.
*/
object OBPAPI5_0_0 extends OBPRestHelper
with APIMethods130
with APIMethods140
with APIMethods200
with APIMethods210
with APIMethods220
with APIMethods300
with CustomAPIMethods300
with APIMethods310
with APIMethods400
with APIMethods500
with MdcLoggable
with VersionedOBPApis{
object OBPAPI5_0_0 extends OBPRestHelper with MdcLoggable with VersionedOBPApis {

val version : ApiVersion = ApiVersion.v5_0_0
val version: ApiVersion = ApiVersion.v5_0_0
val versionStatus = ApiVersionStatus.STABLE.toString

val versionStatus = ApiVersionStatus.STABLE.toString
// Re-export so tests that import OBPAPI5_0_0.Implementations5_0_0 still compile
// after APIMethods500 is replaced with an empty stub.
val Implementations5_0_0 = Http4s500.Implementations5_0_0

// Possible Endpoints from 5.0.0, exclude one endpoint use - method,exclude multiple endpoints use -- method,
// e.g getEndpoints(Implementations5_0_0) -- List(Implementations5_0_0.genericEndpoint, Implementations5_0_0.root)
lazy val endpointsOf5_0_0 = getEndpoints(Implementations5_0_0)

// if old version ResourceDoc objects have the same name endpoint with new version, omit old version ResourceDoc.
// All v5.0.0 endpoints live in Http4s500 — aggregate Http4s500.resourceDocs on top of v4.0.0.
def allResourceDocs = collectResourceDocs(
OBPAPI4_0_0.allResourceDocs,
Implementations5_0_0.resourceDocs
Http4s500.resourceDocs
)

// all endpoints
private val endpoints: List[OBPEndpoint] = OBPAPI4_0_0.routes ++ endpointsOf5_0_0

// Filter the possible endpoints by the disabled / enabled Props settings and add them together
val routes : List[OBPEndpoint] = getAllowedEndpoints(endpoints, allResourceDocs)
// No Lift routes — all v5.0.0 endpoints are served by Http4s500.
val routes: List[OBPEndpoint] = Nil

// register v5.0.0 apis first, Make them available for use!
registerRoutes(routes, allResourceDocs, apiPrefix, true)


logger.info(s"version $version has been run! There are ${routes.length} routes, ${allResourceDocs.length} allResourceDocs.")

// specified response for OPTIONS request.
private val corsResponse: Box[LiftResponse] = Full{
val corsHeaders = List(
"Access-Control-Allow-Origin" -> "*",
"Access-Control-Allow-Methods" -> "GET, POST, OPTIONS, PUT, PATCH, DELETE",
"Access-Control-Allow-Headers" -> "*",
"Access-Control-Allow-Credentials" -> "true",
"Access-Control-Max-Age" -> "1728000" //Tell client that this pre-flight info is valid for 20 days
)
PlainTextResponse("", corsHeaders, HttpStatus.SC_NO_CONTENT)
}
/*
* process OPTIONS http request, just return no content and status is 204
*/
this.serve({
case req if req.requestType.method == "OPTIONS" => corsResponse
})
// CORS for OPTIONS is handled by the http4s corsHandler layer — no Lift serve needed here.
}
23 changes: 9 additions & 14 deletions obp-api/src/main/scala/code/api/v6_0_0/Http4s600.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import code.api.util.http4s.{ErrorResponseConverter, RequestScopeConnection, Res
import code.api.util.http4s.Http4sRequestAttributes.{EndpointHelpers, RequestOps}
import code.api.util.newstyle.ViewNewStyle
import code.api.v2_0_0.JSONFactory200
import code.api.v5_0_0.Http4s500
import code.api.v5_1_0.{Http4s510, JSONFactory510}
import code.api.v6_0_0.JSONFactory600.ScannedApiVersionJsonV600
import code.accountattribute.AccountAttributeX
Expand Down Expand Up @@ -8504,21 +8503,17 @@ object Http4s600 {
val allRoutesWithMiddleware: HttpRoutes[IO] =
ResourceDocMiddleware.apply(resourceDocs)(allRoutes)

// ─── path-rewriting bridge: /obp/v6.0.0/… → /obp/v5.1.0/… → /obp/v5.0.0/… ──
// Tries v5.1.0 native Http4s routes first; if not handled there, falls back to
// the v5.0.0 cascade (v5.0.0 → v4.0.0 → v3.1.0 → v3.0.0).
// ─── path-rewriting bridge: /obp/v6.0.0/… → /obp/v5.1.0/… ─────────────
// Targets v5.1.0; Http4s510 has its own working cascade down to v5.0.0 → v4.0.0 → …
// NOT appended to allRoutes — see object-level scaladoc.
val v600ToV510Bridge: HttpRoutes[IO] = Kleisli[HttpF, Request[IO], Response[IO]] { req =>
lazy val v600ToV510Bridge: HttpRoutes[IO] = Kleisli[HttpF, Request[IO], Response[IO]] { req =>
val rawPath = req.uri.path.renderString
if (rawPath.startsWith("/obp/v6.0.0/")) {
val path510 = rawPath.replaceFirst("/obp/v6\\.0\\.0/", "/obp/v5.1.0/")
val req510 = req.withUri(req.uri.withPath(Uri.Path.unsafeFromString(path510)))
Http4s510.wrappedRoutesV510Services.run(req510)
.orElse {
val path500 = rawPath.replaceFirst("/obp/v6\\.0\\.0/", "/obp/v5.0.0/")
val req500 = req.withUri(req.uri.withPath(Uri.Path.unsafeFromString(path500)))
Http4s500.wrappedRoutesV500Services.run(req500)
}
if (rawPath.startsWith("/obp/v6.0.0/") &&
ResourceDocMatcher.findResourceDoc(req.method.name, req.uri.path, v6ResourceDocIndex).isEmpty) {
val rewritten = rawPath.replaceFirst("/obp/v6\\.0\\.0/", "/obp/v5.1.0/")
val newUri = req.uri.withPath(Uri.Path.unsafeFromString(rewritten))
Http4s510.wrappedRoutesV510Services.run(req.withUri(newUri))
.map(_.putHeaders(Header.Raw(CIString("X-OBP-Version-Served"), "v5.1.0")))
} else {
OptionT.none[IO, Response[IO]]
}
Expand Down
Binary file modified obp-api/src/test/resources/frozen_type_meta_data
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ import code.api.util.APIUtil
import code.api.util.ApiRole._
import code.api.v4_0_0.APIMethods400.Implementations4_0_0
import code.entitlement.Entitlement
import code.setup.PropsReset
import com.github.dwickern.macros.NameOf.nameOf
import com.openbankproject.commons.model.ListResult
import com.openbankproject.commons.util.{ApiVersion, ScannedApiVersion}
import org.scalatest.Tag

import scala.collection.JavaConverters._
class GetScannedApiVersionsTest extends V400ServerSetup {
class GetScannedApiVersionsTest extends V400ServerSetup with PropsReset {

/**
* Test tags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ trait V500ServerSetup extends ServerSetupWithTestData with DefaultUsers {
makeGetRequest(request)
}
val banksJson = getBanksInfo.body.extract[BanksJson400]
if (banksJson.banks.isEmpty) return "DEFAULT_BANK_ID_NOT_SET_Test"
val randomPosition = nextInt(banksJson.banks.size)
val bank = banksJson.banks(randomPosition)
bank.id
Expand Down
4 changes: 3 additions & 1 deletion obp-api/src/test/scala/code/api/v5_1_0/V510ServerSetup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ trait V510ServerSetup extends ServerSetupWithTestData with DefaultUsers {

def randomPrivateAccount(bankId: String): AccountJSON = {
val accountsJson = getPrivateAccounts(bankId, user1).body.extract[AccountsJSON].accounts
if (accountsJson.isEmpty) throw new IllegalStateException(s"No private accounts found for bank $bankId")
val randomPosition = nextInt(accountsJson.size)
accountsJson(randomPosition)
}
Expand All @@ -66,9 +67,10 @@ trait V510ServerSetup extends ServerSetupWithTestData with DefaultUsers {
val request = v5_1_0_Request / "banks" / bankId / "accounts" / "private" <@(consumerAndToken)
makeGetRequest(request)
}

def randomPrivateAccountViaEndpoint(bankId : String): AccountJSON = {
val accountsJson = getPrivateAccountsViaEndpoint(bankId, user1).body.extract[AccountsJSON].accounts
if (accountsJson.isEmpty) throw new IllegalStateException(s"No private accounts found via endpoint for bank $bankId")
val randomPosition = nextInt(accountsJson.size)
accountsJson(randomPosition)
}
Expand Down
2 changes: 1 addition & 1 deletion obp-api/src/test/scala/code/util/APIUtilHeavyTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class APIUtilHeavyTest extends V400ServerSetup with PropsReset {
val bgVersion = ConstantsBG.berlinGroupVersion1.apiShortVersion

feature("test APIUtil.versionIsAllowed method") {
scenario("various disabled/enabled version combinations") {
scenario("Test versionIsAllowed with various disabled/enabled version combinations") {
//This mean, we are only disabled the v4.0.0, all other versions should be enabled
setPropsValues(
"api_disabled_versions" -> "[v4.0.0]",
Expand Down
Loading