Skip to content

Commit febe18d

Browse files
committed
add schema descriptions as jsdocs
1 parent 667f647 commit febe18d

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/core/renderers/schema.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import schemaTemplate from "~/templates/schema.hbs";
55
type SchemaTemplate = {
66
importedSchemas: string[],
77
name: string,
8+
description: string,
89
properties: ModelProperty[],
910
};
1011

11-
export default function generateSchema(name: string, properties: ModelProperty[], importedSchemas: string[]) {
12+
export default function generateSchema(name: string, properties: ModelProperty[], importedSchemas: string[], description?: string) {
1213
const template = getTemplate<SchemaTemplate>(schemaTemplate);
1314
return template({
1415
name,
16+
description: description || "missing-description",
1517
properties,
1618
importedSchemas,
1719
});

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import findPredefinedSchemas from "./core/schemas";
3131
if (schema.type === "object") {
3232
const properties = resolveProperties(schema.properties, schema.required ?? []);
3333
const importedSchemas = resolveSchemasFromProps(schema.properties);
34-
const content = generateSchema(schemaName, properties, importedSchemas);
34+
const content = generateSchema(schemaName, properties, importedSchemas, schema.description);
3535
await createFile(content, `${schemaName}.ts`, outputDir, "dist/schemas");
3636
}
3737
}

src/templates/schema.hbs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
{{#each importedSchemas}}
22
import type {{this}} from "./{{this}}";
33
{{/each}}
4-
4+
/**
5+
* {{{description}}}
6+
*/
57
type {{name}} = {
68
{{#each properties}}
79
/**
8-
* {{{this.description}}}
9-
*/
10-
{{{this.content}}}
10+
* {{{description}}}
11+
*/
12+
{{{content}}}
1113
{{/each}}
1214
};
1315

0 commit comments

Comments
 (0)