Source HTTP API ID path patterns (#26623)

This commit is contained in:
Kit Langton
2026-05-09 22:58:47 -04:00
committed by GitHub
parent 2f11c9f7ed
commit 67b9c9c027
25 changed files with 127 additions and 90 deletions

View File

@@ -4,7 +4,9 @@ import { Identifier } from "@/id/id"
import { zod, ZodOverride } from "@opencode-ai/core/effect-zod"
import { withStatics } from "@opencode-ai/core/schema"
const ptyIdSchema = Schema.String.annotate({ [ZodOverride]: Identifier.schema("pty") }).pipe(Schema.brand("PtyID"))
const ptyIdSchema = Schema.String.check(Schema.isStartsWith("pty"))
.annotate({ [ZodOverride]: Identifier.schema("pty") })
.pipe(Schema.brand("PtyID"))
export type PtyID = typeof ptyIdSchema.Type

View File

@@ -69,14 +69,6 @@ const QueryParameterSchemas: Record<string, OpenApiSchema> = {
"GET /api/session/{sessionID}/message limit": { type: "number" },
}
const PathParameterSchemas: Record<string, OpenApiSchema> = {
sessionID: { type: "string", pattern: "^ses.*" },
messageID: { type: "string", pattern: "^msg.*" },
partID: { type: "string", pattern: "^prt.*" },
permissionID: { type: "string", pattern: "^per.*" },
ptyID: { type: "string", pattern: "^pty.*" },
}
const LegacyComponentDescriptions: Record<string, string> = {
LogLevel: "Log level",
ServerConfig: "Server configuration for opencode serve and web commands",
@@ -506,11 +498,8 @@ function normalizeParameter(param: OpenApiParameter, route: string) {
}
function pathParameterSchema(route: string, name: string) {
if (name in PathParameterSchemas) return PathParameterSchemas[name]
if (name === "id" && route.startsWith("DELETE /experimental/workspace/")) return { type: "string", pattern: "^wrk.*" }
if (name === "id" && route.startsWith("POST /experimental/workspace/")) return { type: "string", pattern: "^wrk.*" }
if (name === "requestID" && route.startsWith("POST /permission/")) return { type: "string", pattern: "^per.*" }
if (name === "requestID" && route.startsWith("POST /question/")) return { type: "string", pattern: "^que.*" }
return undefined
}

View File

@@ -4,32 +4,44 @@ import { Identifier } from "@/id/id"
import { zod, ZodOverride } from "@opencode-ai/core/effect-zod"
import { withStatics } from "@opencode-ai/core/schema"
export const SessionID = Schema.String.annotate({ [ZodOverride]: Identifier.schema("session") }).pipe(
Schema.brand("SessionID"),
withStatics((s) => ({
descending: (id?: string) => s.make(Identifier.descending("session", id)),
zod: zod(s),
})),
)
export const SessionID = Schema.String.check(Schema.isStartsWith("ses"))
.annotate({
[ZodOverride]: Identifier.schema("session"),
})
.pipe(
Schema.brand("SessionID"),
withStatics((s) => ({
descending: (id?: string) => s.make(Identifier.descending("session", id)),
zod: zod(s),
})),
)
export type SessionID = Schema.Schema.Type<typeof SessionID>
export const MessageID = Schema.String.annotate({ [ZodOverride]: Identifier.schema("message") }).pipe(
Schema.brand("MessageID"),
withStatics((s) => ({
ascending: (id?: string) => s.make(Identifier.ascending("message", id)),
zod: zod(s),
})),
)
export const MessageID = Schema.String.check(Schema.isStartsWith("msg"))
.annotate({
[ZodOverride]: Identifier.schema("message"),
})
.pipe(
Schema.brand("MessageID"),
withStatics((s) => ({
ascending: (id?: string) => s.make(Identifier.ascending("message", id)),
zod: zod(s),
})),
)
export type MessageID = Schema.Schema.Type<typeof MessageID>
export const PartID = Schema.String.annotate({ [ZodOverride]: Identifier.schema("part") }).pipe(
Schema.brand("PartID"),
withStatics((s) => ({
ascending: (id?: string) => s.make(Identifier.ascending("part", id)),
zod: zod(s),
})),
)
export const PartID = Schema.String.check(Schema.isStartsWith("prt"))
.annotate({
[ZodOverride]: Identifier.schema("part"),
})
.pipe(
Schema.brand("PartID"),
withStatics((s) => ({
ascending: (id?: string) => s.make(Identifier.ascending("part", id)),
zod: zod(s),
})),
)
export type PartID = Schema.Schema.Type<typeof PartID>