Skip to content

Commit 993ab7c

Browse files
committed
feat: improve schema ids
1 parent 821e9bd commit 993ab7c

4 files changed

Lines changed: 239 additions & 262 deletions

File tree

‎database.schema.json‎

Lines changed: 62 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@
103103
"general",
104104
"programming-language-design",
105105
"git",
106-
"python",
106+
"clojure",
107+
"cpp",
108+
"java",
107109
"rust",
108110
"sql",
109-
"cpp",
110-
"clojure",
111111
"php",
112+
"python",
112113
"kotlin",
113-
"java",
114114
"haskell"
115115
],
116116
"description": "The unique identifier of the entity"
@@ -171,65 +171,22 @@
171171
"general",
172172
"programming-language-design",
173173
"git",
174-
"python",
174+
"clojure",
175+
"cpp",
176+
"java",
175177
"rust",
176178
"sql",
177-
"cpp",
178-
"clojure",
179179
"php",
180+
"python",
180181
"kotlin",
181-
"java",
182182
"haskell"
183183
]
184184
},
185185
"description": "The topics that this resource teaches."
186186
},
187187
"pricing": {
188-
"oneOf": [
189-
{
190-
"type": "object",
191-
"properties": {
192-
"model": {
193-
"type": "string",
194-
"enum": [
195-
"Free",
196-
"Freemium"
197-
],
198-
"description": "The Free(mium) Pricing Model of this resource. 'Free' should be used for resources where 100% (or close) of the content is free. 'Freemium' describes a pricing model where the core content is available for free, but features paid extensions. If the resource has a freemium model but the free portion is very limited, consider using 'Paid' instead and providing an estimated price for the full version. "
199-
}
200-
},
201-
"required": [
202-
"model"
203-
],
204-
"additionalProperties": false,
205-
"description": "FreeFreemiumPricing"
206-
},
207-
{
208-
"type": "object",
209-
"properties": {
210-
"model": {
211-
"type": "string",
212-
"enum": [
213-
"Subscription",
214-
"One Time"
215-
],
216-
"description": "The Paid Pricing Model of this resource. 'Subscription' means the resource is paid on a recurring basis (e.g. monthly or yearly), while 'One Time' means the resource is paid with a single upfront payment. If the price varies or is not fixed, provide a close approximation. Note that the subscription renewal cycle is not specified, so if the price has different renewal cycles, provide the most common or default one (usually monthly)."
217-
},
218-
"amount": {
219-
"type": "number",
220-
"exclusiveMinimum": 0,
221-
"description": "The price of this resource, in US Dollars."
222-
}
223-
},
224-
"required": [
225-
"model",
226-
"amount"
227-
],
228-
"additionalProperties": false,
229-
"title": "PaidPricing"
230-
}
231-
],
232-
"description": "Details about the cost of the resource."
188+
"description": "Details about the cost of the resource.",
189+
"$ref": "#/$defs/Pricing"
233190
},
234191
"pros": {
235192
"description": "Array of pros for using the resource, e.g. 'explains difficult concepts with good analogies'",
@@ -263,5 +220,57 @@
263220
"resources"
264221
],
265222
"additionalProperties": false,
223+
"$defs": {
224+
"FreePricing": {
225+
"type": "object",
226+
"properties": {
227+
"model": {
228+
"type": "string",
229+
"enum": [
230+
"Free",
231+
"Freemium"
232+
],
233+
"description": "The Free(mium) Pricing Model of this resource. 'Free' should be used for resources where 100% (or close) of the content is free. 'Freemium' describes a pricing model where the core content is available for free, but features paid extensions. If the resource has a freemium model but the free portion is very limited, consider using 'Paid' instead and providing an estimated price for the full version. "
234+
}
235+
},
236+
"required": [
237+
"model"
238+
],
239+
"additionalProperties": false
240+
},
241+
"PaidPricing": {
242+
"type": "object",
243+
"properties": {
244+
"model": {
245+
"type": "string",
246+
"enum": [
247+
"Subscription",
248+
"One Time"
249+
],
250+
"description": "The Paid Pricing Model of this resource. 'Subscription' means the resource is paid on a recurring basis (e.g. monthly or yearly), while 'One Time' means the resource is paid with a single upfront payment. If the price varies or is not fixed, provide a close approximation. Note that the subscription renewal cycle is not specified, so if the price has different renewal cycles, provide the most common or default one (usually monthly)."
251+
},
252+
"amount": {
253+
"type": "number",
254+
"exclusiveMinimum": 0,
255+
"description": "The price of this resource, in US Dollars."
256+
}
257+
},
258+
"required": [
259+
"model",
260+
"amount"
261+
],
262+
"additionalProperties": false
263+
},
264+
"Pricing": {
265+
"oneOf": [
266+
{
267+
"$ref": "#/$defs/FreePricing"
268+
},
269+
{
270+
"$ref": "#/$defs/PaidPricing"
271+
}
272+
]
273+
}
274+
},
266275
"$comment": "// Generated by index.ts - DO NOT EDIT THIS FILE DIRECTLY"
267276
}

‎index.ts‎

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,34 +34,36 @@ const EntityTagEnum = z.enum([
3434
...allValidTags.slice(1)
3535
] as [string, ...string[]]);
3636

37+
38+
const PaidPricingSchema = z.strictObject({
39+
model: z
40+
.enum(["Subscription", "One Time"])
41+
.describe(
42+
"The Paid Pricing Model of this resource. 'Subscription' means the resource is paid on a recurring basis (e.g. monthly or yearly), while 'One Time' means the resource is paid with a single upfront payment. If the price varies or is not fixed, provide a close approximation. Note that the subscription renewal cycle is not specified, so if the price has different renewal cycles, provide the most common or default one (usually monthly).",
43+
),
44+
amount: z
45+
.number()
46+
.gt(0)
47+
.describe("The price of this resource, in US Dollars."),
48+
}).meta({ id: "PaidPricing" });
49+
50+
const FreePricingSchema = z.strictObject({
51+
model: z
52+
.enum(["Free", "Freemium"])
53+
.describe(
54+
"The Free(mium) Pricing Model of this resource. 'Free' should be used for resources where 100% (or close) of the content is free. 'Freemium' describes a pricing model where the core content is available for free, but features paid extensions. If the resource has a freemium model but the free portion is very limited, consider using 'Paid' instead and providing an estimated price for the full version. ",
55+
),
56+
}).meta({ id: "FreePricing" });
57+
3758
/**
3859
* The Pricing of a Resource, which can either be Free/Freemium or Paid (Subscription/One Time)
3960
*/
4061
const PricingSchema = z
4162
.discriminatedUnion("model", [
42-
z
43-
.strictObject({
44-
model: z
45-
.enum(["Free", "Freemium"])
46-
.describe(
47-
"The Free(mium) Pricing Model of this resource. 'Free' should be used for resources where 100% (or close) of the content is free. 'Freemium' describes a pricing model where the core content is available for free, but features paid extensions. If the resource has a freemium model but the free portion is very limited, consider using 'Paid' instead and providing an estimated price for the full version. ",
48-
),
49-
})
50-
.describe("FreeFreemiumPricing"),
51-
52-
z.strictObject({
53-
model: z
54-
.enum(["Subscription", "One Time"])
55-
.describe(
56-
"The Paid Pricing Model of this resource. 'Subscription' means the resource is paid on a recurring basis (e.g. monthly or yearly), while 'One Time' means the resource is paid with a single upfront payment. If the price varies or is not fixed, provide a close approximation. Note that the subscription renewal cycle is not specified, so if the price has different renewal cycles, provide the most common or default one (usually monthly).",
57-
),
58-
amount: z
59-
.number()
60-
.gt(0)
61-
.describe("The price of this resource, in US Dollars."),
62-
}).meta({ title: "PaidPricing" }),
63-
63+
FreePricingSchema,
64+
PaidPricingSchema,
6465
])
66+
.meta({ id: "Pricing" })
6567
.describe("Details about the cost of the resource.");
6668

6769
export const LanguageDomainSchema = z
@@ -234,7 +236,7 @@ function main() {
234236
process.exit(1);
235237
}
236238

237-
const jsonSchema = z.toJSONSchema(schema, {});
239+
const jsonSchema = z.toJSONSchema(schema, { reused: "inline", });
238240
jsonSchema.$comment = header;
239241
console.log(JSON.stringify(jsonSchema, null, 2));
240242
}

0 commit comments

Comments
 (0)