Skip to content

Commit 6800ac3

Browse files
authored
Merge pull request #2951 from hongwei1/fix/swagger-v7-null-example
fix: make the v7.0.0 swagger export succeed and name the entity on failure
2 parents 6998b13 + e141dc7 commit 6800ac3

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

‎obp-api/src/main/scala/code/api/ResourceDocs1_4_0/SwaggerJSONFactory.scala‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,13 @@ object SwaggerJSONFactory extends MdcLoggable {
707707
case _ => paramValue
708708
}
709709

710-
val definition = buildSwaggerSchema(paramType, exampleValue)
710+
// Name the entity and field, so an unusable example can be found from the message alone.
711+
val definition =
712+
try buildSwaggerSchema(paramType, exampleValue)
713+
catch {
714+
case e: RuntimeException =>
715+
throw new RuntimeException(s"${entityType.typeSymbol.name}.$paramName: ${e.getMessage}", e)
716+
}
711717

712718
s""" "$paramName": $definition """
713719
})

‎obp-api/src/main/scala/code/api/v7_0_0/Http4s700.scala‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6989,7 +6989,8 @@ object Http4s700 {
69896989
payload_hash = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
69906990
current_payload_hash = "",
69916991
proposed_payload = Extraction.decompose(jsonDynamicResourceDoc),
6992-
current_payload = JNothing,
6992+
// A CREATE has nothing to replace. The swagger export needs an object here, not JNothing.
6993+
current_payload = JObject(Nil),
69936994
requestor_user_id = code.api.util.ExampleValue.userIdExample.value,
69946995
business_justification = "Expose the new loan quote endpoint for the mobile app.",
69956996
checker_user_id = "",

‎obp-api/src/test/scala/code/api/ResourceDocs1_4_0/SwaggerDocsTest.scala‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ class SwaggerDocsTest extends ResourceDocsV140ServerSetup with PropsReset with D
110110
errors.isEmpty should be (true)
111111
}
112112

113+
scenario(s"We will test ${ApiEndpoint1.name} Api - v7.0.0 swagger export succeeds", ApiEndpoint1, VersionOfApi) {
114+
val requestGetSwagger = (ResourceDocsV5_1Request / "resource-docs" / "v7.0.0" / "swagger").GET
115+
val responseGetSwagger = makeGetRequest(requestGetSwagger)
116+
And("We should get 200, not OBP-50000 because one entity has no example")
117+
withClue(responseGetSwagger.body.toString) {
118+
responseGetSwagger.code should equal(200)
119+
}
120+
}
121+
113122
scenario(s"We will test ${ApiEndpoint1.name} Api - v4.0.0", ApiEndpoint1, VersionOfApi) {
114123
val requestGetObp = (ResourceDocsV4_0Request / "resource-docs" / "v4.0.0" / "swagger").GET
115124
val responseGetObp = makeGetRequest(requestGetObp)

0 commit comments

Comments
 (0)