Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: variadic arguments are incorrectly displayed as base type in docs #1556

Merged
merged 46 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
a50bd46
initial WIP - set up tests, add variadic assembly and helper func to …
sumupitchayan Sep 3, 2024
f3cd642
Add variadic field to Parameter schema, parameter constructor, and ma…
sumupitchayan Sep 3, 2024
f9b3f4b
update snapshots with variadic flag
sumupitchayan Sep 3, 2024
9596cc1
add instance-method test and create snapshots for it
sumupitchayan Sep 4, 2024
e7a77da
Update test/docgen/assemblies.ts
sumupitchayan Sep 4, 2024
3a52b97
Update test/docgen/view/initializer.test.ts
sumupitchayan Sep 4, 2024
f72f1ee
fix build, rename new assembly withVariadicParameter
sumupitchayan Sep 4, 2024
ec5f62f
eli comment - fixup findVariadicInitializer method
sumupitchayan Sep 4, 2024
9acb0cb
eli comment: delete unnecessary initializer test
sumupitchayan Sep 4, 2024
4b90a7a
remove unnecessary assertion in initializer snapshot test
sumupitchayan Sep 4, 2024
524b0a3
add static method to variadic assembly fixture
sumupitchayan Sep 4, 2024
dcf6e58
refactor: move all tests to parameter.test.ts
sumupitchayan Sep 4, 2024
da2b384
delete old initializer test and snapshots
sumupitchayan Sep 4, 2024
59a2916
reset snapshots to what they were before - remove 'variadic' keyword …
sumupitchayan Sep 4, 2024
dec0968
undo changes to markdown-render.ts
sumupitchayan Sep 4, 2024
0c63eb8
add condtitional variadic syntax to formatParameter function of each …
sumupitchayan Sep 4, 2024
9a6a601
update snapshots
sumupitchayan Sep 4, 2024
f31420b
Merge branch 'main' into sumughan/fix-variadic-arg-docs
sumupitchayan Sep 4, 2024
14c80d0
remove unused function from markdown-render.ts
sumupitchayan Sep 4, 2024
9ef80a7
Merge branch 'sumughan/fix-variadic-arg-docs' of https://github.com/c…
sumupitchayan Sep 4, 2024
a7dd9af
add variadicOf function to Transpile interface, implement across all …
sumupitchayan Sep 5, 2024
2fa702d
update snapshots
sumupitchayan Sep 5, 2024
6f00baf
Update test/docgen/view/parameter.test.ts
sumupitchayan Sep 5, 2024
88dcb9d
chore: self mutation
invalid-email-address Sep 5, 2024
f19f604
Merge branch 'main' into sumughan/fix-variadic-arg-docs
sumupitchayan Sep 5, 2024
24291ad
Update src/docgen/view/parameter.ts
sumupitchayan Sep 5, 2024
75586cf
rename my-construct-library test assembly to variadic-jsii-example
sumupitchayan Sep 5, 2024
8773a8b
refactor: separate TranspiledProperty and TranspiledParameter interfa…
sumupitchayan Sep 6, 2024
4e588eb
Merge branch 'main' into sumughan/fix-variadic-arg-docs
iliapolo Sep 8, 2024
2cf398d
Update test/docgen/view/parameter.test.ts
sumupitchayan Sep 9, 2024
97abe9e
Update test/docgen/view/parameter.test.ts
sumupitchayan Sep 9, 2024
38adbb1
Update test/docgen/view/parameter.test.ts
sumupitchayan Sep 9, 2024
5ceef1e
Update src/docgen/transpile/typescript.ts
sumupitchayan Sep 9, 2024
68cf1d2
Update src/docgen/transpile/csharp.ts
sumupitchayan Sep 9, 2024
7de541e
chore: self mutation
invalid-email-address Sep 9, 2024
ec84de4
chore: self mutation
invalid-email-address Sep 9, 2024
5a48fb9
Update src/docgen/view/parameter.ts
sumupitchayan Sep 9, 2024
b405b13
eli comment: call this.property instead of this.paramete inside struc…
sumupitchayan Sep 9, 2024
589ac12
Merge branch 'sumughan/fix-variadic-arg-docs' of https://github.com/c…
sumupitchayan Sep 9, 2024
26d69a9
Eli comment: add comment explaining typeschema/formatting pattern in …
sumupitchayan Sep 9, 2024
777af88
update formatting pattern inside variadic type schema
sumupitchayan Sep 9, 2024
6b977d3
update link snapshots
sumupitchayan Sep 9, 2024
685e4dc
Merge branch 'main' into sumughan/fix-variadic-arg-docs
sumupitchayan Sep 9, 2024
5430e96
Update src/docgen/transpile/csharp.ts
iliapolo Sep 10, 2024
e081cf9
Merge branch 'main' into sumughan/fix-variadic-arg-docs
iliapolo Sep 10, 2024
7eca5b8
Update src/docgen/transpile/csharp.ts
iliapolo Sep 10, 2024
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
4 changes: 4 additions & 0 deletions src/docgen/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ export interface ParameterSchema extends Optional, Documentable {
*/
readonly type: TypeSchema;

/**
* Whether the parameter is variadic.
*/
readonly variadic: boolean;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/docgen/transpile/csharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export class CSharpTranspile extends transpile.TranspileBase {
parentType: this.type(parameter.parentType),
typeReference: typeRef,
optional: parameter.optional,
variadic: parameter.variadic,
declaration: this.formatParameter(name, typeRef),
};
}
Expand All @@ -144,6 +145,7 @@ export class CSharpTranspile extends transpile.TranspileBase {
parentType: this.type(property.parentType),
typeReference: typeRef,
optional: property.optional,
variadic: false,
declaration: this.formatProperty(name, typeRef, property),
};
}
Expand Down Expand Up @@ -217,6 +219,10 @@ export class CSharpTranspile extends transpile.TranspileBase {
typeFormatter: (t) => t.name,
});
const suffix = transpiled.optional ? ' = null' : '';

if (transpiled.variadic) {
return `params ${tf}[] ${transpiled.name}${suffix}`;
}
return `${tf} ${transpiled.name}${suffix}`;
}

Expand Down
13 changes: 10 additions & 3 deletions src/docgen/transpile/go.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ export class GoTranspile extends transpile.TranspileBase {
parentType: this.type(parameter.parentType),
typeReference: typeRef,
optional: parameter.optional,
declaration: this.formatParameter(name, typeRef),
variadic: parameter.variadic,
declaration: this.formatParameter(name, typeRef, parameter.variadic),
};
}

Expand All @@ -154,6 +155,8 @@ export class GoTranspile extends transpile.TranspileBase {
parentType: this.type(property.parentType),
typeReference: typeRef,
optional: property.optional,
// Only parameters can be variadic, not properties.
variadic: false,
declaration: this.formatProperty(name, typeRef, property),
};
}
Expand Down Expand Up @@ -219,18 +222,22 @@ export class GoTranspile extends transpile.TranspileBase {
private formatFnParam(
transpiled: transpile.TranspiledParameter | transpile.TranspiledProperty,
): string {
return this.formatParameter(transpiled.name, transpiled.typeReference);
return this.formatParameter(transpiled.name, transpiled.typeReference, transpiled.variadic);
}

private formatImport(type: transpile.TranspiledType): string {
return `import "${type.module}${type.submodule ? `/${type.submodule}` : ''}"`;
}

private formatParameter(name: string, typeReference: transpile.TranspiledTypeReference) {
private formatParameter(name: string, typeReference: transpile.TranspiledTypeReference, variadic: boolean) {
const tf = typeReference.toString({
typeFormatter: (t) => t.name,
});

if (variadic) {
return `${name} ...${tf}`;
}

return `${name} ${tf}`;
}

Expand Down
7 changes: 7 additions & 0 deletions src/docgen/transpile/java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ export class JavaTranspile extends transpile.TranspileBase {
parentType: this.type(parameter.parentType),
typeReference: typeRef,
optional: parameter.optional,
variadic: parameter.variadic,
declaration: this.formatProperty(parameter.name, typeRef),
};
}
Expand All @@ -224,6 +225,7 @@ export class JavaTranspile extends transpile.TranspileBase {
parentType: this.type(property.parentType),
typeReference: typeRef,
optional: property.optional,
variadic: false,
declaration: this.formatProperty(property.name, typeRef),
};
}
Expand Down Expand Up @@ -296,6 +298,11 @@ export class JavaTranspile extends transpile.TranspileBase {
const tf = transpiled.typeReference.toString({
typeFormatter: (t) => t.name,
});

if (transpiled.variadic) {
return `${tf} ${transpiled.name}...`;
}

return `${tf} ${transpiled.name}`;
}

Expand Down
7 changes: 7 additions & 0 deletions src/docgen/transpile/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export class PythonTranspile extends transpile.TranspileBase {
parentType: this.type(property.parentType),
typeReference: typeRef,
optional: property.optional,
variadic: false,
sumupitchayan marked this conversation as resolved.
Show resolved Hide resolved
declaration: this.formatProperty(name, typeRef),
};
}
Expand All @@ -171,6 +172,7 @@ export class PythonTranspile extends transpile.TranspileBase {
parentType: this.type(parameter.parentType),
typeReference: typeRef,
optional: parameter.optional,
variadic: parameter.variadic,
declaration: this.formatProperty(name, typeRef),
};
}
Expand Down Expand Up @@ -306,6 +308,11 @@ export class PythonTranspile extends transpile.TranspileBase {
const tf = transpiled.typeReference.toString({
typeFormatter: (t) => t.name,
});

if (transpiled.variadic) {
return `${transpiled.name}: *${tf}${transpiled.optional ? ' = None' : ''}`;
sumupitchayan marked this conversation as resolved.
Show resolved Hide resolved
}

return `${transpiled.name}: ${tf}${transpiled.optional ? ' = None' : ''}`;
}

Expand Down
4 changes: 4 additions & 0 deletions src/docgen/transpile/transpile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ export interface TranspiledParameter {
* Whether or not the parameter is optional.
*/
readonly optional: boolean;
/**
* Whether or not the parameter is variadic.
*/
readonly variadic: boolean;
/**
* The signature of the property, or its getter if the language
* supports that.
Expand Down
7 changes: 7 additions & 0 deletions src/docgen/transpile/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export class TypeScriptTranspile extends transpile.TranspileBase {
parentType: this.type(property.parentType),
typeReference: typeRef,
optional: property.optional,
variadic: false,
declaration: this.formatProperty(property.name, typeRef),
};
}
Expand All @@ -143,6 +144,7 @@ export class TypeScriptTranspile extends transpile.TranspileBase {
parentType: this.type(parameter.parentType),
typeReference: typeRef,
optional: parameter.optional,
variadic: parameter.variadic,
declaration: this.formatProperty(parameter.name, typeRef),
};
}
Expand Down Expand Up @@ -236,6 +238,11 @@ export class TypeScriptTranspile extends transpile.TranspileBase {
const tf = transpiled.typeReference.toString({
typeFormatter: (t) => t.name,
});

if (transpiled.variadic) {
return `${transpiled.name}${transpiled.optional ? '?' : ''}: ...${tf}[]`;
sumupitchayan marked this conversation as resolved.
Show resolved Hide resolved
}

return `${transpiled.name}${transpiled.optional ? '?' : ''}: ${tf}`;
}

Expand Down
1 change: 1 addition & 0 deletions src/docgen/view/parameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class Parameter {
optional: this.transpiledParam.optional === true ? true : undefined, // to save space
default: this.parameter.spec.docs?.default,
type: this.transpiledParam.typeReference.toJson(),
variadic: this.parameter.spec.variadic ?? false,
sumupitchayan marked this conversation as resolved.
Show resolved Hide resolved
docs: extractDocs(this.parameter.docs),
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
{
"author": {
"email": "john.doe@acme.com",
"name": "John Doe",
"roles": [
"author"
]
},
"dependencies": {
"constructs": "^10.3.0"
},
"dependencyClosure": {
"constructs": {
"targets": {
"dotnet": {
"namespace": "Constructs",
"packageId": "Constructs"
},
"go": {
"moduleName": "github.com/aws/constructs-go"
},
"java": {
"maven": {
"artifactId": "constructs",
"groupId": "software.constructs"
},
"package": "software.constructs"
},
"js": {
"npm": "constructs"
},
"python": {
"distName": "constructs",
"module": "constructs"
}
}
}
},
"description": "",
"docs": {
"stability": "stable"
},
"homepage": "https://github.com/acme/project-name.git",
"jsiiVersion": "5.5.1",
"keywords": [],
"license": "ISC",
"metadata": {
"jsii": {
"pacmak": {
"hasDefaultInterfaces": true
}
},
"tscRootDir": "src"
},
"name": "my-construct-library",
"readme": {
"markdown": ""
},
"repository": {
"type": "git",
"url": "https://github.com/acme/project-name.git"
},
"schema": "jsii/0.10.0",
"targets": {
"js": {
"npm": "my-construct-library"
},
"python": {
"distName": "sumu_constructs.core",
"module": "sumu_constructs.core"
},
"go": {
"moduleName": "github.com/acme/project-name"
}
},
"types": {
"my-construct-library.MyVariadicClass": {
"assembly": "my-construct-library",
"docs": {
"stability": "stable"
},
"fqn": "my-construct-library.MyVariadicClass",
"initializer": {
"docs": {
"stability": "stable"
},
"locationInModule": {
"filename": "src/index.ts",
"line": 22
},
"parameters": [
{
"name": "id",
"type": {
"primitive": "number"
}
},
{
"name": "variadicProps",
"type": {
"primitive": "number"
},
"variadic": true
}
],
"variadic": true
},
"kind": "class",
"locationInModule": {
"filename": "src/index.ts",
"line": 19
},
"methods": [
{
"docs": {
"stability": "stable"
},
"locationInModule": {
"filename": "src/index.ts",
"line": 27
},
"name": "myFunction",
"parameters": [
{
"name": "singleInput",
"type": {
"primitive": "number"
}
},
{
"name": "variadicInput",
"type": {
"primitive": "number"
},
"variadic": true
}
],
"variadic": true
},
{
"docs": {
"stability": "stable"
},
"locationInModule": {
"filename": "src/index.ts",
"line": 27
},
"name": "myStaticFunction",
"parameters": [
{
"name": "staticSingleInput",
"type": {
"primitive": "number"
}
},
{
"name": "staticVariadicInput",
"type": {
"primitive": "number"
},
"variadic": true
}
],
"variadic": true,
"static": true
}
],
"name": "MyVariadicClass",
"properties": [
{
"docs": {
"stability": "stable"
},
"locationInModule": {
"filename": "src/index.ts",
"line": 20
},
"name": "id",
"type": {
"primitive": "number"
}
},
{
"docs": {
"stability": "stable"
},
"locationInModule": {
"filename": "src/index.ts",
"line": 21
},
"name": "props",
"type": {
"collection": {
"elementtype": {
"primitive": "number"
},
"kind": "array"
}
}
}
],
"symbolId": "src/index:MyVariadicClass"
}
},
"version": "1.0.0",
"fingerprint": "MVY8gZ0InYVnyxT4u6+25G013Gn2Cz+1MCYVqOonyPs="
}
Loading
Loading