Merge pull request #1439 from oldbig/bugfix/compile_stackoverflow

modify check logic of whether the same endpoint but different version
This commit is contained in:
Simon Redfern 2019-10-23 18:42:22 +02:00 committed by GitHub
commit fcee7bd010
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 16 deletions

View File

@ -411,7 +411,7 @@ trait OBPRestHelper extends RestHelper with MdcLoggable {
/**
* collect ResourceDoc objects
* Note: if new version ResourceDoc's endpoint have the same name with old version, old version ResourceDoc will be omitted
* Note: if new version ResourceDoc's endpoint have the same 'requestUrl' and 'requestVerb' with old version, old version ResourceDoc will be omitted
* @param allResourceDocs all ResourceDoc objects
* @return collected ResourceDoc objects those omit duplicated old version ResourceDoc objects.
*/
@ -424,11 +424,11 @@ trait OBPRestHelper extends RestHelper with MdcLoggable {
.sortBy(_.implementedInApiVersion)
val result = ArrayBuffer[ResourceDoc]()
val endpointNames = scala.collection.mutable.Set[String]()
val urlAndMethods = scala.collection.mutable.Set[(String, String)]()
for (doc <- docsToOnceToSeq) {
val funcName = doc.partialFunctionName
if(!endpointNames.contains(funcName)) {
endpointNames.add(funcName)
val urlAndMethod = (doc.requestUrl, doc.requestVerb)
if(!urlAndMethods.contains(urlAndMethod)) {
urlAndMethods.add(urlAndMethod)
result += doc
}
}

View File

@ -8,9 +8,11 @@ import code.api.v3_1_0.ListResult
import code.crm.CrmEvent.CrmEvent
import code.transactionrequests.TransactionRequestTypeCharge
import com.openbankproject.commons.model.{Product, _}
import com.openbankproject.commons.util.{EnumValue, OBPEnumeration}
import net.liftweb.common.Full
import net.liftweb.json
import net.liftweb.json.JsonAST.JValue
import net.liftweb.json.{JDouble, JInt, JString}
import net.liftweb.json.JsonAST.{JArray, JBool, JObject, JValue}
import net.liftweb.util.StringHelpers
import scala.reflect.runtime.currentMirror
@ -393,12 +395,17 @@ object JSONFactory1_4_0 {
* the OBP type format.
*/
def translateEntity(entity: Any, isArray:Boolean): String = {
val r = currentMirror.reflect(entity)
val mapOfFields = entity match {
val extractedEntity = entity match {
case Full(v) => v
case Some(v) => v
case v => v
}
val r = currentMirror.reflect(extractedEntity)
val mapOfFields: Map[String, Any] = extractedEntity match {
case ListResult(name, results) => Map((name, results))
case JObject(jFields) => jFields.map(it => (it.name, it.value)).toMap
case _ => r.symbol.typeSignature.members.toStream
.collect { case s: TermSymbol if !s.isMethod => r.reflectField(s)}
.map(r => r.symbol.name.toString.trim -> r.get)
@ -407,7 +414,7 @@ object JSONFactory1_4_0 {
val convertParamName = (name: String) => entity match {
val convertParamName = (name: String) => extractedEntity match {
case _ : JsonFieldReName => StringHelpers.snakify(name)
case _ => name
}
@ -425,7 +432,7 @@ object JSONFactory1_4_0 {
case Some(List(i: Date, _*)) => "\"" + key + """": {"type": "array","items": {"type": "string","format": "date-time"}}"""
//Boolean - 4 kinds
case i: Boolean => "\"" + key + """": {"type":"boolean"}"""
case _: Boolean | _: JBool => "\"" + key + """": {"type":"boolean"}"""
case Some(i: Boolean) => "\"" + key + """": {"type":"boolean"}"""
case List(i: Boolean, _*) => "\"" + key + """": {"type": "array","items": {"type": "boolean"}}"""
case Some(List(i: Boolean, _*)) => "\"" + key + """": {"type": "array","items": {"type": "boolean"}}"""
@ -438,12 +445,18 @@ object JSONFactory1_4_0 {
case Some(List(i: String, _*)) if(key.contains("date")&& i.length != "20181230".length) => "\"" + key + """": {"type": "array","items": {"type": "string","format": "date-time"}}"""
//String-->
case i: String => "\"" + key + """": {"type":"string"}"""
case _: String| _:JString => "\"" + key + """": {"type":"string"}"""
case e: EnumValue => {
val enumValues = OBPEnumeration.getValuesByInstance(e)
.map(it => s""""$it"""")
.mkString("[", ", ", "]")
"\"" + key + s"""": {"type":"string","enum": $enumValues}"""
}
case Some(i: String) => "\"" + key + """": {"type":"string"}"""
case List(i: String, _*) => "\"" + key + """": {"type": "array","items": {"type": "string"}}"""
case Some(List(i: String, _*)) => "\"" + key + """": {"type": "array","items": {"type": "string"}}"""
//Int
case i: Int => "\"" + key + """": {"type":"integer"}"""
case _: Int | _:JInt => "\"" + key + """": {"type":"integer"}"""
case Some(i: Int) => "\"" + key + """": {"type":"integer"}"""
case List(i: Int, _*) => "\"" + key + """": {"type": "array","items": {"type": "integer"}}"""
case Some(List(i: Int, _*)) => "\"" + key + """": {"type": "array","items": {"type": "integer"}}"""
@ -458,7 +471,7 @@ object JSONFactory1_4_0 {
case List(i: Float, _*) => "\"" + key + """": {"type": "array","items": {"type": "number"}}"""
case Some(List(i: Float, _*)) => "\"" + key + """": {"type": "array","items": {"type": "number"}}"""
//Double
case i: Double => "\"" + key + """": {"type":"number"}"""
case _: Double | _: JDouble => "\"" + key + """": {"type":"number"}"""
case Some(i: Double) => "\"" + key + """": {"type":"number"}"""
case List(i: Double, _*) => "\"" + key + """": {"type": "array","items": {"type": "number"}}"""
case Some(List(i: Double, _*)) => "\"" + key + """": {"type": "array","items": {"type": "number"}}"""
@ -473,7 +486,8 @@ object JSONFactory1_4_0 {
case List(i: BigDecimal, _*) => "\"" + key + """": {"type": "array","items": {"type": "number"}}"""
case Some(List(i: BigDecimal, _*)) => "\"" + key + """": {"type": "array","items": {"type": "number"}}"""
//List case classes.
//List case classes.
case JArray(List(f,_*)) => "\"" + key + """":""" +translateEntity(f,true)
case List(f) => "\"" + key + """":""" +translateEntity(f,true)
case List(f,_*) => "\"" + key + """":""" +translateEntity(f,true)
case List(Some(f)) => "\"" + key + """":""" +translateEntity(f,true)

View File

@ -71,6 +71,12 @@ object OBPEnumeration {
def getValuesByClass[T <: EnumValue](clazz: Class[T]): List[T] = getEnumContainer(clazz).values
def getValuesByInstance[T <: EnumValue](instance: T): List[T] = {
val clazz = instance.getClass
val enumType = clazz.getInterfaces.headOption.getOrElse(clazz.getSuperclass)
getValuesByClass(enumType.asInstanceOf[Class[T]])
}
def withNameOption(tp: Type, name: String): Option[EnumValue] = getEnumContainer(tp).withNameOption(name).map(_.asInstanceOf[EnumValue])
def withNameOption[T <: EnumValue](clazz: Class[T], name: String): Option[T] = getEnumContainer(clazz).withNameOption(name)