Skip to content

Commit bdf61bd

Browse files
committed
Copy comments from schema variable to type
Resolves #7
1 parent 175e22f commit bdf61bd

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ See [an example](https://gerritbirkeland.com/typedoc-plugin-zod/types/Abc.html)
1919

2020
## Change Log
2121

22+
### v1.2.1 (2024-08-18)
23+
24+
- Fix warnings about referenced but not present reflections in packages mode, #6.
25+
- Copy comments from schema object declaration to type alias, #7.
26+
2227
### v1.2.0 (2024-06-22)
2328

2429
- Support TypeDoc 0.26.

src/plugin.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@ export function load(app: Application) {
3636
context.project,
3737
),
3838
];
39+
40+
inferredType.comment ??= refOrig.reflection.comment?.clone();
3941
}
4042
}
4143

42-
console.log(context.project.getReflectionById(35)?.getFullName());
43-
console.log(context.project.getReflectionById(70)?.getFullName());
44-
4544
schemaTypes.clear();
4645
});
4746

src/test/plugin.test.mts

+29
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {
55
TSConfigReader,
66
TypeScript as ts,
77
ReflectionType,
8+
Comment,
9+
ProjectReflection,
810
} from "typedoc";
911
import { test, expect, beforeAll } from "vitest";
1012
import { load } from "../plugin.js";
@@ -26,6 +28,11 @@ function convert(entry: string) {
2628
]);
2729
}
2830

31+
function getComment(project: ProjectReflection, path: string) {
32+
const refl = project.getChildByName(path);
33+
return Comment.combineDisplayParts(refl?.comment?.summary);
34+
}
35+
2936
beforeAll(async () => {
3037
app = await Application.bootstrap(
3138
{
@@ -131,3 +138,25 @@ test("Serialized/deserialized projects do not create warnings, #6", () => {
131138

132139
expect(app.logger.hasWarnings()).toBe(false);
133140
});
141+
142+
test("Comments on type aliases, #7", () => {
143+
const project = convert("gh7.ts");
144+
145+
expect(project.toStringHierarchy()).toBe(outdent`
146+
Project typedoc-plugin-zod
147+
TypeAlias Bar: Object
148+
TypeLiteral __type
149+
Property b: string
150+
TypeAlias Foo: Object
151+
TypeLiteral __type
152+
Property a: string
153+
Variable Bar: ZodObject<Bar>
154+
Variable Foo: ZodObject<Foo>
155+
`);
156+
157+
const comments = ["Bar type docs", "Foo docs", "Bar docs", "Foo docs"];
158+
const actualComments = project.children?.map((c) =>
159+
Comment.combineDisplayParts(c.comment?.summary),
160+
);
161+
expect(actualComments).toEqual(comments);
162+
});

src/testdata/gh7.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { object, string, TypeOf } from "zod";
2+
3+
/** Foo docs */
4+
export const Foo = object({
5+
a: string(),
6+
});
7+
8+
export type Foo = TypeOf<typeof Foo>;
9+
10+
/** Bar docs */
11+
export const Bar = object({
12+
b: string(),
13+
});
14+
15+
/** Bar type docs */
16+
export type Bar = TypeOf<typeof Bar>;

0 commit comments

Comments
 (0)