Skip to content

Commit c2b5df2

Browse files
authored
http (feature): Add OpenAPI schema support for Rx return types (#3887)
- Update OpenAPIGenerator to handle Rx[_] return types - Add test case for Rx[HelloRet] return type in SimpleOpenAPITest - Ensure Rx[_] types are correctly represented in OpenAPI schema
1 parent 3a8ff92 commit c2b5df2

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

airframe-http-codegen/src/main/scala/wvlet/airframe/http/openapi/OpenAPIGenerator.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import wvlet.airframe.json.JSON.JSONValue
2121
import wvlet.airframe.json.Json
2222
import wvlet.airframe.metrics.{Count, DataSize, ElapsedTime}
2323
import wvlet.airframe.msgpack.spi.{MsgPack, Value}
24+
import wvlet.airframe.rx.Rx
2425
import wvlet.airframe.surface.*
2526
import wvlet.airframe.surface.reflect.*
2627
import wvlet.airframe.ulid.ULID
@@ -489,6 +490,8 @@ class OpenAPIGenerator(config: OpenAPIGeneratorConfig) extends LogSupport {
489490
Schema(`type` = "string")
490491
case o: OptionSurface =>
491492
getOpenAPISchemaOfSurface(o.elementSurface, seen + s)
493+
case s: Surface if classOf[Rx[_]].isAssignableFrom(s.rawType) =>
494+
getOpenAPISchemaOfSurface(s.typeArgs(0), seen + s)
492495
case s: Surface if Router.isFuture(s) =>
493496
getOpenAPISchemaOfSurface(Router.unwrapFuture(s), seen + s)
494497
case s: Surface if Router.isFinagleReader(s) =>

airframe-http-codegen/src/test/scala/wvlet/airframe/http/openapi/SimpleOpenAPITest.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package wvlet.airframe.http.openapi
1515
import wvlet.airframe.http.openapi.OpenAPI.Schema
1616
import wvlet.airframe.http.{RPC, Router, description}
17+
import wvlet.airframe.rx.Rx
1718
import wvlet.airframe.ulid.ULID
1819
import wvlet.airspec.AirSpec
1920

@@ -193,4 +194,20 @@ object SimpleOpenAPITest extends AirSpec {
193194
val schema = openapi.components.get.schemas.head.head._2.asInstanceOf[Schema]
194195
schema.required shouldBe empty
195196
}
197+
198+
case class HelloRet(p: String = "hello")
199+
@RPC
200+
trait RxTestApi {
201+
def hello(): Rx[HelloRet]
202+
}
203+
204+
test("Rx return type") {
205+
val r = Router.of[RxTestApi]
206+
val yaml = openApiGenerator(r).toYAML
207+
debug(yaml)
208+
yaml.contains("type: object") shouldBe true
209+
yaml.contains("properties:") shouldBe true
210+
yaml.contains("#/components/schemas/HelloRet") shouldBe true
211+
}
212+
196213
}

0 commit comments

Comments
 (0)