Skip to content

Commit

Permalink
refactor/Write getResourceDocsSwagger as a new style endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
constantine2nd committed Aug 31, 2023
1 parent 53a3baa commit 6abebac
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package code.api.ResourceDocs1_4_0

import code.api.Constant.PARAM_LOCALE

import java.util.UUID.randomUUID

import code.api.OBPRestHelper
import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON.canGetCustomersJson
import code.api.builder.OBP_APIBuilder
Expand Down Expand Up @@ -36,11 +36,12 @@ import net.liftweb.json.JsonAST.{JField, JString, JValue}
import net.liftweb.json._
import net.liftweb.util.Helpers.tryo
import net.liftweb.util.Props

import java.util.concurrent.ConcurrentHashMap

import code.api.util.FutureUtil.EndpointContext
import code.api.util.NewStyle.HttpCode
import code.api.v5_0_0.OBPAPI5_0_0
import code.api.v5_1_0.OBPAPI5_1_0
import code.api.v5_1_0.{OBPAPI5_1_0, UserAttributeJsonV510}
import code.util.Helper

import scala.collection.immutable.{List, Nil}
Expand Down Expand Up @@ -692,15 +693,20 @@ trait ResourceDocsAPIMethods extends MdcLoggable with APIMethods220 with APIMeth

def getResourceDocsSwagger : OBPEndpoint = {
case "resource-docs" :: requestedApiVersionString :: "swagger" :: Nil JsonGet _ => {
cc =>{
cc => {
implicit val ec = EndpointContext(Some(cc))
val (resourceDocTags, partialFunctions, _, _, _, _) = ResourceDocsAPIMethodsUtil.getParams()
for {
(resourceDocTags, partialFunctions, locale, contentParam, apiCollectionIdParam, cacheModifierParam) <- tryo(ResourceDocsAPIMethodsUtil.getParams())
requestedApiVersion <- tryo(ApiVersionUtils.valueOf(requestedApiVersionString)) ?~! s"$InvalidApiVersionString Current Version is $requestedApiVersionString"
_ <- booleanToBox(versionIsAllowed(requestedApiVersion), s"$ApiVersionNotSupported Current Version is $requestedApiVersionString")
staticJson <- getResourceDocsSwaggerCached(requestedApiVersionString, resourceDocTags, partialFunctions)
dynamicJson <- getResourceDocsSwagger(requestedApiVersionString, resourceDocTags, partialFunctions)
requestedApiVersion <- NewStyle.function.tryons(s"$InvalidApiVersionString Current Version is $requestedApiVersionString", 400, cc.callContext) {
ApiVersionUtils.valueOf(requestedApiVersionString)
}
_ <- Helper.booleanToFuture(failMsg = s"$ApiVersionNotSupported Current Version is $requestedApiVersionString", cc=cc.callContext) {
versionIsAllowed(requestedApiVersion)
}
staticJson <- Future(getResourceDocsSwaggerCached(requestedApiVersionString, resourceDocTags, partialFunctions).getOrElse(JNull))
dynamicJson <- Future(getResourceDocsSwagger(requestedApiVersionString, resourceDocTags, partialFunctions).getOrElse(JNull))
} yield {
successJsonResponse(staticJson.merge(dynamicJson))
(staticJson.merge(dynamicJson), HttpCode.`200`(cc.callContext))
}
}
}
Expand Down

0 comments on commit 6abebac

Please sign in to comment.