mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 13:07:02 +00:00
feature/exclude_response_json_fields according "excluded.response.field.values" to exclude response json fields.
This commit is contained in:
parent
6435a4a6c2
commit
29eb2164c6
@ -489,7 +489,7 @@
|
||||
<forkMode>once</forkMode>
|
||||
<junitxml>.</junitxml>
|
||||
<filereports>WDF TestSuite.txt</filereports>
|
||||
<argLine>-Drun.mode=test -XX:MaxPermSize=128m -Xms512m -Xmx512m</argLine>
|
||||
<argLine>-Drun.mode=test -XX:MaxMetaspaceSize=512m -Xms512m -Xmx512m</argLine>
|
||||
<tagsToExclude>code.external</tagsToExclude>
|
||||
</configuration>
|
||||
<executions>
|
||||
|
||||
@ -1151,4 +1151,7 @@ dynamic_code_compile_validate_dependencies=[\
|
||||
classOf[ResourceDoc].getTypeName -> "getPathParams",\
|
||||
"scala.reflect.runtime.package\$" -> "universe",\
|
||||
PractiseEndpoint.getClass.getTypeName + "*" -> "*"\
|
||||
]
|
||||
]
|
||||
|
||||
## when api response json field value in the json array, the field will be excluded
|
||||
excluded.response.field.values=["String", "", null, []]
|
||||
@ -573,23 +573,31 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
|
||||
|
||||
def successJsonResponseNewStyle(cc: Any, callContext: Option[CallContext], httpCode : Int = 200)(implicit headers: CustomResponseHeaders = CustomResponseHeaders(Nil)) : JsonResponse = {
|
||||
val jsonAst: JValue = ApiSession.processJson((Extraction.decompose(cc)), callContext)
|
||||
|
||||
// exclude all values that defined in props "excluded.response.field.values"
|
||||
val excludedFieldValues = APIUtil.getPropsValue("excluded.response.field.values").map[JArray](it => json.parse(it).asInstanceOf[JArray])
|
||||
val jsonValue = excludedFieldValues match {
|
||||
case Full(JArray(arr:List[JValue])) =>
|
||||
JsonUtils.deleteFieldRec(jsonAst)(v => arr.contains(v.value))
|
||||
case _ => jsonAst
|
||||
}
|
||||
callContext match {
|
||||
case Some(c) if c.httpCode.isDefined && c.httpCode.get == 204 =>
|
||||
val httpBody = None
|
||||
val jwsHeaders: CustomResponseHeaders = getSignRequestHeadersNewStyle(callContext,httpBody)
|
||||
JsonResponse(JsRaw(""), getHeaders() ::: headers.list ::: jwsHeaders.list, Nil, 204)
|
||||
case Some(c) if c.httpCode.isDefined =>
|
||||
val httpBody = Full(JsonAST.compactRender(jsonAst))
|
||||
val httpBody = Full(JsonAST.compactRender(jsonValue))
|
||||
val jwsHeaders: CustomResponseHeaders = getSignRequestHeadersNewStyle(callContext,httpBody)
|
||||
JsonResponse(jsonAst, getHeaders() ::: headers.list ::: jwsHeaders.list, Nil, c.httpCode.get)
|
||||
JsonResponse(jsonValue, getHeaders() ::: headers.list ::: jwsHeaders.list, Nil, c.httpCode.get)
|
||||
case Some(c) if c.verb.toUpperCase() == "DELETE" =>
|
||||
val httpBody = None
|
||||
val jwsHeaders: CustomResponseHeaders = getSignRequestHeadersNewStyle(callContext,httpBody)
|
||||
JsonResponse(JsRaw(""), getHeaders() ::: headers.list ::: jwsHeaders.list, Nil, 204)
|
||||
case _ =>
|
||||
val httpBody = Full(JsonAST.compactRender(jsonAst))
|
||||
val httpBody = Full(JsonAST.compactRender(jsonValue))
|
||||
val jwsHeaders: CustomResponseHeaders = getSignRequestHeadersNewStyle(callContext,httpBody)
|
||||
JsonResponse(jsonAst, getHeaders() ::: headers.list ::: jwsHeaders.list, Nil, httpCode)
|
||||
JsonResponse(jsonValue, getHeaders() ::: headers.list ::: jwsHeaders.list, Nil, httpCode)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -97,7 +97,7 @@
|
||||
<forkMode>once</forkMode>
|
||||
<junitxml>.</junitxml>
|
||||
<filereports>WDF TestSuite.txt</filereports>
|
||||
<argLine>-Drun.mode=test -XX:MaxPermSize=128m -Xms512m -Xmx512m</argLine>
|
||||
<argLine>-Drun.mode=test -XX:MaxMetaspaceSize=512m -Xms512m -Xmx512m</argLine>
|
||||
<tagsToExclude>code.external</tagsToExclude>
|
||||
</configuration>
|
||||
<executions>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user