Skip to content

Commit c64cc59

Browse files
author
naman-contentstack
committed
add taxonomy support for entry with term_uid
1 parent 9d6a017 commit c64cc59

4 files changed

Lines changed: 5 additions & 4 deletions

File tree

src/generateTS/factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ export default function (userOptions: TSGenOptions) {
624624
};
625625

626626
function type_taxonomy() {
627-
return `${options?.naming?.prefix}Taxonomy`;
627+
return `${options?.naming?.prefix}Taxonomy | ${options?.naming?.prefix}TaxonomyEntry`;
628628
}
629629

630630
function type_json_rte(field: ContentstackTypes.Field) {

src/generateTS/stack/builtins.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export const defaultInterfaces = (
5656
mandatory: boolean;
5757
non_localizable: boolean;
5858
}`,
59+
`export type ${prefix}TaxonomyEntry = ${prefix}Taxonomy & { term_uid: string }`,
5960
];
6061
if (hasJsonRte) {
6162
defaultInterfaces.push(

tests/unit/tsgen/global.fields.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe("global fields", () => {
5151
{
5252
_version?: number;
5353
title: string;
54-
taxonomies?: ITaxonomy[];
54+
taxonomies?: ITaxonomy | ITaxonomyEntry[];
5555
}"
5656
`);
5757
});

tests/unit/tsgen/taxonomies.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe("builtin taxonomies field", () => {
1818
expect([...types.contentstack]).toHaveLength(1);
1919
expect([...types.globalFields]).toHaveLength(0);
2020
expect([...types.contentstack]).toEqual(
21-
expect.arrayContaining(["ITaxonomy"])
21+
expect.arrayContaining(["ITaxonomy | ITaxonomyEntry"])
2222
);
2323
});
2424

@@ -29,7 +29,7 @@ describe("builtin taxonomies field", () => {
2929
_version?: number;
3030
title: string;
3131
boolean: boolean;
32-
taxonomies?: ITaxonomy[];
32+
taxonomies?: ITaxonomy | ITaxonomyEntry[];
3333
}"
3434
`);
3535
});

0 commit comments

Comments
 (0)