Skip to content

Commit b006fda

Browse files
authored
Fix JSON Schema Metadata (#9)
* Fix CharacterDocument type * fix json registry meta * refine outputs
1 parent 60b40af commit b006fda

37 files changed

Lines changed: 173 additions & 3476 deletions

packages/forge-schema/scripts/generate-json-schema.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
import path from "node:path";
22
import { z } from "zod/v4";
3-
import { jsonCollection } from "../src/json-collection.js";
3+
// import { jsonCollection } from "../src/json-collection.js";
44
import { characterDocument } from "../src/models/doc-character.js";
55
import { campaignRuleset } from "../src/models/ruleset-campaign.js";
66
import { coreRuleset } from "../src/models/ruleset-core.js";
77

8-
const characterSchema = z.toJSONSchema(characterDocument, { reused: "ref" });
9-
const registryCampaignSchema = z.toJSONSchema(campaignRuleset, {
8+
const characterDocumentSchema = z.toJSONSchema(characterDocument, {
109
reused: "ref",
1110
});
12-
const registryCoreSchema = z.toJSONSchema(coreRuleset, { reused: "ref" });
11+
const campaignRulesetSchema = z.toJSONSchema(campaignRuleset, {
12+
reused: "ref",
13+
});
14+
const coreRulesetSchema = z.toJSONSchema(coreRuleset, { reused: "ref" });
1315

14-
const testingSchema = z.toJSONSchema(jsonCollection, {
16+
const defaultSchema = z.toJSONSchema(z.globalRegistry, {
1517
target: "draft-2020-12",
1618
unrepresentable: "throw",
1719
cycles: "throw",
1820
reused: "ref",
21+
override(ctx) {
22+
ctx.jsonSchema.$id = ctx.jsonSchema.id;
23+
},
1924
});
2025

2126
/**
@@ -62,10 +67,10 @@ const generateSchemas = async (): Promise<void> => {
6267

6368
// Compose schema data and filenames
6469
const schemas = [
65-
{ data: characterSchema, filename: "character.json" },
66-
{ data: registryCampaignSchema, filename: "campaign.json" },
67-
{ data: registryCoreSchema, filename: "core.json" },
68-
{ data: testingSchema, filename: "schema.json" },
70+
{ data: characterDocumentSchema, filename: "document-character.json" },
71+
{ data: campaignRulesetSchema, filename: "ruleset-campaign.json" },
72+
{ data: coreRulesetSchema, filename: "ruleset-core.json" },
73+
{ data: defaultSchema, filename: "schema.json" },
6974
];
7075

7176
// Dynamically import fs/promises for ESM compatibility
@@ -75,7 +80,7 @@ const generateSchemas = async (): Promise<void> => {
7580
await Promise.all(
7681
schemas.map(async ({ data, filename }) => {
7782
const dest = path.join(directory, filename);
78-
return writeFile(dest, JSON.stringify(data, null, 3), "utf-8");
83+
return writeFile(dest, JSON.stringify(data), "utf-8");
7984
}),
8085
);
8186
};

packages/forge-schema/src/json-collection.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { z } from "zod/v4";
2-
import { jsonCollection } from "../../json-collection.js";
32
import { createReference } from "../../utility/create-reference.js";
43

54
export const ancestry = z
@@ -10,8 +9,8 @@ export const ancestry = z
109
primaryFeature: z.object({ name: z.string(), description: z.string() }),
1110
secondaryFeature: z.object({ name: z.string(), description: z.string() }),
1211
})
13-
.register(jsonCollection, {
14-
id: "Ancestry",
12+
.meta({
13+
title: "Ancestry",
1514
description: "The ancestry of a character",
1615
examples: [
1716
{
@@ -32,17 +31,14 @@ export const ancestry = z
3231
],
3332
});
3433

35-
export const ancestryReference = createReference("heritage/ancestry").register(
36-
jsonCollection,
37-
{
38-
id: "AncestryReference",
39-
description: "A reference to an ancestry",
40-
examples: [
41-
{
42-
_type: "reference",
43-
_key: "heritage/ancestry",
44-
value: "ribbet",
45-
},
46-
],
47-
},
48-
);
34+
export const ancestryReference = createReference("heritage/ancestry").meta({
35+
id: "ReferenceAncestry",
36+
title: "Reference to an Ancestry",
37+
examples: [
38+
{
39+
_type: "reference",
40+
_key: "heritage/ancestry",
41+
value: "ribbet",
42+
},
43+
],
44+
});

packages/forge-schema/src/models/artifact/community.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { z } from "zod/v4";
2-
import { jsonCollection } from "../../json-collection.js";
32
import { createReference } from "../../utility/create-reference.js";
43

54
export const community = z
@@ -12,8 +11,9 @@ export const community = z
1211
description: z.string(),
1312
}),
1413
})
15-
.register(jsonCollection, {
14+
.meta({
1615
id: "Community",
16+
title: "Community",
1717
description: "A community that shaped a characters backstory",
1818
examples: [
1919
{
@@ -30,11 +30,9 @@ export const community = z
3030
],
3131
});
3232

33-
export const communityReference = createReference(
34-
"heritage/community",
35-
).register(jsonCollection, {
36-
id: "CommunityReference",
37-
description: "A reference to a community",
33+
export const communityReference = createReference("heritage/community").meta({
34+
id: "ReferenceCommunity",
35+
title: "Reference to a Community",
3836
examples: [
3937
{
4038
_type: "reference",
Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { z } from "zod/v4";
2-
import { jsonCollection } from "../../json-collection.js";
32
import { createReference } from "../../utility/create-reference.js";
43

54
export const domain = z
@@ -8,8 +7,9 @@ export const domain = z
87
name: z.string(),
98
description: z.string().nullable(),
109
})
11-
.register(jsonCollection, {
10+
.meta({
1211
id: "Domain",
12+
title: "Domain",
1313
description: "A domain of a character class",
1414
examples: [
1515
{
@@ -21,17 +21,14 @@ export const domain = z
2121
],
2222
});
2323

24-
export const domainReference = createReference("role/domain").register(
25-
jsonCollection,
26-
{
27-
id: "DomainReference",
28-
description: "A reference to a domain",
29-
examples: [
30-
{
31-
_type: "reference",
32-
_key: "role/domain",
33-
value: "arcana",
34-
},
35-
],
36-
},
37-
);
24+
export const domainReference = createReference("role/domain").meta({
25+
id: "ReferenceDomain",
26+
title: "Reference to a Domain",
27+
examples: [
28+
{
29+
_type: "reference",
30+
_key: "role/domain",
31+
value: "arcana",
32+
},
33+
],
34+
});
Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { z } from "zod/v4";
2-
import { jsonCollection } from "../../json-collection.js";
32
import { createReference } from "../../utility/create-reference.js";
43
import { damageThresholds } from "../common/damage-threshold.js";
54

@@ -12,8 +11,9 @@ export const inventoryArmor = z
1211
baseScore: z.number().int().min(0),
1312
features: z.array(z.string()).nullable(),
1413
})
15-
.register(jsonCollection, {
16-
id: "ItemArmor",
14+
.meta({
15+
id: "Armor",
16+
title: "Armor",
1717
description: "A set of armor that can be equipped by a character",
1818
examples: [
1919
{
@@ -31,17 +31,14 @@ export const inventoryArmor = z
3131
],
3232
});
3333

34-
export const inventoryArmorReference = createReference("item/armor").register(
35-
jsonCollection,
36-
{
37-
id: "ItemArmorReference",
38-
description: "A reference to an armor",
39-
examples: [
40-
{
41-
_type: "reference",
42-
_key: "item/armor",
43-
value: "full-plate-armor",
44-
},
45-
],
46-
},
47-
);
34+
export const inventoryArmorReference = createReference("item/armor").meta({
35+
id: "ReferenceArmor",
36+
title: "Reference to a piece of Armor",
37+
examples: [
38+
{
39+
_type: "reference",
40+
_key: "item/armor",
41+
value: "full-plate-armor",
42+
},
43+
],
44+
});
Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { z } from "zod/v4";
2-
import { jsonCollection } from "../../json-collection.js";
32
import { createReference } from "../../utility/create-reference.js";
43

54
export const inventoryThing = z
@@ -8,8 +7,9 @@ export const inventoryThing = z
87
name: z.string(),
98
description: z.string().nullable(),
109
})
11-
.register(jsonCollection, {
10+
.meta({
1211
id: "Thing",
12+
title: "Thing",
1313
description: "A thing that can be added to a character's inventory",
1414
examples: [
1515
{
@@ -20,17 +20,14 @@ export const inventoryThing = z
2020
],
2121
});
2222

23-
export const inventoryThingReference = createReference("item/special").register(
24-
jsonCollection,
25-
{
26-
id: "ItemSpecialReference",
27-
description: "A reference to a special item",
28-
examples: [
29-
{
30-
_type: "reference",
31-
_key: "item/special",
32-
value: "suspicious-looking-potion",
33-
},
34-
],
35-
},
36-
);
23+
export const inventoryThingReference = createReference("item/thing").meta({
24+
id: "ReferenceThing",
25+
title: "Reference to a Thing",
26+
examples: [
27+
{
28+
_type: "reference",
29+
_key: "item/thing",
30+
value: "suspicious-looking-potion",
31+
},
32+
],
33+
});

packages/forge-schema/src/models/artifact/inventory-weapon.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { z } from "zod/v4";
2-
import { jsonCollection } from "../../json-collection.js";
32
import { createReference } from "../../utility/create-reference.js";
43
import { damageType } from "../common/damage-type.js";
54
import { diceType } from "../common/dice-type.js";
@@ -17,8 +16,9 @@ export const inventoryWeapon = z
1716
features: z.array(z.string()).nullable(),
1817
burden: z.union([z.literal("One-Handed"), z.literal("Two-Handed")]),
1918
})
20-
.register(jsonCollection, {
19+
.meta({
2120
id: "Weapon",
21+
title: "Weapon",
2222
description: "A weapon that can be equipped by a character",
2323
examples: [
2424
{
@@ -34,17 +34,14 @@ export const inventoryWeapon = z
3434
],
3535
});
3636

37-
export const inventoryWeaponReference = createReference("item/weapon").register(
38-
jsonCollection,
39-
{
40-
id: "ItemWeaponReference",
41-
description: "A reference to a weapon",
42-
examples: [
43-
{
44-
_type: "reference",
45-
_key: "item/weapon",
46-
value: "warhammer",
47-
},
48-
],
49-
},
50-
);
37+
export const inventoryWeaponReference = createReference("item/weapon").meta({
38+
id: "ReferenceWeapon",
39+
title: "Reference to a Weapon",
40+
examples: [
41+
{
42+
_type: "reference",
43+
_key: "item/weapon",
44+
value: "warhammer",
45+
},
46+
],
47+
});

packages/forge-schema/src/models/artifact/role-class.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { z } from "zod/v4";
2-
import { jsonCollection } from "../../json-collection.js";
32
import { createReference } from "../../utility/create-reference.js";
43
import { domainReference } from "./domain.js";
54
import { inventoryArmor } from "./inventory-armor.js";
@@ -31,8 +30,9 @@ export const roleClass = z
3130

3231
subclasses: z.array(roleSubclassReference),
3332
})
34-
.register(jsonCollection, {
33+
.meta({
3534
id: "Class",
35+
title: "Class",
3636
description: "A class of a character",
3737
examples: [
3838
{
@@ -70,17 +70,14 @@ export const roleClass = z
7070
],
7171
});
7272

73-
export const roleClassReference = createReference("role/class").register(
74-
jsonCollection,
75-
{
76-
id: "RoleClassReference",
77-
description: "A reference to a class",
78-
examples: [
79-
{
80-
_type: "reference",
81-
_key: "role/class",
82-
value: "barbarian",
83-
},
84-
],
85-
},
86-
);
73+
export const roleClassReference = createReference("role/class").meta({
74+
id: "ReferenceClass",
75+
title: "Reference to a Class",
76+
examples: [
77+
{
78+
_type: "reference",
79+
_key: "role/class",
80+
value: "barbarian",
81+
},
82+
],
83+
});

0 commit comments

Comments
 (0)