Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions __tests__/__snapshots__/from-schema-test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11241,7 +11241,7 @@ humanOrDroid: HumanOrDroid | null;
getCharacters: Array<Character>;

/**
* @deprecated Field No Longer Available.
* @deprecated \\"Field No Longer Available.\\"
*/
anOldField: string | null;
}
Expand Down Expand Up @@ -11280,7 +11280,7 @@ friends: Array<Character> | null;
appearsIn: Array<Episode> | null;

/**
* @deprecated Field No Longer Available.
* @deprecated \\"Field No Longer Available.\\"
*/
anOldField: string | null;
nonNullArr: Array<Character>;
Expand All @@ -11303,7 +11303,7 @@ appearsIn: Array<Episode> | null;
homePlanet: string | null;

/**
* @deprecated Field No Longer Available.
* @deprecated \\"Field No Longer Available.\\"
*/
anOldField: string | null;
nonNullArr: Array<Character>;
Expand All @@ -11321,7 +11321,7 @@ primaryFunction: string | null;
primaryFunctionNonNull: string;

/**
* @deprecated Field No Longer Available.
* @deprecated \\"Field No Longer Available.\\"
*/
anOldField: string | null;
nonNullArr: Array<Character>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@ exports[`language-typescript DEFAULT_DOCUMENTATION_GENERATOR with a description
"
/**
* This is a thing
* @default myDefaultValue
* @deprecated Use the other field instead
* @default \\"myDefaultValue\\"
* @deprecated \\"Use the other field instead\\"
*/"
`;

exports[`language-typescript DEFAULT_DOCUMENTATION_GENERATOR with a description with 1 json tag 1`] = `
"
/**
* This is a thing
* @default {\\"myDefault\\":\\"Value\\"}
*/"
`;

exports[`language-typescript DEFAULT_DOCUMENTATION_GENERATOR with a description with 1 tag 1`] = `
"
/**
* This is a thing
* @default myDefaultValue
* @default \\"myDefaultValue\\"
*/"
`;

Expand All @@ -27,15 +35,22 @@ exports[`language-typescript DEFAULT_DOCUMENTATION_GENERATOR with a description
exports[`language-typescript DEFAULT_DOCUMENTATION_GENERATOR without a description with >1 tag 1`] = `
"
/**
* @default myDefaultValue
* @deprecated Use the other field instead
* @default \\"myDefaultValue\\"
* @deprecated \\"Use the other field instead\\"
*/"
`;

exports[`language-typescript DEFAULT_DOCUMENTATION_GENERATOR without a description with 1 json tag 1`] = `
"
/**
* @default {\\"myDefault\\":\\"Value\\"}
*/"
`;

exports[`language-typescript DEFAULT_DOCUMENTATION_GENERATOR without a description with 1 tag 1`] = `
"
/**
* @default myDefaultValue
* @default \\"myDefaultValue\\"
*/"
`;

Expand All @@ -46,12 +61,12 @@ exports[`language-typescript DEFAULT_ENUM_FORMATTER w/ deprecated value 1`] = `

/**
* value A
* @deprecated Bad
* @deprecated \\"Bad\\"
*/
a = 'a',

/**
* @deprecated Bad
* @deprecated \\"Bad\\"
*/
b = 'b',

Expand Down
11 changes: 11 additions & 0 deletions packages/language-typescript/src/__tests__/index-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ describe('language-typescript', () => {
tags: [{ tag: 'default', value: 'myDefaultValue' }]
})).toMatchSnapshot();
});
it('with 1 json tag', () => {
expect(DEFAULT_DOCUMENTATION_GENERATOR({
description: 'This is a thing',
tags: [{ tag: 'default', value: { myDefault: 'Value' } }]
})).toMatchSnapshot();
});
it('with >1 tag', () => {
expect(DEFAULT_DOCUMENTATION_GENERATOR({
description: 'This is a thing',
Expand All @@ -141,6 +147,11 @@ describe('language-typescript', () => {
tags: [{ tag: 'default', value: 'myDefaultValue' }]
})).toMatchSnapshot();
});
it('with 1 json tag', () => {
expect(DEFAULT_DOCUMENTATION_GENERATOR({
tags: [{ tag: 'default', value: { myDefault: 'Value' } }]
})).toMatchSnapshot();
});
it('with >1 tag', () => {
expect(DEFAULT_DOCUMENTATION_GENERATOR({
tags: [
Expand Down
15 changes: 12 additions & 3 deletions packages/language-typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,19 @@ ${interfaces}
const fixDescriptionDocblock: (description?: string) => string | undefined = description =>
description ? description.replace(/\n/g, '\n* ') : description;

export const DEFAULT_DOCUMENTATION_GENERATOR: GenerateDocumentation = ({ description, tags = [] }) => (description || tags.length) ? `
export const DEFAULT_DOCUMENTATION_GENERATOR: GenerateDocumentation = ({ description, tags = [] }) => {
if (!description && !tags.length) {
return '';
}
const arr: Array<string | undefined> = [
fixDescriptionDocblock(description),
...tags.map(({ tag, value }) => `@${tag} ${JSON.stringify(value)}`)
];
return `
/**
* ${filterAndJoinArray([fixDescriptionDocblock(description), ...tags.map(({ tag, value }) => `@${tag} ${value}`)], '\n* ')}
*/` : '';
* ${filterAndJoinArray(arr, '\n * ')}
*/`;
};

export const DEFAULT_OPTIONS: IFromQueryOptions = {
wrapList: DEFAULT_WRAP_LIST,
Expand Down
2 changes: 1 addition & 1 deletion packages/util/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {

export interface IJSDocTag {
tag: string;
value: string;
value: string | object;
}

export interface IFieldDocumentation {
Expand Down