From 19cbd2532e6210f034e12299c5c1b00807a91b90 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Tue, 2 Mar 2021 18:35:04 +0200 Subject: [PATCH] fix(go): enums inside structs are not properly serialized (#2636) Serializes struct values according to the jsii protocol, wrapping the data in a `$jsii.struct` object recording both the struct's fully qualified type name, and key-value pairs. This includes recursively transforming field values, so the behavior is now correct. --- packages/@jsii/go-runtime/.gitignore | 2 +- packages/@jsii/go-runtime/build-tools/gen.ts | 9 +- .../go-runtime/jsii-calc-test/main_test.go | 32 +++ .../jsii-runtime-go/{ => internal}/api/api.go | 9 + .../jsii-runtime-go/{ => internal}/api/doc.go | 0 .../{ => internal}/embedded/embedded.go | 0 .../{ => internal}/embedded/embedded_test.go | 0 .../{ => internal}/kernel/begin.go | 2 +- .../{ => internal}/kernel/callbacks.go | 2 +- .../{ => internal}/kernel/client.go | 4 +- .../{ => internal}/kernel/client_test.go | 0 .../{ => internal}/kernel/complete.go | 0 .../{ => internal}/kernel/conversions.go | 4 +- .../{ => internal}/kernel/create.go | 2 +- .../{ => internal}/kernel/del.go | 2 +- .../{ => internal}/kernel/doc.go | 0 .../{ => internal}/kernel/end.go | 0 .../{ => internal}/kernel/get.go | 2 +- .../{ => internal}/kernel/invoke.go | 2 +- .../{ => internal}/kernel/json.go | 0 .../{ => internal}/kernel/load.go | 0 .../{ => internal}/kernel/naming.go | 0 .../kernel/process/consume-stderr.go | 0 .../kernel/process/handshake.go | 3 +- .../kernel/process/jsii-mock-runtime.js | 0 .../{ => internal}/kernel/process/process.go | 2 +- .../kernel/process/process_test.go | 0 .../kernel/request-response-markers.go | 0 .../{ => internal}/kernel/set.go | 2 +- .../{ => internal}/kernel/stats.go | 0 .../{ => internal}/typeregistry/doc.go | 0 .../typeregistry/registration.go | 8 +- .../typeregistry/type-registry.go | 20 +- .../go-runtime/jsii-runtime-go/runtime.go | 29 ++- packages/jsii-calc/lib/compliance.ts | 53 ++++ packages/jsii-calc/test/assembly.jsii | 152 +++++++++++- .../__snapshots__/target-dotnet.test.ts.snap | 160 +++++++++++++ .../__snapshots__/target-go.test.ts.snap | 91 +++++++ .../__snapshots__/target-java.test.ts.snap | 226 ++++++++++++++++++ .../__snapshots__/target-python.test.ts.snap | 104 ++++++++ .../test/__snapshots__/jsii-tree.test.ts.snap | 44 ++++ .../test/__snapshots__/tree.test.ts.snap | 31 +++ .../__snapshots__/type-system.test.ts.snap | 1 + 43 files changed, 970 insertions(+), 28 deletions(-) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/api/api.go (91%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/api/doc.go (100%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/embedded/embedded.go (100%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/embedded/embedded_test.go (100%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/kernel/begin.go (90%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/kernel/callbacks.go (84%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/kernel/client.go (97%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/kernel/client_test.go (100%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/kernel/complete.go (100%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/kernel/conversions.go (97%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/kernel/create.go (94%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/kernel/del.go (86%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/kernel/doc.go (100%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/kernel/end.go (100%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/kernel/get.go (95%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/kernel/invoke.go (95%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/kernel/json.go (100%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/kernel/load.go (100%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/kernel/naming.go (100%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/kernel/process/consume-stderr.go (100%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/kernel/process/handshake.go (99%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/kernel/process/jsii-mock-runtime.js (100%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/kernel/process/process.go (99%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/kernel/process/process_test.go (100%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/kernel/request-response-markers.go (100%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/kernel/set.go (95%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/kernel/stats.go (100%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/typeregistry/doc.go (100%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/typeregistry/registration.go (92%) rename packages/@jsii/go-runtime/jsii-runtime-go/{ => internal}/typeregistry/type-registry.go (86%) diff --git a/packages/@jsii/go-runtime/.gitignore b/packages/@jsii/go-runtime/.gitignore index 34b8d9e989..53892fcbc2 100644 --- a/packages/@jsii/go-runtime/.gitignore +++ b/packages/@jsii/go-runtime/.gitignore @@ -1,5 +1,5 @@ /jsii-calc/ -/jsii-runtime-go/embedded/resources/ +/jsii-runtime-go/internal/embedded/resources/ *.generated.* diff --git a/packages/@jsii/go-runtime/build-tools/gen.ts b/packages/@jsii/go-runtime/build-tools/gen.ts index 48b2b1a684..64e2be6acb 100644 --- a/packages/@jsii/go-runtime/build-tools/gen.ts +++ b/packages/@jsii/go-runtime/build-tools/gen.ts @@ -14,7 +14,12 @@ const EMBEDDED_RUNTIME_SOURCE_ROOT = resolve( const RUNTIME_ROOT = resolve(__dirname, '..', 'jsii-runtime-go'); -const EMBEDDED_RESOURCE_DIR = join(RUNTIME_ROOT, 'embedded', 'resources'); +const EMBEDDED_RESOURCE_DIR = join( + RUNTIME_ROOT, + 'internal', + 'embedded', + 'resources', +); mkdirpSync(EMBEDDED_RESOURCE_DIR); copySync(EMBEDDED_RUNTIME_SOURCE_ROOT, EMBEDDED_RESOURCE_DIR, { @@ -25,7 +30,7 @@ copySync(EMBEDDED_RUNTIME_SOURCE_ROOT, EMBEDDED_RESOURCE_DIR, { recursive: true, }); -const KERNEL_LIB_DIR = resolve(RUNTIME_ROOT, 'kernel'); +const KERNEL_LIB_DIR = resolve(RUNTIME_ROOT, 'internal', 'kernel'); const code = new CodeMaker({ indentationLevel: 1, indentCharacter: '\t' }); const VERSION_FILE = 'version.generated.go'; diff --git a/packages/@jsii/go-runtime/jsii-calc-test/main_test.go b/packages/@jsii/go-runtime/jsii-calc-test/main_test.go index 13320e9916..494b163518 100644 --- a/packages/@jsii/go-runtime/jsii-calc-test/main_test.go +++ b/packages/@jsii/go-runtime/jsii-calc-test/main_test.go @@ -195,6 +195,38 @@ func TestOptionalEnums(t *testing.T) { } } +func TestStructWithEnum(t *testing.T) { + obj := calc.NewTestStructWithEnum() + if !obj.IsStringEnumA(calc.StructWithEnum{Foo: calc.StringEnum_A}) { + t.Error("Failed") + } + + if !obj.IsStringEnumB(calc.StructWithEnum{ + Foo: calc.StringEnum_B, + Bar: calc.AllTypesEnum_THIS_IS_GREAT, + }) { + t.Error("Failed") + } + + ret1 := obj.StructWithFoo() + if ret1.Foo != calc.StringEnum_A { + t.Error("Expecting Foo to be A") + } + + if ret1.Bar != "" { + t.Error("Expecting Bar to be nil") + } + + ret2 := obj.StructWithFooBar() + if ret2.Foo != calc.StringEnum_C { + t.Error("Expecting Foo to be C") + } + + if ret2.Bar != calc.AllTypesEnum_MY_ENUM_VALUE { + t.Error("Expecting Foo to be MY_ENUM_VALUE") + } +} + func TestReturnsSpecialParam(t *testing.T) { retSpecialParam := returnsParam.NewReturnsSpecialParameter() val := retSpecialParam.ReturnsSpecialParam() diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/api/api.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/api/api.go similarity index 91% rename from packages/@jsii/go-runtime/jsii-runtime-go/api/api.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/api/api.go index 6d455fe15c..4292a51058 100644 --- a/packages/@jsii/go-runtime/jsii-runtime-go/api/api.go +++ b/packages/@jsii/go-runtime/jsii-runtime-go/internal/api/api.go @@ -65,6 +65,15 @@ type WireMap struct { MapData map[string]interface{} `json:"$jsii.map"` } +type WireStruct struct { + StructDescriptor `json:"$jsii.struct"` +} + +type StructDescriptor struct { + FQN FQN `json:"fqn"` + Fields map[string]interface{} `json:"data"` +} + type Callback struct { CallbackID *string `json:"cbid"` Cookie *string `json:"cookie"` diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/api/doc.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/api/doc.go similarity index 100% rename from packages/@jsii/go-runtime/jsii-runtime-go/api/doc.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/api/doc.go diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/embedded/embedded.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/embedded/embedded.go similarity index 100% rename from packages/@jsii/go-runtime/jsii-runtime-go/embedded/embedded.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/embedded/embedded.go diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/embedded/embedded_test.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/embedded/embedded_test.go similarity index 100% rename from packages/@jsii/go-runtime/jsii-runtime-go/embedded/embedded_test.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/embedded/embedded_test.go diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/begin.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/begin.go similarity index 90% rename from packages/@jsii/go-runtime/jsii-runtime-go/kernel/begin.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/begin.go index 89abfdf32a..8c5338d2d0 100644 --- a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/begin.go +++ b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/begin.go @@ -1,7 +1,7 @@ package kernel import ( - "github.com/aws/jsii-runtime-go/api" + "github.com/aws/jsii-runtime-go/internal/api" ) type BeginProps struct { diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/callbacks.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/callbacks.go similarity index 84% rename from packages/@jsii/go-runtime/jsii-runtime-go/kernel/callbacks.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/callbacks.go index e77e3bbc7b..d1b8112f26 100644 --- a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/callbacks.go +++ b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/callbacks.go @@ -1,7 +1,7 @@ package kernel import ( - "github.com/aws/jsii-runtime-go/api" + "github.com/aws/jsii-runtime-go/internal/api" ) type CallbacksResponse struct { diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/client.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/client.go similarity index 97% rename from packages/@jsii/go-runtime/jsii-runtime-go/kernel/client.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/client.go index 502062e218..159afac62e 100644 --- a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/client.go +++ b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/client.go @@ -6,8 +6,8 @@ import ( "runtime" "sync" - "github.com/aws/jsii-runtime-go/kernel/process" - "github.com/aws/jsii-runtime-go/typeregistry" + "github.com/aws/jsii-runtime-go/internal/kernel/process" + "github.com/aws/jsii-runtime-go/internal/typeregistry" ) var ( diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/client_test.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/client_test.go similarity index 100% rename from packages/@jsii/go-runtime/jsii-runtime-go/kernel/client_test.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/client_test.go diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/complete.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/complete.go similarity index 100% rename from packages/@jsii/go-runtime/jsii-runtime-go/kernel/complete.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/complete.go diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/conversions.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/conversions.go similarity index 97% rename from packages/@jsii/go-runtime/jsii-runtime-go/kernel/conversions.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/conversions.go index 8d498875b1..9072b5d192 100644 --- a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/conversions.go +++ b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/conversions.go @@ -3,7 +3,7 @@ package kernel import ( "reflect" - "github.com/aws/jsii-runtime-go/api" + "github.com/aws/jsii-runtime-go/internal/api" ) // CastAndSetToPtr accepts a pointer to any type and attempts to cast the value @@ -35,7 +35,7 @@ func (c *client) castAndSetToPtr(ptr reflect.Value, data reflect.Value) { if ref, isRef := castValToRef(data); isRef { // If return data is a jsii struct passed by reference, de-reference it all. - if fields, isStruct := c.Types().StructFields(ptr.Type()); isStruct { + if fields, _, isStruct := c.Types().StructFields(ptr.Type()); isStruct { for _, field := range fields { got, err := c.Get(GetProps{ Property: field.Tag.Get("json"), diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/create.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/create.go similarity index 94% rename from packages/@jsii/go-runtime/jsii-runtime-go/kernel/create.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/create.go index 3c77a81cad..5092aa1fcf 100644 --- a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/create.go +++ b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/create.go @@ -1,6 +1,6 @@ package kernel -import "github.com/aws/jsii-runtime-go/api" +import "github.com/aws/jsii-runtime-go/internal/api" type CreateProps struct { FQN api.FQN `json:"fqn"` diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/del.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/del.go similarity index 86% rename from packages/@jsii/go-runtime/jsii-runtime-go/kernel/del.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/del.go index 87ce60204f..faf0c5bf80 100644 --- a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/del.go +++ b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/del.go @@ -1,6 +1,6 @@ package kernel -import "github.com/aws/jsii-runtime-go/api" +import "github.com/aws/jsii-runtime-go/internal/api" type DelProps struct { ObjRef api.ObjectRef `json:"objref"` diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/doc.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/doc.go similarity index 100% rename from packages/@jsii/go-runtime/jsii-runtime-go/kernel/doc.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/doc.go diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/end.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/end.go similarity index 100% rename from packages/@jsii/go-runtime/jsii-runtime-go/kernel/end.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/end.go diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/get.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/get.go similarity index 95% rename from packages/@jsii/go-runtime/jsii-runtime-go/kernel/get.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/get.go index ee1a83ffc0..90499f00e6 100644 --- a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/get.go +++ b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/get.go @@ -1,6 +1,6 @@ package kernel -import "github.com/aws/jsii-runtime-go/api" +import "github.com/aws/jsii-runtime-go/internal/api" type GetProps struct { Property string `json:"property"` diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/invoke.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/invoke.go similarity index 95% rename from packages/@jsii/go-runtime/jsii-runtime-go/kernel/invoke.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/invoke.go index f5b361e5c1..19d7d3aa05 100644 --- a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/invoke.go +++ b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/invoke.go @@ -1,6 +1,6 @@ package kernel -import "github.com/aws/jsii-runtime-go/api" +import "github.com/aws/jsii-runtime-go/internal/api" type InvokeProps struct { Method string `json:"method"` diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/json.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/json.go similarity index 100% rename from packages/@jsii/go-runtime/jsii-runtime-go/kernel/json.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/json.go diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/load.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/load.go similarity index 100% rename from packages/@jsii/go-runtime/jsii-runtime-go/kernel/load.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/load.go diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/naming.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/naming.go similarity index 100% rename from packages/@jsii/go-runtime/jsii-runtime-go/kernel/naming.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/naming.go diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/process/consume-stderr.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/process/consume-stderr.go similarity index 100% rename from packages/@jsii/go-runtime/jsii-runtime-go/kernel/process/consume-stderr.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/process/consume-stderr.go diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/process/handshake.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/process/handshake.go similarity index 99% rename from packages/@jsii/go-runtime/jsii-runtime-go/kernel/process/handshake.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/process/handshake.go index d2ff9f40b8..8173655ad8 100644 --- a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/process/handshake.go +++ b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/process/handshake.go @@ -2,8 +2,9 @@ package process import ( "fmt" - "github.com/Masterminds/semver/v3" "regexp" + + "github.com/Masterminds/semver/v3" ) type handshakeResponse struct { diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/process/jsii-mock-runtime.js b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/process/jsii-mock-runtime.js similarity index 100% rename from packages/@jsii/go-runtime/jsii-runtime-go/kernel/process/jsii-mock-runtime.js rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/process/jsii-mock-runtime.js diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/process/process.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/process/process.go similarity index 99% rename from packages/@jsii/go-runtime/jsii-runtime-go/kernel/process/process.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/process/process.go index 993b791fc8..6a230168b6 100644 --- a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/process/process.go +++ b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/process/process.go @@ -12,7 +12,7 @@ import ( "sync" "github.com/Masterminds/semver/v3" - "github.com/aws/jsii-runtime-go/embedded" + "github.com/aws/jsii-runtime-go/internal/embedded" ) const JSII_RUNTIME string = "JSII_RUNTIME" diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/process/process_test.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/process/process_test.go similarity index 100% rename from packages/@jsii/go-runtime/jsii-runtime-go/kernel/process/process_test.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/process/process_test.go diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/request-response-markers.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/request-response-markers.go similarity index 100% rename from packages/@jsii/go-runtime/jsii-runtime-go/kernel/request-response-markers.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/request-response-markers.go diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/set.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/set.go similarity index 95% rename from packages/@jsii/go-runtime/jsii-runtime-go/kernel/set.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/set.go index 9a7b76c9d1..00cce92696 100644 --- a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/set.go +++ b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/set.go @@ -1,6 +1,6 @@ package kernel -import "github.com/aws/jsii-runtime-go/api" +import "github.com/aws/jsii-runtime-go/internal/api" type SetProps struct { Property string `json:"property"` diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/kernel/stats.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/stats.go similarity index 100% rename from packages/@jsii/go-runtime/jsii-runtime-go/kernel/stats.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/stats.go diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/typeregistry/doc.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/typeregistry/doc.go similarity index 100% rename from packages/@jsii/go-runtime/jsii-runtime-go/typeregistry/doc.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/typeregistry/doc.go diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/typeregistry/registration.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/typeregistry/registration.go similarity index 92% rename from packages/@jsii/go-runtime/jsii-runtime-go/typeregistry/registration.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/typeregistry/registration.go index 0c6262969a..b718cf112c 100644 --- a/packages/@jsii/go-runtime/jsii-runtime-go/typeregistry/registration.go +++ b/packages/@jsii/go-runtime/jsii-runtime-go/internal/typeregistry/registration.go @@ -4,10 +4,9 @@ import ( "fmt" "reflect" - "github.com/aws/jsii-runtime-go/api" + "github.com/aws/jsii-runtime-go/internal/api" ) - // RegisterClass maps the given FQN to the provided class interface, and proxy // maker function. This returns an error if the class type is not a go interface. func (t *TypeRegistry) RegisterClass(fqn api.FQN, class reflect.Type, maker func() interface{}) error { @@ -84,6 +83,10 @@ func (t *TypeRegistry) RegisterStruct(fqn api.FQN, strct reflect.Type) error { return fmt.Errorf("another type was already registered with %s: %v", fqn, existing) } + if existing, exists := t.typeToFQN[strct]; exists && existing != fqn { + return fmt.Errorf("attempting to register type %s as %s, but it was already registered as: %s", strct.String(), fqn, existing) + } + fields := []reflect.StructField{} numField := strct.NumField() for i := 0; i < numField; i++ { @@ -101,6 +104,7 @@ func (t *TypeRegistry) RegisterStruct(fqn api.FQN, strct reflect.Type) error { } t.fqnToType[fqn] = strct + t.typeToFQN[strct] = fqn t.structFields[strct] = fields return nil diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/typeregistry/type-registry.go b/packages/@jsii/go-runtime/jsii-runtime-go/internal/typeregistry/type-registry.go similarity index 86% rename from packages/@jsii/go-runtime/jsii-runtime-go/typeregistry/type-registry.go rename to packages/@jsii/go-runtime/jsii-runtime-go/internal/typeregistry/type-registry.go index 377d813b62..cd9009a600 100644 --- a/packages/@jsii/go-runtime/jsii-runtime-go/typeregistry/type-registry.go +++ b/packages/@jsii/go-runtime/jsii-runtime-go/internal/typeregistry/type-registry.go @@ -4,7 +4,7 @@ import ( "fmt" "reflect" - "github.com/aws/jsii-runtime-go/api" + "github.com/aws/jsii-runtime-go/internal/api" ) // typeRegistry is used to record runtime type information about the loaded @@ -18,6 +18,10 @@ type TypeRegistry struct { // enums are not included fqnToType map[api.FQN]reflect.Type + // typeToFQN is sued to obtain the jsii fully qualified type name for a + // given native go type. Currently only tracks jsii struct types. + typeToFQN map[reflect.Type]api.FQN + // map enum member FQNs (e.g. "jsii-calc.StringEnum/A") to the corresponding // go const for this member. fqnToEnumMember map[string]interface{} @@ -37,6 +41,7 @@ type TypeRegistry struct { func NewTypeRegistry() *TypeRegistry { return &TypeRegistry{ fqnToType: make(map[api.FQN]reflect.Type), + typeToFQN: make(map[reflect.Type]api.FQN), fqnToEnumMember: make(map[string]interface{}), typeToEnumFQN: make(map[reflect.Type]api.FQN), structFields: make(map[reflect.Type][]reflect.StructField), @@ -44,11 +49,16 @@ func NewTypeRegistry() *TypeRegistry { } } -// IsStruct returns true if the provided type is a registered jsii struct. -func (t *TypeRegistry) StructFields(typ reflect.Type) (fields []reflect.StructField, ok bool) { +// StructFields returns the list of fields associated with a jsii struct type, +// the jsii fully qualified type name, and a boolean telling whether the +// provided type was a registered jsii struct type. +func (t *TypeRegistry) StructFields(typ reflect.Type) (fields []reflect.StructField, fqn api.FQN, ok bool) { + if fqn, ok = t.typeToFQN[typ]; !ok { + return + } + var found []reflect.StructField - found, ok = t.structFields[typ] - if ok { + if found, ok = t.structFields[typ]; ok { // Returning a copy, to ensure our storage does not get mutated. fields = append(fields, found...) } diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/runtime.go b/packages/@jsii/go-runtime/jsii-runtime-go/runtime.go index e729d8727e..95bd2f28d4 100644 --- a/packages/@jsii/go-runtime/jsii-runtime-go/runtime.go +++ b/packages/@jsii/go-runtime/jsii-runtime-go/runtime.go @@ -7,8 +7,8 @@ import ( "reflect" "regexp" - "github.com/aws/jsii-runtime-go/api" - "github.com/aws/jsii-runtime-go/kernel" + "github.com/aws/jsii-runtime-go/internal/api" + "github.com/aws/jsii-runtime-go/internal/kernel" ) // FQN represents a fully-qualified type name in the jsii type system. @@ -315,12 +315,32 @@ func castPtrToRef(data interface{}) interface{} { return result - case reflect.Ptr: - valref, valHasRef := client.FindObjectRef(reflect.ValueOf(data)) + case reflect.Interface, reflect.Ptr: + valref, valHasRef := client.FindObjectRef(dataVal) if valHasRef { return api.ObjectRef{InstanceID: valref} } + case reflect.Struct: + if fields, fqn, isStruct := client.Types().StructFields(dataVal.Type()); isStruct { + data := make(map[string]interface{}) + for _, field := range fields { + fieldVal := dataVal.FieldByIndex(field.Index) + if (fieldVal.Kind() == reflect.Ptr || fieldVal.Kind() == reflect.Interface) && fieldVal.IsNil() { + continue + } + key := field.Tag.Get("json") + data[key] = castPtrToRef(fieldVal.Interface()) + } + + return api.WireStruct{ + StructDescriptor: api.StructDescriptor{ + FQN: fqn, + Fields: data, + }, + } + } + case reflect.Slice: refs := make([]interface{}, dataVal.Len()) for i := 0; i < dataVal.Len(); i++ { @@ -333,6 +353,7 @@ func castPtrToRef(data interface{}) interface{} { return enumRef } } + return data } diff --git a/packages/jsii-calc/lib/compliance.ts b/packages/jsii-calc/lib/compliance.ts index 94c433094c..70cca534b1 100644 --- a/packages/jsii-calc/lib/compliance.ts +++ b/packages/jsii-calc/lib/compliance.ts @@ -2872,3 +2872,56 @@ export class StaticHelloChild extends StaticHelloParent { super(); } } + +// -------------------------------------------------- +// enums within structs + +export interface StructWithEnum { + /** + * An enum value + */ + readonly foo: StringEnum; + + /** + * Optional enum value (of type integer) + * @default AllTypesEnum.YOUR_ENUM_VALUE + */ + readonly bar?: AllTypesEnum; +} + +export class TestStructWithEnum { + /** + * Returns true if `foo` is `StringEnum.A`. + */ + public isStringEnumA(input: StructWithEnum) { + return input.foo === StringEnum.A && !input.bar; + } + + /** + * Returns true if `foo` is `StringEnum.B` and `bar` is `AllTypesEnum.THIS_IS_GREAT`. + */ + public isStringEnumB(input: StructWithEnum) { + return ( + input.foo === StringEnum.B && input.bar === AllTypesEnum.THIS_IS_GREAT + ); + } + + /** + * Returns `foo: StringEnum.C` and `bar: AllTypesEnum.MY_ENUM_VALUE`. + */ + public get structWithFooBar(): StructWithEnum { + return { + foo: StringEnum.C, + bar: AllTypesEnum.MY_ENUM_VALUE, + }; + } + + /** + * Returns `foo: StringEnum.A`. + */ + public get structWithFoo(): StructWithEnum { + return { + foo: StringEnum.A, + }; + } +} diff --git a/packages/jsii-calc/test/assembly.jsii b/packages/jsii-calc/test/assembly.jsii index d62d14f275..133b042915 100644 --- a/packages/jsii-calc/test/assembly.jsii +++ b/packages/jsii-calc/test/assembly.jsii @@ -12178,6 +12178,56 @@ ], "name": "StructUnionConsumer" }, + "jsii-calc.StructWithEnum": { + "assembly": "jsii-calc", + "datatype": true, + "docs": { + "stability": "stable" + }, + "fqn": "jsii-calc.StructWithEnum", + "kind": "interface", + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2879 + }, + "name": "StructWithEnum", + "properties": [ + { + "abstract": true, + "docs": { + "stability": "stable", + "summary": "An enum value." + }, + "immutable": true, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2883 + }, + "name": "foo", + "type": { + "fqn": "jsii-calc.StringEnum" + } + }, + { + "abstract": true, + "docs": { + "default": "AllTypesEnum.YOUR_ENUM_VALUE", + "stability": "stable", + "summary": "Optional enum value (of type integer)." + }, + "immutable": true, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2889 + }, + "name": "bar", + "optional": true, + "type": { + "fqn": "jsii-calc.AllTypesEnum" + } + } + ] + }, "jsii-calc.StructWithJavaReservedWords": { "assembly": "jsii-calc", "datatype": true, @@ -12829,6 +12879,106 @@ } ] }, + "jsii-calc.TestStructWithEnum": { + "assembly": "jsii-calc", + "docs": { + "stability": "stable" + }, + "fqn": "jsii-calc.TestStructWithEnum", + "initializer": { + "docs": { + "stability": "stable" + } + }, + "kind": "class", + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2892 + }, + "methods": [ + { + "docs": { + "stability": "stable", + "summary": "Returns true if `foo` is `StringEnum.A`." + }, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2896 + }, + "name": "isStringEnumA", + "parameters": [ + { + "name": "input", + "type": { + "fqn": "jsii-calc.StructWithEnum" + } + } + ], + "returns": { + "type": { + "primitive": "boolean" + } + } + }, + { + "docs": { + "stability": "stable", + "summary": "Returns true if `foo` is `StringEnum.B` and `bar` is `AllTypesEnum.THIS_IS_GREAT`." + }, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2903 + }, + "name": "isStringEnumB", + "parameters": [ + { + "name": "input", + "type": { + "fqn": "jsii-calc.StructWithEnum" + } + } + ], + "returns": { + "type": { + "primitive": "boolean" + } + } + } + ], + "name": "TestStructWithEnum", + "properties": [ + { + "docs": { + "stability": "stable", + "summary": "Returns `foo: StringEnum.A`." + }, + "immutable": true, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2922 + }, + "name": "structWithFoo", + "type": { + "fqn": "jsii-calc.StructWithEnum" + } + }, + { + "docs": { + "stability": "stable", + "summary": "Returns `foo: StringEnum.C` and `bar: AllTypesEnum.MY_ENUM_VALUE`." + }, + "immutable": true, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2912 + }, + "name": "structWithFooBar", + "type": { + "fqn": "jsii-calc.StructWithEnum" + } + } + ] + }, "jsii-calc.Thrower": { "assembly": "jsii-calc", "docs": { @@ -14606,5 +14756,5 @@ } }, "version": "3.20.120", - "fingerprint": "JMTvoEnsqFjh72kI95PtIx01MmNxAbZV41K/nIgoZ4Q=" + "fingerprint": "GfueSeyZdyEIZp4V4lbddw+TnoCel74KSDMPxp2phmw=" } diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap index 07d3ed7867..a09e5303eb 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap @@ -2810,6 +2810,7 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┣━ 📄 IStructB.cs ┃ ┣━ 📄 IStructParameterType.cs ┃ ┣━ 📄 IStructReturningDelegate.cs + ┃ ┣━ 📄 IStructWithEnum.cs ┃ ┣━ 📄 IStructWithJavaReservedWords.cs ┃ ┣━ 📄 ISupportsNiceJavaBuilderProps.cs ┃ ┣━ 📄 ITopLevelStruct.cs @@ -2894,6 +2895,7 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┣━ 📄 StructParameterType.cs ┃ ┣━ 📄 StructPassing.cs ┃ ┣━ 📄 StructUnionConsumer.cs + ┃ ┣━ 📄 StructWithEnum.cs ┃ ┣━ 📄 StructWithJavaReservedWords.cs ┃ ┣━ 📁 Submodule ┃ ┃ ┣━ 📁 BackReferences @@ -2928,6 +2930,7 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┣━ 📄 SupportsNiceJavaBuilderProps.cs ┃ ┣━ 📄 SupportsNiceJavaBuilderWithRequiredProps.cs ┃ ┣━ 📄 SyncVirtualMethods.cs + ┃ ┣━ 📄 TestStructWithEnum.cs ┃ ┣━ 📄 Thrower.cs ┃ ┣━ 📄 TopLevelStruct.cs ┃ ┣━ 📄 UmaskCheck.cs @@ -9919,6 +9922,67 @@ namespace Amazon.JSII.Tests.CalculatorNamespace `; +exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/IStructWithEnum.cs 1`] = ` +using Amazon.JSII.Runtime.Deputy; + +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CalculatorNamespace +{ + [JsiiInterface(nativeType: typeof(IStructWithEnum), fullyQualifiedName: "jsii-calc.StructWithEnum")] + public interface IStructWithEnum + { + /// An enum value. + [JsiiProperty(name: "foo", typeJson: "{\\"fqn\\":\\"jsii-calc.StringEnum\\"}")] + Amazon.JSII.Tests.CalculatorNamespace.StringEnum Foo + { + get; + } + + /// Optional enum value (of type integer). + /// + /// Default: AllTypesEnum.YOUR_ENUM_VALUE + /// + [JsiiProperty(name: "bar", typeJson: "{\\"fqn\\":\\"jsii-calc.AllTypesEnum\\"}", isOptional: true)] + [Amazon.JSII.Runtime.Deputy.JsiiOptional] + Amazon.JSII.Tests.CalculatorNamespace.AllTypesEnum? Bar + { + get + { + return null; + } + } + + [JsiiTypeProxy(nativeType: typeof(IStructWithEnum), fullyQualifiedName: "jsii-calc.StructWithEnum")] + internal sealed class _Proxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.IStructWithEnum + { + private _Proxy(ByRefValue reference): base(reference) + { + } + + /// An enum value. + [JsiiProperty(name: "foo", typeJson: "{\\"fqn\\":\\"jsii-calc.StringEnum\\"}")] + public Amazon.JSII.Tests.CalculatorNamespace.StringEnum Foo + { + get => GetInstanceProperty()!; + } + + /// Optional enum value (of type integer). + /// + /// Default: AllTypesEnum.YOUR_ENUM_VALUE + /// + [JsiiOptional] + [JsiiProperty(name: "bar", typeJson: "{\\"fqn\\":\\"jsii-calc.AllTypesEnum\\"}", isOptional: true)] + public Amazon.JSII.Tests.CalculatorNamespace.AllTypesEnum? Bar + { + get => GetInstanceProperty(); + } + } + } +} + +`; + exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/IStructWithJavaReservedWords.cs 1`] = ` using Amazon.JSII.Runtime.Deputy; @@ -14559,6 +14623,42 @@ namespace Amazon.JSII.Tests.CalculatorNamespace `; +exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/StructWithEnum.cs 1`] = ` +using Amazon.JSII.Runtime.Deputy; + +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CalculatorNamespace +{ + #pragma warning disable CS8618 + + [JsiiByValue(fqn: "jsii-calc.StructWithEnum")] + public class StructWithEnum : Amazon.JSII.Tests.CalculatorNamespace.IStructWithEnum + { + /// An enum value. + [JsiiProperty(name: "foo", typeJson: "{\\"fqn\\":\\"jsii-calc.StringEnum\\"}", isOverride: true)] + public Amazon.JSII.Tests.CalculatorNamespace.StringEnum Foo + { + get; + set; + } + + /// Optional enum value (of type integer). + /// + /// Default: AllTypesEnum.YOUR_ENUM_VALUE + /// + [JsiiOptional] + [JsiiProperty(name: "bar", typeJson: "{\\"fqn\\":\\"jsii-calc.AllTypesEnum\\"}", isOptional: true, isOverride: true)] + public Amazon.JSII.Tests.CalculatorNamespace.AllTypesEnum? Bar + { + get; + set; + } + } +} + +`; + exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/StructWithJavaReservedWords.cs 1`] = ` using Amazon.JSII.Runtime.Deputy; @@ -15606,6 +15706,66 @@ namespace Amazon.JSII.Tests.CalculatorNamespace `; +exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/TestStructWithEnum.cs 1`] = ` +using Amazon.JSII.Runtime.Deputy; + +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CalculatorNamespace +{ + [JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.TestStructWithEnum), fullyQualifiedName: "jsii-calc.TestStructWithEnum")] + public class TestStructWithEnum : DeputyBase + { + public TestStructWithEnum(): base(new DeputyProps(System.Array.Empty())) + { + } + + /// Used by jsii to construct an instance of this class from a Javascript-owned object reference + /// The Javascript-owned object reference + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + protected TestStructWithEnum(ByRefValue reference): base(reference) + { + } + + /// Used by jsii to construct an instance of this class from DeputyProps + /// The deputy props + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + protected TestStructWithEnum(DeputyProps props): base(props) + { + } + + /// Returns true if \`foo\` is \`StringEnum.A\`. + [JsiiMethod(name: "isStringEnumA", returnsJson: "{\\"type\\":{\\"primitive\\":\\"boolean\\"}}", parametersJson: "[{\\"name\\":\\"input\\",\\"type\\":{\\"fqn\\":\\"jsii-calc.StructWithEnum\\"}}]")] + public virtual bool IsStringEnumA(Amazon.JSII.Tests.CalculatorNamespace.IStructWithEnum input) + { + return InvokeInstanceMethod(new System.Type[]{typeof(Amazon.JSII.Tests.CalculatorNamespace.IStructWithEnum)}, new object[]{input})!; + } + + /// Returns true if \`foo\` is \`StringEnum.B\` and \`bar\` is \`AllTypesEnum.THIS_IS_GREAT\`. + [JsiiMethod(name: "isStringEnumB", returnsJson: "{\\"type\\":{\\"primitive\\":\\"boolean\\"}}", parametersJson: "[{\\"name\\":\\"input\\",\\"type\\":{\\"fqn\\":\\"jsii-calc.StructWithEnum\\"}}]")] + public virtual bool IsStringEnumB(Amazon.JSII.Tests.CalculatorNamespace.IStructWithEnum input) + { + return InvokeInstanceMethod(new System.Type[]{typeof(Amazon.JSII.Tests.CalculatorNamespace.IStructWithEnum)}, new object[]{input})!; + } + + /// Returns \`foo: StringEnum.A\`. + [JsiiProperty(name: "structWithFoo", typeJson: "{\\"fqn\\":\\"jsii-calc.StructWithEnum\\"}")] + public virtual Amazon.JSII.Tests.CalculatorNamespace.IStructWithEnum StructWithFoo + { + get => GetInstanceProperty()!; + } + + /// Returns \`foo: StringEnum.C\` and \`bar: AllTypesEnum.MY_ENUM_VALUE\`. + [JsiiProperty(name: "structWithFooBar", typeJson: "{\\"fqn\\":\\"jsii-calc.StructWithEnum\\"}")] + public virtual Amazon.JSII.Tests.CalculatorNamespace.IStructWithEnum StructWithFooBar + { + get => GetInstanceProperty()!; + } + } +} + +`; + exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/Thrower.cs 1`] = ` using Amazon.JSII.Runtime.Deputy; diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap index 0fa6db0132..080d981328 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap @@ -11282,6 +11282,13 @@ func StructUnionConsumer_IsStructB(struct_ interface{}) bool { return returns } +type StructWithEnum struct { + // An enum value. + Foo StringEnum \`json:"foo"\` + // Optional enum value (of type integer). + Bar AllTypesEnum \`json:"bar"\` +} + type StructWithJavaReservedWords struct { Default string \`json:"default"\` Assert string \`json:"assert"\` @@ -11718,6 +11725,79 @@ func (s *syncVirtualMethods) WriteA(value float64) { ) } +type TestStructWithEnum interface { + StructWithFoo() StructWithEnum + StructWithFooBar() StructWithEnum + IsStringEnumA(input StructWithEnum) bool + IsStringEnumB(input StructWithEnum) bool +} + +// The jsii proxy struct for TestStructWithEnum +type testStructWithEnum struct { + _ byte // padding +} + +func (t *testStructWithEnum) StructWithFoo() StructWithEnum { + var returns StructWithEnum + _jsii_.Get( + t, + "structWithFoo", + &returns, + ) + return returns +} + +func (t *testStructWithEnum) StructWithFooBar() StructWithEnum { + var returns StructWithEnum + _jsii_.Get( + t, + "structWithFooBar", + &returns, + ) + return returns +} + + +func NewTestStructWithEnum() TestStructWithEnum { + _init_.Initialize() + t := testStructWithEnum{} + + _jsii_.Create( + "jsii-calc.TestStructWithEnum", + []interface{}{}, + []_jsii_.FQN{}, + []_jsii_.Override{}, + &t, + ) + return &t +} + +// Returns true if \`foo\` is \`StringEnum.A\`. +func (t *testStructWithEnum) IsStringEnumA(input StructWithEnum) bool { + var returns bool + _jsii_.Invoke( + t, + "isStringEnumA", + []interface{}{input}, + true, + &returns, + ) + return returns +} + +// Returns true if \`foo\` is \`StringEnum.B\` and \`bar\` is \`AllTypesEnum.THIS_IS_GREAT\`. +func (t *testStructWithEnum) IsStringEnumB(input StructWithEnum) bool { + var returns bool + _jsii_.Invoke( + t, + "isStringEnumB", + []interface{}{input}, + true, + &returns, + ) + return returns +} + type Thrower interface { ThrowError() } @@ -13537,6 +13617,10 @@ func init() { return &structUnionConsumer{} }, ) + _jsii_.RegisterStruct( + "jsii-calc.StructWithEnum", + reflect.TypeOf((*StructWithEnum)(nil)).Elem(), + ) _jsii_.RegisterStruct( "jsii-calc.StructWithJavaReservedWords", reflect.TypeOf((*StructWithJavaReservedWords)(nil)).Elem(), @@ -13577,6 +13661,13 @@ func init() { return &syncVirtualMethods{} }, ) + _jsii_.RegisterClass( + "jsii-calc.TestStructWithEnum", + reflect.TypeOf((*TestStructWithEnum)(nil)).Elem(), + func() interface{} { + return &testStructWithEnum{} + }, + ) _jsii_.RegisterClass( "jsii-calc.Thrower", reflect.TypeOf((*Thrower)(nil)).Elem(), diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.ts.snap index 66da64d930..a98118ed7b 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.ts.snap @@ -3721,6 +3721,7 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┣━ 📄 StructParameterType.java ┃ ┣━ 📄 StructPassing.java ┃ ┣━ 📄 StructUnionConsumer.java + ┃ ┣━ 📄 StructWithEnum.java ┃ ┣━ 📄 StructWithJavaReservedWords.java ┃ ┣━ 📁 submodule ┃ ┃ ┣━ 📁 back_references @@ -3750,6 +3751,7 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┣━ 📄 SupportsNiceJavaBuilderProps.java ┃ ┣━ 📄 SupportsNiceJavaBuilderWithRequiredProps.java ┃ ┣━ 📄 SyncVirtualMethods.java + ┃ ┣━ 📄 TestStructWithEnum.java ┃ ┣━ 📄 Thrower.java ┃ ┣━ 📄 TopLevelStruct.java ┃ ┣━ 📄 UmaskCheck.java @@ -19013,6 +19015,163 @@ public class StructUnionConsumer extends software.amazon.jsii.JsiiObject { `; +exports[`Generated code for "jsii-calc": /java/src/main/java/software/amazon/jsii/tests/calculator/StructWithEnum.java 1`] = ` +package software.amazon.jsii.tests.calculator; + +/** + */ +@javax.annotation.Generated(value = "jsii-pacmak") +@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.StructWithEnum") +@software.amazon.jsii.Jsii.Proxy(StructWithEnum.Jsii$Proxy.class) +@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) +public interface StructWithEnum extends software.amazon.jsii.JsiiSerializable { + + /** + * An enum value. + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + @org.jetbrains.annotations.NotNull software.amazon.jsii.tests.calculator.StringEnum getFoo(); + + /** + * Optional enum value (of type integer). + *

+ * Default: AllTypesEnum.YOUR_ENUM_VALUE + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + default @org.jetbrains.annotations.Nullable software.amazon.jsii.tests.calculator.AllTypesEnum getBar() { + return null; + } + + /** + * @return a {@link Builder} of {@link StructWithEnum} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + static Builder builder() { + return new Builder(); + } + /** + * A builder for {@link StructWithEnum} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public static final class Builder implements software.amazon.jsii.Builder { + private software.amazon.jsii.tests.calculator.StringEnum foo; + private software.amazon.jsii.tests.calculator.AllTypesEnum bar; + + /** + * Sets the value of {@link StructWithEnum#getFoo} + * @param foo An enum value. This parameter is required. + * @return {@code this} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public Builder foo(software.amazon.jsii.tests.calculator.StringEnum foo) { + this.foo = foo; + return this; + } + + /** + * Sets the value of {@link StructWithEnum#getBar} + * @param bar Optional enum value (of type integer). + * @return {@code this} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public Builder bar(software.amazon.jsii.tests.calculator.AllTypesEnum bar) { + this.bar = bar; + return this; + } + + /** + * Builds the configured instance. + * @return a new instance of {@link StructWithEnum} + * @throws NullPointerException if any required attribute was not provided + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + @Override + public StructWithEnum build() { + return new Jsii$Proxy(foo, bar); + } + } + + /** + * An implementation for {@link StructWithEnum} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + @software.amazon.jsii.Internal + final class Jsii$Proxy extends software.amazon.jsii.JsiiObject implements StructWithEnum { + private final software.amazon.jsii.tests.calculator.StringEnum foo; + private final software.amazon.jsii.tests.calculator.AllTypesEnum bar; + + /** + * Constructor that initializes the object based on values retrieved from the JsiiObject. + * @param objRef Reference to the JSII managed object. + */ + protected Jsii$Proxy(final software.amazon.jsii.JsiiObjectRef objRef) { + super(objRef); + this.foo = software.amazon.jsii.Kernel.get(this, "foo", software.amazon.jsii.NativeType.forClass(software.amazon.jsii.tests.calculator.StringEnum.class)); + this.bar = software.amazon.jsii.Kernel.get(this, "bar", software.amazon.jsii.NativeType.forClass(software.amazon.jsii.tests.calculator.AllTypesEnum.class)); + } + + /** + * Constructor that initializes the object based on literal property values passed by the {@link Builder}. + */ + protected Jsii$Proxy(final software.amazon.jsii.tests.calculator.StringEnum foo, final software.amazon.jsii.tests.calculator.AllTypesEnum bar) { + super(software.amazon.jsii.JsiiObject.InitializationMode.JSII); + this.foo = java.util.Objects.requireNonNull(foo, "foo is required"); + this.bar = bar; + } + + @Override + public final software.amazon.jsii.tests.calculator.StringEnum getFoo() { + return this.foo; + } + + @Override + public final software.amazon.jsii.tests.calculator.AllTypesEnum getBar() { + return this.bar; + } + + @Override + @software.amazon.jsii.Internal + public com.fasterxml.jackson.databind.JsonNode $jsii$toJson() { + final com.fasterxml.jackson.databind.ObjectMapper om = software.amazon.jsii.JsiiObjectMapper.INSTANCE; + final com.fasterxml.jackson.databind.node.ObjectNode data = com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.objectNode(); + + data.set("foo", om.valueToTree(this.getFoo())); + if (this.getBar() != null) { + data.set("bar", om.valueToTree(this.getBar())); + } + + final com.fasterxml.jackson.databind.node.ObjectNode struct = com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.objectNode(); + struct.set("fqn", om.valueToTree("jsii-calc.StructWithEnum")); + struct.set("data", data); + + final com.fasterxml.jackson.databind.node.ObjectNode obj = com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.objectNode(); + obj.set("$jsii.struct", struct); + + return obj; + } + + @Override + public final boolean equals(final Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + StructWithEnum.Jsii$Proxy that = (StructWithEnum.Jsii$Proxy) o; + + if (!foo.equals(that.foo)) return false; + return this.bar != null ? this.bar.equals(that.bar) : that.bar == null; + } + + @Override + public final int hashCode() { + int result = this.foo.hashCode(); + result = 31 * result + (this.bar != null ? this.bar.hashCode() : 0); + return result; + } + } +} + +`; + exports[`Generated code for "jsii-calc": /java/src/main/java/software/amazon/jsii/tests/calculator/StructWithJavaReservedWords.java 1`] = ` package software.amazon.jsii.tests.calculator; @@ -19872,6 +20031,71 @@ public class SyncVirtualMethods extends software.amazon.jsii.JsiiObject { `; +exports[`Generated code for "jsii-calc": /java/src/main/java/software/amazon/jsii/tests/calculator/TestStructWithEnum.java 1`] = ` +package software.amazon.jsii.tests.calculator; + +/** + */ +@javax.annotation.Generated(value = "jsii-pacmak") +@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) +@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.TestStructWithEnum") +public class TestStructWithEnum extends software.amazon.jsii.JsiiObject { + + protected TestStructWithEnum(final software.amazon.jsii.JsiiObjectRef objRef) { + super(objRef); + } + + protected TestStructWithEnum(final software.amazon.jsii.JsiiObject.InitializationMode initializationMode) { + super(initializationMode); + } + + /** + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public TestStructWithEnum() { + super(software.amazon.jsii.JsiiObject.InitializationMode.JSII); + software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this); + } + + /** + * Returns true if \`foo\` is \`StringEnum.A\`. + *

+ * @param input This parameter is required. + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public @org.jetbrains.annotations.NotNull java.lang.Boolean isStringEnumA(final @org.jetbrains.annotations.NotNull software.amazon.jsii.tests.calculator.StructWithEnum input) { + return software.amazon.jsii.Kernel.call(this, "isStringEnumA", software.amazon.jsii.NativeType.forClass(java.lang.Boolean.class), new Object[] { java.util.Objects.requireNonNull(input, "input is required") }); + } + + /** + * Returns true if \`foo\` is \`StringEnum.B\` and \`bar\` is \`AllTypesEnum.THIS_IS_GREAT\`. + *

+ * @param input This parameter is required. + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public @org.jetbrains.annotations.NotNull java.lang.Boolean isStringEnumB(final @org.jetbrains.annotations.NotNull software.amazon.jsii.tests.calculator.StructWithEnum input) { + return software.amazon.jsii.Kernel.call(this, "isStringEnumB", software.amazon.jsii.NativeType.forClass(java.lang.Boolean.class), new Object[] { java.util.Objects.requireNonNull(input, "input is required") }); + } + + /** + * Returns \`foo: StringEnum.A\`. + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public @org.jetbrains.annotations.NotNull software.amazon.jsii.tests.calculator.StructWithEnum getStructWithFoo() { + return software.amazon.jsii.Kernel.get(this, "structWithFoo", software.amazon.jsii.NativeType.forClass(software.amazon.jsii.tests.calculator.StructWithEnum.class)); + } + + /** + * Returns \`foo: StringEnum.C\` and \`bar: AllTypesEnum.MY_ENUM_VALUE\`. + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public @org.jetbrains.annotations.NotNull software.amazon.jsii.tests.calculator.StructWithEnum getStructWithFooBar() { + return software.amazon.jsii.Kernel.get(this, "structWithFooBar", software.amazon.jsii.NativeType.forClass(software.amazon.jsii.tests.calculator.StructWithEnum.class)); + } +} + +`; + exports[`Generated code for "jsii-calc": /java/src/main/java/software/amazon/jsii/tests/calculator/Thrower.java 1`] = ` package software.amazon.jsii.tests.calculator; @@ -23029,12 +23253,14 @@ jsii-calc.StructB=software.amazon.jsii.tests.calculator.StructB jsii-calc.StructParameterType=software.amazon.jsii.tests.calculator.StructParameterType jsii-calc.StructPassing=software.amazon.jsii.tests.calculator.StructPassing jsii-calc.StructUnionConsumer=software.amazon.jsii.tests.calculator.StructUnionConsumer +jsii-calc.StructWithEnum=software.amazon.jsii.tests.calculator.StructWithEnum jsii-calc.StructWithJavaReservedWords=software.amazon.jsii.tests.calculator.StructWithJavaReservedWords jsii-calc.Sum=software.amazon.jsii.tests.calculator.Sum jsii-calc.SupportsNiceJavaBuilder=software.amazon.jsii.tests.calculator.SupportsNiceJavaBuilder jsii-calc.SupportsNiceJavaBuilderProps=software.amazon.jsii.tests.calculator.SupportsNiceJavaBuilderProps jsii-calc.SupportsNiceJavaBuilderWithRequiredProps=software.amazon.jsii.tests.calculator.SupportsNiceJavaBuilderWithRequiredProps jsii-calc.SyncVirtualMethods=software.amazon.jsii.tests.calculator.SyncVirtualMethods +jsii-calc.TestStructWithEnum=software.amazon.jsii.tests.calculator.TestStructWithEnum jsii-calc.Thrower=software.amazon.jsii.tests.calculator.Thrower jsii-calc.TopLevelStruct=software.amazon.jsii.tests.calculator.TopLevelStruct jsii-calc.UmaskCheck=software.amazon.jsii.tests.calculator.UmaskCheck diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap index 5771ea5b69..bda56da08c 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap @@ -8475,6 +8475,56 @@ class StructUnionConsumer( return typing.cast(builtins.bool, jsii.sinvoke(cls, "isStructB", [struct])) +@jsii.data_type( + jsii_type="jsii-calc.StructWithEnum", + jsii_struct_bases=[], + name_mapping={"foo": "foo", "bar": "bar"}, +) +class StructWithEnum: + def __init__( + self, + *, + foo: StringEnum, + bar: typing.Optional[AllTypesEnum] = None, + ) -> None: + ''' + :param foo: An enum value. + :param bar: Optional enum value (of type integer). Default: AllTypesEnum.YOUR_ENUM_VALUE + ''' + self._values: typing.Dict[str, typing.Any] = { + "foo": foo, + } + if bar is not None: + self._values["bar"] = bar + + @builtins.property + def foo(self) -> StringEnum: + '''An enum value.''' + result = self._values.get("foo") + assert result is not None, "Required property 'foo' is missing" + return typing.cast(StringEnum, result) + + @builtins.property + def bar(self) -> typing.Optional[AllTypesEnum]: + '''Optional enum value (of type integer). + + :default: AllTypesEnum.YOUR_ENUM_VALUE + ''' + result = self._values.get("bar") + return typing.cast(typing.Optional[AllTypesEnum], result) + + def __eq__(self, rhs: typing.Any) -> builtins.bool: + return isinstance(rhs, self.__class__) and rhs._values == self._values + + def __ne__(self, rhs: typing.Any) -> builtins.bool: + return not (rhs == self) + + def __repr__(self) -> str: + return "StructWithEnum(%s)" % ", ".join( + k + "=" + repr(v) for k, v in self._values.items() + ) + + @jsii.data_type( jsii_type="jsii-calc.StructWithJavaReservedWords", jsii_struct_bases=[], @@ -8772,6 +8822,58 @@ class SyncVirtualMethods( jsii.set(self, "valueOfOtherProperty", value) +class TestStructWithEnum( + metaclass=jsii.JSIIMeta, + jsii_type="jsii-calc.TestStructWithEnum", +): + def __init__(self) -> None: + jsii.create(TestStructWithEnum, self, []) + + @jsii.member(jsii_name="isStringEnumA") + def is_string_enum_a( + self, + *, + foo: StringEnum, + bar: typing.Optional[AllTypesEnum] = None, + ) -> builtins.bool: + '''Returns true if \`\`foo\`\` is \`\`StringEnum.A\`\`. + + :param foo: An enum value. + :param bar: Optional enum value (of type integer). Default: AllTypesEnum.YOUR_ENUM_VALUE + ''' + input = StructWithEnum(foo=foo, bar=bar) + + return typing.cast(builtins.bool, jsii.invoke(self, "isStringEnumA", [input])) + + @jsii.member(jsii_name="isStringEnumB") + def is_string_enum_b( + self, + *, + foo: StringEnum, + bar: typing.Optional[AllTypesEnum] = None, + ) -> builtins.bool: + '''Returns true if \`\`foo\`\` is \`\`StringEnum.B\`\` and \`\`bar\`\` is \`\`AllTypesEnum.THIS_IS_GREAT\`\`. + + :param foo: An enum value. + :param bar: Optional enum value (of type integer). Default: AllTypesEnum.YOUR_ENUM_VALUE + ''' + input = StructWithEnum(foo=foo, bar=bar) + + return typing.cast(builtins.bool, jsii.invoke(self, "isStringEnumB", [input])) + + @builtins.property # type: ignore[misc] + @jsii.member(jsii_name="structWithFoo") + def struct_with_foo(self) -> StructWithEnum: + '''Returns \`\`foo: StringEnum.A\`\`.''' + return typing.cast(StructWithEnum, jsii.get(self, "structWithFoo")) + + @builtins.property # type: ignore[misc] + @jsii.member(jsii_name="structWithFooBar") + def struct_with_foo_bar(self) -> StructWithEnum: + '''Returns \`\`foo: StringEnum.C\`\` and \`\`bar: AllTypesEnum.MY_ENUM_VALUE\`\`.''' + return typing.cast(StructWithEnum, jsii.get(self, "structWithFooBar")) + + class Thrower(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.Thrower"): def __init__(self) -> None: jsii.create(Thrower, self, []) @@ -9829,12 +9931,14 @@ __all__ = [ "StructParameterType", "StructPassing", "StructUnionConsumer", + "StructWithEnum", "StructWithJavaReservedWords", "Sum", "SupportsNiceJavaBuilder", "SupportsNiceJavaBuilderProps", "SupportsNiceJavaBuilderWithRequiredProps", "SyncVirtualMethods", + "TestStructWithEnum", "Thrower", "TopLevelStruct", "UmaskCheck", diff --git a/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.ts.snap b/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.ts.snap index ef44e72781..70e646aea2 100644 --- a/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.ts.snap +++ b/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.ts.snap @@ -1885,6 +1885,25 @@ exports[`jsii-tree --all 1`] = ` │ │ │ └── type: string │ │ └─┬ valueOfOtherProperty property (stable) │ │ └── type: string + │ ├─┬ class TestStructWithEnum (stable) + │ │ └─┬ members + │ │ ├── () initializer (stable) + │ │ ├─┬ isStringEnumA(input) method (stable) + │ │ │ ├─┬ parameters + │ │ │ │ └─┬ input + │ │ │ │ └── type: jsii-calc.StructWithEnum + │ │ │ └── returns: boolean + │ │ ├─┬ isStringEnumB(input) method (stable) + │ │ │ ├─┬ parameters + │ │ │ │ └─┬ input + │ │ │ │ └── type: jsii-calc.StructWithEnum + │ │ │ └── returns: boolean + │ │ ├─┬ structWithFoo property (stable) + │ │ │ ├── immutable + │ │ │ └── type: jsii-calc.StructWithEnum + │ │ └─┬ structWithFooBar property (stable) + │ │ ├── immutable + │ │ └── type: jsii-calc.StructWithEnum │ ├─┬ class Thrower (stable) │ │ └─┬ members │ │ ├── () initializer (stable) @@ -2572,6 +2591,16 @@ exports[`jsii-tree --all 1`] = ` │ │ ├── abstract │ │ ├── immutable │ │ └── type: Optional + │ ├─┬ interface StructWithEnum (stable) + │ │ └─┬ members + │ │ ├─┬ foo property (stable) + │ │ │ ├── abstract + │ │ │ ├── immutable + │ │ │ └── type: jsii-calc.StringEnum + │ │ └─┬ bar property (stable) + │ │ ├── abstract + │ │ ├── immutable + │ │ └── type: Optional │ ├─┬ interface StructWithJavaReservedWords (stable) │ │ └─┬ members │ │ ├─┬ default property (stable) @@ -3075,6 +3104,7 @@ exports[`jsii-tree --inheritance 1`] = ` │ │ └── base: SupportsNiceJavaBuilderWithRequiredProps │ ├── class SupportsNiceJavaBuilderWithRequiredProps │ ├── class SyncVirtualMethods + │ ├── class TestStructWithEnum │ ├── class Thrower │ ├── class UmaskCheck │ ├─┬ class UnaryOperation @@ -3186,6 +3216,7 @@ exports[`jsii-tree --inheritance 1`] = ` │ ├── interface StructA │ ├── interface StructB │ ├── interface StructParameterType + │ ├── interface StructWithEnum │ ├── interface StructWithJavaReservedWords │ ├── interface SupportsNiceJavaBuilderProps │ ├── interface TopLevelStruct @@ -4097,6 +4128,13 @@ exports[`jsii-tree --members 1`] = ` │ │ ├── otherProperty property │ │ ├── theProperty property │ │ └── valueOfOtherProperty property + │ ├─┬ class TestStructWithEnum + │ │ └─┬ members + │ │ ├── () initializer + │ │ ├── isStringEnumA(input) method + │ │ ├── isStringEnumB(input) method + │ │ ├── structWithFoo property + │ │ └── structWithFooBar property │ ├─┬ class Thrower │ │ └─┬ members │ │ ├── () initializer @@ -4391,6 +4429,10 @@ exports[`jsii-tree --members 1`] = ` │ │ └─┬ members │ │ ├── scope property │ │ └── props property + │ ├─┬ interface StructWithEnum + │ │ └─┬ members + │ │ ├── foo property + │ │ └── bar property │ ├─┬ interface StructWithJavaReservedWords │ │ └─┬ members │ │ ├── default property @@ -4750,6 +4792,7 @@ exports[`jsii-tree --types 1`] = ` │ ├── class SupportsNiceJavaBuilder │ ├── class SupportsNiceJavaBuilderWithRequiredProps │ ├── class SyncVirtualMethods + │ ├── class TestStructWithEnum │ ├── class Thrower │ ├── class UmaskCheck │ ├── class UnaryOperation @@ -4830,6 +4873,7 @@ exports[`jsii-tree --types 1`] = ` │ ├── interface StructA │ ├── interface StructB │ ├── interface StructParameterType + │ ├── interface StructWithEnum │ ├── interface StructWithJavaReservedWords │ ├── interface SupportsNiceJavaBuilderProps │ ├── interface TopLevelStruct diff --git a/packages/jsii-reflect/test/__snapshots__/tree.test.ts.snap b/packages/jsii-reflect/test/__snapshots__/tree.test.ts.snap index e847895178..57c7434203 100644 --- a/packages/jsii-reflect/test/__snapshots__/tree.test.ts.snap +++ b/packages/jsii-reflect/test/__snapshots__/tree.test.ts.snap @@ -1981,6 +1981,25 @@ exports[`showAll 1`] = ` │ │ │ └── type: string │ │ └─┬ valueOfOtherProperty property │ │ └── type: string + │ ├─┬ class TestStructWithEnum + │ │ └─┬ members + │ │ ├── () initializer + │ │ ├─┬ isStringEnumA(input) method + │ │ │ ├─┬ parameters + │ │ │ │ └─┬ input + │ │ │ │ └── type: jsii-calc.StructWithEnum + │ │ │ └── returns: boolean + │ │ ├─┬ isStringEnumB(input) method + │ │ │ ├─┬ parameters + │ │ │ │ └─┬ input + │ │ │ │ └── type: jsii-calc.StructWithEnum + │ │ │ └── returns: boolean + │ │ ├─┬ structWithFoo property + │ │ │ ├── immutable + │ │ │ └── type: jsii-calc.StructWithEnum + │ │ └─┬ structWithFooBar property + │ │ ├── immutable + │ │ └── type: jsii-calc.StructWithEnum │ ├─┬ class Thrower │ │ └─┬ members │ │ ├── () initializer @@ -2668,6 +2687,16 @@ exports[`showAll 1`] = ` │ │ ├── abstract │ │ ├── immutable │ │ └── type: Optional + │ ├─┬ interface StructWithEnum + │ │ └─┬ members + │ │ ├─┬ foo property + │ │ │ ├── abstract + │ │ │ ├── immutable + │ │ │ └── type: jsii-calc.StringEnum + │ │ └─┬ bar property + │ │ ├── abstract + │ │ ├── immutable + │ │ └── type: Optional │ ├─┬ interface StructWithJavaReservedWords │ │ └─┬ members │ │ ├─┬ default property @@ -3169,6 +3198,7 @@ exports[`types 1`] = ` │ ├── class SupportsNiceJavaBuilder │ ├── class SupportsNiceJavaBuilderWithRequiredProps │ ├── class SyncVirtualMethods + │ ├── class TestStructWithEnum │ ├── class Thrower │ ├── class UmaskCheck │ ├── class UnaryOperation @@ -3249,6 +3279,7 @@ exports[`types 1`] = ` │ ├── interface StructA │ ├── interface StructB │ ├── interface StructParameterType + │ ├── interface StructWithEnum │ ├── interface StructWithJavaReservedWords │ ├── interface SupportsNiceJavaBuilderProps │ ├── interface TopLevelStruct diff --git a/packages/jsii-reflect/test/__snapshots__/type-system.test.ts.snap b/packages/jsii-reflect/test/__snapshots__/type-system.test.ts.snap index 0c57a972f7..9881b70cbc 100644 --- a/packages/jsii-reflect/test/__snapshots__/type-system.test.ts.snap +++ b/packages/jsii-reflect/test/__snapshots__/type-system.test.ts.snap @@ -136,6 +136,7 @@ Array [ "jsii-calc.SupportsNiceJavaBuilder", "jsii-calc.SupportsNiceJavaBuilderWithRequiredProps", "jsii-calc.SyncVirtualMethods", + "jsii-calc.TestStructWithEnum", "jsii-calc.Thrower", "jsii-calc.UmaskCheck", "jsii-calc.UnaryOperation",