Type Imports
Share types between contracts with import
API Definition
config/apis/calm_turtle.rb
rb
# frozen_string_literal: true
Apiwork::API.define '/calm_turtle' do
key_format :camel
export :openapi
export :apiwork
resources :customers
resources :orders
endModels
app/models/calm_turtle/customer.rb
rb
# frozen_string_literal: true
module CalmTurtle
class Customer < ApplicationRecord
validates :name, presence: true
end
endDatabase Table
| Column | Type | Nullable | Default |
|---|---|---|---|
| id | string | ||
| billing_address | json | ✓ | |
| created_at | datetime | ||
| name | string | ||
| updated_at | datetime |
app/models/calm_turtle/order.rb
rb
# frozen_string_literal: true
module CalmTurtle
class Order < ApplicationRecord
validates :order_number, presence: true
end
endDatabase Table
| Column | Type | Nullable | Default |
|---|---|---|---|
| id | string | ||
| created_at | datetime | ||
| order_number | string | ||
| shipping_address | json | ✓ | |
| updated_at | datetime |
Contracts
app/contracts/calm_turtle/customer_contract.rb
rb
# frozen_string_literal: true
module CalmTurtle
class CustomerContract < Apiwork::Contract::Base
object :address do
string :street
string :city
string :country
end
object :customer do
uuid :id
string :name
reference :billing_address, to: :address
datetime :created_at
datetime :updated_at
end
object :create_payload do
string :name
reference :billing_address, to: :address
end
action :create do
request do
body do
reference :customer, to: :create_payload
end
end
response do
body do
reference :customer
end
end
end
end
endapp/contracts/calm_turtle/order_contract.rb
rb
# frozen_string_literal: true
module CalmTurtle
class OrderContract < Apiwork::Contract::Base
import CustomerContract, as: :customer
object :order do
uuid :id
string :order_number
reference :shipping_address, to: :customer_address
datetime :created_at
datetime :updated_at
end
object :create_payload do
string :order_number
reference :shipping_address, to: :customer_address
end
action :create do
request do
body do
reference :order, to: :create_payload
end
end
response do
body do
reference :order
end
end
end
end
endControllers
app/controllers/calm_turtle/orders_controller.rb
rb
# frozen_string_literal: true
module CalmTurtle
class OrdersController < ApplicationController
def create
order = Order.create(contract.body[:order])
expose({ order: })
end
end
endRequest Examples
Create order
Request
http
POST /calm_turtle/orders
Content-Type: application/json
{
"order": {
"orderNumber": "ORD-001",
"shippingAddress": {
"street": "456 Oak Ave",
"city": "Shelbyville",
"country": "US"
}
}
}Response 201
json
{
"order": {
"id": "f951f663-b887-5470-8c0c-03e090cd26eb",
"createdAt": "2026-04-01T12:00:00.000Z",
"orderNumber": "ORD-001",
"shippingAddress": {
"street": "456 Oak Ave",
"city": "Shelbyville",
"country": "US"
},
"updatedAt": "2026-04-01T12:00:00.000Z"
}
}Exports
OpenAPI
yml
---
openapi: 3.1.0
info:
title: "/calm_turtle"
version: 1.0.0
paths:
"/customers":
get:
operationId: customersIndex
responses:
'200':
content:
application/json:
schema: {}
description: ''
post:
operationId: customersCreate
requestBody:
content:
application/json:
schema:
properties:
customer:
"$ref": "#/components/schemas/customerCreatePayload"
type: object
required:
- customer
required: true
responses:
'200':
content:
application/json:
schema:
properties:
customer:
"$ref": "#/components/schemas/customer"
type: object
required:
- customer
description: ''
"/customers/{id}":
get:
operationId: customersShow
parameters:
- in: path
name: id
required: true
schema:
type: string
responses:
'200':
content:
application/json:
schema: {}
description: ''
patch:
operationId: customersUpdate
parameters:
- in: path
name: id
required: true
schema:
type: string
responses:
'200':
content:
application/json:
schema: {}
description: ''
delete:
operationId: customersDestroy
parameters:
- in: path
name: id
required: true
schema:
type: string
responses:
'200':
content:
application/json:
schema: {}
description: ''
"/orders":
get:
operationId: ordersIndex
responses:
'200':
content:
application/json:
schema: {}
description: ''
post:
operationId: ordersCreate
requestBody:
content:
application/json:
schema:
properties:
order:
"$ref": "#/components/schemas/orderCreatePayload"
type: object
required:
- order
required: true
responses:
'200':
content:
application/json:
schema:
properties:
order:
"$ref": "#/components/schemas/order"
type: object
required:
- order
description: ''
"/orders/{id}":
get:
operationId: ordersShow
parameters:
- in: path
name: id
required: true
schema:
type: string
responses:
'200':
content:
application/json:
schema: {}
description: ''
patch:
operationId: ordersUpdate
parameters:
- in: path
name: id
required: true
schema:
type: string
responses:
'200':
content:
application/json:
schema: {}
description: ''
delete:
operationId: ordersDestroy
parameters:
- in: path
name: id
required: true
schema:
type: string
responses:
'200':
content:
application/json:
schema: {}
description: ''
components:
schemas:
customer:
properties:
billingAddress:
"$ref": "#/components/schemas/customerAddress"
createdAt:
type: string
format: date-time
id:
type: string
format: uuid
name:
type: string
updatedAt:
type: string
format: date-time
type: object
required:
- billingAddress
- createdAt
- id
- name
- updatedAt
customerAddress:
properties:
city:
type: string
country:
type: string
street:
type: string
type: object
required:
- city
- country
- street
customerCreatePayload:
properties:
billingAddress:
"$ref": "#/components/schemas/customerAddress"
name:
type: string
type: object
required:
- billingAddress
- name
order:
properties:
createdAt:
type: string
format: date-time
id:
type: string
format: uuid
orderNumber:
type: string
shippingAddress:
"$ref": "#/components/schemas/customerAddress"
updatedAt:
type: string
format: date-time
type: object
required:
- createdAt
- id
- orderNumber
- shippingAddress
- updatedAt
orderCreatePayload:
properties:
orderNumber:
type: string
shippingAddress:
"$ref": "#/components/schemas/customerAddress"
type: object
required:
- orderNumber
- shippingAddressApiwork
json
{
"base_path": "/calm_turtle",
"enums": [],
"error_codes": [],
"fingerprint": "2e3af20641d12b5f",
"info": null,
"locales": [],
"resources": [
{
"actions": [
{
"name": "customers.index",
"deprecated": null,
"description": null,
"method": "get",
"operation_id": null,
"path": "/customers",
"raises": [],
"request": {
"body": [],
"description": null,
"query": []
},
"response": {
"body": {
"deprecated": null,
"description": null,
"nullable": null,
"optional": null,
"type": ""
},
"description": null,
"no_content": false
},
"summary": null,
"tags": []
},
{
"name": "customers.show",
"deprecated": null,
"description": null,
"method": "get",
"operation_id": null,
"path": "/customers/:id",
"raises": [],
"request": {
"body": [],
"description": null,
"query": []
},
"response": {
"body": {
"deprecated": null,
"description": null,
"nullable": null,
"optional": null,
"type": ""
},
"description": null,
"no_content": false
},
"summary": null,
"tags": []
},
{
"name": "customers.create",
"deprecated": false,
"description": null,
"method": "post",
"operation_id": null,
"path": "/customers",
"raises": [],
"request": {
"body": [
{
"name": "customer",
"deprecated": false,
"description": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "customer_create_payload"
}
],
"description": null,
"query": []
},
"response": {
"body": {
"deprecated": null,
"description": null,
"nullable": null,
"optional": null,
"type": "object",
"partial": null,
"shape": [
{
"name": "customer",
"deprecated": false,
"description": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "customer"
}
]
},
"description": null,
"no_content": false
},
"summary": null,
"tags": []
},
{
"name": "customers.update",
"deprecated": null,
"description": null,
"method": "patch",
"operation_id": null,
"path": "/customers/:id",
"raises": [],
"request": {
"body": [],
"description": null,
"query": []
},
"response": {
"body": {
"deprecated": null,
"description": null,
"nullable": null,
"optional": null,
"type": ""
},
"description": null,
"no_content": false
},
"summary": null,
"tags": []
},
{
"name": "customers.destroy",
"deprecated": null,
"description": null,
"method": "delete",
"operation_id": null,
"path": "/customers/:id",
"raises": [],
"request": {
"body": [],
"description": null,
"query": []
},
"response": {
"body": {
"deprecated": null,
"description": null,
"nullable": null,
"optional": null,
"type": ""
},
"description": null,
"no_content": false
},
"summary": null,
"tags": []
}
],
"identifier": "customers",
"name": "customers",
"parent_identifiers": [],
"path": "customers",
"resources": [],
"scope": "customer"
},
{
"actions": [
{
"name": "orders.index",
"deprecated": null,
"description": null,
"method": "get",
"operation_id": null,
"path": "/orders",
"raises": [],
"request": {
"body": [],
"description": null,
"query": []
},
"response": {
"body": {
"deprecated": null,
"description": null,
"nullable": null,
"optional": null,
"type": ""
},
"description": null,
"no_content": false
},
"summary": null,
"tags": []
},
{
"name": "orders.show",
"deprecated": null,
"description": null,
"method": "get",
"operation_id": null,
"path": "/orders/:id",
"raises": [],
"request": {
"body": [],
"description": null,
"query": []
},
"response": {
"body": {
"deprecated": null,
"description": null,
"nullable": null,
"optional": null,
"type": ""
},
"description": null,
"no_content": false
},
"summary": null,
"tags": []
},
{
"name": "orders.create",
"deprecated": false,
"description": null,
"method": "post",
"operation_id": null,
"path": "/orders",
"raises": [],
"request": {
"body": [
{
"name": "order",
"deprecated": false,
"description": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "order_create_payload"
}
],
"description": null,
"query": []
},
"response": {
"body": {
"deprecated": null,
"description": null,
"nullable": null,
"optional": null,
"type": "object",
"partial": null,
"shape": [
{
"name": "order",
"deprecated": false,
"description": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "order"
}
]
},
"description": null,
"no_content": false
},
"summary": null,
"tags": []
},
{
"name": "orders.update",
"deprecated": null,
"description": null,
"method": "patch",
"operation_id": null,
"path": "/orders/:id",
"raises": [],
"request": {
"body": [],
"description": null,
"query": []
},
"response": {
"body": {
"deprecated": null,
"description": null,
"nullable": null,
"optional": null,
"type": ""
},
"description": null,
"no_content": false
},
"summary": null,
"tags": []
},
{
"name": "orders.destroy",
"deprecated": null,
"description": null,
"method": "delete",
"operation_id": null,
"path": "/orders/:id",
"raises": [],
"request": {
"body": [],
"description": null,
"query": []
},
"response": {
"body": {
"deprecated": null,
"description": null,
"nullable": null,
"optional": null,
"type": ""
},
"description": null,
"no_content": false
},
"summary": null,
"tags": []
}
],
"identifier": "orders",
"name": "orders",
"parent_identifiers": [],
"path": "orders",
"resources": [],
"scope": "order"
}
],
"types": [
{
"recursive": false,
"deprecated": false,
"description": null,
"example": null,
"name": "customer_address",
"scope": "customer",
"type": "object",
"extends": [],
"shape": [
{
"name": "city",
"deprecated": false,
"description": null,
"nullable": false,
"optional": false,
"type": "string",
"example": null,
"format": null,
"max": null,
"min": null
},
{
"name": "country",
"deprecated": false,
"description": null,
"nullable": false,
"optional": false,
"type": "string",
"example": null,
"format": null,
"max": null,
"min": null
},
{
"name": "street",
"deprecated": false,
"description": null,
"nullable": false,
"optional": false,
"type": "string",
"example": null,
"format": null,
"max": null,
"min": null
}
]
},
{
"recursive": false,
"deprecated": false,
"description": null,
"example": null,
"name": "customer",
"scope": "customer",
"type": "object",
"extends": [],
"shape": [
{
"name": "billingAddress",
"deprecated": false,
"description": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "customer_address"
},
{
"name": "createdAt",
"deprecated": false,
"description": null,
"nullable": false,
"optional": false,
"type": "datetime",
"example": null
},
{
"name": "id",
"deprecated": false,
"description": null,
"nullable": false,
"optional": false,
"type": "uuid",
"example": null
},
{
"name": "name",
"deprecated": false,
"description": null,
"nullable": false,
"optional": false,
"type": "string",
"example": null,
"format": null,
"max": null,
"min": null
},
{
"name": "updatedAt",
"deprecated": false,
"description": null,
"nullable": false,
"optional": false,
"type": "datetime",
"example": null
}
]
},
{
"recursive": false,
"deprecated": false,
"description": null,
"example": null,
"name": "customer_create_payload",
"scope": "customer",
"type": "object",
"extends": [],
"shape": [
{
"name": "billingAddress",
"deprecated": false,
"description": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "customer_address"
},
{
"name": "name",
"deprecated": false,
"description": null,
"nullable": false,
"optional": false,
"type": "string",
"example": null,
"format": null,
"max": null,
"min": null
}
]
},
{
"recursive": false,
"deprecated": false,
"description": null,
"example": null,
"name": "order",
"scope": "order",
"type": "object",
"extends": [],
"shape": [
{
"name": "createdAt",
"deprecated": false,
"description": null,
"nullable": false,
"optional": false,
"type": "datetime",
"example": null
},
{
"name": "id",
"deprecated": false,
"description": null,
"nullable": false,
"optional": false,
"type": "uuid",
"example": null
},
{
"name": "orderNumber",
"deprecated": false,
"description": null,
"nullable": false,
"optional": false,
"type": "string",
"example": null,
"format": null,
"max": null,
"min": null
},
{
"name": "shippingAddress",
"deprecated": false,
"description": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "customer_address"
},
{
"name": "updatedAt",
"deprecated": false,
"description": null,
"nullable": false,
"optional": false,
"type": "datetime",
"example": null
}
]
},
{
"recursive": false,
"deprecated": false,
"description": null,
"example": null,
"name": "order_create_payload",
"scope": "order",
"type": "object",
"extends": [],
"shape": [
{
"name": "orderNumber",
"deprecated": false,
"description": null,
"nullable": false,
"optional": false,
"type": "string",
"example": null,
"format": null,
"max": null,
"min": null
},
{
"name": "shippingAddress",
"deprecated": false,
"description": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "customer_address"
}
]
}
]
}Codegen
TypeScript
ts
export interface CustomerAddress {
city: string;
country: string;
street: string;
}
export interface Customer {
billingAddress: CustomerAddress;
createdAt: string;
id: string;
name: string;
updatedAt: string;
}
export interface CustomerCreatePayload {
billingAddress: CustomerAddress;
name: string;
}ts
export * from './customer';
export * from './order';ts
import type { CustomerAddress } from './customer';
export interface Order {
createdAt: string;
id: string;
orderNumber: string;
shippingAddress: CustomerAddress;
updatedAt: string;
}
export interface OrderCreatePayload {
orderNumber: string;
shippingAddress: CustomerAddress;
}ts
import type { Customer, CustomerCreatePayload } from '../domains/customer';
export type CustomersIndexMethod = 'GET';
export type CustomersIndexPath = '/customers';
export type CustomersIndexResponseBody = undefined;
export interface CustomersIndexResponse {
body: CustomersIndexResponseBody;
}
export interface CustomersIndex {
method: CustomersIndexMethod;
path: CustomersIndexPath;
response: CustomersIndexResponse;
}
export type CustomersShowMethod = 'GET';
export type CustomersShowPath = '/customers/:id';
export interface CustomersShowPathParams {
id: string;
}
export type CustomersShowResponseBody = undefined;
export interface CustomersShowResponse {
body: CustomersShowResponseBody;
}
export interface CustomersShow {
method: CustomersShowMethod;
path: CustomersShowPath;
pathParams: CustomersShowPathParams;
response: CustomersShowResponse;
}
export type CustomersCreateMethod = 'POST';
export type CustomersCreatePath = '/customers';
export interface CustomersCreateRequestBody {
customer: CustomerCreatePayload;
}
export type CustomersCreateResponseBody = { customer: Customer };
export interface CustomersCreateRequest {
body: CustomersCreateRequestBody;
}
export interface CustomersCreateResponse {
body: CustomersCreateResponseBody;
}
export interface CustomersCreate {
method: CustomersCreateMethod;
path: CustomersCreatePath;
request: CustomersCreateRequest;
response: CustomersCreateResponse;
}
export type CustomersUpdateMethod = 'PATCH';
export type CustomersUpdatePath = '/customers/:id';
export interface CustomersUpdatePathParams {
id: string;
}
export type CustomersUpdateResponseBody = undefined;
export interface CustomersUpdateResponse {
body: CustomersUpdateResponseBody;
}
export interface CustomersUpdate {
method: CustomersUpdateMethod;
path: CustomersUpdatePath;
pathParams: CustomersUpdatePathParams;
response: CustomersUpdateResponse;
}
export type CustomersDestroyMethod = 'DELETE';
export type CustomersDestroyPath = '/customers/:id';
export interface CustomersDestroyPathParams {
id: string;
}
export type CustomersDestroyResponseBody = undefined;
export interface CustomersDestroyResponse {
body: CustomersDestroyResponseBody;
}
export interface CustomersDestroy {
method: CustomersDestroyMethod;
path: CustomersDestroyPath;
pathParams: CustomersDestroyPathParams;
response: CustomersDestroyResponse;
}ts
export * from './customers';
export * from './orders';ts
import type { Order, OrderCreatePayload } from '../domains/order';
export type OrdersIndexMethod = 'GET';
export type OrdersIndexPath = '/orders';
export type OrdersIndexResponseBody = undefined;
export interface OrdersIndexResponse {
body: OrdersIndexResponseBody;
}
export interface OrdersIndex {
method: OrdersIndexMethod;
path: OrdersIndexPath;
response: OrdersIndexResponse;
}
export type OrdersShowMethod = 'GET';
export type OrdersShowPath = '/orders/:id';
export interface OrdersShowPathParams {
id: string;
}
export type OrdersShowResponseBody = undefined;
export interface OrdersShowResponse {
body: OrdersShowResponseBody;
}
export interface OrdersShow {
method: OrdersShowMethod;
path: OrdersShowPath;
pathParams: OrdersShowPathParams;
response: OrdersShowResponse;
}
export type OrdersCreateMethod = 'POST';
export type OrdersCreatePath = '/orders';
export interface OrdersCreateRequestBody {
order: OrderCreatePayload;
}
export type OrdersCreateResponseBody = { order: Order };
export interface OrdersCreateRequest {
body: OrdersCreateRequestBody;
}
export interface OrdersCreateResponse {
body: OrdersCreateResponseBody;
}
export interface OrdersCreate {
method: OrdersCreateMethod;
path: OrdersCreatePath;
request: OrdersCreateRequest;
response: OrdersCreateResponse;
}
export type OrdersUpdateMethod = 'PATCH';
export type OrdersUpdatePath = '/orders/:id';
export interface OrdersUpdatePathParams {
id: string;
}
export type OrdersUpdateResponseBody = undefined;
export interface OrdersUpdateResponse {
body: OrdersUpdateResponseBody;
}
export interface OrdersUpdate {
method: OrdersUpdateMethod;
path: OrdersUpdatePath;
pathParams: OrdersUpdatePathParams;
response: OrdersUpdateResponse;
}
export type OrdersDestroyMethod = 'DELETE';
export type OrdersDestroyPath = '/orders/:id';
export interface OrdersDestroyPathParams {
id: string;
}
export type OrdersDestroyResponseBody = undefined;
export interface OrdersDestroyResponse {
body: OrdersDestroyResponseBody;
}
export interface OrdersDestroy {
method: OrdersDestroyMethod;
path: OrdersDestroyPath;
pathParams: OrdersDestroyPathParams;
response: OrdersDestroyResponse;
}Zod
ts
import * as z from 'zod';
export const CustomerAddressSchema = z.object({
city: z.string(),
country: z.string(),
street: z.string(),
});
export const CustomerSchema = z.object({
billingAddress: CustomerAddressSchema,
createdAt: z.iso.datetime(),
id: z.uuid(),
name: z.string(),
updatedAt: z.iso.datetime(),
});
export const CustomerCreatePayloadSchema = z.object({
billingAddress: CustomerAddressSchema,
name: z.string(),
});
export interface CustomerAddress {
city: string;
country: string;
street: string;
}
export interface Customer {
billingAddress: CustomerAddress;
createdAt: string;
id: string;
name: string;
updatedAt: string;
}
export interface CustomerCreatePayload {
billingAddress: CustomerAddress;
name: string;
}ts
export * from './customer';
export * from './order';ts
import type { CustomerAddress } from './customer';
import * as z from 'zod';
import { CustomerAddressSchema } from './customer';
export const OrderSchema = z.object({
createdAt: z.iso.datetime(),
id: z.uuid(),
orderNumber: z.string(),
shippingAddress: CustomerAddressSchema,
updatedAt: z.iso.datetime(),
});
export const OrderCreatePayloadSchema = z.object({
orderNumber: z.string(),
shippingAddress: CustomerAddressSchema,
});
export interface Order {
createdAt: string;
id: string;
orderNumber: string;
shippingAddress: CustomerAddress;
updatedAt: string;
}
export interface OrderCreatePayload {
orderNumber: string;
shippingAddress: CustomerAddress;
}ts
import type { Customer, CustomerCreatePayload } from '../domains/customer';
import * as z from 'zod';
import {
CustomerCreatePayloadSchema,
CustomerSchema,
} from '../domains/customer';
export const CustomersIndexResponseBodySchema = undefined;
export const CustomersShowPathParamsSchema = z.object({ id: z.string() });
export const CustomersShowResponseBodySchema = undefined;
export const CustomersCreateRequestBodySchema = z.object({
customer: CustomerCreatePayloadSchema,
});
export const CustomersCreateResponseBodySchema = z.object({
customer: CustomerSchema,
});
export const CustomersUpdatePathParamsSchema = z.object({ id: z.string() });
export const CustomersUpdateResponseBodySchema = undefined;
export const CustomersDestroyPathParamsSchema = z.object({ id: z.string() });
export const CustomersDestroyResponseBodySchema = undefined;
export type CustomersIndexMethod = 'GET';
export type CustomersIndexPath = '/customers';
export type CustomersIndexResponseBody = undefined;
export interface CustomersIndexResponse {
body: CustomersIndexResponseBody;
}
export interface CustomersIndex {
method: CustomersIndexMethod;
path: CustomersIndexPath;
response: CustomersIndexResponse;
}
export type CustomersShowMethod = 'GET';
export type CustomersShowPath = '/customers/:id';
export interface CustomersShowPathParams {
id: string;
}
export type CustomersShowResponseBody = undefined;
export interface CustomersShowResponse {
body: CustomersShowResponseBody;
}
export interface CustomersShow {
method: CustomersShowMethod;
path: CustomersShowPath;
pathParams: CustomersShowPathParams;
response: CustomersShowResponse;
}
export type CustomersCreateMethod = 'POST';
export type CustomersCreatePath = '/customers';
export interface CustomersCreateRequestBody {
customer: CustomerCreatePayload;
}
export type CustomersCreateResponseBody = { customer: Customer };
export interface CustomersCreateRequest {
body: CustomersCreateRequestBody;
}
export interface CustomersCreateResponse {
body: CustomersCreateResponseBody;
}
export interface CustomersCreate {
method: CustomersCreateMethod;
path: CustomersCreatePath;
request: CustomersCreateRequest;
response: CustomersCreateResponse;
}
export type CustomersUpdateMethod = 'PATCH';
export type CustomersUpdatePath = '/customers/:id';
export interface CustomersUpdatePathParams {
id: string;
}
export type CustomersUpdateResponseBody = undefined;
export interface CustomersUpdateResponse {
body: CustomersUpdateResponseBody;
}
export interface CustomersUpdate {
method: CustomersUpdateMethod;
path: CustomersUpdatePath;
pathParams: CustomersUpdatePathParams;
response: CustomersUpdateResponse;
}
export type CustomersDestroyMethod = 'DELETE';
export type CustomersDestroyPath = '/customers/:id';
export interface CustomersDestroyPathParams {
id: string;
}
export type CustomersDestroyResponseBody = undefined;
export interface CustomersDestroyResponse {
body: CustomersDestroyResponseBody;
}
export interface CustomersDestroy {
method: CustomersDestroyMethod;
path: CustomersDestroyPath;
pathParams: CustomersDestroyPathParams;
response: CustomersDestroyResponse;
}ts
export * from './customers';
export * from './orders';ts
import type { Order, OrderCreatePayload } from '../domains/order';
import * as z from 'zod';
import { OrderCreatePayloadSchema, OrderSchema } from '../domains/order';
export const OrdersIndexResponseBodySchema = undefined;
export const OrdersShowPathParamsSchema = z.object({ id: z.string() });
export const OrdersShowResponseBodySchema = undefined;
export const OrdersCreateRequestBodySchema = z.object({
order: OrderCreatePayloadSchema,
});
export const OrdersCreateResponseBodySchema = z.object({ order: OrderSchema });
export const OrdersUpdatePathParamsSchema = z.object({ id: z.string() });
export const OrdersUpdateResponseBodySchema = undefined;
export const OrdersDestroyPathParamsSchema = z.object({ id: z.string() });
export const OrdersDestroyResponseBodySchema = undefined;
export type OrdersIndexMethod = 'GET';
export type OrdersIndexPath = '/orders';
export type OrdersIndexResponseBody = undefined;
export interface OrdersIndexResponse {
body: OrdersIndexResponseBody;
}
export interface OrdersIndex {
method: OrdersIndexMethod;
path: OrdersIndexPath;
response: OrdersIndexResponse;
}
export type OrdersShowMethod = 'GET';
export type OrdersShowPath = '/orders/:id';
export interface OrdersShowPathParams {
id: string;
}
export type OrdersShowResponseBody = undefined;
export interface OrdersShowResponse {
body: OrdersShowResponseBody;
}
export interface OrdersShow {
method: OrdersShowMethod;
path: OrdersShowPath;
pathParams: OrdersShowPathParams;
response: OrdersShowResponse;
}
export type OrdersCreateMethod = 'POST';
export type OrdersCreatePath = '/orders';
export interface OrdersCreateRequestBody {
order: OrderCreatePayload;
}
export type OrdersCreateResponseBody = { order: Order };
export interface OrdersCreateRequest {
body: OrdersCreateRequestBody;
}
export interface OrdersCreateResponse {
body: OrdersCreateResponseBody;
}
export interface OrdersCreate {
method: OrdersCreateMethod;
path: OrdersCreatePath;
request: OrdersCreateRequest;
response: OrdersCreateResponse;
}
export type OrdersUpdateMethod = 'PATCH';
export type OrdersUpdatePath = '/orders/:id';
export interface OrdersUpdatePathParams {
id: string;
}
export type OrdersUpdateResponseBody = undefined;
export interface OrdersUpdateResponse {
body: OrdersUpdateResponseBody;
}
export interface OrdersUpdate {
method: OrdersUpdateMethod;
path: OrdersUpdatePath;
pathParams: OrdersUpdatePathParams;
response: OrdersUpdateResponse;
}
export type OrdersDestroyMethod = 'DELETE';
export type OrdersDestroyPath = '/orders/:id';
export interface OrdersDestroyPathParams {
id: string;
}
export type OrdersDestroyResponseBody = undefined;
export interface OrdersDestroyResponse {
body: OrdersDestroyResponseBody;
}
export interface OrdersDestroy {
method: OrdersDestroyMethod;
path: OrdersDestroyPath;
pathParams: OrdersDestroyPathParams;
response: OrdersDestroyResponse;
}Sorbus
ts
import type { CustomersOperationTree, OrdersOperationTree } from './endpoints';
import { createClientFactory } from 'sorbus';
import { contract } from './contract';
export interface Client {
customers: CustomersOperationTree;
orders: OrdersOperationTree;
}
export const createClient = createClientFactory<Client>(contract);ts
import { customers, orders } from './endpoints';
export const contract = {
endpoints: {
customers,
orders,
},
} as const;ts
import * as z from 'zod';
export const CustomerAddressSchema = z.object({
city: z.string(),
country: z.string(),
street: z.string(),
});
export const CustomerSchema = z.object({
billingAddress: CustomerAddressSchema,
createdAt: z.iso.datetime(),
id: z.uuid(),
name: z.string(),
updatedAt: z.iso.datetime(),
});
export const CustomerCreatePayloadSchema = z.object({
billingAddress: CustomerAddressSchema,
name: z.string(),
});
export interface CustomerAddress {
city: string;
country: string;
street: string;
}
export interface Customer {
billingAddress: CustomerAddress;
createdAt: string;
id: string;
name: string;
updatedAt: string;
}
export interface CustomerCreatePayload {
billingAddress: CustomerAddress;
name: string;
}ts
export * from './customer';
export * from './order';ts
import type { CustomerAddress } from './customer';
import * as z from 'zod';
import { CustomerAddressSchema } from './customer';
export const OrderSchema = z.object({
createdAt: z.iso.datetime(),
id: z.uuid(),
orderNumber: z.string(),
shippingAddress: CustomerAddressSchema,
updatedAt: z.iso.datetime(),
});
export const OrderCreatePayloadSchema = z.object({
orderNumber: z.string(),
shippingAddress: CustomerAddressSchema,
});
export interface Order {
createdAt: string;
id: string;
orderNumber: string;
shippingAddress: CustomerAddress;
updatedAt: string;
}
export interface OrderCreatePayload {
orderNumber: string;
shippingAddress: CustomerAddress;
}ts
import type { Operation } from 'sorbus';
import type { Customer, CustomerCreatePayload } from '../domains/customer';
import * as z from 'zod';
import {
CustomerCreatePayloadSchema,
CustomerSchema,
} from '../domains/customer';
export const CustomersIndexResponseBodySchema = undefined;
export const CustomersShowPathParamsSchema = z.object({ id: z.string() });
export const CustomersShowResponseBodySchema = undefined;
export const CustomersCreateRequestBodySchema = z.object({
customer: CustomerCreatePayloadSchema,
});
export const CustomersCreateResponseBodySchema = z.object({
customer: CustomerSchema,
});
export const CustomersUpdatePathParamsSchema = z.object({ id: z.string() });
export const CustomersUpdateResponseBodySchema = undefined;
export const CustomersDestroyPathParamsSchema = z.object({ id: z.string() });
export const CustomersDestroyResponseBodySchema = undefined;
export type CustomersIndexMethod = 'GET';
export type CustomersIndexPath = '/customers';
export type CustomersIndexResponseBody = undefined;
export interface CustomersIndexResponse {
body: CustomersIndexResponseBody;
}
export interface CustomersIndex {
method: CustomersIndexMethod;
path: CustomersIndexPath;
response: CustomersIndexResponse;
}
export type CustomersShowMethod = 'GET';
export type CustomersShowPath = '/customers/:id';
export interface CustomersShowPathParams {
id: string;
}
export type CustomersShowResponseBody = undefined;
export interface CustomersShowResponse {
body: CustomersShowResponseBody;
}
export interface CustomersShow {
method: CustomersShowMethod;
path: CustomersShowPath;
pathParams: CustomersShowPathParams;
response: CustomersShowResponse;
}
export type CustomersCreateMethod = 'POST';
export type CustomersCreatePath = '/customers';
export interface CustomersCreateRequestBody {
customer: CustomerCreatePayload;
}
export type CustomersCreateResponseBody = { customer: Customer };
export interface CustomersCreateRequest {
body: CustomersCreateRequestBody;
}
export interface CustomersCreateResponse {
body: CustomersCreateResponseBody;
}
export interface CustomersCreate {
method: CustomersCreateMethod;
path: CustomersCreatePath;
request: CustomersCreateRequest;
response: CustomersCreateResponse;
}
export type CustomersUpdateMethod = 'PATCH';
export type CustomersUpdatePath = '/customers/:id';
export interface CustomersUpdatePathParams {
id: string;
}
export type CustomersUpdateResponseBody = undefined;
export interface CustomersUpdateResponse {
body: CustomersUpdateResponseBody;
}
export interface CustomersUpdate {
method: CustomersUpdateMethod;
path: CustomersUpdatePath;
pathParams: CustomersUpdatePathParams;
response: CustomersUpdateResponse;
}
export type CustomersDestroyMethod = 'DELETE';
export type CustomersDestroyPath = '/customers/:id';
export interface CustomersDestroyPathParams {
id: string;
}
export type CustomersDestroyResponseBody = undefined;
export interface CustomersDestroyResponse {
body: CustomersDestroyResponseBody;
}
export interface CustomersDestroy {
method: CustomersDestroyMethod;
path: CustomersDestroyPath;
pathParams: CustomersDestroyPathParams;
response: CustomersDestroyResponse;
}
export const customers = {
create: {
method: 'POST',
path: '/customers',
request: {
body: CustomersCreateRequestBodySchema,
},
response: {
body: CustomersCreateResponseBodySchema,
},
},
destroy: {
method: 'DELETE',
path: '/customers/:id',
pathParams: CustomersDestroyPathParamsSchema,
response: {
body: CustomersDestroyResponseBodySchema,
},
},
index: {
method: 'GET',
path: '/customers',
response: {
body: CustomersIndexResponseBodySchema,
},
},
show: {
method: 'GET',
path: '/customers/:id',
pathParams: CustomersShowPathParamsSchema,
response: {
body: CustomersShowResponseBodySchema,
},
},
update: {
method: 'PATCH',
path: '/customers/:id',
pathParams: CustomersUpdatePathParamsSchema,
response: {
body: CustomersUpdateResponseBodySchema,
},
},
} as const;
export interface CustomersOperationTree {
create: Operation<CustomersCreate>;
destroy: Operation<CustomersDestroy>;
index: Operation<CustomersIndex>;
show: Operation<CustomersShow>;
update: Operation<CustomersUpdate>;
}ts
export * from './customers';
export * from './orders';ts
import type { Operation } from 'sorbus';
import type { Order, OrderCreatePayload } from '../domains/order';
import * as z from 'zod';
import { OrderCreatePayloadSchema, OrderSchema } from '../domains/order';
export const OrdersIndexResponseBodySchema = undefined;
export const OrdersShowPathParamsSchema = z.object({ id: z.string() });
export const OrdersShowResponseBodySchema = undefined;
export const OrdersCreateRequestBodySchema = z.object({
order: OrderCreatePayloadSchema,
});
export const OrdersCreateResponseBodySchema = z.object({ order: OrderSchema });
export const OrdersUpdatePathParamsSchema = z.object({ id: z.string() });
export const OrdersUpdateResponseBodySchema = undefined;
export const OrdersDestroyPathParamsSchema = z.object({ id: z.string() });
export const OrdersDestroyResponseBodySchema = undefined;
export type OrdersIndexMethod = 'GET';
export type OrdersIndexPath = '/orders';
export type OrdersIndexResponseBody = undefined;
export interface OrdersIndexResponse {
body: OrdersIndexResponseBody;
}
export interface OrdersIndex {
method: OrdersIndexMethod;
path: OrdersIndexPath;
response: OrdersIndexResponse;
}
export type OrdersShowMethod = 'GET';
export type OrdersShowPath = '/orders/:id';
export interface OrdersShowPathParams {
id: string;
}
export type OrdersShowResponseBody = undefined;
export interface OrdersShowResponse {
body: OrdersShowResponseBody;
}
export interface OrdersShow {
method: OrdersShowMethod;
path: OrdersShowPath;
pathParams: OrdersShowPathParams;
response: OrdersShowResponse;
}
export type OrdersCreateMethod = 'POST';
export type OrdersCreatePath = '/orders';
export interface OrdersCreateRequestBody {
order: OrderCreatePayload;
}
export type OrdersCreateResponseBody = { order: Order };
export interface OrdersCreateRequest {
body: OrdersCreateRequestBody;
}
export interface OrdersCreateResponse {
body: OrdersCreateResponseBody;
}
export interface OrdersCreate {
method: OrdersCreateMethod;
path: OrdersCreatePath;
request: OrdersCreateRequest;
response: OrdersCreateResponse;
}
export type OrdersUpdateMethod = 'PATCH';
export type OrdersUpdatePath = '/orders/:id';
export interface OrdersUpdatePathParams {
id: string;
}
export type OrdersUpdateResponseBody = undefined;
export interface OrdersUpdateResponse {
body: OrdersUpdateResponseBody;
}
export interface OrdersUpdate {
method: OrdersUpdateMethod;
path: OrdersUpdatePath;
pathParams: OrdersUpdatePathParams;
response: OrdersUpdateResponse;
}
export type OrdersDestroyMethod = 'DELETE';
export type OrdersDestroyPath = '/orders/:id';
export interface OrdersDestroyPathParams {
id: string;
}
export type OrdersDestroyResponseBody = undefined;
export interface OrdersDestroyResponse {
body: OrdersDestroyResponseBody;
}
export interface OrdersDestroy {
method: OrdersDestroyMethod;
path: OrdersDestroyPath;
pathParams: OrdersDestroyPathParams;
response: OrdersDestroyResponse;
}
export const orders = {
create: {
method: 'POST',
path: '/orders',
request: {
body: OrdersCreateRequestBodySchema,
},
response: {
body: OrdersCreateResponseBodySchema,
},
},
destroy: {
method: 'DELETE',
path: '/orders/:id',
pathParams: OrdersDestroyPathParamsSchema,
response: {
body: OrdersDestroyResponseBodySchema,
},
},
index: {
method: 'GET',
path: '/orders',
response: {
body: OrdersIndexResponseBodySchema,
},
},
show: {
method: 'GET',
path: '/orders/:id',
pathParams: OrdersShowPathParamsSchema,
response: {
body: OrdersShowResponseBodySchema,
},
},
update: {
method: 'PATCH',
path: '/orders/:id',
pathParams: OrdersUpdatePathParamsSchema,
response: {
body: OrdersUpdateResponseBodySchema,
},
},
} as const;
export interface OrdersOperationTree {
create: Operation<OrdersCreate>;
destroy: Operation<OrdersDestroy>;
index: Operation<OrdersIndex>;
show: Operation<OrdersShow>;
update: Operation<OrdersUpdate>;
}