You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FastAPI plugin for automatic OpenAPI schema generation from [msgspec](https://github.com/jcrist/msgspec) structs. Enables Swagger UI documentation and TypeScript type generation.
4
9
5
10
## Features
@@ -64,6 +69,27 @@ MsgSpecPlugin.inject(app)
64
69
# ✅ Full OpenAPI documentation (developer experience)
65
70
```
66
71
72
+
## Why msgspec Over Pydantic?
73
+
74
+
**Performance**: msgspec is significantly faster than Pydantic for serialization:
75
+
76
+
- 5-10x faster serialization
77
+
- Lower memory usage
78
+
- Native JSON encoding
79
+
80
+
**When to use this plugin**:
81
+
82
+
- ✅ High-throughput APIs
83
+
- ✅ Performance-critical services
84
+
- ✅ You want msgspec speed + OpenAPI docs
85
+
- ✅ TypeScript type generation needed
86
+
87
+
**When to stick with Pydantic**:
88
+
89
+
- ❌ Complex validation logic (Pydantic has richer validation)
90
+
- ❌ ORM integration (Pydantic works better with SQLAlchemy)
91
+
- ❌ You don't need extreme performance
92
+
67
93
## TypeScript Type Generation
68
94
69
95
Generate TypeScript types from your OpenAPI schema:
@@ -136,18 +162,77 @@ The plugin handles `Optional`, `list`, and other generic types automatically.
136
162
3.**Response updates** - Patches FastAPI's OpenAPI schema to reference your structs
137
163
4.**Caching** - Schema generation happens once, then cached
138
164
165
+
## Limitations & Design Decisions
166
+
167
+
### Why `response_model=Any`?
168
+
169
+
FastAPI tries to validate/serialize the response using Pydantic when you specify a `response_model`. Since we're using msgspec structs (not Pydantic models), we use `Any` to bypass FastAPI's response handling:
0 commit comments