autogen-squareup
Auto-generated, strongly-typed Rust client for the Square API.
Generated from the official Square OpenAPI spec using openapi-generator.
Installation
[]
= "0.1"
= { = "1", = ["macros", "rt-multi-thread"] }
To use only specific API groups (reduces compile time):
[]
= { = "0.1", = false, = ["payments", "customers", "native-tls"] }
Quick Start
use SquareClient;
use payments_api;
async
Environments
use SquareClient;
// Production (default)
let client = new;
// Sandbox
let client = sandbox;
// Explicit environment
use Environment;
let client = with_env;
Usage Examples
Create a Payment
use SquareClient;
use payments_api;
use ;
async
List Locations
use SquareClient;
use locations_api;
async
List Customers
use SquareClient;
use customers_api;
async
Feature Flags
All 44 API groups are enabled by default. Use default-features = false and select only what you need:
| Feature | API |
|---|---|
payments |
Payments |
orders |
Orders |
invoices |
Invoices |
customers |
Customers |
catalog |
Catalog |
inventory |
Inventory |
subscriptions |
Subscriptions |
bookings |
Bookings |
loyalty |
Loyalty |
gift-cards |
Gift Cards |
gift-card-activities |
Gift Card Activities |
labor |
Labor |
team |
Team |
locations |
Locations |
merchants |
Merchants |
oauth |
OAuth |
terminal |
Terminal |
disputes |
Disputes |
refunds |
Refunds |
checkout |
Checkout |
cards |
Cards |
bank-accounts |
Bank Accounts |
apple-pay |
Apple Pay |
cash-drawers |
Cash Drawers |
customer-groups |
Customer Groups |
customer-segments |
Customer Segments |
customer-custom-attributes |
Customer Custom Attributes |
booking-custom-attributes |
Booking Custom Attributes |
location-custom-attributes |
Location Custom Attributes |
merchant-custom-attributes |
Merchant Custom Attributes |
order-custom-attributes |
Order Custom Attributes |
devices |
Devices |
employees |
Employees |
events |
Events |
channels |
Channels |
mobile-authorization |
Mobile Authorization |
payouts |
Payouts |
sites |
Sites |
snippets |
Snippets |
transactions |
Transactions |
transfer-order |
Transfer Order |
v1-transactions |
V1 Transactions (deprecated) |
vendors |
Vendors |
webhook-subscriptions |
Webhook Subscriptions |
TLS features:
| Feature | Description |
|---|---|
native-tls |
Use system TLS (default) |
rustls |
Use rustls instead |
Nullable Fields
The Square API marks most fields as both optional and nullable. This crate correctly distinguishes between the three states using Option<Option<T>>:
// Field omitted from JSON (not sent)
field: None
// Field explicitly set to null
field: Some
// Field set to a value
field: Some
This uses serde_with::double_option under the hood, so serialization works correctly:
None— field is omitted from the request bodySome(None)— field is sent asnullSome(Some(v))— field is sent with the value
Regenerating from the Spec
To regenerate the client from the latest Square OpenAPI spec:
# Requires: brew install openapi-generator
This fetches the latest spec, runs the generator, applies post-processing fixes for known spec bugs, re-applies feature gates, and verifies compilation.
Architecture
- Types and API methods are auto-generated by openapi-generator from the official Square OpenAPI spec
SquareClientis a thin hand-written wrapper that handles auth (Bearer token) and environment switching (production/sandbox)- Generated code is committed — no build-time generation, no proc macros. Run
./generate.shto update when the spec changes.
Why Not squareup?
The existing squareup crate is hand-written. This crate is auto-generated from the spec, which avoids several issues:
| Issue | squareup |
autogen-squareup |
|---|---|---|
due_date type |
DateTime (wrong — spec says string) |
String |
| Nullable fields | Sends null (no skip_serializing_if) |
Omits field when None |
Money.amount |
i32 (truncates large values) |
i64 |
| Thread safety | env::set_var (unsafe in async) |
No global state |
| Nullable semantics | Single Option<T> |
Option<Option<T>> (omit vs null vs value) |
License
MIT