bugfix/fixed the swaggerDocs for V500 and V510

This commit is contained in:
hongwei 2023-03-23 15:26:34 +01:00
parent aca5e3d147
commit 76870327f1
8 changed files with 63 additions and 34 deletions

View File

@ -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)

View File

@ -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

View File

@ -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)}}"""

View File

@ -1591,7 +1591,7 @@ trait APIMethods300 {
|${authenticationRequiredMessage(true)}
""".stripMargin,
EmptyBody,
userJsonV200,
userJsonV300,
List(UserNotLoggedIn, UnknownError),
List(apiTagUser, apiTagNewStyle))

View File

@ -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))
}
}
}

View File

@ -1083,6 +1083,10 @@ case class CustomerMessageJsonV400(
from_person: String
)
case class JsonCodeTemplateJson(
code: String
)
object JSONFactory400 {
def createCustomerMessageJson(cMessage : CustomerMessage) : CustomerMessageJsonV400 = {

View File

@ -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) {

View File

@ -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) {