Merge branch 'develop' of github.com:OpenBankProject/OBP-API into develop

This commit is contained in:
Simon Redfern 2018-02-20 22:36:08 +01:00
commit a6977c68ff
5 changed files with 49 additions and 38 deletions

View File

@ -1069,6 +1069,7 @@ object SwaggerDefinitionsJSON {
function = "getBranches"
)
// Used to describe the OBP API calls for documentation and API discovery purposes
val canCreateCustomerSwagger = CanCreateCustomer()
val resourceDocJson = ResourceDocJson(
operation_id = "String",
request_verb = "String",
@ -1085,7 +1086,7 @@ object SwaggerDefinitionsJSON {
tags = List("String"),
typed_request_body = json.parse("""{"request": { "type" :"string" }}"""),
typed_success_response_body = json.parse("""{"response": { "type" :"string" }}"""),
roles = Some(List(canCreateCustomer))
roles = Some(List(canCreateCustomerSwagger))
)
val resourceDocsJson = ResourceDocsJson(resource_docs = List(resourceDocJson))

View File

@ -15,6 +15,7 @@ import scala.collection.immutable.ListMap
import scala.reflect.runtime.currentMirror
import scala.reflect.runtime.universe._
import code.api.util.ErrorMessages._
import net.liftweb.json.JsonAST.JValue
object SwaggerJSONFactory {
//Info Object
@ -443,6 +444,12 @@ object SwaggerJSONFactory {
// _ = print("\n val properties for comprehension: " + key + " is " + value)
} yield {
value match {
//TODO: this maybe wrong, JValue will have many types: JObject, JBool, JInt, JDouble , but here we just map one type `String`
case i:JValue => "\"" + key + """": {"type":"string","example":"This is a json String."}"""
case Some(i:JValue) => "\"" + key + """": {"type":"string","example":"This is a json String."}"""
case List(i: JValue, _*) => "\"" + key + """": {"type":"array", "items":{"type":"string","example":"This is a json String."}}"""
case Some(List(i: JValue, _*)) => "\"" + key + """": {"type":"array", "items":{"type":"string","example":"This is a json String."}}"""
//Boolean - 4 kinds
case i: Boolean => "\"" + key + """": {"type":"boolean", "example":"""" +i+"\"}"
case Some(i: Boolean) => "\"" + key + """": {"type":"boolean", "example":"""" +i+"\"}"

View File

@ -1149,7 +1149,7 @@ object APIUtil extends MdcLoggable {
//check #511, https://github.com/OpenBankProject/OBP-API/issues/511
// get rid of JValue, but in API-EXPLORER or other places, it need the Empty JValue "{}"
// So create the EmptyClassJson to set the empty JValue "{}"
case class EmptyClassJson()
case class EmptyClassJson(jsonString: String ="{}")
// Used to document the API calls
case class ResourceDoc(

View File

@ -1,3 +1,3 @@
wget http://www-eu.apache.org/dist/kafka/0.10.2.0/kafka_2.11-0.10.2.0.tgz && \
tar xzf kafka_2.11-0.10.2.0.tgz && \
rm -f kafka_2.11-0.10.2.0.tgz
wget http://www-eu.apache.org/dist/kafka/0.10.2.1/kafka_2.11-0.10.2.1.tgz && \
tar xzf kafka_2.11-0.10.2.1.tgz && \
rm -f kafka_2.11-0.10.2.1.tgz

View File

@ -31,41 +31,44 @@ class SwaggerFactoryUnitTest extends FlatSpec
translateCaseClassToSwaggerFormatString should not include("$colon")
}
it should ("Test all the case classes in SwaggerDefinitionsJSON") in{
val allSwaggerDefinitionCaseClasses = SwaggerDefinitionsJSON.allFields
it should ("Test all V300, V220 and V210, exampleRequestBodies and successResponseBodies and all the case classes in SwaggerDefinitionsJSON") in {
val listNestingMissDefinition: List[String] =
for (e <- allSwaggerDefinitionCaseClasses.toList if e!= null)
yield {
SwaggerJSONFactory.translateEntity(e)
}
logger.debug(listNestingMissDefinition)
listNestingMissDefinition.toString() should not include("$colon")
}
it should ("Test all V300, V220 and V210, exampleRequestBodies and successResponseBodies") in {
val resourceDocList: ArrayBuffer[ResourceDoc] = OBPAPI3_0_0.allResourceDocs ++ OBPAPI2_2_0.allResourceDocs++ OBPAPI2_1_0.allResourceDocs
val resourceDocList: ArrayBuffer[ResourceDoc] = OBPAPI3_0_0.allResourceDocs ++ OBPAPI2_2_0.allResourceDocs ++ OBPAPI2_1_0.allResourceDocs
//Translate every entity(JSON Case Class) in a list to appropriate swagger format
val listOfExampleRequestBodyDefinition =
for (e <- resourceDocList if e.exampleRequestBody != null)
yield {
SwaggerJSONFactory.translateEntity(e.exampleRequestBody)
}
val listOfSuccessRequestBodyDefinition =
for (e <- resourceDocList if e.successResponseBody != null)
yield {
SwaggerJSONFactory.translateEntity(e.successResponseBody)
}
//Translate every entity(JSON Case Class) in a list to appropriate swagger format
val listOfExampleRequestBodyDefinition =
for (e <- resourceDocList if e.exampleRequestBody != null)
yield {
SwaggerJSONFactory.translateEntity(e.exampleRequestBody)
}
val listOfSuccessRequestBodyDefinition =
for (e <- resourceDocList if e.successResponseBody != null)
yield {
SwaggerJSONFactory.translateEntity(e.successResponseBody)
}
listOfExampleRequestBodyDefinition.toString() should not include("$colon")
listOfSuccessRequestBodyDefinition.toString() should not include("$colon")
logger.debug(listOfExampleRequestBodyDefinition)
logger.debug(listOfExampleRequestBodyDefinition)
}
val allSwaggerDefinitionCaseClasses = SwaggerDefinitionsJSON.allFields
val listNestingMissDefinition: List[String] =
for (e <- allSwaggerDefinitionCaseClasses.toList if e != null)
yield {
SwaggerJSONFactory.translateEntity(e)
}
val allStrings = listOfExampleRequestBodyDefinition ++ listOfSuccessRequestBodyDefinition ++ listNestingMissDefinition
//All of the following are invalid value in Swagger, if any of them are exsiting, need check the source code!
allStrings.toString() should not include ("$colon")
allStrings.toString() should not include ("Nil$")
allStrings.toString() should not include ("JArray")
allStrings.toString() should not include ("JBool")
allStrings.toString() should not include ("JInt")
allStrings.toString() should not include ("JNothing")
allStrings.toString() should not include ("JNull")
allStrings.toString() should not include ("JObject")
allStrings.toString() should not include ("JString")
logger.debug(allStrings)
}
}