aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2023-01-21 20:38:51 +0100
committerGitHub <[email protected]>2023-01-21 19:38:51 +0000
commitf839ae23270773b476ee39610a0b399e1432bac7 (patch)
tree79bfa17779fbd6e7abdefcfbf040bab1166f6583 /scripts
parent440325eb0f53d6fd1c13e2c955984accd8f76143 (diff)
downloadfaker-f839ae23270773b476ee39610a0b399e1432bac7.tar.xz
faker-f839ae23270773b476ee39610a0b399e1432bac7.zip
docs: unwrap complex array params (#1753)
Diffstat (limited to 'scripts')
-rw-r--r--scripts/apidoc/signature.ts50
1 files changed, 30 insertions, 20 deletions
diff --git a/scripts/apidoc/signature.ts b/scripts/apidoc/signature.ts
index 22eed268..f2a4bd85 100644
--- a/scripts/apidoc/signature.ts
+++ b/scripts/apidoc/signature.ts
@@ -233,27 +233,37 @@ function analyzeParameterOptions(
return [];
}
- if (parameterType.type === 'union') {
- return parameterType.types.flatMap((type) =>
- analyzeParameterOptions(name, type)
- );
- } else if (parameterType.type === 'reflection') {
- const properties = parameterType.declaration.children ?? [];
- return properties.map((property) => ({
- name: `${name}.${property.name}${isOptional(property) ? '?' : ''}`,
- type: declarationTypeToText(property),
- default: extractDefaultFromComment(property.comment),
- description: mdToHtml(
- toBlock(
- property.comment ??
- (property.type as ReflectionType)?.declaration?.signatures?.[0]
- .comment
- )
- ),
- }));
- }
+ switch (parameterType.type) {
+ case 'array':
+ return analyzeParameterOptions(`${name}[]`, parameterType.elementType);
+
+ case 'union':
+ return parameterType.types.flatMap((type) =>
+ analyzeParameterOptions(name, type)
+ );
+
+ case 'reflection': {
+ const properties = parameterType.declaration.children ?? [];
+ return properties.map((property) => ({
+ name: `${name}.${property.name}${isOptional(property) ? '?' : ''}`,
+ type: declarationTypeToText(property),
+ default: extractDefaultFromComment(property.comment),
+ description: mdToHtml(
+ toBlock(
+ property.comment ??
+ (property.type as ReflectionType)?.declaration?.signatures?.[0]
+ .comment
+ )
+ ),
+ }));
+ }
+
+ case 'typeOperator':
+ return analyzeParameterOptions(name, parameterType.target);
- return [];
+ default:
+ return [];
+ }
}
function isOptional(parameter: Reflection): boolean {