Skip to content

Commit a7fd804

Browse files
authored
feat(console): describe the websocket protocols in the openapi document (#1282)
* feat(console): describe the websocket protocols in the openapi document The /api/console/sock entry of the OpenAPI document was an empty operation, so a client author learned nothing about the socket from it. Describe the two protocols that share the path, the hello that opens version 1, and the client and server frames. The description is additive: no route, parameter or schema changes. Signed-off-by: TheMeinerLP <github@themeinerlp.dev> * build(ui): regenerate the api types for the console socket description Signed-off-by: TheMeinerLP <github@themeinerlp.dev> --------- Signed-off-by: TheMeinerLP <github@themeinerlp.dev>
1 parent 0101b3f commit a7fd804

4 files changed

Lines changed: 32 additions & 0 deletions

File tree

‎docs/openapi/ingot-openapi.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4227,6 +4227,7 @@
42274227
},
42284228
"/api/console/sock" : {
42294229
"patch" : {
4230+
"description" : "WebSocket upgrade. Two protocols share the path, and the first message decides. A message that starts with 'Authorization:' opens the legacy protocol: raw log lines, 'keep-alive' echoed, a command line gets no answer frame. A JSON object with type 'hello' opens version 1, where every message is a JSON frame. Client frames: hello (protocols, token, client, logLevel, resume), execute (id, command, confirm), confirm (id, accept), complete (id, line, cursor). Server frames: welcome (protocol, boot, seq, replay), log (seq, node, level, text, dropped), result (id, status, exitCode, output, data, node, confirmed), confirm (id, command, reason), complete (id, replace, candidates), error (code, message, id, retryable, supported). The frames are described in the console commands reference.",
42304231
"responses" : { },
42314232
"tags" : [ "Console" ]
42324233
}

‎reposilite-backend/src/integration/kotlin/com/reposilite/web/OpenApiSnapshotIntegrationTest.kt‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,28 @@ internal class OpenApiSnapshotIntegrationTest : ReposiliteSpecification() {
8282
.contains("exit code")
8383
}
8484

85+
@Test
86+
fun `console socket describes both protocols and the frames of version 1`() {
87+
// given: the OpenAPI document the server serves
88+
val document = MAPPER.readTree(Unirest.get("$base/openapi").asString().body)
89+
90+
// when: the description of the socket route is read
91+
val description = document.path("paths").path("/api/console/sock").path("patch").path("description").asText()
92+
93+
// then: it names the legacy protocol, the hello that opens version 1 and the frames of the session
94+
assertThat(description)
95+
.describedAs("description of /api/console/sock")
96+
.contains("Authorization:")
97+
.contains("hello")
98+
.contains("welcome")
99+
.contains("execute")
100+
.contains("result")
101+
.contains("confirm")
102+
.contains("complete")
103+
.contains("log")
104+
.contains("error")
105+
}
106+
85107
@Test
86108
fun `own security status describes its 200 answer`() {
87109
// given: the OpenAPI document the server serves

‎reposilite-backend/src/main/kotlin/com/reposilite/console/infrastructure/ConsoleWebSocketHandler.kt‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ internal class ConsoleWebSocketHandler(
206206
@OpenApi(
207207
path = "/api/console/sock",
208208
methods = [HttpMethod.PATCH],
209+
description = "WebSocket upgrade. Two protocols share the path, and the first message decides. A message that starts " +
210+
"with 'Authorization:' opens the legacy protocol: raw log lines, 'keep-alive' echoed, a command line gets no " +
211+
"answer frame. A JSON object with type 'hello' opens version 1, where every message is a JSON frame. Client " +
212+
"frames: hello (protocols, token, client, logLevel, resume), execute (id, command, confirm), confirm (id, " +
213+
"accept), complete (id, line, cursor). Server frames: welcome (protocol, boot, seq, replay), log (seq, node, " +
214+
"level, text, dropped), result (id, status, exitCode, output, data, node, confirmed), confirm (id, command, " +
215+
"reason), complete (id, replace, candidates), error (code, message, id, retryable, supported). The frames are " +
216+
"described in the console commands reference.",
209217
tags = ["Console"]
210218
)
211219
override fun accept(ws: WsConfig) {

‎reposilite-frontend/src/types/api.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,7 @@ export interface paths {
15911591
delete?: never;
15921592
options?: never;
15931593
head?: never;
1594+
/** @description WebSocket upgrade. Two protocols share the path, and the first message decides. A message that starts with 'Authorization:' opens the legacy protocol: raw log lines, 'keep-alive' echoed, a command line gets no answer frame. A JSON object with type 'hello' opens version 1, where every message is a JSON frame. Client frames: hello (protocols, token, client, logLevel, resume), execute (id, command, confirm), confirm (id, accept), complete (id, line, cursor). Server frames: welcome (protocol, boot, seq, replay), log (seq, node, level, text, dropped), result (id, status, exitCode, output, data, node, confirmed), confirm (id, command, reason), complete (id, replace, candidates), error (code, message, id, retryable, supported). The frames are described in the console commands reference. */
15941595
patch: {
15951596
parameters: {
15961597
query?: never;

0 commit comments

Comments
 (0)