Skip to content

Commit

Permalink
Fix barricade processor, so it should create mock responses for all p…
Browse files Browse the repository at this point in the history
…rovided endpoints
  • Loading branch information
ZeeshanShabbir committed Jun 22, 2022
1 parent 978da26 commit 7b56659
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions app/src/main/assets/barricade/categories/success.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
"Test",
"Test2",
"Test3"
]
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import retrofit2.http.GET
interface ApiService {
@GET("/jokes/random")
@Barricade(
endpoint = "random",
responses = [
com.mutualmobile.barricade.annotation.Response(
fileName = "success.json",
Expand All @@ -22,5 +23,14 @@ interface ApiService {
suspend fun getRandomJoke(): Response<JokeResponse>

@GET("/jokes/categories")
@Barricade(
endpoint = "categories",
responses = [
com.mutualmobile.barricade.annotation.Response(
fileName = "success.json",
isDefault = true
)
]
)
suspend fun getJokeCategories(): Response<List<String>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,9 @@ class BarricadeProcessor(

file writeToFile "\tprivate val configs = hashMapOf<String, $PACKAGE_NAME.response.BarricadeResponseSet>()\n\n"
file writeToFile "\tinit {\n"
file writeToFile "\t\tval barricadeResponsesForRandom = mutableListOf<com.mutualmobile.barricade.response.BarricadeResponse>()\n"
symbols.forEach { symbol ->
symbol.accept(BarricadeVisitor(file, logger), Unit)
}
file writeToFile "\t\tconfigs.put(\"random\", com.mutualmobile.barricade.response.BarricadeResponseSet(barricadeResponsesForRandom, 0))\n"
file writeToFile "\t}\n\n"
file writeToFile "\toverride fun getConfigs(): HashMap<String, $PACKAGE_NAME.response.BarricadeResponseSet> = configs\n"
file writeToFile "\toverride fun getResponseForEndpoint(endpoint: String): $PACKAGE_NAME.response.BarricadeResponse? {\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ class BarricadeVisitor(
(it as KSAnnotation).arguments
}

file writeToFile "\t\tval barricadeResponsesFor$endpoint = mutableListOf<com.mutualmobile.barricade.response.BarricadeResponse>()\n"

responses.forEach { response ->
val fileName = response.first { it.name?.asString() == Response::fileName.name }.value as String
val isDefault = response.first { it.name?.asString() == Response::isDefault.name }.value as Boolean
val statusCode = response.first { it.name?.asString() == Response::statusCode.name }.value as Int
val type = response.first { it.name?.asString() == Response::type.name }.value as String
file writeToFile "\t\tbarricadeResponsesForRandom.add(${BarricadeProcessor.PACKAGE_NAME}.response.BarricadeResponse($statusCode, \"$fileName\", \"$type\"))\n"
file writeToFile "\t\tbarricadeResponsesFor$endpoint.add(${BarricadeProcessor.PACKAGE_NAME}.response.BarricadeResponse($statusCode, \"$fileName\", \"$type\"))\n"
logger.info("Found args: $fileName, $isDefault, $statusCode, $type")
}
file writeToFile "\t\tconfigs.put(\"$endpoint\", com.mutualmobile.barricade.response.BarricadeResponseSet(barricadeResponsesFor$endpoint, 0))\n"

}
}

0 comments on commit 7b56659

Please sign in to comment.