Merge pull request #2148 from hongwei1/develop

feature/support all the versions for the collection-endpoint
This commit is contained in:
Simon Redfern 2022-11-09 15:11:21 +01:00 committed by GitHub
commit ecefb88dcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 162 additions and 9 deletions

View File

@ -283,7 +283,7 @@ trait ResourceDocsAPIMethods extends MdcLoggable with APIMethods220 with APIMeth
logger.debug(s"Generating OBP Resource Docs requestedApiVersion is $requestedApiVersionString")
val requestedApiVersion = ApiVersionUtils.valueOf(requestedApiVersionString)
val dynamicDocs = (DynamicEntityHelper.doc ++ DynamicEndpointHelper.doc ++ DynamicEndpoints.dynamicResourceDocs)
val dynamicDocs = allDynamicResourceDocs
.filter(rd => rd.implementedInApiVersion == requestedApiVersion)
.map(it => it.specifiedUrl match {
case Some(_) => it
@ -331,7 +331,7 @@ trait ResourceDocsAPIMethods extends MdcLoggable with APIMethods220 with APIMeth
var cacheKey = (randomUUID().toString, randomUUID().toString, randomUUID().toString)
CacheKeyFromArguments.buildCacheKey {
Caching.memoizeSyncWithProvider (Some(cacheKey.toString())) (getDynamicResourceDocsTTL second) {
val dynamicDocs = (DynamicEntityHelper.doc ++ DynamicEndpointHelper.doc ++ DynamicEndpoints.dynamicResourceDocs)
val dynamicDocs = allDynamicResourceDocs
.filter(rd => if (bankId.isDefined) rd.createdByBankId == bankId else true)
.map(it => it.specifiedUrl match {
case Some(_) => it
@ -816,7 +816,7 @@ trait ResourceDocsAPIMethods extends MdcLoggable with APIMethods220 with APIMeth
resourceDocs match {
case docs @Some(_) => resourceDocsToJValue(docs)
case _ =>
val dynamicDocs = (DynamicEntityHelper.doc ++ DynamicEndpointHelper.doc ++ DynamicEndpoints.dynamicResourceDocs).toList
val dynamicDocs = allDynamicResourceDocs
resourceDocsToJValue(Some(dynamicDocs))
}
}

View File

@ -38,6 +38,9 @@ import code.UserRefreshes.UserRefreshes
import code.accountholders.AccountHolders
import code.api.Constant._
import code.api.OAuthHandshake._
import code.api.UKOpenBanking.v2_0_0.OBP_UKOpenBanking_200
import code.api.UKOpenBanking.v3_1_0.OBP_UKOpenBanking_310
import code.api.berlin.group.v1.OBP_BERLIN_GROUP_1
import code.api.builder.OBP_APIBuilder
import code.api.dynamic.endpoint.OBPAPIDynamicEndpoint
import code.api.dynamic.endpoint.helper.{DynamicEndpointHelper, DynamicEndpoints, DynamicEntityHelper}
@ -52,6 +55,7 @@ import code.api.v1_2.ErrorMessage
import code.api.v2_0_0.CreateEntitlementJSON
import code.api.dynamic.endpoint.helper.DynamicEndpointHelper
import code.api.dynamic.entity.OBPAPIDynamicEntity
import code.api.v5_0_0.OBPAPI5_0_0
import code.api.{DirectLogin, _}
import code.authtypevalidation.AuthenticationTypeValidationProvider
import code.bankconnectors.Connector
@ -4273,4 +4277,21 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
}
val allowedAnswerTransactionRequestChallengeAttempts = APIUtil.getPropsAsIntValue("answer_transactionRequest_challenge_allowed_attempts").openOr(3)
lazy val allStaticResourceDocs = (OBPAPI5_0_0.allResourceDocs
++ OBP_UKOpenBanking_200.allResourceDocs
++ OBP_UKOpenBanking_310.allResourceDocs
++ code.api.Polish.v2_1_1_1.OBP_PAPI_2_1_1_1.allResourceDocs
++ code.api.STET.v1_4.OBP_STET_1_4.allResourceDocs
++ OBP_BERLIN_GROUP_1.allResourceDocs
++ code.api.AUOpenBanking.v1_0_0.ApiCollector.allResourceDocs
++ code.api.MxOF.CNBV9_1_0_0.allResourceDocs
++ code.api.berlin.group.v1_3.OBP_BERLIN_GROUP_1_3.allResourceDocs
++ code.api.MxOF.OBP_MXOF_1_0_0.allResourceDocs
++ code.api.BahrainOBF.v1_0_0.ApiCollector.allResourceDocs).toList
def allDynamicResourceDocs= (DynamicEntityHelper.doc ++ DynamicEndpointHelper.doc ++ DynamicEndpoints.dynamicResourceDocs).toList
def getAllResourceDocs = allStaticResourceDocs ++ allDynamicResourceDocs
}

View File

@ -10,6 +10,9 @@ import code.DynamicEndpoint.DynamicEndpointSwagger
import code.accountattribute.AccountAttributeX
import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON
import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON.{jsonDynamicResourceDoc, _}
import code.api.UKOpenBanking.v2_0_0.OBP_UKOpenBanking_200
import code.api.UKOpenBanking.v3_1_0.OBP_UKOpenBanking_310
import code.api.berlin.group.v1.OBP_BERLIN_GROUP_1
import code.api.dynamic.endpoint.helper.practise.{DynamicEndpointCodeGenerator, PractiseEndpoint}
import code.api.dynamic.endpoint.helper.{CompiledObjects, DynamicEndpointHelper, DynamicEndpoints, DynamicEntityHelper, DynamicEntityInfo}
import code.api.util.APIUtil.{fullBoxOrException, _}
@ -38,6 +41,7 @@ import code.api.v3_1_0._
import code.api.v4_0_0.JSONFactory400._
import code.api.dynamic.endpoint.helper._
import code.api.dynamic.endpoint.helper.practise.PractiseEndpoint
import code.api.v5_0_0.OBPAPI5_0_0
import code.api.{ChargePolicy, Constant, JsonResponseException}
import code.apicollection.MappedApiCollectionsProvider
import code.apicollectionendpoint.MappedApiCollectionEndpointsProvider
@ -9208,8 +9212,7 @@ trait APIMethods400 {
json.extract[PostApiCollectionEndpointJson400]
}
_ <- Helper.booleanToFuture(failMsg = s"$InvalidOperationId Current OPERATION_ID(${postJson.operation_id})", cc=Some(cc)) {
(DynamicEntityHelper.doc ++ DynamicEndpointHelper.doc ++ DynamicEndpoints.dynamicResourceDocs ++ OBPAPI4_0_0.allResourceDocs).toList
.find(_.operationId==postJson.operation_id).isDefined
getAllResourceDocs.find(_.operationId==postJson.operation_id.trim).isDefined
}
(apiCollection, callContext) <- NewStyle.function.getApiCollectionByUserIdAndCollectionName(cc.userId, apiCollectionName, Some(cc))
apiCollectionEndpoint <- Future{MappedApiCollectionEndpointsProvider.getApiCollectionEndpointByApiCollectionIdAndOperationId(apiCollection.apiCollectionId, postJson.operation_id)}
@ -9258,8 +9261,7 @@ trait APIMethods400 {
json.extract[PostApiCollectionEndpointJson400]
}
_ <- Helper.booleanToFuture(failMsg = s"$InvalidOperationId Current OPERATION_ID(${postJson.operation_id})", cc=Some(cc)) {
(DynamicEntityHelper.doc ++ DynamicEndpointHelper.doc ++ DynamicEndpoints.dynamicResourceDocs ++ OBPAPI4_0_0.allResourceDocs).toList
.find(_.operationId==postJson.operation_id).isDefined
getAllResourceDocs.find(_.operationId==postJson.operation_id.trim).isDefined
}
(apiCollection, callContext) <- NewStyle.function.getApiCollectionById(apiCollectioId, Some(cc))
apiCollectionEndpoint <- Future{MappedApiCollectionEndpointsProvider.getApiCollectionEndpointByApiCollectionIdAndOperationId(apiCollection.apiCollectionId, postJson.operation_id)}

View File

@ -136,7 +136,7 @@ class ApiCollectionEndpointTest extends V400ServerSetup {
apiCollectionEndpointsJsonGetAfterDelete.api_collection_endpoints.length should be (0)
{
Then(s"we test the $ApiEndpoint6")
Then(s"we test the $ApiEndpoint6- OBPv400")
val requestApiCollectionEndpoint = (v4_0_0_Request / "my" / "api-collection-ids" / apiCollectionId / "api-collection-endpoints").POST <@ (user1)
lazy val postApiCollectionEndpointJson = SwaggerDefinitionsJSON.postApiCollectionEndpointJson400.copy(operation_id="OBPv4.0.0-getBanks")
@ -151,6 +151,136 @@ class ApiCollectionEndpointTest extends V400ServerSetup {
val operationId= apiCollectionEndpoint.operation_id
}
{
Then(s"we test the $ApiEndpoint6- OBPv500")
val requestApiCollectionEndpoint = (v4_0_0_Request / "my" / "api-collection-ids" / apiCollectionId / "api-collection-endpoints").POST <@ (user1)
lazy val postApiCollectionEndpointJson = SwaggerDefinitionsJSON.postApiCollectionEndpointJson400.copy(operation_id="OBPv5.0.0-createCustomer")
val responseApiCollectionEndpointJson = makePostRequest(requestApiCollectionEndpoint, write(postApiCollectionEndpointJson))
Then("We should get a 201")
responseApiCollectionEndpointJson.code should equal(201)
val apiCollectionEndpoint = responseApiCollectionEndpointJson.body.extract[ApiCollectionEndpointJson400]
apiCollectionEndpoint.operation_id should be (postApiCollectionEndpointJson.operation_id)
apiCollectionEndpoint.api_collection_endpoint_id shouldNot be (null)
val operationId= apiCollectionEndpoint.operation_id
}
{
Then(s"we test the $ApiEndpoint6- UKv3.1-createAccountAccessConsents")
val requestApiCollectionEndpoint = (v4_0_0_Request / "my" / "api-collection-ids" / apiCollectionId / "api-collection-endpoints").POST <@ (user1)
lazy val postApiCollectionEndpointJson = SwaggerDefinitionsJSON.postApiCollectionEndpointJson400.copy(operation_id="UKv3.1-createAccountAccessConsents")
val responseApiCollectionEndpointJson = makePostRequest(requestApiCollectionEndpoint, write(postApiCollectionEndpointJson))
Then("We should get a 201")
responseApiCollectionEndpointJson.code should equal(201)
val apiCollectionEndpoint = responseApiCollectionEndpointJson.body.extract[ApiCollectionEndpointJson400]
apiCollectionEndpoint.operation_id should be (postApiCollectionEndpointJson.operation_id)
apiCollectionEndpoint.api_collection_endpoint_id shouldNot be (null)
val operationId= apiCollectionEndpoint.operation_id
}
{
Then(s"we test the $ApiEndpoint6- BGv1.3-getConsentStatus")
val requestApiCollectionEndpoint = (v4_0_0_Request / "my" / "api-collection-ids" / apiCollectionId / "api-collection-endpoints").POST <@ (user1)
lazy val postApiCollectionEndpointJson = SwaggerDefinitionsJSON.postApiCollectionEndpointJson400.copy(operation_id="BGv1.3-getConsentStatus")
val responseApiCollectionEndpointJson = makePostRequest(requestApiCollectionEndpoint, write(postApiCollectionEndpointJson))
Then("We should get a 201")
responseApiCollectionEndpointJson.code should equal(201)
val apiCollectionEndpoint = responseApiCollectionEndpointJson.body.extract[ApiCollectionEndpointJson400]
apiCollectionEndpoint.operation_id should be (postApiCollectionEndpointJson.operation_id)
apiCollectionEndpoint.api_collection_endpoint_id shouldNot be (null)
val operationId= apiCollectionEndpoint.operation_id
}
{
Then(s"we test the $ApiEndpoint6- STETv1.4-consentsPut")
val requestApiCollectionEndpoint = (v4_0_0_Request / "my" / "api-collection-ids" / apiCollectionId / "api-collection-endpoints").POST <@ (user1)
lazy val postApiCollectionEndpointJson = SwaggerDefinitionsJSON.postApiCollectionEndpointJson400.copy(operation_id="STETv1.4-consentsPut")
val responseApiCollectionEndpointJson = makePostRequest(requestApiCollectionEndpoint, write(postApiCollectionEndpointJson))
Then("We should get a 201")
responseApiCollectionEndpointJson.code should equal(201)
val apiCollectionEndpoint = responseApiCollectionEndpointJson.body.extract[ApiCollectionEndpointJson400]
apiCollectionEndpoint.operation_id should be (postApiCollectionEndpointJson.operation_id)
apiCollectionEndpoint.api_collection_endpoint_id shouldNot be (null)
val operationId= apiCollectionEndpoint.operation_id
}
{
Then(s"we test the $ApiEndpoint6- PAPIv2.1.1.1-getAccount")
val requestApiCollectionEndpoint = (v4_0_0_Request / "my" / "api-collection-ids" / apiCollectionId / "api-collection-endpoints").POST <@ (user1)
lazy val postApiCollectionEndpointJson = SwaggerDefinitionsJSON.postApiCollectionEndpointJson400.copy(operation_id="PAPIv2.1.1.1-getAccount")
val responseApiCollectionEndpointJson = makePostRequest(requestApiCollectionEndpoint, write(postApiCollectionEndpointJson))
Then("We should get a 201")
responseApiCollectionEndpointJson.code should equal(201)
val apiCollectionEndpoint = responseApiCollectionEndpointJson.body.extract[ApiCollectionEndpointJson400]
apiCollectionEndpoint.operation_id should be (postApiCollectionEndpointJson.operation_id)
apiCollectionEndpoint.api_collection_endpoint_id shouldNot be (null)
val operationId= apiCollectionEndpoint.operation_id
}
{
Then(s"we test the $ApiEndpoint6- AUv1.0.0-listBalance")
val requestApiCollectionEndpoint = (v4_0_0_Request / "my" / "api-collection-ids" / apiCollectionId / "api-collection-endpoints").POST <@ (user1)
lazy val postApiCollectionEndpointJson = SwaggerDefinitionsJSON.postApiCollectionEndpointJson400.copy(operation_id="AUv1.0.0-listBalance")
val responseApiCollectionEndpointJson = makePostRequest(requestApiCollectionEndpoint, write(postApiCollectionEndpointJson))
Then("We should get a 201")
responseApiCollectionEndpointJson.code should equal(201)
val apiCollectionEndpoint = responseApiCollectionEndpointJson.body.extract[ApiCollectionEndpointJson400]
apiCollectionEndpoint.operation_id should be (postApiCollectionEndpointJson.operation_id)
apiCollectionEndpoint.api_collection_endpoint_id shouldNot be (null)
val operationId= apiCollectionEndpoint.operation_id
}
{
Then(s"we test the $ApiEndpoint6- BAHRAIN-OBFv1.0.0-accountAccessConsentsPost")
val requestApiCollectionEndpoint = (v4_0_0_Request / "my" / "api-collection-ids" / apiCollectionId / "api-collection-endpoints").POST <@ (user1)
lazy val postApiCollectionEndpointJson = SwaggerDefinitionsJSON.postApiCollectionEndpointJson400.copy(operation_id="BAHRAIN-OBFv1.0.0-accountAccessConsentsPost")
val responseApiCollectionEndpointJson = makePostRequest(requestApiCollectionEndpoint, write(postApiCollectionEndpointJson))
Then("We should get a 201")
responseApiCollectionEndpointJson.code should equal(201)
val apiCollectionEndpoint = responseApiCollectionEndpointJson.body.extract[ApiCollectionEndpointJson400]
apiCollectionEndpoint.operation_id should be (postApiCollectionEndpointJson.operation_id)
apiCollectionEndpoint.api_collection_endpoint_id shouldNot be (null)
val operationId= apiCollectionEndpoint.operation_id
}
{
Then(s"we test the $ApiEndpoint6- CNBV9v1.0.0-getMxAtms")
val requestApiCollectionEndpoint = (v4_0_0_Request / "my" / "api-collection-ids" / apiCollectionId / "api-collection-endpoints").POST <@ (user1)
lazy val postApiCollectionEndpointJson = SwaggerDefinitionsJSON.postApiCollectionEndpointJson400.copy(operation_id="CNBV9v1.0.0-getMxAtms")
val responseApiCollectionEndpointJson = makePostRequest(requestApiCollectionEndpoint, write(postApiCollectionEndpointJson))
Then("We should get a 201")
responseApiCollectionEndpointJson.code should equal(201)
val apiCollectionEndpoint = responseApiCollectionEndpointJson.body.extract[ApiCollectionEndpointJson400]
apiCollectionEndpoint.operation_id should be (postApiCollectionEndpointJson.operation_id)
apiCollectionEndpoint.api_collection_endpoint_id shouldNot be (null)
val operationId= apiCollectionEndpoint.operation_id
}
{
Then(s"we test the $ApiEndpoint7")
@ -162,7 +292,7 @@ class ApiCollectionEndpointTest extends V400ServerSetup {
val apiCollectionsJsonGet400 = responseGet.body.extract[ApiCollectionEndpointsJson400]
apiCollectionsJsonGet400.api_collection_endpoints.length should be (1)
apiCollectionsJsonGet400.api_collection_endpoints.length should be (9)
}
}
}