cloudfront: Go documentation examples for optional array fields cause compilation errors
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 267
- Avg merge
- 1d 25m
- Merged PRs (30d)
- 14
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
**[TypeScript source](https://github.com/aws/aws-cdk/blob/82c2fdb246557fa4804e2dc88ce16c28db52956c/packages/aws-cdk-lib/aws-cloudfront/lib/response-headers-policy.ts#L68):**
```typescript
/**
* 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[];
```
**[Generated Go type](https://pkg.go.dev/github.com/aws/aws-cdk-go/awscdk/v2/awscloudfront#ResponseHeadersPolicyProps):**
```go
RemoveHeaders *[]*string `field:"optional" json:"removeHeaders" yaml:"removeHeaders"`
```
**[Go Example Code](https://github.com/aws/aws-cdk-go/blob/29493a3ccc867f6424ec19b361571fc17f1ee809/awscdk/awscloudfront/ResponseHeadersPolicyProps.go#L83-L85):**
```go
// 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):
```go
// 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
Contributor guide
Research direction
Start by tracing the Rosetta TypeScript-to-Go documentation example generation described in the issue, then compare the TypeScript optional-array declarations with the generated Go types and examples for ResponseHeadersPolicyProps.RemoveHeaders and CertificateProps.SubjectAlternativeNames. Run the relevant documentation generation or validation flow if available; done means the generated examples compile with pointer-to-slice fields.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, typescript
- Domain
- documentation, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100