Skip to content

Commit dd1718c

Browse files
committed
json schema backend root level @type
1 parent 402c7fb commit dd1718c

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

packages/core/src/backend/schema/jsonschema.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ describe("JsonSchemaBackend", () => {
274274
expect(schema.description).toBe("Automated brain extraction tool for FSL");
275275

276276
const props = schema.properties as Record<string, JsonSchema>;
277+
expect(props["@type"]).toEqual({ const: "unknown/bet" });
278+
expect(schema.required).toContain("@type");
277279
expect(props["infile"]?.type).toBe("string");
278280
expect(props["infile"]?.format).toBe("path");
279281
expect(props["maskfile"]?.type).toBe("string");

packages/core/src/backend/schema/jsonschema.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,18 @@ class SchemaBuilder {
2727
const rootBinding = this.ctx.resolve(this.ctx.expr);
2828
if (!rootBinding) return envelope;
2929

30-
return { ...envelope, ...this.fromBinding(rootBinding) };
30+
const schema = { ...envelope, ...this.fromBinding(rootBinding) };
31+
32+
if (this.ctx.app?.id && schema.properties) {
33+
const pkg = this.ctx.package?.name ?? "unknown";
34+
schema.properties = {
35+
"@type": { const: `${pkg}/${this.ctx.app.id}` },
36+
...schema.properties,
37+
};
38+
schema.required = ["@type", ...(schema.required ?? [])];
39+
}
40+
41+
return schema;
3142
}
3243

3344
private fromBinding(binding: Binding): JsonSchema {

0 commit comments

Comments
 (0)