swaggo / swag

Automatically generate RESTful API documentation with Swagger 2.0 for Go.
MIT License
10.47k stars 1.19k forks source link

Web Socket Support #1868

Open martinyonatann opened 1 month ago

martinyonatann commented 1 month ago

Is your feature request related to a problem? Please describe. Yes, the problem relates to the inability to fully document and interact with WebSocket endpoints within Swaggo-generated Swagger documentation. While Swaggo is excellent for documenting and testing standard RESTful APIs, it currently lacks native support for WebSocket protocol interactions. This creates a challenge when trying to document WebSocket endpoints, as Swagger UI cannot initiate a WebSocket connection or correctly display its behavior.

Describe the solution you'd like I would like Swaggo to support WebSocket documentation more explicitly. This could include:

  1. Native WebSocket Support: A way to declare endpoints as WebSocket connections in the Swagger documentation. This might involve using specific tags or parameters that indicate the endpoint upgrades the HTTP connection to a WebSocket.
  2. Interactive Testing: Although Swagger UI is primarily for HTTP, it would be beneficial to integrate or link to tools that can establish WebSocket connections directly from the documentation interface, allowing developers to test WebSocket endpoints as easily as they do HTTP endpoints.
  3. Clear Documentation Examples: Provide out-of-the-box templates or examples for documenting WebSocket endpoints, including details like required headers, authentication, and sample connection upgrades.

Describe alternatives you've considered Currently, the alternative involves documenting WebSocket endpoints in Swagger as if they were standard HTTP GET or POST requests, then adding descriptive notes in the documentation to instruct users on how to manually upgrade the connection to a WebSocket. Another alternative is to use third-party tools like wscat or browser-based WebSocket clients to interact with the WebSocket endpoints, but this lacks integration with the Swaggo/Swagger ecosystem.

Additional context WebSocket support is crucial for applications that rely on real-time communication, such as chat applications, live notifications, or real-time data feeds. Integrating this into Swaggo would greatly enhance its utility for developers working on these types of projects. Additionally, the growing popularity of WebSockets in modern web applications makes this feature increasingly relevant.

iiiusky commented 4 weeks ago

Any progress?