Skip to content

Commit

Permalink
fix(jsii): Defaulted parameters were not rendered as optional
Browse files Browse the repository at this point in the history
Parameters with a default value were not represented as optional in the assembly
documents due to an oversight when re-writing `jsii`. There was also no coverage
in the test corpus for this use-case, so I've added some.

Fixes #233
  • Loading branch information
RomainMuller committed Sep 17, 2018
1 parent b664805 commit 29ed0b1
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 121 deletions.
6 changes: 5 additions & 1 deletion packages/jsii-calc/lib/compliance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ export class RuntimeTypeChecking {
public methodWithOptionalArguments(arg1: number, arg2: string, arg3?: Date) {
arg1; arg2; arg3;
}

public methodWithDefaultedArguments(arg1: number = 2, arg2: string, arg3: Date = new Date()) {
arg1; arg2; arg3;
}
}

export namespace DerivedClassHasNoProperties {
Expand Down Expand Up @@ -865,4 +869,4 @@ export class AbstractClassReturner {
abstractProperty: 'hello-abstract-property'
}
}
}
}
29 changes: 27 additions & 2 deletions packages/jsii-calc/test/assembly.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
"license": "Apache-2.0",
"name": "jsii-calc",
"readme": {
"markdown": "# jsii Calculator\n\nThis library is used to demonstrate and test the features of JSII\n\n## Sphinx\n\nThis file will be incorporated into the sphinx documentation.\n\nIf this file starts with an \"H1\" line (in our case `# jsii Calculator`), this\nheading will be used as the Sphinx topic name. Otherwise, the name of the module\n(`jsii-calc`) will be used instead.\n\n\n\n\n"
"markdown": "## JSII Calculator\n\nThis library is used to demonstrate and test the features of JSII\n"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -2270,6 +2270,31 @@
},
"kind": "class",
"methods": [
{
"name": "methodWithDefaultedArguments",
"parameters": [
{
"name": "arg1",
"type": {
"optional": true,
"primitive": "number"
}
},
{
"name": "arg2",
"type": {
"primitive": "string"
}
},
{
"name": "arg3",
"type": {
"optional": true,
"primitive": "date"
}
}
]
},
{
"docs": {
"comment": "Used to verify verification of number of method arguments."
Expand Down Expand Up @@ -3070,5 +3095,5 @@
}
},
"version": "0.7.5",
"fingerprint": "XrmsNUcNdYiHEC6BRVT5XoeVmYQZzjYgiu6MyibgOwk="
"fingerprint": "WmbZAXfb68uGbtlkMmOidSrR0I7wqQ244qpVqnrtNSY="
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
@scope/jsii-calc-base
=====================

Reference
---------

.. tabs::

.. group-tab:: C#
Expand Down Expand Up @@ -121,6 +118,9 @@ Reference
Reference
---------

.. py:module:: @scope/jsii-calc-base
Base
Expand Down Expand Up @@ -188,7 +188,7 @@ BaseProps (interface)



:extends: :py:class:`@scope/jsii-calc-base-of-base.VeryBaseProps`\
:extends: :py:class:`@scope/jsii-calc-base-of-base.VeryBaseProps`


.. py:attribute:: bar
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
@scope/jsii-calc-lib
====================

Reference
---------

.. tabs::

.. group-tab:: C#
Expand Down Expand Up @@ -121,6 +118,9 @@ Reference
Reference
---------

.. py:module:: @scope/jsii-calc-lib
EnumFromScopedModule (enum)
Expand Down Expand Up @@ -282,7 +282,7 @@ Number
Represents a concrete number.


:extends: :py:class:`~@scope/jsii-calc-lib.Value`\
:extends: :py:class:`~@scope/jsii-calc-lib.Value`
:param value: The number.
:type value: number

Expand Down Expand Up @@ -332,7 +332,7 @@ Operation
Represents an operation on values.


:extends: :py:class:`~@scope/jsii-calc-lib.Value`\
:extends: :py:class:`~@scope/jsii-calc-lib.Value`
:abstract: Yes

.. py:method:: toString() -> string
Expand Down Expand Up @@ -424,7 +424,7 @@ Value
Abstract class which represents a numeric value.


:extends: :py:class:`@scope/jsii-calc-base.Base`\
:extends: :py:class:`@scope/jsii-calc-base.Base`
:abstract: Yes

.. py:method:: toString() -> string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
"license": "Apache-2.0",
"name": "jsii-calc",
"readme": {
"markdown": "# jsii Calculator\n\nThis library is used to demonstrate and test the features of JSII\n\n## Sphinx\n\nThis file will be incorporated into the sphinx documentation.\n\nIf this file starts with an \"H1\" line (in our case `# jsii Calculator`), this\nheading will be used as the Sphinx topic name. Otherwise, the name of the module\n(`jsii-calc`) will be used instead.\n\n\n\n\n"
"markdown": "## JSII Calculator\n\nThis library is used to demonstrate and test the features of JSII\n"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -2270,6 +2270,31 @@
},
"kind": "class",
"methods": [
{
"name": "methodWithDefaultedArguments",
"parameters": [
{
"name": "arg1",
"type": {
"optional": true,
"primitive": "number"
}
},
{
"name": "arg2",
"type": {
"primitive": "string"
}
},
{
"name": "arg3",
"type": {
"optional": true,
"primitive": "date"
}
}
]
},
{
"docs": {
"comment": "Used to verify verification of number of method arguments."
Expand Down Expand Up @@ -3070,5 +3095,5 @@
}
},
"version": "0.7.5",
"fingerprint": "XrmsNUcNdYiHEC6BRVT5XoeVmYQZzjYgiu6MyibgOwk="
"fingerprint": "WmbZAXfb68uGbtlkMmOidSrR0I7wqQ244qpVqnrtNSY="
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ protected RuntimeTypeChecking(DeputyProps props): base(props)
{
}

[JsiiMethod("methodWithDefaultedArguments", null, "[{\"name\":\"arg1\",\"type\":{\"primitive\":\"number\",\"optional\":true}},{\"name\":\"arg2\",\"type\":{\"primitive\":\"string\"}},{\"name\":\"arg3\",\"type\":{\"primitive\":\"date\",\"optional\":true}}]")]
public virtual void MethodWithDefaultedArguments(double? arg1, string arg2, DateTime? arg3)
{
InvokeInstanceVoidMethod(new object[]{arg1, arg2, arg3});
}

/// <summary>Used to verify verification of number of method arguments.</summary>
[JsiiMethod("methodWithOptionalArguments", null, "[{\"name\":\"arg1\",\"type\":{\"primitive\":\"number\"}},{\"name\":\"arg2\",\"type\":{\"primitive\":\"string\"}},{\"name\":\"arg3\",\"type\":{\"primitive\":\"date\",\"optional\":true}}]")]
public virtual void MethodWithOptionalArguments(double arg1, string arg2, DateTime? arg3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ public RuntimeTypeChecking() {
software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this);
}

public void methodWithDefaultedArguments(@javax.annotation.Nullable final java.lang.Number arg1, final java.lang.String arg2, @javax.annotation.Nullable final java.time.Instant arg3) {
this.jsiiCall("methodWithDefaultedArguments", Void.class, java.util.stream.Stream.concat(java.util.stream.Stream.concat(java.util.stream.Stream.of(arg1), java.util.stream.Stream.of(java.util.Objects.requireNonNull(arg2, "arg2 is required"))), java.util.stream.Stream.of(arg3)).toArray());
}

public void methodWithDefaultedArguments(@javax.annotation.Nullable final java.lang.Number arg1, final java.lang.String arg2) {
this.jsiiCall("methodWithDefaultedArguments", Void.class, java.util.stream.Stream.concat(java.util.stream.Stream.of(arg1), java.util.stream.Stream.of(java.util.Objects.requireNonNull(arg2, "arg2 is required"))).toArray());
}

/**
* Used to verify verification of number of method arguments.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
## JSII Calculator

This library is used to demonstrate and test the features of JSII

## Sphinx

This file will be incorporated into the sphinx documentation.

If this file starts with an "H1" line (in our case `# jsii Calculator`), this
heading will be used as the Sphinx topic name. Otherwise, the name of the module
(`jsii-calc`) will be used instead.





Loading

0 comments on commit 29ed0b1

Please sign in to comment.