From 76870327f1337f083351c398c3a67eef7b49fcdb Mon Sep 17 00:00:00 2001 From: hongwei Date: Thu, 23 Mar 2023 15:26:34 +0100 Subject: [PATCH] bugfix/fixed the swaggerDocs for V500 and V510 --- .../ResourceDocsAPIMethods.scala | 14 ++--- .../SwaggerDefinitionsJSON.scala | 58 +++++++++++++------ .../SwaggerJSONFactory.scala | 5 +- .../scala/code/api/v3_0_0/APIMethods300.scala | 2 +- .../scala/code/api/v4_0_0/APIMethods400.scala | 6 +- .../code/api/v4_0_0/JSONFactory4.0.0.scala | 4 ++ .../v4_0_0/EndpointMappingBankLevelTest.scala | 4 +- .../code/api/v4_0_0/EndpointMappingTest.scala | 4 +- 8 files changed, 63 insertions(+), 34 deletions(-) diff --git a/obp-api/src/main/scala/code/api/ResourceDocs1_4_0/ResourceDocsAPIMethods.scala b/obp-api/src/main/scala/code/api/ResourceDocs1_4_0/ResourceDocsAPIMethods.scala index b0f2c8311..e5e538d39 100644 --- a/obp-api/src/main/scala/code/api/ResourceDocs1_4_0/ResourceDocsAPIMethods.scala +++ b/obp-api/src/main/scala/code/api/ResourceDocs1_4_0/ResourceDocsAPIMethods.scala @@ -4,6 +4,7 @@ import code.api.Constant.PARAM_LOCALE import java.util.UUID.randomUUID import code.api.OBPRestHelper +import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON.canGetCustomers import code.api.builder.OBP_APIBuilder import code.api.cache.Caching import code.api.dynamic.endpoint.helper.{DynamicEndpointHelper, DynamicEndpoints} @@ -24,7 +25,7 @@ import code.util.Helper.MdcLoggable import com.github.dwickern.macros.NameOf.nameOf import com.openbankproject.commons.model.{BankId, ListResult, User} import com.openbankproject.commons.model.enums.ContentParam.{ALL, DYNAMIC, STATIC} -import com.openbankproject.commons.model.enums.{ContentParam} +import com.openbankproject.commons.model.enums.ContentParam import com.openbankproject.commons.util.ApiStandards._ import com.openbankproject.commons.util.{ApiVersion, ScannedApiVersion} import com.tesobe.CacheKeyFromArguments @@ -176,11 +177,8 @@ trait ResourceDocsAPIMethods extends MdcLoggable with APIMethods220 with APIMeth { // only `obp` standard show the `localResourceDocs` case version: ScannedApiVersion - if(version.apiStandard == obp.toString && version==ApiVersion.v4_0_0) => - activePlusLocalResourceDocs ++= localResourceDocs.filterNot(_.partialFunctionName == nameOf(getResourceDocsObp)) - case version: ScannedApiVersion - if(version.apiStandard == obp.toString && version!=ApiVersion.v4_0_0) => - activePlusLocalResourceDocs ++= localResourceDocs.filterNot(_.partialFunctionName == nameOf(getResourceDocsObpV400)) + if(version.apiStandard == obp.toString) => + activePlusLocalResourceDocs ++= localResourceDocs case _ => ; // all other standards only show their own apis. } @@ -410,7 +408,9 @@ trait ResourceDocsAPIMethods extends MdcLoggable with APIMethods220 with APIMeth emptyObjectJson, emptyObjectJson, UnknownError :: Nil, - List(apiTagDocumentation)) + List(apiTagDocumentation), + Some(List(canGetCustomers)) + ) val exampleResourceDocsJson = JSONFactory1_4_0.createResourceDocsJson(List(exampleResourceDoc), false, None) diff --git a/obp-api/src/main/scala/code/api/ResourceDocs1_4_0/SwaggerDefinitionsJSON.scala b/obp-api/src/main/scala/code/api/ResourceDocs1_4_0/SwaggerDefinitionsJSON.scala index b6dfa76f9..8f424a8ef 100644 --- a/obp-api/src/main/scala/code/api/ResourceDocs1_4_0/SwaggerDefinitionsJSON.scala +++ b/obp-api/src/main/scala/code/api/ResourceDocs1_4_0/SwaggerDefinitionsJSON.scala @@ -11,7 +11,7 @@ import code.api.dynamic.endpoint.helper.practise.PractiseEndpoint import code.api.util.APIUtil.{defaultJValue, _} import code.api.util.ApiRole._ import code.api.util.ExampleValue._ -import code.api.util.{APIUtil, ApiTrigger, ExampleValue} +import code.api.util.{APIUtil, ApiRole, ApiTrigger, ExampleValue} import code.api.v2_2_0.JSONFactory220.{AdapterImplementationJson, MessageDocJson, MessageDocsJson} import code.api.v3_0_0.JSONFactory300.createBranchJsonV300 import code.api.v3_0_0.custom.JSONFactoryCustom300 @@ -31,7 +31,7 @@ import com.github.dwickern.macros.NameOf.nameOf import com.openbankproject.commons.model import com.openbankproject.commons.model.PinResetReason.{FORGOT, GOOD_SECURITY_PRACTICE} import com.openbankproject.commons.model.enums.{AttributeCategory, CardAttributeType, ChallengeType} -import com.openbankproject.commons.model.{UserAuthContextUpdateStatus, ViewBasic, _} +import com.openbankproject.commons.model.{TransactionRequestSimple, UserAuthContextUpdateStatus, ViewBasic, _} import com.openbankproject.commons.util.{ApiVersion, FieldNameApiVersions, ReflectUtils, RequiredArgs, RequiredInfo} import net.liftweb.json import java.net.URLEncoder @@ -582,17 +582,29 @@ object SwaggerDefinitionsJSON { creditorAccount = PaymentAccount(iban = "DE75512108001245126199"), creditorName = "John Miles" ) + + val transactionRequestSimple= TransactionRequestSimple( + otherBankRoutingScheme = bankRoutingSchemeExample.value, + otherBankRoutingAddress = bankRoutingAddressExample.value, + otherBranchRoutingScheme = branchRoutingSchemeExample.value, + otherBranchRoutingAddress = branchRoutingAddressExample.value, + otherAccountRoutingScheme = accountRoutingSchemeExample.value, + otherAccountRoutingAddress = accountRoutingAddressExample.value, + otherAccountSecondaryRoutingScheme = accountRoutingSchemeExample.value, + otherAccountSecondaryRoutingAddress = accountRoutingAddressExample.value + ) val transactionRequestBodyAllTypes = TransactionRequestBodyAllTypes ( to_sandbox_tan = Some(transactionRequestAccount), to_sepa = Some(transactionRequestIban), to_counterparty = Some(transactionRequestCounterpartyId), + to_simple = Some(transactionRequestSimple), to_transfer_to_phone = Some(transactionRequestTransferToPhone), to_transfer_to_atm = Some(transactionRequestTransferToAtm), to_transfer_to_account = Some(transactionRequestTransferToAccount), to_sepa_credit_transfers = Some(sepaCreditTransfers), value = amountOfMoney, - description = "String" + description = descriptionExample.value ) val transactionRequest = TransactionRequest( @@ -1928,6 +1940,25 @@ object SwaggerDefinitionsJSON { ExampleValue.typeExample.value, ExampleValue.textExample.value, ) + val viewJSON300 = ViewJSON300( + bank_id = bankIdExample.value, + account_id = accountIdExample.value, + view_id = viewIdExample.value + ) + + val viewsJSON300 = ViewsJSON300( + list = List(viewJSON300) + ) + + val userJsonV300 = UserJsonV300( + user_id = ExampleValue.userIdExample.value, + email = ExampleValue.emailExample.value, + provider_id = providerIdValueExample.value, + provider = providerValueExample.value, + username = usernameExample.value, + entitlements = entitlementJSONs, + views = Some(viewsJSON300) + ) val userJsonV400 = UserJsonV400( user_id = ExampleValue.userIdExample.value, @@ -1936,24 +1967,11 @@ object SwaggerDefinitionsJSON { provider = providerValueExample.value, username = usernameExample.value, entitlements = entitlementJSONs, - views = None, + views = Some(viewsJSON300), agreements = Some(List(userAgreementJson)), is_deleted = false, last_marketing_agreement_signed_date = Some(DateWithDayExampleObject), is_locked = false - ) - val userJsonWithAgreementsV400 = UserJsonV400( - user_id = ExampleValue.userIdExample.value, - email = ExampleValue.emailExample.value, - provider_id = providerIdValueExample.value, - provider = providerValueExample.value, - username = usernameExample.value, - entitlements = entitlementJSONs, - views = None, - agreements = Some(Nil), - is_deleted = false, - last_marketing_agreement_signed_date = Some(DateWithDayExampleObject), - is_locked = false ) val userIdJsonV400 = UserIdJsonV400( user_id = ExampleValue.userIdExample.value @@ -4353,6 +4371,8 @@ object SwaggerDefinitionsJSON { views_available = List(viewBasicCommons), bank_id = bankIdExample.value ) + + val canGetCustomers = ApiRole.canGetCustomers val cardAttributeCommons = CardAttributeCommons( bankId = Some(BankId(bankIdExample.value)), @@ -4843,7 +4863,9 @@ object SwaggerDefinitionsJSON { successResponseBody = Option(json.parse(successResponseBodyExample.value)) ) - val jsonCodeTemplate = "code" -> URLEncoder.encode("""println("hello")""", "UTF-8") + val jsonCodeTemplateJson = JsonCodeTemplateJson( + URLEncoder.encode("""println("hello")""", "UTF-8") + ) val supportedCurrenciesJson = SupportedCurrenciesJson( supportedCurrenciesExample.value diff --git a/obp-api/src/main/scala/code/api/ResourceDocs1_4_0/SwaggerJSONFactory.scala b/obp-api/src/main/scala/code/api/ResourceDocs1_4_0/SwaggerJSONFactory.scala index 6d4b2a8a4..3267f8f6d 100644 --- a/obp-api/src/main/scala/code/api/ResourceDocs1_4_0/SwaggerJSONFactory.scala +++ b/obp-api/src/main/scala/code/api/ResourceDocs1_4_0/SwaggerJSONFactory.scala @@ -606,7 +606,7 @@ object SwaggerJSONFactory extends MdcLoggable { val paramValue = it._2 val exampleValue = paramValue match { - case Some(v) => v + case Some(v) => v // Here it will get the value from Option/Box, case _ => paramValue } @@ -652,6 +652,7 @@ object SwaggerJSONFactory extends MdcLoggable { //Boolean - 4 kinds case _ if isAnyOfType[Boolean, JBool, XBoolean] => s""" {"type":"boolean" $example}""" + case _ if exampleValue.isInstanceOf[Boolean] => s""" {"type":"boolean" $example}""" //TODO. Here need to be enhanced. case _ if isAnyOfType[Option[Boolean], Option[JBool], Option[XBoolean]] => s""" {"type":"boolean" $example}""" case _ if isAnyOfType[Coll[Boolean], Coll[JBool], Coll[XBoolean]] => s""" {"type":"array", "items":{"type": "boolean"}}""" case _ if isAnyOfType[Option[Coll[Boolean]],Option[Coll[JBool]],Option[Coll[XBoolean]]] => s""" {"type":"array", "items":{"type": "boolean"}}""" @@ -707,6 +708,8 @@ object SwaggerJSONFactory extends MdcLoggable { val value = exampleValue match { case Some(v: Array[_]) if v.nonEmpty => v.head case Some(coll :Coll[_]) if coll.nonEmpty => coll.head + case (v: Array[_]) if v.nonEmpty => v.head + case (coll: Coll[_]) if coll.nonEmpty => coll.head case _ => null } s""" {"type": "array", "items":${buildSwaggerSchema(tp, value)}}""" diff --git a/obp-api/src/main/scala/code/api/v3_0_0/APIMethods300.scala b/obp-api/src/main/scala/code/api/v3_0_0/APIMethods300.scala index 77e1ccbda..aea646289 100644 --- a/obp-api/src/main/scala/code/api/v3_0_0/APIMethods300.scala +++ b/obp-api/src/main/scala/code/api/v3_0_0/APIMethods300.scala @@ -1591,7 +1591,7 @@ trait APIMethods300 { |${authenticationRequiredMessage(true)} """.stripMargin, EmptyBody, - userJsonV200, + userJsonV300, List(UserNotLoggedIn, UnknownError), List(apiTagUser, apiTagNewStyle)) diff --git a/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala b/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala index 72a795640..54d1e0ff5 100644 --- a/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala +++ b/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala @@ -3615,7 +3615,7 @@ trait APIMethods400 { | """.stripMargin, EmptyBody, - userJsonWithAgreementsV400, + userJsonV400, List(UserNotLoggedIn, UserHasMissingRoles, UserNotFoundById, UnknownError), List(apiTagUser, apiTagNewStyle), Some(List(canGetAnyUser))) @@ -10600,7 +10600,7 @@ trait APIMethods400 { |auto compilation and debug |""", jsonResourceDocFragment, - jsonCodeTemplate, + jsonCodeTemplateJson, List( $UserNotLoggedIn, InvalidJsonFormat, @@ -10633,7 +10633,7 @@ trait APIMethods400 { code = DynamicEndpointCodeGenerator.buildTemplate(resourceDocFragment) } yield { - ("code" -> URLEncoder.encode(code, "UTF-8"), HttpCode.`201`(cc.callContext)) + (JsonCodeTemplateJson(URLEncoder.encode(code, "UTF-8")), HttpCode.`201`(cc.callContext)) } } } diff --git a/obp-api/src/main/scala/code/api/v4_0_0/JSONFactory4.0.0.scala b/obp-api/src/main/scala/code/api/v4_0_0/JSONFactory4.0.0.scala index 634430445..c17132116 100644 --- a/obp-api/src/main/scala/code/api/v4_0_0/JSONFactory4.0.0.scala +++ b/obp-api/src/main/scala/code/api/v4_0_0/JSONFactory4.0.0.scala @@ -1083,6 +1083,10 @@ case class CustomerMessageJsonV400( from_person: String ) +case class JsonCodeTemplateJson( + code: String +) + object JSONFactory400 { def createCustomerMessageJson(cMessage : CustomerMessage) : CustomerMessageJsonV400 = { diff --git a/obp-api/src/test/scala/code/api/v4_0_0/EndpointMappingBankLevelTest.scala b/obp-api/src/test/scala/code/api/v4_0_0/EndpointMappingBankLevelTest.scala index 337ba386c..e9c4c579b 100644 --- a/obp-api/src/test/scala/code/api/v4_0_0/EndpointMappingBankLevelTest.scala +++ b/obp-api/src/test/scala/code/api/v4_0_0/EndpointMappingBankLevelTest.scala @@ -1,6 +1,6 @@ package code.api.v4_0_0 -import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON.jsonCodeTemplate +import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON.jsonCodeTemplateJson import code.api.util.APIUtil.OAuth._ import code.api.util.ApiRole._ import code.api.util.ErrorMessages.{UserNotLoggedIn, _} @@ -30,7 +30,7 @@ class EndpointMappingBankLevelTest extends V400ServerSetup { object ApiEndpoint5 extends Tag(nameOf(Implementations4_0_0.deleteBankLevelEndpointMapping)) val rightEntity = endpointMappingRequestBodyExample - val wrongEntity = jsonCodeTemplate + val wrongEntity = jsonCodeTemplateJson feature("Add a EndpointMapping v4.0.0- Unauthorized access") { scenario("We will call the endpoint without user credentials", ApiEndpoint1, VersionOfApi) { diff --git a/obp-api/src/test/scala/code/api/v4_0_0/EndpointMappingTest.scala b/obp-api/src/test/scala/code/api/v4_0_0/EndpointMappingTest.scala index ea15d52a8..3a994b0c1 100644 --- a/obp-api/src/test/scala/code/api/v4_0_0/EndpointMappingTest.scala +++ b/obp-api/src/test/scala/code/api/v4_0_0/EndpointMappingTest.scala @@ -1,6 +1,6 @@ package code.api.v4_0_0 -import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON.jsonCodeTemplate +import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON.jsonCodeTemplateJson import code.api.util.APIUtil.OAuth._ import code.api.util.ApiRole.{CanCreateEndpointMapping, _} import code.api.util.ErrorMessages.{UserNotLoggedIn, _} @@ -30,7 +30,7 @@ class EndpointMappingTest extends V400ServerSetup { object ApiEndpoint5 extends Tag(nameOf(Implementations4_0_0.deleteEndpointMapping)) val rightEntity = endpointMappingRequestBodyExample - val wrongEntity = jsonCodeTemplate + val wrongEntity = jsonCodeTemplateJson feature("Add a EndpointMapping v4.0.0- Unauthorized access") { scenario("We will call the endpoint without user credentials", ApiEndpoint1, VersionOfApi) {