Commit 0f331c7
authored
Fix documentation loss for attribute fields (#626)
Description of changes:
Fields marked with `is_attribute: true` were intermittently losing their documentation comments during code generation. These fields get processed twice:
1. From AWS SDK model (with documentation)
2. From attribute unpacking (with `nil` ShapeRef, losing documentation)
The issue was **non-deterministic** - sometimes documentation was preserved, sometimes it was lost, even with identical configuration.
**Cause**
The execution order depended on **Go's randomized map iteration** in `pkg/model/model.go`:
```go
for memberName, memberShapeRef := range inputShape.MemberRefs {
```
Since both field creation paths store to the same map location (`r.Fields[fPath]`), whichever runs **last wins**:
- **Lucky order**: Attribute unpacking → AWS SDK processing = Documentation preserved
- **Unlucky order**: AWS SDK processing → Attribute unpacking = Documentation lost
The `UnpackAttributes()` method called `NewField()` with `nil` ShapeRef:
```go
f := NewField(r, fPath, fieldNames, nil, fieldConfig)
```
This caused fallback to `simpleStringShapeRef` which has no documentation.
This explains why the issue seemed random and why adding unrelated config changes could "trigger" the problem.
**Solution**
This makes documentation preservation **deterministic** regardless of execution order:
- **If attribute unpacking runs first**: No existing field found → uses `nil` ShapeRef -> SDK run adds the documentation
- **If AWS SDK processing runs first**: Existing documented field found → reuses documented ShapeRef
In both cases, the final result preserves documentation when available.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.1 parent 82d9fa6 commit 0f331c7
1 file changed
+8
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
299 | 299 | | |
300 | 300 | | |
301 | 301 | | |
302 | | - | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
303 | 310 | | |
304 | 311 | | |
305 | 312 | | |
| |||
0 commit comments