diff --git a/scripts/apidoc/signature.ts b/scripts/apidoc/signature.ts index 109cd55d0ff..c41b758ce31 100644 --- a/scripts/apidoc/signature.ts +++ b/scripts/apidoc/signature.ts @@ -304,7 +304,17 @@ function typeToText(type_?: Type, short = false): string { case 'reference': if (!type.typeArguments || !type.typeArguments.length) { - return type.name; + const reflection = type.reflection as DeclarationReflection | undefined; + const reflectionType = reflection?.type; + if ( + (reflectionType?.type === 'literal' || + reflectionType?.type === 'union') && + !type.name.match(/Char$/) + ) { + return typeToText(reflectionType, short); + } else { + return type.name; + } } else if (type.name === 'LiteralUnion') { return [ typeToText(type.typeArguments[0], short), diff --git a/test/scripts/apidoc/__snapshots__/signature.spec.ts.snap b/test/scripts/apidoc/__snapshots__/signature.spec.ts.snap index 533d13daec0..f93bcd497e9 100644 --- a/test/scripts/apidoc/__snapshots__/signature.spec.ts.snap +++ b/test/scripts/apidoc/__snapshots__/signature.spec.ts.snap @@ -44,7 +44,7 @@ exports[`signature > analyzeSignature() > complexArrayParameter 1`] = ` "returns": "T", "seeAlsos": [], "since": "", - "sourcePath": "test/scripts/apidoc/signature.example.ts#L330", + "sourcePath": "test/scripts/apidoc/signature.example.ts#L343", "title": "Complex Array Parameter", } `; @@ -70,7 +70,7 @@ exports[`signature > analyzeSignature() > defaultBooleanParamMethod 1`] = ` "returns": "number", "seeAlsos": [], "since": "", - "sourcePath": "test/scripts/apidoc/signature.example.ts#L99", + "sourcePath": "test/scripts/apidoc/signature.example.ts#L101", "title": "Default Boolean Param Method", } `; @@ -120,7 +120,7 @@ exports[`signature > analyzeSignature() > functionParamMethod 1`] = ` "returns": "number", "seeAlsos": [], "since": "", - "sourcePath": "test/scripts/apidoc/signature.example.ts#L119", + "sourcePath": "test/scripts/apidoc/signature.example.ts#L121", "title": "Function Param Method", } `; @@ -130,7 +130,7 @@ exports[`signature > analyzeSignature() > literalUnionParamMethod 1`] = ` "deprecated": undefined, "description": "

Test with LiteralUnion.

", - "examples": "
ts
faker.literalUnionParamMethod(value: 'a' | 'b' | string, namedValue: AB | string, array: readonly Array<'a' | 'b' | string>, namedArray: readonly Array<AB | string>, mixed: 'a' | 'b' | string | readonly Array<'a' | 'b' | string>, namedMixed: AB | string | readonly Array<AB | string>): string
+  "examples": "
ts
faker.literalUnionParamMethod(value: 'a' | 'b' | string, namedValue: 'a' | 'b' | string, array: readonly Array<'a' | 'b' | string>, namedArray: readonly Array<'a' | 'b' | string>, mixed: 'a' | 'b' | string | readonly Array<'a' | 'b' | string>, namedMixed: 'a' | 'b' | string | readonly Array<'a' | 'b' | string>): string
 
", "name": "literalUnionParamMethod", @@ -147,7 +147,7 @@ exports[`signature > analyzeSignature() > literalUnionParamMethod 1`] = ` "description": "

'a' or 'b'.

", "name": "namedValue", - "type": "AB | string", + "type": "'a' | 'b' | string", }, { "default": undefined, @@ -161,7 +161,7 @@ exports[`signature > analyzeSignature() > literalUnionParamMethod 1`] = ` "description": "

Array of 'a' or 'b'.

", "name": "namedArray", - "type": "Array", + "type": "Array<'a' | 'b' | string>", }, { "default": undefined, @@ -175,13 +175,13 @@ exports[`signature > analyzeSignature() > literalUnionParamMethod 1`] = ` "description": "

Value 'a' or 'b' or an array thereof.

", "name": "namedMixed", - "type": "AB | string | Array", + "type": "'a' | 'b' | string | Array<'a' | 'b' | string>", }, ], "returns": "string", "seeAlsos": [], "since": "", - "sourcePath": "test/scripts/apidoc/signature.example.ts#L142", + "sourcePath": "test/scripts/apidoc/signature.example.ts#L155", "title": "Literal Union Param Method", } `; @@ -202,7 +202,7 @@ exports[`signature > analyzeSignature() > methodWithDeprecated 1`] = ` "test.apidoc.methodWithExample()", ], "since": "", - "sourcePath": "test/scripts/apidoc/signature.example.ts#L260", + "sourcePath": "test/scripts/apidoc/signature.example.ts#L273", "title": "Method With Deprecated", } `; @@ -255,7 +255,7 @@ exports[`signature > analyzeSignature() > methodWithDeprecatedOption 1`] = ` "returns": "number", "seeAlsos": [], "since": "", - "sourcePath": "test/scripts/apidoc/signature.example.ts#L272", + "sourcePath": "test/scripts/apidoc/signature.example.ts#L285", "title": "Method With Deprecated Option", } `; @@ -274,7 +274,7 @@ exports[`signature > analyzeSignature() > methodWithExample 1`] = ` "returns": "number", "seeAlsos": [], "since": "", - "sourcePath": "test/scripts/apidoc/signature.example.ts#L249", + "sourcePath": "test/scripts/apidoc/signature.example.ts#L262", "title": "Method With Example", } `; @@ -295,7 +295,7 @@ exports[`signature > analyzeSignature() > methodWithMultipleSeeMarkers 1`] = ` "test.apidoc.methodWithDeprecated()", ], "since": "", - "sourcePath": "test/scripts/apidoc/signature.example.ts#L299", + "sourcePath": "test/scripts/apidoc/signature.example.ts#L312", "title": "Method With Multiple See Markers", } `; @@ -316,7 +316,7 @@ exports[`signature > analyzeSignature() > methodWithMultipleSeeMarkersAndBacktic "test.apidoc.methodWithDeprecated() with parameter bar and baz.", ], "since": "", - "sourcePath": "test/scripts/apidoc/signature.example.ts#L309", + "sourcePath": "test/scripts/apidoc/signature.example.ts#L322", "title": "Method With Multiple See Markers And Backticks", } `; @@ -334,7 +334,7 @@ exports[`signature > analyzeSignature() > methodWithSinceMarker 1`] = ` "returns": "number", "seeAlsos": [], "since": "1.0.0", - "sourcePath": "test/scripts/apidoc/signature.example.ts#L318", + "sourcePath": "test/scripts/apidoc/signature.example.ts#L331", "title": "Method With Since Marker", } `; @@ -374,7 +374,7 @@ exports[`signature > analyzeSignature() > multiParamMethod 1`] = ` "returns": "number", "seeAlsos": [], "since": "", - "sourcePath": "test/scripts/apidoc/signature.example.ts#L110", + "sourcePath": "test/scripts/apidoc/signature.example.ts#L112", "title": "Multi Param Method", } `; @@ -392,7 +392,7 @@ exports[`signature > analyzeSignature() > noParamMethod 1`] = ` "returns": "number", "seeAlsos": [], "since": "", - "sourcePath": "test/scripts/apidoc/signature.example.ts#L72", + "sourcePath": "test/scripts/apidoc/signature.example.ts#L74", "title": "No Param Method", } `; @@ -418,7 +418,7 @@ exports[`signature > analyzeSignature() > optionalStringParamMethod 1`] = ` "returns": "number", "seeAlsos": [], "since": "", - "sourcePath": "test/scripts/apidoc/signature.example.ts#L90", + "sourcePath": "test/scripts/apidoc/signature.example.ts#L92", "title": "Optional String Param Method", } `; @@ -487,7 +487,7 @@ It also has a more complex description.

"returns": "number", "seeAlsos": [], "since": "", - "sourcePath": "test/scripts/apidoc/signature.example.ts#L199", + "sourcePath": "test/scripts/apidoc/signature.example.ts#L212", "title": "Options Inline Param Method With Defaults", } `; @@ -527,7 +527,7 @@ exports[`signature > analyzeSignature() > optionsInterfaceParamMethodWithDefault "returns": "number", "seeAlsos": [], "since": "", - "sourcePath": "test/scripts/apidoc/signature.example.ts#L235", + "sourcePath": "test/scripts/apidoc/signature.example.ts#L248", "title": "Options Interface Param Method With Defaults", } `; @@ -594,7 +594,7 @@ exports[`signature > analyzeSignature() > optionsParamMethod 1`] = ` "returns": "number", "seeAlsos": [], "since": "", - "sourcePath": "test/scripts/apidoc/signature.example.ts#L169", + "sourcePath": "test/scripts/apidoc/signature.example.ts#L182", "title": "Options Param Method", } `; @@ -634,7 +634,7 @@ exports[`signature > analyzeSignature() > optionsTypeParamMethodWithDefaults 1`] "returns": "number", "seeAlsos": [], "since": "", - "sourcePath": "test/scripts/apidoc/signature.example.ts#L217", + "sourcePath": "test/scripts/apidoc/signature.example.ts#L230", "title": "Options Type Param Method With Defaults", } `; @@ -660,7 +660,7 @@ exports[`signature > analyzeSignature() > requiredNumberParamMethod 1`] = ` "returns": "number", "seeAlsos": [], "since": "", - "sourcePath": "test/scripts/apidoc/signature.example.ts#L81", + "sourcePath": "test/scripts/apidoc/signature.example.ts#L83", "title": "Required Number Param Method", } `; @@ -670,7 +670,11 @@ exports[`signature > analyzeSignature() > stringUnionParamMethod 1`] = ` "deprecated": undefined, "description": "

Test with string union.

", - "examples": "
ts
faker.stringUnionParamMethod(value: 'a' | 'b'): string
+  "examples": "
ts
faker.stringUnionParamMethod(value: 'a' | 'b', options?: {
+  casing: 'lower' | 'mixed' | 'upper',
+  excludes: readonly AlphaNumericChar[],
+  format: 'binary' | 'css' | 'decimal' | 'hex'
+}): string
 
", "name": "stringUnionParamMethod", @@ -682,11 +686,39 @@ exports[`signature > analyzeSignature() > stringUnionParamMethod 1`] = ` "name": "value", "type": "'a' | 'b'", }, + { + "default": undefined, + "description": "

The options parameter.

+", + "name": "options?", + "type": "{ ... }", + }, + { + "default": undefined, + "description": "

The casing parameter.

+", + "name": "options.casing?", + "type": "'lower' | 'mixed' | 'upper'", + }, + { + "default": undefined, + "description": "

The excludes parameter.

+", + "name": "options.excludes?", + "type": "readonly AlphaNumericChar[]", + }, + { + "default": undefined, + "description": "

The format parameter.

+", + "name": "options.format?", + "type": "'binary' | 'css' | 'decimal' | 'hex'", + }, ], "returns": "string", "seeAlsos": [], "since": "", - "sourcePath": "test/scripts/apidoc/signature.example.ts#L128", + "sourcePath": "test/scripts/apidoc/signature.example.ts#L134", "title": "String Union Param Method", } `; diff --git a/test/scripts/apidoc/signature.example.ts b/test/scripts/apidoc/signature.example.ts index 1013365f4eb..87bc331e07a 100644 --- a/test/scripts/apidoc/signature.example.ts +++ b/test/scripts/apidoc/signature.example.ts @@ -1,3 +1,5 @@ +import type { Casing, ColorFormat } from '../../../src'; +import type { AlphaNumericChar } from '../../../src/modules/string'; import type { LiteralUnion } from '../../../src/utils/types'; /** @@ -124,9 +126,20 @@ export class SignatureTest { * Test with string union. * * @param value `'a'` or `'b'`. + * @param options The options parameter. + * @param options.casing The casing parameter. + * @param options.format The format parameter. + * @param options.excludes The excludes parameter. */ - stringUnionParamMethod(value: 'a' | 'b'): string { - return value; + stringUnionParamMethod( + value: 'a' | 'b', + options?: { + casing?: Casing; + format?: 'hex' | ColorFormat; + excludes?: ReadonlyArray; + } + ): string { + return value + options.format; } /**