Skip to content

Commit 0755604

Browse files
docs: add market-data-unwrap example to documentation
- Add market-data-unwrap to examples README with feature matrix - Reference issue #86 in json-protobuf-compatibility guide Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 035906c commit 0755604

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

docs/examples/README.md

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ This starts a working HTTP API with user management, authentication, and OpenAPI
2727
| **[validation-showcase](../../examples/validation-showcase/)** | Order processing API | buf.validate patterns: string, numeric, array, map, nested validation |
2828
| **[nested-resources](../../examples/nested-resources/)** | Organization hierarchy API | Deep path nesting (3 levels), multiple path params per endpoint |
2929
| **[multi-service-api](../../examples/multi-service-api/)** | Multi-tenant platform | Multiple services, different auth levels, service/method headers |
30+
| **[market-data-unwrap](../../examples/market-data-unwrap/)** | Financial market data API | Unwrap annotation for map values, JSON/protobuf compatibility |
3031

3132
---
3233

@@ -98,6 +99,29 @@ cd examples/multi-service-api && make demo
9899
- Service-level headers applied to all methods
99100
- Method-level headers for specific operations (X-Confirm-Delete, X-Audit-Reason)
100101

102+
### market-data-unwrap
103+
Financial market data API demonstrating the `unwrap` annotation.
104+
- `(sebuf.http.unwrap)` annotation for cleaner JSON serialization
105+
- Map values serialized as arrays instead of wrapped objects
106+
- Real-world pattern from APIs like Alpaca Market Data
107+
108+
```bash
109+
cd examples/market-data-unwrap && make run # Start server
110+
cd examples/market-data-unwrap && make client # Run client example
111+
```
112+
113+
**JSON output with unwrap:**
114+
```json
115+
{"bars": {"TSLA": [{"c": 143.08, ...}]}}
116+
```
117+
118+
**Without unwrap (standard protobuf):**
119+
```json
120+
{"bars": {"TSLA": {"bars": [{"c": 143.08, ...}]}}}
121+
```
122+
123+
See [JSON/Protobuf Compatibility Guide](../json-protobuf-compatibility.md) for details.
124+
101125
---
102126

103127
## Running Examples
@@ -117,18 +141,19 @@ make clean # Remove generated files
117141

118142
## What Each Example Demonstrates
119143

120-
| Feature | simple-api | restful-crud | validation | nested | multi-service |
121-
|---------|:----------:|:------------:|:----------:|:------:|:-------------:|
122-
| HTTP verbs (GET/POST) | Yes | Yes | Yes | Yes | Yes |
123-
| PUT/PATCH/DELETE | - | Yes | - | Yes | Yes |
124-
| Path parameters | - | Yes | - | Yes | Yes |
125-
| Query parameters | - | Yes | - | Yes | - |
126-
| buf.validate | Basic | Basic | Comprehensive | Basic | Basic |
127-
| Header validation | - | Yes | - | - | Yes |
128-
| Multiple services | - | - | - | - | Yes |
129-
| Nested resources | - | - | - | Yes | - |
130-
| Oneof helpers | Yes | - | - | - | - |
131-
| **HTTP Client** | - | **Yes** | - | - | - |
144+
| Feature | simple-api | restful-crud | validation | nested | multi-service | market-data |
145+
|---------|:----------:|:------------:|:----------:|:------:|:-------------:|:-----------:|
146+
| HTTP verbs (GET/POST) | Yes | Yes | Yes | Yes | Yes | Yes |
147+
| PUT/PATCH/DELETE | - | Yes | - | Yes | Yes | - |
148+
| Path parameters | - | Yes | - | Yes | Yes | - |
149+
| Query parameters | - | Yes | - | Yes | - | Yes |
150+
| buf.validate | Basic | Basic | Comprehensive | Basic | Basic | Yes |
151+
| Header validation | - | Yes | - | - | Yes | Yes |
152+
| Multiple services | - | - | - | - | Yes | - |
153+
| Nested resources | - | - | - | Yes | - | - |
154+
| Oneof helpers | Yes | - | - | - | - | - |
155+
| **HTTP Client** | - | **Yes** | - | - | - | **Yes** |
156+
| **Unwrap annotation** | - | - | - | - | - | **Yes** |
132157

133158
---
134159

docs/json-protobuf-compatibility.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
55
Protobuf and JSON have different type systems and serialization behaviors. While sebuf handles most conversions automatically, some patterns require explicit annotations to produce the expected JSON output. This guide covers these edge cases and how to address them.
66

7+
> **Note**: The `unwrap` annotation was added to address [issue #86](https://github.com/SebastienMelki/sebuf/issues/86) - supporting unwrapped repeated fields in map values for JSON marshaling.
8+
79
## Table of Contents
810

911
- [Overview](#overview)

0 commit comments

Comments
 (0)