How to setup schema in Raw Web Socket?

Hello! could you please give a simple example how do i set up the schema? Ultimately, I need it to generate AsyncApi.

https://tapir.softwaremill.com/en/latest/endpoint/websockets.html#raw-web-sockets

typed web sockets is not suitable for me as it closes the connection on request decoding errors

What you’ll need to do in this case is use the .requestSchema / .responseSchema methods on the web socket output. The schema can be derived, though you’ll need to transform it so that it’s a schema for WebSocketFrame: this disables run-time validations, but the documentations should be ok. For example:

  case class MyFrame(data: String)
  val myWsOutput = webSocketBodyRaw(AkkaStreams)
    .requestsSchema(Schema.derived[MyFrame].as[WebSocketFrame])
  endpoint.out(myWsOutput)
1 Like

thanks, now it works as expected

1 Like