-
Notifications
You must be signed in to change notification settings - Fork 248
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
Go: impossible to tell which fields are required in a struct #2536
Labels
bug
This issue is a bug.
effort/medium
Medium work item – a couple days of effort
language/go
Regarding GoLang bindings
p2
Comments
5 tasks
7 tasks
RomainMuller
added a commit
that referenced
this issue
Apr 11, 2022
Adds a `required` or `optional` tag on struct fields to denote whether they are required or optional (obviously). This is a cheap-ass way to provide documentation visibility to users. This isn't perfect as ideally, one would want compile-time enforcement of these, however this isn't currently posisble with Go (we explored several options, including via the use of generics, but it did not end up with any particularly improved solution). Fixes #2536
RomainMuller
added a commit
that referenced
this issue
Apr 25, 2022
Adds a `field:"required"` or `field:"optional"` tag on struct fields to denote whether they are required or optional (obviously). This is a cheap-ass way to provide documentation visibility to users. This isn't perfect as ideally, one would want compile-time enforcement of these, however this isn't currently posisble with Go (we explored several options, including via the use of generics, but it did not end up with any particularly improved solution). This does however include runtime enforcement with a dedicated error message. Fixes #2536 Fixes #2672
Repository owner
moved this from In Review
to Done
in CDK Go General Availability
Apr 25, 2022
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug
This issue is a bug.
effort/medium
Medium work item – a couple days of effort
language/go
Regarding GoLang bindings
p2
🐛 Bug Report
Affected Languages
Golang
TypeScript
orJavascript
Python
Java
C#
,F#
, ...)General Information
What is the problem?
When generating Go structs from jsii data types, there is currently no indication (let alone compile-type check) to tell users which fields in the struct are required and which are optional:
Go output:
What are our options in Go to address this? At the minimum, we should obviously generate some documentation that indicates which fields are required and what are the default values. Is there a way to get type-checking help?
Addendum:
This issue tracks adding doc comments indicating which fields are
required
vsoptional
to ensure that this is available during autocompletion. IE, when a user starts typing a property name, the documentation for that property will be displayed in their IDE telling them whether the field is optional or required.There is an additional ticket to panic at runtime when required fields are nil #2672
The text was updated successfully, but these errors were encountered: