Key and Path Formats
PascalCase keys with key_format :pascal and kebab-case paths with path_format :kebab
API Definition
config/apis/nimble_gecko.rb
rb
# frozen_string_literal: true
Apiwork::API.define '/nimble_gecko' do
key_format :pascal
path_format :kebab
export :openapi
export :typescript
export :zod
resources :meal_plans
endModels
app/models/nimble_gecko/meal_plan.rb
rb
# frozen_string_literal: true
module NimbleGecko
class MealPlan < ApplicationRecord
has_many :cooking_steps, dependent: :destroy
accepts_nested_attributes_for :cooking_steps, allow_destroy: true
validates :title, presence: true
end
endDatabase Table
| Column | Type | Nullable | Default |
|---|---|---|---|
| id | string | ||
| cook_time | integer | ✓ | |
| created_at | datetime | ||
| serving_size | integer | ✓ | |
| title | string | ||
| updated_at | datetime |
app/models/nimble_gecko/cooking_step.rb
rb
# frozen_string_literal: true
module NimbleGecko
class CookingStep < ApplicationRecord
belongs_to :meal_plan
validates :instruction, presence: true
validates :step_number, presence: true
end
endDatabase Table
| Column | Type | Nullable | Default |
|---|---|---|---|
| id | string | ||
| created_at | datetime | ||
| duration_minutes | integer | ✓ | |
| instruction | string | ||
| meal_plan_id | string | ||
| step_number | integer | ||
| updated_at | datetime |
Representations
app/representations/nimble_gecko/meal_plan_representation.rb
rb
# frozen_string_literal: true
module NimbleGecko
class MealPlanRepresentation < Apiwork::Representation::Base
attribute :id
attribute :title, writable: true
attribute :cook_time, writable: true
attribute :serving_size, writable: true
attribute :created_at
attribute :updated_at
has_many :cooking_steps, include: :always, writable: true
end
endapp/representations/nimble_gecko/cooking_step_representation.rb
rb
# frozen_string_literal: true
module NimbleGecko
class CookingStepRepresentation < Apiwork::Representation::Base
attribute :id
attribute :step_number, writable: true
attribute :instruction, writable: true
attribute :duration_minutes, writable: true
end
endContracts
app/contracts/nimble_gecko/meal_plan_contract.rb
rb
# frozen_string_literal: true
module NimbleGecko
class MealPlanContract < Apiwork::Contract::Base
representation MealPlanRepresentation
end
endControllers
app/controllers/nimble_gecko/meal_plans_controller.rb
rb
# frozen_string_literal: true
module NimbleGecko
class MealPlansController < ApplicationController
before_action :set_meal_plan, only: %i[show update destroy]
def index
meal_plans = MealPlan.all
expose meal_plans
end
def show
expose meal_plan
end
def create
meal_plan = MealPlan.create(contract.body[:meal_plan])
expose meal_plan
end
def update
meal_plan.update(contract.body[:meal_plan])
expose meal_plan
end
def destroy
meal_plan.destroy
expose meal_plan
end
private
attr_reader :meal_plan
def set_meal_plan
@meal_plan = MealPlan.find(params[:id])
end
end
endRequest Examples
Create meal plan with PascalCase body
Request
http
POST /nimble_gecko/meal-plans
Content-Type: application/json
{
"MealPlan": {
"Title": "Pasta Carbonara",
"CookTime": 30,
"ServingSize": 4,
"CookingSteps": [
{
"StepNumber": 1,
"Instruction": "Boil salted water",
"DurationMinutes": 10
},
{
"StepNumber": 2,
"Instruction": "Cook pasta until al dente",
"DurationMinutes": 8
},
{
"StepNumber": 3,
"Instruction": "Mix with egg yolk sauce",
"DurationMinutes": 5
}
]
}
}Response 404
json
{
"status": 404,
"error": "Not Found"
}List meal plans
Request
http
GET /nimble_gecko/meal-plansResponse 404
json
{
"status": 404,
"error": "Not Found"
}Update meal plan with PascalCase body
Request
http
PATCH /nimble_gecko/meal-plans/60e6912b-2e98-5f0c-892b-391c9c742417
Content-Type: application/json
{
"MealPlan": {
"CookTime": 25,
"ServingSize": 6
}
}Response 404
json
{
"status": 404,
"error": "Not Found"
}Generated Output
Introspection
json
{
"base_path": "/nimble-gecko",
"enums": {
"layer": {
"deprecated": false,
"description": null,
"example": null,
"values": [
"http",
"contract",
"domain"
]
}
},
"error_codes": {
"unprocessable_entity": {
"description": "Unprocessable Entity",
"status": 422
}
},
"info": null,
"resources": {
"meal_plans": {
"actions": {
"index": {
"deprecated": false,
"description": null,
"method": "get",
"operation_id": null,
"path": "/meal-plans",
"raises": [],
"request": {
"body": {},
"query": {
"page": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "reference",
"reference": "meal_plan_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": "meal_plan_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": "/meal-plans/: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": "meal_plan_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": "/meal-plans",
"raises": [
"unprocessable_entity"
],
"request": {
"body": {
"meal_plan": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "meal_plan_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": "meal_plan_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": "/meal-plans/:id",
"raises": [
"unprocessable_entity"
],
"request": {
"body": {
"meal_plan": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "meal_plan_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": "meal_plan_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": "/meal-plans/: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": "meal_plans",
"parent_identifiers": [],
"path": "meal-plans",
"resources": {}
}
},
"types": {
"cooking_step": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"duration_minutes": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": true,
"optional": false,
"type": "integer",
"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
},
"instruction": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "string",
"format": null,
"max": null,
"min": null
},
"step_number": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "integer",
"format": null,
"max": null,
"min": null
}
},
"type": "object",
"variants": []
},
"cooking_step_create_payload": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"duration_minutes": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": true,
"optional": true,
"type": "integer",
"format": null,
"max": null,
"min": null
},
"instruction": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "string",
"format": null,
"max": null,
"min": null
},
"step_number": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "integer",
"format": null,
"max": null,
"min": null
}
},
"type": "object",
"variants": []
},
"cooking_step_nested_create_payload": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"OP": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "literal",
"value": "create"
},
"duration_minutes": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": true,
"optional": true,
"type": "integer",
"format": null,
"max": null,
"min": null
},
"instruction": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "string",
"format": null,
"max": null,
"min": null
},
"step_number": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "integer",
"format": null,
"max": null,
"min": null
}
},
"type": "object",
"variants": []
},
"cooking_step_nested_delete_payload": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"OP": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "literal",
"value": "delete"
},
"id": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "string",
"format": null,
"max": null,
"min": null
}
},
"type": "object",
"variants": []
},
"cooking_step_nested_payload": {
"deprecated": false,
"description": null,
"discriminator": "OP",
"example": null,
"extends": [],
"shape": {},
"type": "union",
"variants": [
{
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "cooking_step_nested_create_payload"
},
{
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "cooking_step_nested_update_payload"
},
{
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "cooking_step_nested_delete_payload"
}
]
},
"cooking_step_nested_update_payload": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"OP": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "literal",
"value": "update"
},
"duration_minutes": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": true,
"optional": true,
"type": "integer",
"format": null,
"max": null,
"min": null
},
"id": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "string",
"format": null,
"max": null,
"min": null
},
"instruction": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "string",
"format": null,
"max": null,
"min": null
},
"step_number": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "integer",
"format": null,
"max": null,
"min": null
}
},
"type": "object",
"variants": []
},
"cooking_step_update_payload": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"duration_minutes": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": true,
"optional": true,
"type": "integer",
"format": null,
"max": null,
"min": null
},
"instruction": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "string",
"format": null,
"max": null,
"min": null
},
"step_number": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "integer",
"format": null,
"max": null,
"min": null
}
},
"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": []
},
"meal_plan": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"cook_time": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": true,
"optional": false,
"type": "integer",
"format": null,
"max": null,
"min": null
},
"cooking_steps": {
"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": "cooking_step"
},
"shape": {}
},
"created_at": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "datetime"
},
"id": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "string",
"format": null,
"max": null,
"min": null
},
"serving_size": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": true,
"optional": false,
"type": "integer",
"format": null,
"max": null,
"min": null
},
"title": {
"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": []
},
"meal_plan_create_payload": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"cook_time": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": true,
"optional": true,
"type": "integer",
"format": null,
"max": null,
"min": null
},
"cooking_steps": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "array",
"max": null,
"min": null,
"of": {
"default": null,
"deprecated": null,
"description": null,
"example": null,
"nullable": null,
"optional": null,
"type": "reference",
"reference": "cooking_step_nested_payload"
},
"shape": {}
},
"serving_size": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": true,
"optional": true,
"type": "integer",
"format": null,
"max": null,
"min": null
},
"title": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "string",
"format": null,
"max": null,
"min": null
}
},
"type": "object",
"variants": []
},
"meal_plan_create_success_response_body": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"meal_plan": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "meal_plan"
},
"meta": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "object",
"partial": false,
"shape": {}
}
},
"type": "object",
"variants": []
},
"meal_plan_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"
},
"meal_plans": {
"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": "meal_plan"
},
"shape": {}
},
"meta": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "object",
"partial": false,
"shape": {}
}
},
"type": "object",
"variants": []
},
"meal_plan_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": []
},
"meal_plan_show_success_response_body": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"meal_plan": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "meal_plan"
},
"meta": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "object",
"partial": false,
"shape": {}
}
},
"type": "object",
"variants": []
},
"meal_plan_update_payload": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"cook_time": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": true,
"optional": true,
"type": "integer",
"format": null,
"max": null,
"min": null
},
"cooking_steps": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "array",
"max": null,
"min": null,
"of": {
"default": null,
"deprecated": null,
"description": null,
"example": null,
"nullable": null,
"optional": null,
"type": "reference",
"reference": "cooking_step_nested_payload"
},
"shape": {}
},
"serving_size": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": true,
"optional": true,
"type": "integer",
"format": null,
"max": null,
"min": null
},
"title": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "string",
"format": null,
"max": null,
"min": null
}
},
"type": "object",
"variants": []
},
"meal_plan_update_success_response_body": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"meal_plan": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "meal_plan"
},
"meta": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "object",
"partial": false,
"shape": {}
}
},
"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 CookingStep {
DurationMinutes: null | number;
Id: string;
Instruction: string;
StepNumber: number;
}
export interface CookingStepNestedCreatePayload {
OP?: 'create';
DurationMinutes?: null | number;
Instruction: string;
StepNumber: number;
}
export interface CookingStepNestedDeletePayload {
OP?: 'delete';
Id: string;
}
export type CookingStepNestedPayload = CookingStepNestedCreatePayload | CookingStepNestedUpdatePayload | CookingStepNestedDeletePayload;
export interface CookingStepNestedUpdatePayload {
OP?: 'update';
DurationMinutes?: null | number;
Id?: string;
Instruction?: string;
StepNumber?: number;
}
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 MealPlan {
CookTime: null | number;
CookingSteps: CookingStep[];
CreatedAt: string;
Id: string;
ServingSize: null | number;
Title: string;
UpdatedAt: string;
}
export interface MealPlanCreatePayload {
CookTime?: null | number;
CookingSteps?: CookingStepNestedPayload[];
ServingSize?: null | number;
Title: string;
}
export interface MealPlanCreateSuccessResponseBody {
MealPlan: MealPlan;
Meta?: Record<string, unknown>;
}
export interface MealPlanIndexSuccessResponseBody {
MealPlans: MealPlan[];
Meta?: Record<string, unknown>;
Pagination: OffsetPagination;
}
export interface MealPlanPage {
Number?: number;
Size?: number;
}
export interface MealPlanShowSuccessResponseBody {
MealPlan: MealPlan;
Meta?: Record<string, unknown>;
}
export interface MealPlanUpdatePayload {
CookTime?: null | number;
CookingSteps?: CookingStepNestedPayload[];
ServingSize?: null | number;
Title?: string;
}
export interface MealPlanUpdateSuccessResponseBody {
MealPlan: MealPlan;
Meta?: Record<string, unknown>;
}
export interface MealPlansCreateRequest {
body: MealPlansCreateRequestBody;
}
export interface MealPlansCreateRequestBody {
MealPlan: MealPlanCreatePayload;
}
export interface MealPlansCreateResponse {
body: MealPlansCreateResponseBody;
}
export type MealPlansCreateResponseBody = ErrorResponseBody | MealPlanCreateSuccessResponseBody;
export type MealPlansDestroyResponse = never;
export interface MealPlansIndexRequest {
query: MealPlansIndexRequestQuery;
}
export interface MealPlansIndexRequestQuery {
Page?: MealPlanPage;
}
export interface MealPlansIndexResponse {
body: MealPlansIndexResponseBody;
}
export type MealPlansIndexResponseBody = ErrorResponseBody | MealPlanIndexSuccessResponseBody;
export interface MealPlansShowResponse {
body: MealPlansShowResponseBody;
}
export type MealPlansShowResponseBody = ErrorResponseBody | MealPlanShowSuccessResponseBody;
export interface MealPlansUpdateRequest {
body: MealPlansUpdateRequestBody;
}
export interface MealPlansUpdateRequestBody {
MealPlan: MealPlanUpdatePayload;
}
export interface MealPlansUpdateResponse {
body: MealPlansUpdateResponseBody;
}
export type MealPlansUpdateResponseBody = ErrorResponseBody | MealPlanUpdateSuccessResponseBody;
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 CookingStepSchema = z.object({
DurationMinutes: z.number().int().nullable(),
Id: z.string(),
Instruction: z.string(),
StepNumber: z.number().int()
});
export const CookingStepNestedCreatePayloadSchema = z.object({
OP: z.literal('create').optional(),
DurationMinutes: z.number().int().nullable().optional(),
Instruction: z.string(),
StepNumber: z.number().int()
});
export const CookingStepNestedDeletePayloadSchema = z.object({
OP: z.literal('delete').optional(),
Id: z.string()
});
export const CookingStepNestedUpdatePayloadSchema = z.object({
OP: z.literal('update').optional(),
DurationMinutes: z.number().int().nullable().optional(),
Id: z.string().optional(),
Instruction: z.string().optional(),
StepNumber: z.number().int().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 MealPlanPageSchema = z.object({
Number: z.number().int().min(1).optional(),
Size: z.number().int().min(1).max(100).optional()
});
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 CookingStepNestedPayloadSchema = z.discriminatedUnion('OP', [
CookingStepNestedCreatePayloadSchema,
CookingStepNestedUpdatePayloadSchema,
CookingStepNestedDeletePayloadSchema
]);
export const ErrorSchema = z.object({
Issues: z.array(IssueSchema),
Layer: LayerSchema
});
export const MealPlanSchema = z.object({
CookTime: z.number().int().nullable(),
CookingSteps: z.array(CookingStepSchema),
CreatedAt: z.iso.datetime(),
Id: z.string(),
ServingSize: z.number().int().nullable(),
Title: z.string(),
UpdatedAt: z.iso.datetime()
});
export const ErrorResponseBodySchema = ErrorSchema;
export const MealPlanCreatePayloadSchema = z.object({
CookTime: z.number().int().nullable().optional(),
CookingSteps: z.array(CookingStepNestedPayloadSchema).optional(),
ServingSize: z.number().int().nullable().optional(),
Title: z.string()
});
export const MealPlanCreateSuccessResponseBodySchema = z.object({
MealPlan: MealPlanSchema,
Meta: z.record(z.string(), z.unknown()).optional()
});
export const MealPlanIndexSuccessResponseBodySchema = z.object({
MealPlans: z.array(MealPlanSchema),
Meta: z.record(z.string(), z.unknown()).optional(),
Pagination: OffsetPaginationSchema
});
export const MealPlanShowSuccessResponseBodySchema = z.object({
MealPlan: MealPlanSchema,
Meta: z.record(z.string(), z.unknown()).optional()
});
export const MealPlanUpdatePayloadSchema = z.object({
CookTime: z.number().int().nullable().optional(),
CookingSteps: z.array(CookingStepNestedPayloadSchema).optional(),
ServingSize: z.number().int().nullable().optional(),
Title: z.string().optional()
});
export const MealPlanUpdateSuccessResponseBodySchema = z.object({
MealPlan: MealPlanSchema,
Meta: z.record(z.string(), z.unknown()).optional()
});
export const MealPlansIndexRequestQuerySchema = z.object({
Page: MealPlanPageSchema.optional()
});
export const MealPlansIndexRequestSchema = z.object({
query: MealPlansIndexRequestQuerySchema
});
export const MealPlansIndexResponseBodySchema = z.union([MealPlanIndexSuccessResponseBodySchema, ErrorResponseBodySchema]);
export const MealPlansIndexResponseSchema = z.object({
body: MealPlansIndexResponseBodySchema
});
export const MealPlansShowResponseBodySchema = z.union([MealPlanShowSuccessResponseBodySchema, ErrorResponseBodySchema]);
export const MealPlansShowResponseSchema = z.object({
body: MealPlansShowResponseBodySchema
});
export const MealPlansCreateRequestBodySchema = z.object({
MealPlan: MealPlanCreatePayloadSchema
});
export const MealPlansCreateRequestSchema = z.object({
body: MealPlansCreateRequestBodySchema
});
export const MealPlansCreateResponseBodySchema = z.union([MealPlanCreateSuccessResponseBodySchema, ErrorResponseBodySchema]);
export const MealPlansCreateResponseSchema = z.object({
body: MealPlansCreateResponseBodySchema
});
export const MealPlansUpdateRequestBodySchema = z.object({
MealPlan: MealPlanUpdatePayloadSchema
});
export const MealPlansUpdateRequestSchema = z.object({
body: MealPlansUpdateRequestBodySchema
});
export const MealPlansUpdateResponseBodySchema = z.union([MealPlanUpdateSuccessResponseBodySchema, ErrorResponseBodySchema]);
export const MealPlansUpdateResponseSchema = z.object({
body: MealPlansUpdateResponseBodySchema
});
export const MealPlansDestroyResponseSchema = z.never();
export interface CookingStep {
DurationMinutes: null | number;
Id: string;
Instruction: string;
StepNumber: number;
}
export interface CookingStepNestedCreatePayload {
OP?: 'create';
DurationMinutes?: null | number;
Instruction: string;
StepNumber: number;
}
export interface CookingStepNestedDeletePayload {
OP?: 'delete';
Id: string;
}
export type CookingStepNestedPayload = CookingStepNestedCreatePayload | CookingStepNestedUpdatePayload | CookingStepNestedDeletePayload;
export interface CookingStepNestedUpdatePayload {
OP?: 'update';
DurationMinutes?: null | number;
Id?: string;
Instruction?: string;
StepNumber?: number;
}
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 MealPlan {
CookTime: null | number;
CookingSteps: CookingStep[];
CreatedAt: string;
Id: string;
ServingSize: null | number;
Title: string;
UpdatedAt: string;
}
export interface MealPlanCreatePayload {
CookTime?: null | number;
CookingSteps?: CookingStepNestedPayload[];
ServingSize?: null | number;
Title: string;
}
export interface MealPlanCreateSuccessResponseBody {
MealPlan: MealPlan;
Meta?: Record<string, unknown>;
}
export interface MealPlanIndexSuccessResponseBody {
MealPlans: MealPlan[];
Meta?: Record<string, unknown>;
Pagination: OffsetPagination;
}
export interface MealPlanPage {
Number?: number;
Size?: number;
}
export interface MealPlanShowSuccessResponseBody {
MealPlan: MealPlan;
Meta?: Record<string, unknown>;
}
export interface MealPlanUpdatePayload {
CookTime?: null | number;
CookingSteps?: CookingStepNestedPayload[];
ServingSize?: null | number;
Title?: string;
}
export interface MealPlanUpdateSuccessResponseBody {
MealPlan: MealPlan;
Meta?: Record<string, unknown>;
}
export interface MealPlansCreateRequest {
body: MealPlansCreateRequestBody;
}
export interface MealPlansCreateRequestBody {
MealPlan: MealPlanCreatePayload;
}
export interface MealPlansCreateResponse {
body: MealPlansCreateResponseBody;
}
export type MealPlansCreateResponseBody = ErrorResponseBody | MealPlanCreateSuccessResponseBody;
export type MealPlansDestroyResponse = never;
export interface MealPlansIndexRequest {
query: MealPlansIndexRequestQuery;
}
export interface MealPlansIndexRequestQuery {
Page?: MealPlanPage;
}
export interface MealPlansIndexResponse {
body: MealPlansIndexResponseBody;
}
export type MealPlansIndexResponseBody = ErrorResponseBody | MealPlanIndexSuccessResponseBody;
export interface MealPlansShowResponse {
body: MealPlansShowResponseBody;
}
export type MealPlansShowResponseBody = ErrorResponseBody | MealPlanShowSuccessResponseBody;
export interface MealPlansUpdateRequest {
body: MealPlansUpdateRequestBody;
}
export interface MealPlansUpdateRequestBody {
MealPlan: MealPlanUpdatePayload;
}
export interface MealPlansUpdateResponse {
body: MealPlansUpdateResponseBody;
}
export type MealPlansUpdateResponseBody = ErrorResponseBody | MealPlanUpdateSuccessResponseBody;
export interface OffsetPagination {
Current: number;
Items: number;
Next?: null | number;
Prev?: null | number;
Total: number;
}OpenAPI
yml
---
openapi: 3.1.0
info:
title: "/nimble_gecko"
version: 1.0.0
paths:
"/meal-plans":
get:
operationId: MealPlansIndex
parameters:
- in: query
name: Page
required: false
schema:
"$ref": "#/components/schemas/MealPlanPage"
responses:
'200':
content:
application/json:
schema:
"$ref": "#/components/schemas/MealPlanIndexSuccessResponseBody"
description: Successful response
post:
operationId: MealPlansCreate
requestBody:
content:
application/json:
schema:
properties:
MealPlan:
"$ref": "#/components/schemas/MealPlanCreatePayload"
type: object
required:
- MealPlan
required: true
responses:
'200':
content:
application/json:
schema:
"$ref": "#/components/schemas/MealPlanCreateSuccessResponseBody"
description: Successful response
'422':
description: Unprocessable Entity
content:
application/json:
schema:
"$ref": "#/components/schemas/ErrorResponseBody"
"/meal-plans/{Id}":
get:
operationId: MealPlansShow
parameters:
- in: path
name: Id
required: true
schema:
type: string
responses:
'200':
content:
application/json:
schema:
"$ref": "#/components/schemas/MealPlanShowSuccessResponseBody"
description: Successful response
patch:
operationId: MealPlansUpdate
parameters:
- in: path
name: Id
required: true
schema:
type: string
requestBody:
content:
application/json:
schema:
properties:
MealPlan:
"$ref": "#/components/schemas/MealPlanUpdatePayload"
type: object
required:
- MealPlan
required: true
responses:
'200':
content:
application/json:
schema:
"$ref": "#/components/schemas/MealPlanUpdateSuccessResponseBody"
description: Successful response
'422':
description: Unprocessable Entity
content:
application/json:
schema:
"$ref": "#/components/schemas/ErrorResponseBody"
delete:
operationId: MealPlansDestroy
parameters:
- in: path
name: Id
required: true
schema:
type: string
responses:
'204':
description: No content
components:
schemas:
CookingStep:
properties:
DurationMinutes:
type:
- integer
- 'null'
Id:
type: string
Instruction:
type: string
StepNumber:
type: integer
type: object
required:
- DurationMinutes
- Id
- Instruction
- StepNumber
CookingStepNestedCreatePayload:
properties:
OP:
const: create
type: string
DurationMinutes:
type:
- integer
- 'null'
Instruction:
type: string
StepNumber:
type: integer
type: object
required:
- Instruction
- StepNumber
CookingStepNestedDeletePayload:
properties:
OP:
const: delete
type: string
Id:
type: string
type: object
required:
- Id
CookingStepNestedPayload:
oneOf:
- "$ref": "#/components/schemas/CookingStepNestedCreatePayload"
- "$ref": "#/components/schemas/CookingStepNestedUpdatePayload"
- "$ref": "#/components/schemas/CookingStepNestedDeletePayload"
discriminator:
mapping:
Create: "#/components/schemas/CookingStepNestedCreatePayload"
Update: "#/components/schemas/CookingStepNestedUpdatePayload"
Delete: "#/components/schemas/CookingStepNestedDeletePayload"
propertyName: OP
CookingStepNestedUpdatePayload:
properties:
OP:
const: update
type: string
DurationMinutes:
type:
- integer
- 'null'
Id:
type: string
Instruction:
type: string
StepNumber:
type: integer
type: object
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
MealPlan:
properties:
CookTime:
type:
- integer
- 'null'
CookingSteps:
items:
"$ref": "#/components/schemas/CookingStep"
type: array
CreatedAt:
type: string
format: date-time
Id:
type: string
ServingSize:
type:
- integer
- 'null'
Title:
type: string
UpdatedAt:
type: string
format: date-time
type: object
required:
- CookTime
- CookingSteps
- CreatedAt
- Id
- ServingSize
- Title
- UpdatedAt
MealPlanCreatePayload:
properties:
CookTime:
type:
- integer
- 'null'
CookingSteps:
items:
"$ref": "#/components/schemas/CookingStepNestedPayload"
type: array
ServingSize:
type:
- integer
- 'null'
Title:
type: string
type: object
required:
- Title
MealPlanCreateSuccessResponseBody:
properties:
MealPlan:
"$ref": "#/components/schemas/MealPlan"
Meta:
properties: {}
type: object
type: object
required:
- MealPlan
MealPlanIndexSuccessResponseBody:
properties:
Pagination:
"$ref": "#/components/schemas/OffsetPagination"
MealPlans:
items:
"$ref": "#/components/schemas/MealPlan"
type: array
Meta:
properties: {}
type: object
type: object
required:
- Pagination
- MealPlans
MealPlanPage:
properties:
Number:
type: integer
minimum: 1
Size:
type: integer
minimum: 1
maximum: 100
type: object
MealPlanShowSuccessResponseBody:
properties:
MealPlan:
"$ref": "#/components/schemas/MealPlan"
Meta:
properties: {}
type: object
type: object
required:
- MealPlan
MealPlanUpdatePayload:
properties:
CookTime:
type:
- integer
- 'null'
CookingSteps:
items:
"$ref": "#/components/schemas/CookingStepNestedPayload"
type: array
ServingSize:
type:
- integer
- 'null'
Title:
type: string
type: object
MealPlanUpdateSuccessResponseBody:
properties:
MealPlan:
"$ref": "#/components/schemas/MealPlan"
Meta:
properties: {}
type: object
type: object
required:
- MealPlan
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