Code generation for surety contracts
Project description
surety-scaffold
Code generation toolkit for the surety contract-testing framework.
Bootstraps surety schemas, contracts, callers, and test scaffolding from existing JSON payloads, JSON Schema, and OpenAPI specs — so you can start contract-based testing without writing boilerplate by hand.
Installation
pip install surety-scaffold
Requires surety>=0.0.4.
Features
Extract contract from JSON
Turn a raw JSON payload into surety Dictionary class definitions.
Programmatic:
import json
from surety.scaffold import extract_from_json
payload = json.dumps({
"order_id": 42,
"status": "pending",
"total": 199.99,
"is_express": False,
"customer": {
"customer_id": 7,
"email": "jane@example.com"
},
"items": [
{"sku": "ABC-1", "qty": 2}
]
})
print(extract_from_json(payload, class_name="Order"))
Output:
from surety import Array, Bool, Dictionary, Float, Int, String
class Customer(Dictionary):
CustomerId = Int(name='customer_id', required=True)
Email = String(name='email', required=True)
class Items(Dictionary):
Sku = String(name='sku', required=True)
Qty = Int(name='qty', required=True)
class Order(Dictionary):
OrderId = Int(name='order_id', required=True)
Status = String(name='status', required=True)
Total = Float(name='total', required=True)
IsExpress = Bool(name='is_express', required=True)
Customer = Customer(name='customer', required=True)
Items = Array(Items, name='items', required=True)
Type inference rules:
| JSON value | Surety type |
|---|---|
true / false |
Bool |
| integer | Int |
| float | Float |
| UUID string | Uuid |
| ISO 8601 datetime or date string | DateTime |
| any other string | String |
object {} |
nested Dictionary subclass |
| array of objects | Array(NestedClass, ...) |
| array of primitives | Array(PrimitiveType, ...) |
null |
String(allow_none=True) |
Nested objects produce their own Dictionary subclass and are always emitted before the class that references them. Arrays of objects merge all items across the array to capture the full set of fields. Duplicate class names (same key appearing at different nesting levels) are disambiguated automatically with a numeric suffix.
Key naming:
JSON keys are converted to PascalCase for both the class attribute name and the generated class name. snake_case, camelCase, and kebab-case are all handled.
CLI:
# Pass JSON as an argument
surety-scaffold '{"order_id": 1, "status": "pending"}' --class-name Order
# Pipe from a file or command
cat response.json | surety-scaffold --class-name Order
# Skip clipboard copy
surety-scaffold '{"x": 1}' --no-clipboard
The result is printed to stdout and automatically copied to the clipboard (pbcopy on macOS, xclip on Linux).
usage: surety-scaffold [-h] [--class-name CLASS_NAME] [--no-clipboard] [json]
positional arguments:
json JSON string to extract from. Reads from stdin if omitted.
options:
--class-name, -c Name for the top-level generated class (default: Schema).
--no-clipboard Do not copy the result to the clipboard.
Roadmap
The following features are planned for this library. They complement the core surety framework with static analysis, code generation, and developer tooling.
In scope for surety-scaffold
| # | Feature | Status |
|---|---|---|
| 1 | Extract contract from JSON — infer surety schemas from raw API responses | done |
| 4 | Parse JSON Schema / OpenAPI — generate surety Dictionary classes from JSON Schema or OpenAPI 3.x specs, resolving $ref and mapping constraints |
planned |
| 5 | Generate callers — produce ApiContract boilerplate and caller function stubs from OpenAPI operations |
planned |
| 12 | Generate test scenarios (basic) — scaffold positive pytest test cases (required fields, full fields, with_values overrides) for a given contract |
planned |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file surety_scaffold-0.0.1.tar.gz.
File metadata
- Download URL: surety_scaffold-0.0.1.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e8419de3b62a54b9a9b42ce71f5ba76b482dba58778aac54a65d92568b641e6
|
|
| MD5 |
47f8c91cf58cd8d58715aee3a7ddc293
|
|
| BLAKE2b-256 |
ba00198fb2126957ab8df70b605981856d600413f25849d5a555d6aedfd07542
|
File details
Details for the file surety_scaffold-0.0.1-py3-none-any.whl.
File metadata
- Download URL: surety_scaffold-0.0.1-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b411c8a64e1cee5a1e944287d36aef79873bf2223631488b7defb040c69dc00
|
|
| MD5 |
1976789e6d3510c41b511c8476ccaffb
|
|
| BLAKE2b-256 |
edc98a9176b40acde22334adea7a1e0d09da14b338f67f3201686e4a11581f15
|