Skip to content

Commit d877255

Browse files
author
Arturo R Montesinos
committed
Initial import of GPT-created project
0 parents  commit d877255

20 files changed

+410
-0
lines changed

.github/workflows/ci.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: CI
2+
on:
3+
push:
4+
pull_request:
5+
6+
jobs:
7+
test:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
- uses: actions/setup-python@v5
12+
with:
13+
python-version: "3.11"
14+
- name: Install
15+
run: |
16+
python -m pip install --upgrade pip
17+
pip install -e .
18+
pip install pytest
19+
- name: Tests
20+
run: pytest -q

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
__pycache__/
2+
.pytest_cache/
3+
.venv/
4+
dist/
5+
build/
6+
*.egg-info/
7+
.coverage
8+
.DS_Store
9+
.idea/
10+
.vscode/

.pre-commit-config.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
repos:
2+
- repo: https://github.com/psf/black
3+
rev: 24.8.0
4+
hooks:
5+
- id: black
6+
- repo: https://github.com/pycqa/ruff-pre-commit
7+
rev: v0.6.3
8+
hooks:
9+
- id: ruff
10+
args: [--fix]
11+
- repo: https://github.com/pre-commit/mirrors-mypy
12+
rev: v1.10.0
13+
hooks:
14+
- id: mypy
15+
additional_dependencies: []

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.PHONY: format lint test
2+
format:
3+
pre-commit run --all-files || true
4+
lint:
5+
ruff src tests
6+
test:
7+
pytest -q

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
![status-badge](https://img.shields.io/badge/status-experimental-blue) ![license](https://img.shields.io/badge/license-MIT-green)
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`.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# ADR-0001: Name and Scope
2+
**Status**: Accepted
3+
4+
We name the tool **TypeSketch**: a concise type‑oriented YAML derived from JSON samples.
5+
Scope: exploration and documentation; not a full validator. JSON Schema/OpenAPI output may be added later.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# ADR-0002: Language & Packaging
2+
**Status**: Accepted
3+
4+
Python 3.9+ for a zero‑deps CLI (`typesketch`) installed via pip/pipx.

docs/adr/ADR-0003-heuristics.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# ADR-0003: Inference Heuristics
2+
**Status**: Accepted
3+
4+
- Scalar types: int, number, boolean, null, string.
5+
- Simple format hints: url, email, datetime, html-string.
6+
- Arrays: merge shapes of item objects; scalar arrays use union (`string | int`).
7+
- Key ordering: by frequency desc, then alpha as tiebreaker.
8+
- Limits: arrays are sampled (default 200). No deep recursion guards yet.

docs/curation/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Curation Notes
2+
This folder captures the Software Curator rationale behind architectural decisions and heuristics.

0 commit comments

Comments
 (0)