Skip to content

Commit

Permalink
Copy comments from schema variable to type
Browse files Browse the repository at this point in the history
Resolves #7
  • Loading branch information
Gerrit0 committed Aug 18, 2024
1 parent 175e22f commit bdf61bd
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ See [an example](https://gerritbirkeland.com/typedoc-plugin-zod/types/Abc.html)

## Change Log

### v1.2.1 (2024-08-18)

- Fix warnings about referenced but not present reflections in packages mode, #6.
- Copy comments from schema object declaration to type alias, #7.

### v1.2.0 (2024-06-22)

- Support TypeDoc 0.26.
Expand Down
5 changes: 2 additions & 3 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ export function load(app: Application) {
context.project,
),
];

inferredType.comment ??= refOrig.reflection.comment?.clone();
}
}

console.log(context.project.getReflectionById(35)?.getFullName());
console.log(context.project.getReflectionById(70)?.getFullName());

schemaTypes.clear();
});

Expand Down
29 changes: 29 additions & 0 deletions src/test/plugin.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
TSConfigReader,
TypeScript as ts,
ReflectionType,
Comment,
ProjectReflection,
} from "typedoc";
import { test, expect, beforeAll } from "vitest";
import { load } from "../plugin.js";
Expand All @@ -26,6 +28,11 @@ function convert(entry: string) {
]);
}

function getComment(project: ProjectReflection, path: string) {
const refl = project.getChildByName(path);
return Comment.combineDisplayParts(refl?.comment?.summary);
}

beforeAll(async () => {
app = await Application.bootstrap(
{
Expand Down Expand Up @@ -131,3 +138,25 @@ test("Serialized/deserialized projects do not create warnings, #6", () => {

expect(app.logger.hasWarnings()).toBe(false);
});

test("Comments on type aliases, #7", () => {
const project = convert("gh7.ts");

expect(project.toStringHierarchy()).toBe(outdent`
Project typedoc-plugin-zod
TypeAlias Bar: Object
TypeLiteral __type
Property b: string
TypeAlias Foo: Object
TypeLiteral __type
Property a: string
Variable Bar: ZodObject<Bar>
Variable Foo: ZodObject<Foo>
`);

const comments = ["Bar type docs", "Foo docs", "Bar docs", "Foo docs"];
const actualComments = project.children?.map((c) =>
Comment.combineDisplayParts(c.comment?.summary),
);
expect(actualComments).toEqual(comments);
});
16 changes: 16 additions & 0 deletions src/testdata/gh7.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { object, string, TypeOf } from "zod";

/** Foo docs */
export const Foo = object({
a: string(),
});

export type Foo = TypeOf<typeof Foo>;

/** Bar docs */
export const Bar = object({
b: string(),
});

/** Bar type docs */
export type Bar = TypeOf<typeof Bar>;

0 comments on commit bdf61bd

Please sign in to comment.