-
Notifications
You must be signed in to change notification settings - Fork 263
Open
Labels
documentationThis is a problem with documentation.This is a problem with documentation.effort/mediumMedium work item – a couple days of effortMedium work item – a couple days of effortlanguage/goRegarding GoLang bindingsRegarding GoLang bindingsp2
Description
Describe the issue
The code examples in the official CDK Go documentation fail to compile when copied directly.
This occurs with optional array fields, where there is a type mismatch in the generated examples.
Details:
- When a TypeScript property is defined as an optional array (e.g.,
removeHeaders?: string[]), jsii correctly generates the Go type as
*[]*string(pointer to a slice) - However, the documentation examples show code that assigns
[]*string(a slice) directly to this field, which causes a type mismatch and compilation failure
This affects multiple packages across CDK, including:
@aws-cdk/aws-cloudfront-ResponseHeadersPolicyProps.RemoveHeaders@aws-cdk/aws-certificatemanager-CertificateProps.SubjectAlternativeNames
Example from CloudFront documentation
/**
* A list of HTTP response headers that CloudFront removes from HTTP responses
* that it sends to viewers.
*
* @default - no headers are removed
*/
readonly removeHeaders?: string[];RemoveHeaders *[]*string `field:"optional" json:"removeHeaders" yaml:"removeHeaders"`// RemoveHeaders: []*string{
// jsii.String("Server"),
// },Compilation error:
cannot use []*string{...} (value of type []*string) as type *[]*string in struct literal
Working code (not shown in documentation):
// Option 1: Take address of slice literal
myResponseHeadersPolicy := cloudfront.NewResponseHeadersPolicy(this, jsii.String("ResponseHeadersPolicy"), &ResponseHeadersPolicyProps{
RemoveHeaders: &[]*string{jsii.String("Server")},
})
// Option 2: Use intermediate variable
headers := []*string{jsii.String("Server")}
myResponseHeadersPolicy := cloudfront.NewResponseHeadersPolicy(this, jsii.String("ResponseHeadersPolicy"), &ResponseHeadersPolicyProps{
RemoveHeaders: &headers,
})This appears to be a Rosetta (TypeScript-to-Go translation tool) issue. The generated examples don't account for the fact that *[]*string requires a pointer to a slice, not a slice directly.
Links
- CloudFront Go API docs: https://pkg.go.dev/github.com/aws/aws-cdk-go/awscdk/v2/awscloudfront#ResponseHeadersPolicyProps
- CloudFront Go Example Code: https://github.com/aws/aws-cdk-go/blob/29493a3ccc867f6424ec19b361571fc17f1ee809/awscdk/awscloudfront/ResponseHeadersPolicyProps.go#L83-L85
- TypeScript source (CloudFront): https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-cloudfront/lib/response-headers-policy.ts#L68
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
documentationThis is a problem with documentation.This is a problem with documentation.effort/mediumMedium work item – a couple days of effortMedium work item – a couple days of effortlanguage/goRegarding GoLang bindingsRegarding GoLang bindingsp2