|
| 1 | +# TypeSketch — infer a type‑oriented YAML from JSON |
| 2 | +> A tiny CLI that reads JSON from stdin and emits a concise, type‑oriented YAML **TypeSketch** — perfect for docs, quick API archeology, and codegen stubs. |
| 3 | +
|
| 4 | +  |
| 5 | + |
| 6 | +## Why |
| 7 | +When exploring unfamiliar APIs, we often need a *human‑readable* schema sketch rather than a full JSON Schema. TypeSketch summarizes field shapes, union types, and common formats (url, datetime, email, html-string) directly from example payloads. |
| 8 | + |
| 9 | +## Features |
| 10 | +- Infer scalar/union types and simple format hints |
| 11 | +- Expand arrays of objects as proper YAML lists (no angle‑brackets) |
| 12 | +- Merge multiple objects into a unified shape sorted by field popularity |
| 13 | +- Configurable array sampling, depth, and indentation |
| 14 | +- Zero-deps runtime (only Python stdlib) |
| 15 | + |
| 16 | +## Quickstart |
| 17 | +```bash |
| 18 | +pipx install . # or: pip install -e . |
| 19 | +echo '{"id":1,"name":"X","tags":["a",2],"url":"https://x"}' | typesketch --root item |
| 20 | +``` |
| 21 | + |
| 22 | +Output: |
| 23 | +```yaml |
| 24 | +item: |
| 25 | + id: int |
| 26 | + name: string |
| 27 | + tags: |
| 28 | + - string | int |
| 29 | + url: url |
| 30 | +``` |
| 31 | +
|
| 32 | +## CLI |
| 33 | +```bash |
| 34 | +# Read JSON from stdin |
| 35 | +curl https://api.example.com/shops | typesketch |
| 36 | + |
| 37 | +# Use a custom root key and show stats |
| 38 | +cat data.json | typesketch --root Shops --stats |
| 39 | + |
| 40 | +# Treat single object as a one-item list |
| 41 | +cat item.json | typesketch --force-list |
| 42 | +``` |
| 43 | + |
| 44 | +See `typesketch --help`. |
| 45 | + |
| 46 | +## Software Curator Principles |
| 47 | +- **Curation-first**: ADRs under `docs/adr/` document naming, heuristics, and trade-offs. |
| 48 | +- **Reproducible**: Unit tests and golden fixtures in `tests/`. |
| 49 | +- **Auditable**: Minimal, readable functions with explicit heuristics and TODOs for future refinement. |
| 50 | +- **Extendable**: Clear seams for adding new detectors (currency, color-hex, uuid, etc.). |
| 51 | + |
| 52 | +## Roadmap |
| 53 | +- [ ] JSON Schema / OpenAPI emitters |
| 54 | +- [ ] Presence/requiredness stats |
| 55 | +- [ ] Friendly collapse rules for very deep objects |
| 56 | +- [ ] YAML → Markdown renderer for docs sites |
| 57 | +- [ ] Pluggable detector registry |
| 58 | +- [ ] Streaming mode for very large inputs |
| 59 | + |
| 60 | +## License |
| 61 | +MIT — see `LICENSE`. |
0 commit comments