fix(api): type /scripts/list response as ListableScript (#9577)

* fix(api): type /scripts/list response as ListableScript

GET /w/{workspace}/scripts/list is documented as returning the full Script
schema, but it actually returns a lighter object (Rust ListableScript) that
omits heavy fields like content, created_by, parent_hashes, deleted,
is_template and has_preprocessor. The OpenAPI docs — and the generated clients
— therefore over-promise fields that are never present at runtime.

Add an accurate ListableScript schema and point the /scripts/list response at
it. Regenerating the frontend client surfaced several consumers that were typed
against the full Script for list results; retype them to ListableScript. They
only use the lighter fields — full-script fields elsewhere come from separate
getScriptByPath/getScriptByHash fetches and are unchanged.

Addresses #5451

* fix: type /scripts/list as ListableScript matching the Rust struct, retype its consumers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: fail when ListableScript and its openapi schema drift apart

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Ruben Fiszel <ruben@windmill.dev>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Amey Pawar
2026-11-19 11:20:49 +01:00
committed by GitHub
co-authored by Claude Opus 5.5 Ruben Fiszel
parent 0659b8a125
commit f3b31b18f5
9 changed files with 204 additions and 48 deletions
+1
View File
@@ -17542,6 +17542,7 @@ dependencies = [
"rand 0.9.5",
"serde",
"serde_json",
"serde_yml",
"sqlx",
"strum",
"tracing",
+104 -34
View File
@@ -11097,40 +11097,7 @@ paths:
schema:
type: array
items:
allOf:
- $ref: "#/components/schemas/Script"
- type: object
properties:
is_draft:
type: boolean
description: |
True when the authed user has a draft for this
script — either no deployed row exists at this
path (draft-only) or the user saved a per-user
draft on top of the deployed row.
draft_path:
type: string
description: |
User-typed path the editor has staged but not
yet deployed. Surfaced for draft-only rows so
the home list can render the meaningful name
instead of the autogenerated
`u/{user}/draft_{uuid}` URL path. Omitted
when unchanged.
draft_users:
description: |
Workspace users (including the authed user, and
the legacy NULL-email row if any) who have a
per-user draft at this path. Drives the home
page's user-avatar circles inside the Draft
badge. Omitted when no drafts exist.
type: array
items:
type: object
properties:
username:
type: string
nullable: true
$ref: "#/components/schemas/ListableScript"
/w/{workspace}/scripts/list_paths:
get:
@@ -32214,6 +32181,109 @@ components:
- type
- path
ListableScript:
type: object
description: |
A script as returned by the list endpoint: the deployed row's summary
fields, without its content, lock or schema.
properties:
hash:
type: string
path:
type: string
summary:
type: string
description:
type: string
created_at:
type: string
format: date-time
archived:
type: boolean
extra_perms:
type: object
additionalProperties:
type: boolean
language:
$ref: "#/components/schemas/ScriptLang"
kind:
type: string
enum: [script, failure, trigger, approval, preprocessor]
starred:
type: boolean
tag:
type: string
nullable: true
draft_only:
type: boolean
description: |
True on rows built from a draft that was never deployed. Omitted
on deployed rows.
has_deploy_errors:
type: boolean
ws_error_handler_muted:
type: boolean
nullable: true
auto_kind:
type: string
use_codebase:
type: boolean
description: Omitted when false.
deployment_msg:
type: string
description: Only returned with `with_deployment_msg=true`.
labels:
type: array
items:
type: string
inherited_labels:
type: array
items:
type: string
is_draft:
type: boolean
description: |
True when the authed user has a draft for this
script — either no deployed row exists at this
path (draft-only) or the user saved a per-user
draft on top of the deployed row. Omitted when false.
draft_path:
type: string
description: |
User-typed path the editor has staged but not
yet deployed. Surfaced for draft-only rows so
the home list can render the meaningful name
instead of the autogenerated
`u/{user}/draft_{uuid}` URL path. Omitted
when unchanged.
draft_users:
description: |
Workspace users (including the authed user, and
the legacy NULL-email row if any) who have a
per-user draft at this path. Drives the home
page's user-avatar circles inside the Draft
badge. Omitted when no drafts exist.
type: array
items:
type: object
properties:
username:
type: string
nullable: true
required:
- hash
- path
- summary
- created_at
- archived
- extra_perms
- language
- kind
- starred
- tag
- has_deploy_errors
- ws_error_handler_muted
Script:
type: object
properties:
+3
View File
@@ -26,3 +26,6 @@ bitflags.workspace = true
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
sqlx = { workspace = true, features = ["postgres"] }
[dev-dependencies]
serde_yml.workspace = true
@@ -0,0 +1,78 @@
//! `openapi.yaml` describes the `/scripts/list` row by hand, so a field added to
//! `ListableScript` must also be added to its `ListableScript` schema, or every
//! generated client silently lacks it.
use std::collections::BTreeSet;
use serde_json::Value;
use windmill_types::scripts::{ListableScript, ScriptHash, ScriptKind, ScriptLang};
use windmill_types::user_drafts::DraftUserRef;
fn listable_script(populated: bool) -> ListableScript {
let some = |s: &str| populated.then(|| s.to_string());
ListableScript {
hash: ScriptHash(1),
path: "f/a/b".to_string(),
summary: String::new(),
created_at: chrono::Utc::now(),
archived: false,
extra_perms: serde_json::json!({}),
language: ScriptLang::Bun,
starred: false,
tag: None,
description: some("d"),
draft_only: populated.then_some(true),
has_deploy_errors: false,
ws_error_handler_muted: None,
auto_kind: some("lib"),
use_codebase: populated,
deployment_msg: some("m"),
kind: ScriptKind::Script,
labels: populated.then(|| vec!["l".to_string()]),
is_draft: populated,
draft_path: some("u/x/y"),
draft_users: populated.then(|| sqlx::types::Json(vec![DraftUserRef { username: None }])),
inherited_labels: populated.then(|| vec!["l".to_string()]),
}
}
fn keys(script: &ListableScript) -> BTreeSet<String> {
match serde_json::to_value(script).unwrap() {
Value::Object(o) => o.into_iter().map(|(k, _)| k).collect(),
v => panic!("ListableScript serialized to {v}"),
}
}
#[test]
fn listable_script_schema_matches_its_serialization() {
let spec: serde_yml::Value = serde_yml::from_str(include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../windmill-api/openapi.yaml"
)))
.unwrap();
let schema = &spec["components"]["schemas"]["ListableScript"];
let names = |v: &serde_yml::Value| -> BTreeSet<String> {
match v {
serde_yml::Value::Mapping(m) => {
m.keys().map(|k| k.as_str().unwrap().to_string()).collect()
}
serde_yml::Value::Sequence(s) => {
s.iter().map(|k| k.as_str().unwrap().to_string()).collect()
}
v => panic!("unexpected {v:?}"),
}
};
let properties = names(&schema["properties"]);
let required = names(&schema["required"]);
assert_eq!(
keys(&listable_script(true)),
properties,
"ListableScript's serialized fields and the properties of its openapi.yaml schema differ"
);
assert_eq!(
keys(&listable_script(false)),
required,
"the fields ListableScript always serializes and the `required` list of its openapi.yaml schema differ"
);
}
+8 -4
View File
@@ -74,7 +74,11 @@ import { createTarBlob, type TarEntry } from "../../utils/tar.ts";
import { withEsbuild } from "../../utils/esbuild_loader.ts";
import { execSync } from "node:child_process";
import { NewScript, Script, ScriptModule } from "../../../gen/types.gen.ts";
import {
ListableScript,
NewScript,
ScriptModule,
} from "../../../gen/types.gen.ts";
import {
isRawAppBackendPath as isRawAppBackendPathInternal,
isAppInlineScriptPath as isAppInlineScriptPathInternal,
@@ -1383,7 +1387,7 @@ async function list(
let page = 0;
const perPage = 10;
const total: Script[] = [];
const total: ListableScript[] = [];
while (true) {
const res = await wmill.listScripts({
workspace: workspace.workspaceId,
@@ -1404,10 +1408,10 @@ async function list(
console.log(JSON.stringify(total));
} else {
new Table()
.header(["path", "summary", "language", "created by"])
.header(["path", "summary", "language", "created at"])
.padding(2)
.border(true)
.body(total.map((x) => [x.path, x.summary, x.language, x.created_by]))
.body(total.map((x) => [x.path, x.summary, x.language, x.created_at]))
.render();
}
}
@@ -6,7 +6,7 @@
import SearchItems from '$lib/components/SearchItems.svelte'
import NoItemFound from '$lib/components/home/NoItemFound.svelte'
import RowIcon from '$lib/components/common/table/RowIcon.svelte'
import { type Script, ScriptService } from '$lib/gen'
import { type ListableScript, ScriptService } from '$lib/gen'
import { emptyString } from '$lib/utils'
import { Skeleton } from '$lib/components/common'
import { useOperatingWorkspace } from '$lib/components/operatingWorkspace.svelte'
@@ -20,8 +20,8 @@
let { filter = $bindable(''), children }: Props = $props()
let scripts: Script[] | undefined = $state(undefined)
let filteredItems: (Script & { marked?: string })[] = $state([])
let scripts: ListableScript[] | undefined = $state(undefined)
let filteredItems: (ListableScript & { marked?: string })[] = $state([])
let prefilteredItems = $derived(scripts ?? [])
const dispatch = createEventDispatcher()
@@ -1,6 +1,6 @@
<script lang="ts">
import { copilotInfo } from '$lib/aiStore'
import { ScriptService, type Script } from '$lib/gen'
import { ScriptService, type ListableScript } from '$lib/gen'
import { Wand2, Loader2 } from 'lucide-svelte'
import SearchItems from '../SearchItems.svelte'
@@ -11,14 +11,14 @@
const operatingWorkspace = useOperatingWorkspace()
let scripts: Script[] | undefined = $state(undefined)
let scripts: ListableScript[] | undefined = $state(undefined)
interface Props {
funcDesc: string
trigger?: boolean
loading?: boolean
preFilter: string
disableAi?: boolean
filteredItems?: (Script & { marked?: string })[] | (Item & { marked?: string })[]
filteredItems?: (ListableScript & { marked?: string })[] | (Item & { marked?: string })[]
}
let {
@@ -56,7 +56,7 @@ import {
type FlowValue,
type FlowModule,
type ScriptLang,
type Script,
type ListableScript,
type Flow
} from '$lib/gen'
import uFuzzy from '@leeoniya/ufuzzy'
@@ -2908,7 +2908,7 @@ export class WorkspaceRunnablesSearch {
private uf: uFuzzy
private scriptsWorkspace: string | undefined = undefined
private flowsWorkspace: string | undefined = undefined
private scripts: Script[] | undefined = undefined
private scripts: ListableScript[] | undefined = undefined
private flows: Flow[] | undefined = undefined
private scriptCache: Map<string, Awaited<ReturnType<typeof ScriptService.getScriptByPath>>> =
new Map()
@@ -9,7 +9,7 @@
type ListableApp,
type ListableRawApp,
type ListableResource,
type Script,
type ListableScript,
type SearchJobsIndexResponse
} from '$lib/gen'
import { clickOutside, isMac, scroll_into_view_if_needed_polyfill } from '$lib/utils'
@@ -533,7 +533,7 @@
// search_id: string
// }
type TableScript = TableItem<Script, 'script'>
type TableScript = TableItem<ListableScript, 'script'>
type TableFlow = TableItem<Flow, 'flow'>
type TableApp = TableItem<ListableApp, 'app'>
type TableRawApp = TableItem<ListableRawApp, 'raw_app'>