Forum Discussion

fred33's avatar
New Contributor
5 years ago

SwaggerSocket support in Swagger ?!



we want to do REST with WebSockets, and we have perfect reasons to do it.


There is the SwaggerSocket specifications (for websockets with REST), it looked perfect for our needs !!!


In Swagger UI (Open API) we see that we can select the schemes "ws" and "wss" (in addition to http/https),

so this looked promising... (Swagger UI supporting the SwaggerSocket specs ?!!!)


However, when selecting "ws" and "wss" and when testing a REST request, nothing happends when cklicking on "Execute"... when opening the developper tools of the web browser, we see in the console "Fetch API cannot load wss:{host}/{path}. URL scheme must be "http" or "https" for CORS request".


So it looks like - with ws/wss - the Swagger UI wants to do an HTTP(S) request (new XMLHttpRequest) with a URL starting with "ws:" or "wss:" scheme,
however we would rather expect a WebSocket connection (new WebSocket) to be initiated ...


The Swagger doc is also poor on "ws", "wss" schemes and we find nothing stating that Swagger UI supports SwaggerSockets ...


So is SwaggerSocket simply not (/no more) supported in Swagger UI, or are we doing something wrong ?


Thanks in advance,



2 Replies

  • HKosova's avatar
    SmartBear Alumni (Retired)

    Swagger UI does not support WebSockets, and OpenAPI Specification is not really suitable for WebSocket APIs.


    Check out AsyncAPI instead.

    • fred33's avatar
      New Contributor

      Thank you Helen,


      Swagger UI does not support WebSockets

      Ok, I understand and I will stop investigating this case.


      > OpenAPI Specification is not really suitable for WebSocket APIs.

      Well, it's perfectly suitable for some specific cases, like ours.

      As a short example, imagine a database (tables: pet, store, user) that you can manage [control] and for which you would like to be notified [monitor] if something was Created/Updated/Deleted (like by another application for example) :
      - OpenAPI enable to descritbe all resources + operations available from Client > Server (requests + responses) : this represent 100% of the "control" side need and potentially 98% of the doc.
      - Notifications from Server > Client are very simple, and as they are generic for all tables, they require just 2% of the doc: for any table (pet, store, user), you can be notified that an item was Created/Updated/Modified.

      - Swagger UI would enable to test 100% of the controlling side, which is a great job.
      - WebSocket has an interest for performance on high density servers (low bandwidth + fast notification) and to have notifications pass through NAT/Firewall. 


      > AsyncAPI

      Thanks for the info, but I have already explored this link from some previous posts on your site.

      AsyncAPI may be great for "Event-Driven Architectures", but for the case reported above it looks like not appropriate (a huge solution for a light problem).


      As Swagger is the creator of:

      - SwaggerSockets (specifications for using REST over WebSockets)

      - Open API specs (which define "ws" and "wss" schemes, the schemes for WebSocket))

      - Swagger UI (which accepts "ws" and "wss" schemes for WebSocket)

      this means that people at swagger spent time and energy on this subject (WebSockets + REST) and produced interesting specs and tools managing this.


      I can understand that Swagger UI abandonned this support (which may be useful to not so many developers), but this would have been interesting to learn a little bit more from the company that created those specs and tools.


      Anyway, thanks again Helen,