diff --git a/__tests__/__snapshots__/from-schema-test.ts.snap b/__tests__/__snapshots__/from-schema-test.ts.snap index fca6c7f..a2aa096 100644 --- a/__tests__/__snapshots__/from-schema-test.ts.snap +++ b/__tests__/__snapshots__/from-schema-test.ts.snap @@ -11241,7 +11241,7 @@ humanOrDroid: HumanOrDroid | null; getCharacters: Array; /** - * @deprecated Field No Longer Available. + * @deprecated \\"Field No Longer Available.\\" */ anOldField: string | null; } @@ -11280,7 +11280,7 @@ friends: Array | null; appearsIn: Array | null; /** - * @deprecated Field No Longer Available. + * @deprecated \\"Field No Longer Available.\\" */ anOldField: string | null; nonNullArr: Array; @@ -11303,7 +11303,7 @@ appearsIn: Array | null; homePlanet: string | null; /** - * @deprecated Field No Longer Available. + * @deprecated \\"Field No Longer Available.\\" */ anOldField: string | null; nonNullArr: Array; @@ -11321,7 +11321,7 @@ primaryFunction: string | null; primaryFunctionNonNull: string; /** - * @deprecated Field No Longer Available. + * @deprecated \\"Field No Longer Available.\\" */ anOldField: string | null; nonNullArr: Array; diff --git a/packages/language-typescript/src/__tests__/__snapshots__/index-test.ts.snap b/packages/language-typescript/src/__tests__/__snapshots__/index-test.ts.snap index 257997c..5a0cba7 100644 --- a/packages/language-typescript/src/__tests__/__snapshots__/index-test.ts.snap +++ b/packages/language-typescript/src/__tests__/__snapshots__/index-test.ts.snap @@ -4,8 +4,16 @@ 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\\"} */" `; @@ -13,7 +21,7 @@ exports[`language-typescript DEFAULT_DOCUMENTATION_GENERATOR with a description " /** * This is a thing -* @default myDefaultValue + * @default \\"myDefaultValue\\" */" `; @@ -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\\" */" `; @@ -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', diff --git a/packages/language-typescript/src/__tests__/index-test.ts b/packages/language-typescript/src/__tests__/index-test.ts index 145fee9..f61e269 100644 --- a/packages/language-typescript/src/__tests__/index-test.ts +++ b/packages/language-typescript/src/__tests__/index-test.ts @@ -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', @@ -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: [ diff --git a/packages/language-typescript/src/index.ts b/packages/language-typescript/src/index.ts index 8bc9db5..7fcafe8 100644 --- a/packages/language-typescript/src/index.ts +++ b/packages/language-typescript/src/index.ts @@ -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 = [ + 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, diff --git a/packages/util/src/parser.ts b/packages/util/src/parser.ts index 231daa5..0e6313c 100644 --- a/packages/util/src/parser.ts +++ b/packages/util/src/parser.ts @@ -7,7 +7,7 @@ import { export interface IJSDocTag { tag: string; - value: string; + value: string | object; } export interface IFieldDocumentation {