-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouter_asyncapi.go
More file actions
108 lines (89 loc) · 4.21 KB
/
router_asyncapi.go
File metadata and controls
108 lines (89 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package forge
import "github.com/xraph/forge/internal/router"
// WithAsyncAPI enables AsyncAPI 3.0.0 spec generation.
func WithAsyncAPI(config AsyncAPIConfig) RouterOption {
return router.WithAsyncAPI(config)
}
// WithWebSocketMessages defines send/receive message schemas for WebSocket endpoints
// sendSchema: messages that the client sends to the server (action: send)
// receiveSchema: messages that the server sends to the client (action: receive).
func WithWebSocketMessages(sendSchema, receiveSchema any) RouteOption {
return router.WithWebSocketMessages(sendSchema, receiveSchema)
}
// WithSSEMessages defines message schemas for SSE endpoints
// messageSchemas: map of event names to their schemas
// SSE is receive-only (server -> client), so action is always "receive".
func WithSSEMessages(messageSchemas map[string]any) RouteOption {
return router.WithSSEMessages(messageSchemas)
}
// WithSSEMessage defines a single message schema for SSE endpoints
// eventName: the SSE event name (e.g., "message", "update", "notification")
// schema: the message schema
func WithSSEMessage(eventName string, schema any) RouteOption {
return router.WithSSEMessage(eventName, schema)
}
// WithAsyncAPIOperationID sets a custom operation ID for AsyncAPI.
func WithAsyncAPIOperationID(id string) RouteOption {
return router.WithAsyncAPIOperationID(id)
}
// WithAsyncAPITags adds tags to the AsyncAPI operation.
func WithAsyncAPITags(tags ...string) RouteOption {
return router.WithAsyncAPITags(tags...)
}
// WithAsyncAPIChannelName sets a custom channel name (overrides path-based naming).
func WithAsyncAPIChannelName(name string) RouteOption {
return router.WithAsyncAPIChannelName(name)
}
// WithAsyncAPIBinding adds protocol-specific bindings
// bindingType: "ws" or "http" or "server" or "channel" or "operation" or "message"
// binding: the binding object (e.g., WebSocketChannelBinding, HTTPServerBinding)
func WithAsyncAPIBinding(bindingType string, binding any) RouteOption {
return router.WithAsyncAPIBinding(bindingType, binding)
}
// WithMessageExamples adds message examples for send/receive
// direction: "send" or "receive"
// examples: map of example name to example value
func WithMessageExamples(direction string, examples map[string]any) RouteOption {
return router.WithMessageExamples(direction, examples)
}
// WithMessageExample adds a single message example.
func WithMessageExample(direction, name string, example any) RouteOption {
return router.WithMessageExample(direction, name, example)
}
// WithAsyncAPIChannelDescription sets the channel description.
func WithAsyncAPIChannelDescription(description string) RouteOption {
return router.WithAsyncAPIChannelDescription(description)
}
// WithAsyncAPIChannelSummary sets the channel summary.
func WithAsyncAPIChannelSummary(summary string) RouteOption {
return router.WithAsyncAPIChannelSummary(summary)
}
// WithCorrelationID adds correlation ID configuration for request-reply patterns
// location: runtime expression like "$message.header#/correlationId"
// description: description of the correlation ID
func WithCorrelationID(location, description string) RouteOption {
return router.WithCorrelationID(location, description)
}
// WithMessageHeaders defines headers schema for messages
// headersSchema: Go type with header:"name" tags.
func WithMessageHeaders(headersSchema any) RouteOption {
return router.WithMessageHeaders(headersSchema)
}
// WithMessageContentType sets the content type for messages
// Default is "application/json".
func WithMessageContentType(contentType string) RouteOption {
return router.WithMessageContentType(contentType)
}
// WithAsyncAPIExternalDocs adds external documentation link.
func WithAsyncAPIExternalDocs(url, description string) RouteOption {
return router.WithAsyncAPIExternalDocs(url, description)
}
// WithServerProtocol specifies which servers this operation should be available on
// serverNames: list of server names from AsyncAPIConfig.Servers.
func WithServerProtocol(serverNames ...string) RouteOption {
return router.WithServerProtocol(serverNames...)
}
// WithAsyncAPISecurity adds security requirements to the operation.
func WithAsyncAPISecurity(requirements map[string][]string) RouteOption {
return router.WithAsyncAPISecurity(requirements)
}