Source workspace path pattern (#26632)
This commit is contained in:
@@ -111,7 +111,7 @@ Concrete first targets:
|
|||||||
- `[x]` `permissionID`
|
- `[x]` `permissionID`
|
||||||
- `[x]` `ptyID`
|
- `[x]` `ptyID`
|
||||||
|
|
||||||
Leave ambiguous route-local `id` overrides for workspace routes until they are renamed or explicitly typed in endpoint params.
|
- `[x]` Remove ambiguous workspace `id` path overrides once the endpoint source schema emits the `wrk` pattern.
|
||||||
|
|
||||||
Verification:
|
Verification:
|
||||||
|
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import { Identifier } from "@/id/id"
|
|||||||
import { zod, ZodOverride } from "@opencode-ai/core/effect-zod"
|
import { zod, ZodOverride } from "@opencode-ai/core/effect-zod"
|
||||||
import { withStatics } from "@opencode-ai/core/schema"
|
import { withStatics } from "@opencode-ai/core/schema"
|
||||||
|
|
||||||
const workspaceIdSchema = Schema.String.annotate({ [ZodOverride]: Identifier.schema("workspace") }).pipe(
|
const workspaceIdSchema = Schema.String.check(Schema.isStartsWith("wrk"))
|
||||||
Schema.brand("WorkspaceID"),
|
.annotate({ [ZodOverride]: Identifier.schema("workspace") })
|
||||||
)
|
.pipe(Schema.brand("WorkspaceID"))
|
||||||
|
|
||||||
export type WorkspaceID = typeof workspaceIdSchema.Type
|
export type WorkspaceID = typeof workspaceIdSchema.Type
|
||||||
|
|
||||||
|
|||||||
@@ -478,7 +478,7 @@ function flattenOptions(options: OpenApiSchema[] | undefined): OpenApiSchema[] |
|
|||||||
function normalizeParameter(param: OpenApiParameter, route: string) {
|
function normalizeParameter(param: OpenApiParameter, route: string) {
|
||||||
if (!param.schema || typeof param.schema !== "object") return
|
if (!param.schema || typeof param.schema !== "object") return
|
||||||
if (param.in === "path") {
|
if (param.in === "path") {
|
||||||
param.schema = pathParameterSchema(route, param.name) ?? stripOptionalNull(param.schema)
|
param.schema = stripOptionalNull(param.schema)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (param.in === "query") {
|
if (param.in === "query") {
|
||||||
@@ -497,12 +497,6 @@ function normalizeParameter(param: OpenApiParameter, route: string) {
|
|||||||
param.schema = stripOptionalNull(param.schema)
|
param.schema = stripOptionalNull(param.schema)
|
||||||
}
|
}
|
||||||
|
|
||||||
function pathParameterSchema(route: string, name: string) {
|
|
||||||
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.*" }
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
export const PublicApi = OpenCodeHttpApi.annotateMerge(
|
export const PublicApi = OpenCodeHttpApi.annotateMerge(
|
||||||
OpenApi.annotations({
|
OpenApi.annotations({
|
||||||
title: "opencode",
|
title: "opencode",
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
ToolListQuery,
|
ToolListQuery,
|
||||||
} from "../../src/server/routes/instance/httpapi/groups/experimental"
|
} from "../../src/server/routes/instance/httpapi/groups/experimental"
|
||||||
import { InstancePaths, VcsDiffQuery } from "../../src/server/routes/instance/httpapi/groups/instance"
|
import { InstancePaths, VcsDiffQuery } from "../../src/server/routes/instance/httpapi/groups/instance"
|
||||||
|
import { WorkspacePaths } from "../../src/server/routes/instance/httpapi/groups/workspace"
|
||||||
import {
|
import {
|
||||||
ListQuery as SessionListQuery,
|
ListQuery as SessionListQuery,
|
||||||
MessagesQuery,
|
MessagesQuery,
|
||||||
@@ -82,6 +83,7 @@ const pathParamPatterns = [
|
|||||||
{ method: "post", path: "/permission/:requestID/reply", name: "requestID", pattern: "^per" },
|
{ method: "post", path: "/permission/:requestID/reply", name: "requestID", pattern: "^per" },
|
||||||
{ method: "post", path: "/question/:requestID/reply", name: "requestID", pattern: "^que" },
|
{ method: "post", path: "/question/:requestID/reply", name: "requestID", pattern: "^que" },
|
||||||
{ method: "put", path: PtyPaths.update, name: "ptyID", pattern: "^pty" },
|
{ method: "put", path: PtyPaths.update, name: "ptyID", pattern: "^pty" },
|
||||||
|
{ method: "delete", path: WorkspacePaths.remove, name: "id", pattern: "^wrk" },
|
||||||
] satisfies Array<{ method: Method; path: string; name: string; pattern: string }>
|
] satisfies Array<{ method: Method; path: string; name: string; pattern: string }>
|
||||||
|
|
||||||
function app() {
|
function app() {
|
||||||
|
|||||||
Reference in New Issue
Block a user