Skip to content

Commit f7f4ba1

Browse files
docs: add JSON/protobuf compatibility guide for unwrap feature
- Create new docs/json-protobuf-compatibility.md with comprehensive guide for handling map values that serialize as arrays - Update http-generation.md with unwrap annotation example - Update openapi-generation.md with unwrap schema mapping - Update client-generation.md with unwrap serialization note - Update getting-started.md with link to new compatibility guide - Update CLAUDE.md with unwrap annotation and test references Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 35681c1 commit f7f4ba1

File tree

6 files changed

+406
-0
lines changed

6 files changed

+406
-0
lines changed

CLAUDE.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,20 @@ service UserService {
151151
}
152152
```
153153

154+
**Unwrap Annotation** - For map values that should serialize as arrays in JSON:
155+
```protobuf
156+
// Wrapper message with unwrap annotation
157+
message BarList {
158+
repeated Bar bars = 1 [(sebuf.http.unwrap) = true];
159+
}
160+
161+
message Response {
162+
// JSON: {"bars": {"AAPL": [...], "GOOG": [...]}}
163+
// Without unwrap: {"bars": {"AAPL": {"bars": [...]}, ...}}
164+
map<string, BarList> bars = 1;
165+
}
166+
```
167+
154168
## Development Commands
155169

156170
### Testing
@@ -209,6 +223,7 @@ The project uses a comprehensive two-tier testing approach:
209223
- **Function-level testing**: Tests individual functions for HTTP and OpenAPI generators
210224
- **Mocked components**: Uses protogen mocks for isolated testing
211225
- **File locations**: internal/httpgen/ and internal/openapiv3/ test files
226+
- **Unwrap tests**: internal/httpgen/unwrap_test.go for map value unwrapping
212227

213228
## Validation System
214229

docs/client-generation.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ const (
181181
client := api.NewUserServiceClient("http://localhost:8080")
182182
```
183183

184+
The client automatically handles special JSON serialization, including messages with `unwrap` annotations for map values. See [JSON/Protobuf Compatibility](./json-protobuf-compatibility.md) for details.
185+
184186
### Binary Protobuf
185187

186188
For better performance with large payloads:

docs/getting-started.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ curl -X GET http://localhost:8080/api/v1/users/1
203203
- **[Client Generation Guide](./client-generation.md)** - Type-safe HTTP clients
204204
- **[OpenAPI Guide](./openapi-generation.md)** - Documentation customization
205205
- **[Validation Guide](./validation.md)** - Automatic request validation
206+
- **[JSON/Protobuf Compatibility](./json-protobuf-compatibility.md)** - Handling serialization edge cases
206207

207208
## More examples
208209

docs/http-generation.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,27 @@ message UploadFileRequest {
11691169
}
11701170
```
11711171

1172+
### Map with Array Values (Unwrap)
1173+
1174+
When you need a map where values are arrays (common in market data APIs):
1175+
1176+
```protobuf
1177+
import "sebuf/http/annotations.proto";
1178+
1179+
// Wrapper message with unwrap annotation
1180+
message BarList {
1181+
repeated Bar bars = 1 [(sebuf.http.unwrap) = true];
1182+
}
1183+
1184+
message GetBarsResponse {
1185+
// JSON output: {"bars": {"AAPL": [...], "GOOG": [...]}}
1186+
// Instead of: {"bars": {"AAPL": {"bars": [...]}, ...}}
1187+
map<string, BarList> bars = 1;
1188+
}
1189+
```
1190+
1191+
See [JSON and Protobuf Compatibility](./json-protobuf-compatibility.md) for complete details.
1192+
11721193
## Best Practices
11731194

11741195
### 1. Consistent URL Design
@@ -1426,6 +1447,7 @@ The OpenAPI spec will automatically reflect your HTTP annotations and routing.
14261447
**See also:**
14271448
- [Getting Started Guide](./getting-started.md)
14281449
- [Validation Guide](./validation.md)
1450+
- [JSON/Protobuf Compatibility](./json-protobuf-compatibility.md)
14291451
- [All Examples](./examples/)
14301452

14311453
**Feature-specific examples:**

0 commit comments

Comments
 (0)