Value Transforms
Transform values on input/output and handle nil/empty string conversion
API Definition
config/apis/swift_fox.rb
rb
# frozen_string_literal: true
Apiwork::API.define '/swift_fox' do
key_format :camel
export :openapi
export :typescript
export :zod
resources :contacts
endModels
app/models/swift_fox/contact.rb
rb
# frozen_string_literal: true
module SwiftFox
class Contact < ApplicationRecord
validates :name, presence: true
end
endDatabase Table
| Column | Type | Nullable | Default |
|---|---|---|---|
| id | string | ||
| created_at | datetime | ||
| string | ✓ | ||
| name | string | ||
| notes | string | ✓ | |
| phone | string | ✓ | |
| updated_at | datetime |
Representations
app/representations/swift_fox/contact_representation.rb
rb
# frozen_string_literal: true
module SwiftFox
class ContactRepresentation < Apiwork::Representation::Base
attribute :id
attribute :name, writable: true
attribute :email, decode: ->(v) { v&.downcase }, encode: ->(v) { v&.downcase }, writable: true
attribute :phone, empty: true, writable: true
attribute :notes, empty: true, writable: true
attribute :created_at
attribute :updated_at
end
endContracts
app/contracts/swift_fox/contact_contract.rb
rb
# frozen_string_literal: true
module SwiftFox
class ContactContract < Apiwork::Contract::Base
representation ContactRepresentation
end
endControllers
app/controllers/swift_fox/contacts_controller.rb
rb
# frozen_string_literal: true
module SwiftFox
class ContactsController < ApplicationController
before_action :set_contact, only: %i[show update destroy]
def index
contacts = Contact.all
expose contacts
end
def show
expose contact
end
def create
contact = Contact.create(contract.body[:contact])
expose contact
end
def update
contact.update(contract.body[:contact])
expose contact
end
def destroy
contact.destroy
expose contact
end
private
attr_reader :contact
def set_contact
@contact = Contact.find(params[:id])
end
end
endRequest Examples
Create with transforms
Request
http
POST /swift_fox/contacts
Content-Type: application/json
{
"contact": {
"name": "John Doe",
"email": "John.Doe@Example.COM",
"phone": "",
"notes": ""
}
}Response 201
json
{
"contact": {
"id": "a8683ee9-6e2e-525c-84e5-103a4b4230cb",
"name": "John Doe",
"email": "john.doe@example.com",
"phone": "",
"notes": "",
"createdAt": "2024-01-01T12:00:00.000Z",
"updatedAt": "2024-01-01T12:00:00.000Z"
}
}Show transformed data
Request
http
GET /swift_fox/contacts/a8683ee9-6e2e-525c-84e5-103a4b4230cbResponse 200
json
{
"contact": {
"id": "a8683ee9-6e2e-525c-84e5-103a4b4230cb",
"name": "Jane Doe",
"email": "jane@example.com",
"phone": "",
"notes": "",
"createdAt": "2024-01-01T12:00:00.000Z",
"updatedAt": "2024-01-01T12:00:00.000Z"
}
}Generated Output
Introspection
json
{
"base_path": "/swift_fox",
"enums": {
"layer": {
"deprecated": false,
"description": null,
"example": null,
"values": [
"http",
"contract",
"domain"
]
}
},
"error_codes": {
"unprocessable_entity": {
"description": "Unprocessable Entity",
"status": 422
}
},
"info": null,
"resources": {
"contacts": {
"actions": {
"index": {
"deprecated": false,
"description": null,
"method": "get",
"operation_id": null,
"path": "/contacts",
"raises": [],
"request": {
"body": {},
"query": {
"page": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "reference",
"reference": "contact_page"
}
}
},
"response": {
"body": {
"default": null,
"deprecated": null,
"description": null,
"example": null,
"nullable": null,
"optional": null,
"type": "union",
"discriminator": null,
"variants": [
{
"default": null,
"deprecated": null,
"description": null,
"example": null,
"nullable": null,
"optional": null,
"type": "reference",
"reference": "contact_index_success_response_body"
},
{
"default": null,
"deprecated": null,
"description": null,
"example": null,
"nullable": null,
"optional": null,
"type": "reference",
"reference": "error_response_body"
}
]
},
"no_content": false
},
"summary": null,
"tags": []
},
"show": {
"deprecated": false,
"description": null,
"method": "get",
"operation_id": null,
"path": "/contacts/:id",
"raises": [],
"request": {
"body": {},
"query": {}
},
"response": {
"body": {
"default": null,
"deprecated": null,
"description": null,
"example": null,
"nullable": null,
"optional": null,
"type": "union",
"discriminator": null,
"variants": [
{
"default": null,
"deprecated": null,
"description": null,
"example": null,
"nullable": null,
"optional": null,
"type": "reference",
"reference": "contact_show_success_response_body"
},
{
"default": null,
"deprecated": null,
"description": null,
"example": null,
"nullable": null,
"optional": null,
"type": "reference",
"reference": "error_response_body"
}
]
},
"no_content": false
},
"summary": null,
"tags": []
},
"create": {
"deprecated": false,
"description": null,
"method": "post",
"operation_id": null,
"path": "/contacts",
"raises": [
"unprocessable_entity"
],
"request": {
"body": {
"contact": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "contact_create_payload"
}
},
"query": {}
},
"response": {
"body": {
"default": null,
"deprecated": null,
"description": null,
"example": null,
"nullable": null,
"optional": null,
"type": "union",
"discriminator": null,
"variants": [
{
"default": null,
"deprecated": null,
"description": null,
"example": null,
"nullable": null,
"optional": null,
"type": "reference",
"reference": "contact_create_success_response_body"
},
{
"default": null,
"deprecated": null,
"description": null,
"example": null,
"nullable": null,
"optional": null,
"type": "reference",
"reference": "error_response_body"
}
]
},
"no_content": false
},
"summary": null,
"tags": []
},
"update": {
"deprecated": false,
"description": null,
"method": "patch",
"operation_id": null,
"path": "/contacts/:id",
"raises": [
"unprocessable_entity"
],
"request": {
"body": {
"contact": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "contact_update_payload"
}
},
"query": {}
},
"response": {
"body": {
"default": null,
"deprecated": null,
"description": null,
"example": null,
"nullable": null,
"optional": null,
"type": "union",
"discriminator": null,
"variants": [
{
"default": null,
"deprecated": null,
"description": null,
"example": null,
"nullable": null,
"optional": null,
"type": "reference",
"reference": "contact_update_success_response_body"
},
{
"default": null,
"deprecated": null,
"description": null,
"example": null,
"nullable": null,
"optional": null,
"type": "reference",
"reference": "error_response_body"
}
]
},
"no_content": false
},
"summary": null,
"tags": []
},
"destroy": {
"deprecated": false,
"description": null,
"method": "delete",
"operation_id": null,
"path": "/contacts/:id",
"raises": [],
"request": {
"body": {},
"query": {}
},
"response": {
"body": {
"default": null,
"deprecated": null,
"description": null,
"example": null,
"nullable": null,
"optional": null,
"type": null
},
"no_content": true
},
"summary": null,
"tags": []
}
},
"identifier": "contacts",
"parent_identifiers": [],
"path": "contacts",
"resources": {}
}
},
"types": {
"contact": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"created_at": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "datetime"
},
"email": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": true,
"optional": false,
"type": "string",
"format": null,
"max": null,
"min": null
},
"id": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "string",
"format": null,
"max": null,
"min": null
},
"name": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "string",
"format": null,
"max": null,
"min": null
},
"notes": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "string",
"format": null,
"max": null,
"min": null
},
"phone": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "string",
"format": null,
"max": null,
"min": null
},
"updated_at": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "datetime"
}
},
"type": "object",
"variants": []
},
"contact_create_payload": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"email": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": true,
"optional": true,
"type": "string",
"format": null,
"max": null,
"min": null
},
"name": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "string",
"format": null,
"max": null,
"min": null
},
"notes": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "string",
"format": null,
"max": null,
"min": null
},
"phone": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "string",
"format": null,
"max": null,
"min": null
}
},
"type": "object",
"variants": []
},
"contact_create_success_response_body": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"contact": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "contact"
},
"meta": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "object",
"partial": false,
"shape": {}
}
},
"type": "object",
"variants": []
},
"contact_index_success_response_body": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"pagination": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "offset_pagination"
},
"contacts": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "array",
"max": null,
"min": null,
"of": {
"default": null,
"deprecated": null,
"description": null,
"example": null,
"nullable": null,
"optional": null,
"type": "reference",
"reference": "contact"
},
"shape": {}
},
"meta": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "object",
"partial": false,
"shape": {}
}
},
"type": "object",
"variants": []
},
"contact_page": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"number": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "integer",
"format": null,
"max": null,
"min": 1
},
"size": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "integer",
"format": null,
"max": 100,
"min": 1
}
},
"type": "object",
"variants": []
},
"contact_show_success_response_body": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"contact": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "contact"
},
"meta": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "object",
"partial": false,
"shape": {}
}
},
"type": "object",
"variants": []
},
"contact_update_payload": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"email": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": true,
"optional": true,
"type": "string",
"format": null,
"max": null,
"min": null
},
"name": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "string",
"format": null,
"max": null,
"min": null
},
"notes": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "string",
"format": null,
"max": null,
"min": null
},
"phone": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "string",
"format": null,
"max": null,
"min": null
}
},
"type": "object",
"variants": []
},
"contact_update_success_response_body": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"contact": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "contact"
},
"meta": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "object",
"partial": false,
"shape": {}
}
},
"type": "object",
"variants": []
},
"error": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"issues": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "array",
"max": null,
"min": null,
"of": {
"default": null,
"deprecated": null,
"description": null,
"example": null,
"nullable": null,
"optional": null,
"type": "reference",
"reference": "issue"
},
"shape": {}
},
"layer": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "layer"
}
},
"type": "object",
"variants": []
},
"error_response_body": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [
"error"
],
"shape": {},
"type": "object",
"variants": []
},
"issue": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"code": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "string",
"format": null,
"max": null,
"min": null
},
"detail": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "string",
"format": null,
"max": null,
"min": null
},
"meta": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "object",
"partial": false,
"shape": {}
},
"path": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "array",
"max": null,
"min": null,
"of": {
"default": null,
"deprecated": null,
"description": null,
"example": null,
"nullable": null,
"optional": null,
"type": "string",
"format": null,
"max": null,
"min": null
},
"shape": {}
},
"pointer": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "string",
"format": null,
"max": null,
"min": null
}
},
"type": "object",
"variants": []
},
"offset_pagination": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"current": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "integer",
"format": null,
"max": null,
"min": null
},
"items": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "integer",
"format": null,
"max": null,
"min": null
},
"next": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": true,
"optional": true,
"type": "integer",
"format": null,
"max": null,
"min": null
},
"prev": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": true,
"optional": true,
"type": "integer",
"format": null,
"max": null,
"min": null
},
"total": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "integer",
"format": null,
"max": null,
"min": null
}
},
"type": "object",
"variants": []
}
}
}TypeScript
ts
export interface Contact {
createdAt: string;
email: null | string;
id: string;
name: string;
notes: string;
phone: string;
updatedAt: string;
}
export interface ContactCreatePayload {
email?: null | string;
name: string;
notes?: string;
phone?: string;
}
export interface ContactCreateSuccessResponseBody {
contact: Contact;
meta?: Record<string, unknown>;
}
export interface ContactIndexSuccessResponseBody {
contacts: Contact[];
meta?: Record<string, unknown>;
pagination: OffsetPagination;
}
export interface ContactPage {
number?: number;
size?: number;
}
export interface ContactShowSuccessResponseBody {
contact: Contact;
meta?: Record<string, unknown>;
}
export interface ContactUpdatePayload {
email?: null | string;
name?: string;
notes?: string;
phone?: string;
}
export interface ContactUpdateSuccessResponseBody {
contact: Contact;
meta?: Record<string, unknown>;
}
export interface ContactsCreateRequest {
body: ContactsCreateRequestBody;
}
export interface ContactsCreateRequestBody {
contact: ContactCreatePayload;
}
export interface ContactsCreateResponse {
body: ContactsCreateResponseBody;
}
export type ContactsCreateResponseBody = ContactCreateSuccessResponseBody | ErrorResponseBody;
export type ContactsDestroyResponse = never;
export interface ContactsIndexRequest {
query: ContactsIndexRequestQuery;
}
export interface ContactsIndexRequestQuery {
page?: ContactPage;
}
export interface ContactsIndexResponse {
body: ContactsIndexResponseBody;
}
export type ContactsIndexResponseBody = ContactIndexSuccessResponseBody | ErrorResponseBody;
export interface ContactsShowResponse {
body: ContactsShowResponseBody;
}
export type ContactsShowResponseBody = ContactShowSuccessResponseBody | ErrorResponseBody;
export interface ContactsUpdateRequest {
body: ContactsUpdateRequestBody;
}
export interface ContactsUpdateRequestBody {
contact: ContactUpdatePayload;
}
export interface ContactsUpdateResponse {
body: ContactsUpdateResponseBody;
}
export type ContactsUpdateResponseBody = ContactUpdateSuccessResponseBody | ErrorResponseBody;
export interface Error {
issues: Issue[];
layer: Layer;
}
export type ErrorResponseBody = Error;
export interface Issue {
code: string;
detail: string;
meta: Record<string, unknown>;
path: string[];
pointer: string;
}
export type Layer = 'contract' | 'domain' | 'http';
export interface OffsetPagination {
current: number;
items: number;
next?: null | number;
prev?: null | number;
total: number;
}Zod
ts
import { z } from 'zod';
export const LayerSchema = z.enum(['contract', 'domain', 'http']);
export const ContactSchema = z.object({
createdAt: z.iso.datetime(),
email: z.string().nullable(),
id: z.string(),
name: z.string(),
notes: z.string(),
phone: z.string(),
updatedAt: z.iso.datetime()
});
export const ContactCreatePayloadSchema = z.object({
email: z.string().nullable().optional(),
name: z.string(),
notes: z.string().optional(),
phone: z.string().optional()
});
export const ContactPageSchema = z.object({
number: z.number().int().min(1).optional(),
size: z.number().int().min(1).max(100).optional()
});
export const ContactUpdatePayloadSchema = z.object({
email: z.string().nullable().optional(),
name: z.string().optional(),
notes: z.string().optional(),
phone: z.string().optional()
});
export const IssueSchema = z.object({
code: z.string(),
detail: z.string(),
meta: z.record(z.string(), z.unknown()),
path: z.array(z.string()),
pointer: z.string()
});
export const OffsetPaginationSchema = z.object({
current: z.number().int(),
items: z.number().int(),
next: z.number().int().nullable().optional(),
prev: z.number().int().nullable().optional(),
total: z.number().int()
});
export const ContactCreateSuccessResponseBodySchema = z.object({
contact: ContactSchema,
meta: z.record(z.string(), z.unknown()).optional()
});
export const ContactIndexSuccessResponseBodySchema = z.object({
contacts: z.array(ContactSchema),
meta: z.record(z.string(), z.unknown()).optional(),
pagination: OffsetPaginationSchema
});
export const ContactShowSuccessResponseBodySchema = z.object({
contact: ContactSchema,
meta: z.record(z.string(), z.unknown()).optional()
});
export const ContactUpdateSuccessResponseBodySchema = z.object({
contact: ContactSchema,
meta: z.record(z.string(), z.unknown()).optional()
});
export const ErrorSchema = z.object({
issues: z.array(IssueSchema),
layer: LayerSchema
});
export const ErrorResponseBodySchema = ErrorSchema;
export const ContactsIndexRequestQuerySchema = z.object({
page: ContactPageSchema.optional()
});
export const ContactsIndexRequestSchema = z.object({
query: ContactsIndexRequestQuerySchema
});
export const ContactsIndexResponseBodySchema = z.union([ContactIndexSuccessResponseBodySchema, ErrorResponseBodySchema]);
export const ContactsIndexResponseSchema = z.object({
body: ContactsIndexResponseBodySchema
});
export const ContactsShowResponseBodySchema = z.union([ContactShowSuccessResponseBodySchema, ErrorResponseBodySchema]);
export const ContactsShowResponseSchema = z.object({
body: ContactsShowResponseBodySchema
});
export const ContactsCreateRequestBodySchema = z.object({
contact: ContactCreatePayloadSchema
});
export const ContactsCreateRequestSchema = z.object({
body: ContactsCreateRequestBodySchema
});
export const ContactsCreateResponseBodySchema = z.union([ContactCreateSuccessResponseBodySchema, ErrorResponseBodySchema]);
export const ContactsCreateResponseSchema = z.object({
body: ContactsCreateResponseBodySchema
});
export const ContactsUpdateRequestBodySchema = z.object({
contact: ContactUpdatePayloadSchema
});
export const ContactsUpdateRequestSchema = z.object({
body: ContactsUpdateRequestBodySchema
});
export const ContactsUpdateResponseBodySchema = z.union([ContactUpdateSuccessResponseBodySchema, ErrorResponseBodySchema]);
export const ContactsUpdateResponseSchema = z.object({
body: ContactsUpdateResponseBodySchema
});
export const ContactsDestroyResponseSchema = z.never();
export interface Contact {
createdAt: string;
email: null | string;
id: string;
name: string;
notes: string;
phone: string;
updatedAt: string;
}
export interface ContactCreatePayload {
email?: null | string;
name: string;
notes?: string;
phone?: string;
}
export interface ContactCreateSuccessResponseBody {
contact: Contact;
meta?: Record<string, unknown>;
}
export interface ContactIndexSuccessResponseBody {
contacts: Contact[];
meta?: Record<string, unknown>;
pagination: OffsetPagination;
}
export interface ContactPage {
number?: number;
size?: number;
}
export interface ContactShowSuccessResponseBody {
contact: Contact;
meta?: Record<string, unknown>;
}
export interface ContactUpdatePayload {
email?: null | string;
name?: string;
notes?: string;
phone?: string;
}
export interface ContactUpdateSuccessResponseBody {
contact: Contact;
meta?: Record<string, unknown>;
}
export interface ContactsCreateRequest {
body: ContactsCreateRequestBody;
}
export interface ContactsCreateRequestBody {
contact: ContactCreatePayload;
}
export interface ContactsCreateResponse {
body: ContactsCreateResponseBody;
}
export type ContactsCreateResponseBody = ContactCreateSuccessResponseBody | ErrorResponseBody;
export type ContactsDestroyResponse = never;
export interface ContactsIndexRequest {
query: ContactsIndexRequestQuery;
}
export interface ContactsIndexRequestQuery {
page?: ContactPage;
}
export interface ContactsIndexResponse {
body: ContactsIndexResponseBody;
}
export type ContactsIndexResponseBody = ContactIndexSuccessResponseBody | ErrorResponseBody;
export interface ContactsShowResponse {
body: ContactsShowResponseBody;
}
export type ContactsShowResponseBody = ContactShowSuccessResponseBody | ErrorResponseBody;
export interface ContactsUpdateRequest {
body: ContactsUpdateRequestBody;
}
export interface ContactsUpdateRequestBody {
contact: ContactUpdatePayload;
}
export interface ContactsUpdateResponse {
body: ContactsUpdateResponseBody;
}
export type ContactsUpdateResponseBody = ContactUpdateSuccessResponseBody | ErrorResponseBody;
export interface Error {
issues: Issue[];
layer: Layer;
}
export type ErrorResponseBody = Error;
export interface Issue {
code: string;
detail: string;
meta: Record<string, unknown>;
path: string[];
pointer: string;
}
export type Layer = 'contract' | 'domain' | 'http';
export interface OffsetPagination {
current: number;
items: number;
next?: null | number;
prev?: null | number;
total: number;
}OpenAPI
yml
---
openapi: 3.1.0
info:
title: "/swift_fox"
version: 1.0.0
paths:
"/contacts":
get:
operationId: contactsIndex
parameters:
- in: query
name: page
required: false
schema:
"$ref": "#/components/schemas/contactPage"
responses:
'200':
content:
application/json:
schema:
"$ref": "#/components/schemas/contactIndexSuccessResponseBody"
description: Successful response
post:
operationId: contactsCreate
requestBody:
content:
application/json:
schema:
properties:
contact:
"$ref": "#/components/schemas/contactCreatePayload"
type: object
required:
- contact
required: true
responses:
'200':
content:
application/json:
schema:
"$ref": "#/components/schemas/contactCreateSuccessResponseBody"
description: Successful response
'422':
description: Unprocessable Entity
content:
application/json:
schema:
"$ref": "#/components/schemas/errorResponseBody"
"/contacts/{id}":
get:
operationId: contactsShow
parameters:
- in: path
name: id
required: true
schema:
type: string
responses:
'200':
content:
application/json:
schema:
"$ref": "#/components/schemas/contactShowSuccessResponseBody"
description: Successful response
patch:
operationId: contactsUpdate
parameters:
- in: path
name: id
required: true
schema:
type: string
requestBody:
content:
application/json:
schema:
properties:
contact:
"$ref": "#/components/schemas/contactUpdatePayload"
type: object
required:
- contact
required: true
responses:
'200':
content:
application/json:
schema:
"$ref": "#/components/schemas/contactUpdateSuccessResponseBody"
description: Successful response
'422':
description: Unprocessable Entity
content:
application/json:
schema:
"$ref": "#/components/schemas/errorResponseBody"
delete:
operationId: contactsDestroy
parameters:
- in: path
name: id
required: true
schema:
type: string
responses:
'204':
description: No content
components:
schemas:
contact:
properties:
createdAt:
type: string
format: date-time
email:
type:
- string
- 'null'
id:
type: string
name:
type: string
notes:
type: string
phone:
type: string
updatedAt:
type: string
format: date-time
type: object
required:
- createdAt
- email
- id
- name
- notes
- phone
- updatedAt
contactCreatePayload:
properties:
email:
type:
- string
- 'null'
name:
type: string
notes:
type: string
phone:
type: string
type: object
required:
- name
contactCreateSuccessResponseBody:
properties:
contact:
"$ref": "#/components/schemas/contact"
meta:
properties: {}
type: object
type: object
required:
- contact
contactIndexSuccessResponseBody:
properties:
pagination:
"$ref": "#/components/schemas/offsetPagination"
contacts:
items:
"$ref": "#/components/schemas/contact"
type: array
meta:
properties: {}
type: object
type: object
required:
- pagination
- contacts
contactPage:
properties:
number:
type: integer
minimum: 1
size:
type: integer
minimum: 1
maximum: 100
type: object
contactShowSuccessResponseBody:
properties:
contact:
"$ref": "#/components/schemas/contact"
meta:
properties: {}
type: object
type: object
required:
- contact
contactUpdatePayload:
properties:
email:
type:
- string
- 'null'
name:
type: string
notes:
type: string
phone:
type: string
type: object
contactUpdateSuccessResponseBody:
properties:
contact:
"$ref": "#/components/schemas/contact"
meta:
properties: {}
type: object
type: object
required:
- contact
error:
properties:
issues:
items:
"$ref": "#/components/schemas/issue"
type: array
layer:
enum:
- http
- contract
- domain
type: string
type: object
required:
- issues
- layer
errorResponseBody:
"$ref": "#/components/schemas/error"
issue:
properties:
code:
type: string
detail:
type: string
meta:
properties: {}
type: object
path:
items:
type: string
type: array
pointer:
type: string
type: object
required:
- code
- detail
- meta
- path
- pointer
offsetPagination:
properties:
current:
type: integer
items:
type: integer
next:
type:
- integer
- 'null'
prev:
type:
- integer
- 'null'
total:
type: integer
type: object
required:
- current
- items
- total