Skip to content

Refactor/migrate bg endpoints#2819

Open
hongwei1 wants to merge 9 commits into
OpenBankProject:developfrom
hongwei1:refactor/migrateBGEndpoints
Open

Refactor/migrate bg endpoints#2819
hongwei1 wants to merge 9 commits into
OpenBankProject:developfrom
hongwei1:refactor/migrateBGEndpoints

Conversation

@hongwei1
Copy link
Copy Markdown
Contributor

No description provided.

hongwei1 added 9 commits May 28, 2026 14:20
…ponse format

Add Http4sBGv13PIIS (1 endpoint: POST /funds-confirmations) and Http4sBGv13 aggregator
wired into Http4sApp ahead of the Lift bridge.

Fix ErrorResponseConverter to emit ErrorMessagesBG (tppMessages) format for all
Berlin Group paths, mirroring APIUtil.failedJsonResponse's URL-prefix check. Without
this, BG v1.3 tests that assert tppMessages structure receive the standard OBP
{code,message} format and fail with "head of empty list".
…ttp4s

Also fixes ResourceDocMatcher.apiPrefixPattern to handle Berlin Group paths
(/berlin-group/v1.3/...) in addition to OBP-standard paths (/obp/vX.X.X/...).
Without this fix the middleware could not strip the BG prefix, segment counts
mismatched, findResourceDoc returned None, and auth was bypassed.
Port all 22 Account Information Service endpoints from the Lift
APIMethods_AccountInformationServiceAISApi builder to native http4s
handlers in Http4sBGv13AIS.

Key implementation details:
- All route handlers declared as lazy val to avoid 64KB <init> limit
- ResourceDocs split into private initXxxResourceDocs() methods
- Body-dispatch pattern for startConsentAuthorisationAll (3 POST variants)
  and updateConsentsPsuDataAll (4 PUT variants) — single handler,
  internal if/else on JSON body shape
- authMode = UserOrApplication for applicationAccess endpoints
  (createConsent, deleteConsent, startConsentAuthorisationAll,
   updateConsentsPsuDataAll); default UserOnly for others
- getAccountList/getConsentAuthorisation use withBalance/delta query params
  read from req.uri
- Consent SCA flow (startConsentAuthorisation → updateConsentsPsuData
  challenge answer) fully ported including ChallengeType and
  StrongCustomerAuthenticationStatus enums

Also fix ResourceDocMiddleware.validateOnly to reject duplicate query
parameters (e.g. ?withBalance=true&withBalance=false) with OBP-10014
before auth processing, returning {"code":400,"message":"..."} so
ErrorMessage can be extracted by BG test assertions.

All 30 AIS scenarios pass with the http4s path (Lift bridge receives zero
BG v1.3 AIS requests).
Port all 24 Payment Initiation Service endpoints from the Lift
APIMethods_PaymentInitiationServicePISApi builder to native http4s
handlers in Http4sBGv13PIS.

Key implementation details:
- All route handlers declared as lazy val (64KB <init> limit avoidance)
- ResourceDocs split into four private init*ResourceDocs() methods
- initiatePaymentImpl private helper shared by initiatePayments,
  initiatePeriodicPayments, and initiateBulkPayments
- cancelPayment uses a custom IO handler (not executeFutureWithStatus)
  to produce a truly-empty 204 NoContent for direct cancellations,
  vs 202 Accepted with CancelPaymentResponseJson for SCA-required cases
- Body-dispatch for multi-variant POST/PUT endpoints:
  startPaymentAuthorisationAll (3 POST variants),
  startPaymentInitiationCancellationAuthorisationAll (3 POST variants),
  updatePaymentPsuDataAll (4 PUT variants),
  updatePaymentCancellationPsuDataAll (4 PUT variants)
  — single handler per URL, internal dispatch via
  checkTransactionAuthorisation / checkUpdatePsuAuthentication /
  checkSelectPsuAuthenticationMethod / checkAuthorisationConfirmation
- getPaymentInitiationStatus uses JsonDSL ~ operator for proper JSON
  (fixes missing-comma bug in Lift's string interpolation)
- authMode = UserOrApplication for initiate-payment endpoints

All 26 PIS scenarios pass. Full BG v1.3 suite (72 tests) all green.
When the berlin_group_v1_3_alias_path prop is configured (e.g. "my-bank/v1.3"),
Http4sBGv13Alias.wrappedRoutes intercepts requests arriving at the alias prefix,
rewrites the URI path to the canonical /berlin-group/v1.3/... prefix, then
delegates to Http4sBGv13.wrappedRoutes. This mirrors the Lift
OBP_BERLIN_GROUP_1_3_Alias behaviour: same endpoints, same auth, different URL
namespace.

- Http4sBGv13Alias.resourceDocs: canonical docs re-stamped with alias
  implementedInApiVersion (for resource-docs endpoint discovery)
- Http4sBGv13Alias.wrappedRoutes: HttpRoutes.empty when alias prop absent,
  path-rewriting bridge when active
- Wire into Http4sApp.baseServices after Http4sBGv13.wrappedRoutes
All 55 Berlin Group v1.3 endpoints (AIS/PIS/SigningBaskets/PIIS) are now
served natively by Http4sBGv13.wrappedRoutes. This commit completes the
migration by:

ResourceDocsAPIMethods:
- Add explicit case ConstantsBG.berlinGroupVersion1 in all three match
  blocks (resourceDocs / versionRoutes / activeResourceDocs), mirroring
  the berlinGroupVersion2 pattern. BG v1.3 resource-docs are now served
  from Http4sBGv13.resourceDocs instead of the ScannedApis fallthrough.

OBP_BERLIN_GROUP_1_3:
- Set routes = Nil; remove registerRoutes call.
  allResourceDocs and endpoints retained for ScannedApis version-discovery.

OBP_BERLIN_GROUP_1_3_Alias:
- Set routes = Nil; remove conditional registerRoutes block.
  allResourceDocs retained; Http4sBGv13Alias.wrappedRoutes handles the
  alias path prefix when berlin_group_v1_3_alias_path is configured.

All 72 BG v1.3 tests (AIS/PIS/PIIS/SigningBaskets) pass via the http4s
path; the Lift bridge receives zero BG v1.3 requests.
…o refactor/migrateBGEndpoints

# Conflicts:
#	obp-api/src/main/scala/code/api/ResourceDocs1_4_0/ResourceDocsAPIMethods.scala
#	obp-api/src/main/scala/code/api/util/http4s/Http4sApp.scala
…d tests

Following the same pattern used for UK Open Banking v3.1.0 (AccountsApi.scala),
comment out all 5 BG v1.3 Lift builder files — their endpoints are now served
by the Http4sBGv13* http4s objects:

Commented out (every line prefixed with //):
- AccountInformationServiceAISApi.scala  (AIS, 22 endpoints)
- PaymentInitiationServicePISApi.scala   (PIS, 24 endpoints)
- ConfirmationOfFundsServicePIISApi.scala (PIIS, 1 endpoint)
- SigningBasketsApi.scala                (SigningBaskets, 8 endpoints)
- CommonServicesApi.scala                (aggregation only)

Aggregators cleaned up (mirror OBP_UKOpenBanking_310 pattern):
- OBP_BERLIN_GROUP_1_3: remove builder imports, replace allResourceDocs
  with Http4sBGv13.resourceDocs, drop endpoints val, add commented-out
  original code block
- OBP_BERLIN_GROUP_1_3_Alias: simplify to use Http4sBGv13Alias.resourceDocs

NewStyle.scala: inline checkPaymentServerTypeError from the retired PIS
builder (was imported directly from APIMethods_PaymentInitiationServicePISApi)

Tests updated to reference http4s equivalents instead of builder:
- AccountInformationServiceAISApiTest: import Http4sBGv13AIS; string literals
  for body-dispatch variant Tags
- PaymentInitiationServicePISApiTest: import Http4sBGv13PIS; string literals
  for variant Tags; filter resourceDocs by partialFunctionName
- ConfirmationOfFundsServicePIISApiTest: alias import Http4sBGv13PIIS;
  filter by partialFunctionName
- SigningBasketServiceSBSApiTest: alias import Http4sBGv13SigningBaskets
- APIUtilHeavyTest: replace APIMethods_AccountInformationServiceAISApi with
  Http4sBGv13AIS; use props-based filtering (same pattern as UK v3.1)

All 72 BG v1.3 tests pass.
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant