mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 17:56:46 +00:00
dynamic_entity_refactor_simplify: fix wrong documentation, refactor json validation
This commit is contained in:
parent
2b7ab67582
commit
0ead4fb235
@ -11,7 +11,7 @@ import code.api.util._
|
||||
import code.api.v1_4_0.JSONFactory1_4_0.{ChallengeAnswerJSON, TransactionRequestAccountJsonV140}
|
||||
import code.api.v2_1_0._
|
||||
import code.api.v3_1_0.ListResult
|
||||
import code.dynamicEntity.DynamicEntityCommons
|
||||
import code.dynamicEntity.{DynamicEntityCommons, DynamicEntityDefinition}
|
||||
import code.model.dataAccess.AuthUser
|
||||
import code.model.toUserExtended
|
||||
import code.transactionrequests.TransactionRequests.TransactionChallengeTypes._
|
||||
@ -23,8 +23,8 @@ import com.openbankproject.commons.model._
|
||||
import net.liftweb.common.{Box, Full}
|
||||
import net.liftweb.http.rest.RestHelper
|
||||
import net.liftweb.json.Serialization.write
|
||||
import net.liftweb.json.Extraction.decompose
|
||||
import code.api.util.ExampleValue.{dynamicEntityRequestBodyExample, dynamicEntityResponseBodyExample}
|
||||
import com.openbankproject.commons.model.enums.DynamicEntityFieldType
|
||||
import net.liftweb.util.StringHelpers
|
||||
import org.atteo.evo.inflector.English
|
||||
import net.liftweb.json._
|
||||
@ -720,15 +720,7 @@ trait APIMethods400 {
|
||||
val jFields = metadataJson.asInstanceOf[JObject].obj
|
||||
require(jFields.size == 1, "json format for create or update DynamicEntity is not correct, it should have a single key value for structure definition")
|
||||
val JField(_, definition) = jFields.head
|
||||
val rqs = (definition \ "required").extract[Array[String]]
|
||||
|
||||
val propertiesFields = (definition \ "properties").asInstanceOf[JObject].values
|
||||
require(rqs.toSet.diff(propertiesFields.keySet).isEmpty)
|
||||
propertiesFields.values.foreach(pair => {
|
||||
val map = pair.asInstanceOf[Map[String, _]]
|
||||
require(map("type").isInstanceOf[String])
|
||||
require(map("example") != null)
|
||||
})
|
||||
definition.extract[DynamicEntityDefinition]
|
||||
}
|
||||
|
||||
resourceDocs += ResourceDoc(
|
||||
@ -737,19 +729,16 @@ trait APIMethods400 {
|
||||
nameOf(createDynamicEntity),
|
||||
"POST",
|
||||
"/management/dynamic_entities",
|
||||
"Add DynamicEntity",
|
||||
s"""Add a DynamicEntity.
|
||||
"Create DynamicEntity",
|
||||
s"""Create a DynamicEntity.
|
||||
|
|
||||
|
|
||||
|${authenticationRequiredMessage(true)}
|
||||
|
|
||||
|Explanation of Fields:
|
||||
|Create one DynamicEntity, after created success, the corresponding CURD endpoints will be generated automatically
|
||||
|
|
||||
|* method_name is required String value
|
||||
|* connector_name is required String value
|
||||
|* is_bank_id_exact_match is required boolean value, if bank_id_pattern is exact bank_id value, this value is true; if bank_id_pattern is null or a regex, this value is false
|
||||
|* bank_id_pattern is optional String value, it can be null, a exact bank_id or a regex
|
||||
|* parameters is optional array of key value pairs. You can set some parameters for this method
|
||||
|Current support filed types as follow:
|
||||
|${DynamicEntityFieldType.values.map(_.toString).mkString("[", ", ", "]")}
|
||||
|
|
||||
|""",
|
||||
dynamicEntityRequestBodyExample,
|
||||
@ -770,7 +759,7 @@ trait APIMethods400 {
|
||||
for {
|
||||
(Full(u), callContext) <- authorizedAccess(cc)
|
||||
_ <- NewStyle.function.hasEntitlement("", u.userId, canCreateDynamicEntity, callContext)
|
||||
failMsg = s"$InvalidJsonFormat The Json body should be the same structure as document example's metadataJason."
|
||||
failMsg = s"$InvalidJsonFormat The Json body should be the same structure as request body example."
|
||||
postedData <- NewStyle.function.tryons(failMsg, 400, callContext) {
|
||||
validateDynamicEntityJson(json)
|
||||
|
||||
@ -799,13 +788,10 @@ trait APIMethods400 {
|
||||
|
|
||||
|${authenticationRequiredMessage(true)}
|
||||
|
|
||||
|Explanations of Fields:
|
||||
|Update one DynamicEntity, after update finished, the corresponding CURD endpoints will be changed.
|
||||
|
|
||||
|* method_name is required String value
|
||||
|* connector_name is required String value
|
||||
|* is_bank_id_exact_match is required boolean value, if bank_id_pattern is exact bank_id value, this value is true; if bank_id_pattern is null or a regex, this value is false
|
||||
|* bank_id_pattern is optional String value, it can be null, a exact bank_id or a regex
|
||||
|* parameters is optional array of key value pairs. You can set some parameters for this method
|
||||
|Current support filed types as follow:
|
||||
|${DynamicEntityFieldType.values.map(_.toString).mkString("[", ", ", "]")}
|
||||
|
|
||||
|""",
|
||||
dynamicEntityRequestBodyExample,
|
||||
@ -827,7 +813,7 @@ trait APIMethods400 {
|
||||
(Full(u), callContext) <- authorizedAccess(cc)
|
||||
_ <- NewStyle.function.hasEntitlement("", u.userId, canUpdateDynamicEntity, callContext)
|
||||
|
||||
failMsg = s"$InvalidJsonFormat The Json body should be the same structure as document example's metadataJason."
|
||||
failMsg = s"$InvalidJsonFormat The Json body should be the same structure as request body example."
|
||||
putData <- NewStyle.function.tryons(failMsg, 400, callContext) {
|
||||
validateDynamicEntityJson(json)
|
||||
val JField(name, _) = json.asInstanceOf[JObject].obj.head
|
||||
|
||||
@ -51,6 +51,6 @@ object DynamicEntityFieldType extends OBPEnumeration[DynamicEntityFieldType]{
|
||||
object number extends Value
|
||||
object integer extends Value
|
||||
object boolean extends Value
|
||||
// object array extends Value //TODO in the future, we consider support these type
|
||||
// object `object` extends Value
|
||||
// object array extends Value
|
||||
// object `object` extends Value //TODO in the future, we consider support nested type
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user