Polymorphic Associations
Comments that belong to different content types (posts, videos)
API Definition
config/apis/gentle_owl.rb
rb
# frozen_string_literal: true
Apiwork::API.define '/gentle_owl' do
key_format :camel
export :openapi
export :typescript
export :zod
resources :comments
endModels
app/models/gentle_owl/comment.rb
rb
# frozen_string_literal: true
module GentleOwl
class Comment < ApplicationRecord
belongs_to :commentable, polymorphic: true
validates :body, presence: true
end
endDatabase Table
| Column | Type | Nullable | Default |
|---|---|---|---|
| id | string | ||
| author_name | string | ✓ | |
| body | text | ||
| commentable_id | string | ||
| commentable_type | string | ||
| created_at | datetime | ||
| updated_at | datetime |
app/models/gentle_owl/post.rb
rb
# frozen_string_literal: true
module GentleOwl
class Post < ApplicationRecord
has_many :comments, as: :commentable, dependent: :destroy
validates :title, presence: true
end
endDatabase Table
| Column | Type | Nullable | Default |
|---|---|---|---|
| id | string | ||
| body | text | ✓ | |
| created_at | datetime | ||
| title | string | ||
| updated_at | datetime |
app/models/gentle_owl/video.rb
rb
# frozen_string_literal: true
module GentleOwl
class Video < ApplicationRecord
has_many :comments, as: :commentable, dependent: :destroy
validates :title, :url, presence: true
end
endDatabase Table
| Column | Type | Nullable | Default |
|---|---|---|---|
| id | string | ||
| created_at | datetime | ||
| duration | integer | ✓ | |
| title | string | ||
| updated_at | datetime | ||
| url | string |
Representations
app/representations/gentle_owl/comment_representation.rb
rb
# frozen_string_literal: true
module GentleOwl
class CommentRepresentation < Apiwork::Representation::Base
attribute :id
attribute :body, writable: true
attribute :author_name, writable: true
attribute :commentable_type, filterable: true, writable: true
attribute :commentable_id, writable: true
attribute :created_at, sortable: true
attribute :updated_at, sortable: true
belongs_to :commentable, polymorphic: [PostRepresentation, VideoRepresentation]
end
endapp/representations/gentle_owl/post_representation.rb
rb
# frozen_string_literal: true
module GentleOwl
class PostRepresentation < Apiwork::Representation::Base
type_name :post
attribute :id
attribute :title, filterable: true, writable: true
attribute :body, writable: true
attribute :created_at, sortable: true
attribute :updated_at, sortable: true
has_many :comments
end
endapp/representations/gentle_owl/video_representation.rb
rb
# frozen_string_literal: true
module GentleOwl
class VideoRepresentation < Apiwork::Representation::Base
type_name :video
attribute :id
attribute :title, filterable: true, writable: true
attribute :url, writable: true
attribute :duration, writable: true
attribute :created_at, sortable: true
attribute :updated_at, sortable: true
has_many :comments
end
endContracts
app/contracts/gentle_owl/comment_contract.rb
rb
# frozen_string_literal: true
module GentleOwl
class CommentContract < Apiwork::Contract::Base
representation CommentRepresentation
end
endControllers
app/controllers/gentle_owl/comments_controller.rb
rb
# frozen_string_literal: true
module GentleOwl
class CommentsController < ApplicationController
before_action :set_comment, only: %i[show update destroy]
def index
comments = Comment.all
expose comments
end
def show
expose comment
end
def create
comment = Comment.create(contract.body[:comment])
expose comment
end
def update
comment.update(contract.body[:comment])
expose comment
end
def destroy
comment.destroy
expose comment
end
private
attr_reader :comment
def set_comment
@comment = Comment.find(params[:id])
end
end
endRequest Examples
List all comments
Request
http
GET /gentle_owl/commentsResponse 200
json
{
"comments": [
{
"id": "d1ff1866-6fad-545c-839e-2d972eb5729c",
"body": "Great post!",
"authorName": "John Doe",
"commentableType": "post",
"commentableId": "96988365-65b2-5455-a8a8-491aa772ba47",
"createdAt": "2024-01-01T12:00:00.000Z",
"updatedAt": "2024-01-01T12:00:00.000Z"
},
{
"id": "6027b33b-0a17-5c68-bcc1-527ae6105f2c",
"body": "Helpful video!",
"authorName": "Jane Doe",
"commentableType": "video",
"commentableId": "df4ddc5a-953d-52f5-b5b5-7ddf16fa8f57",
"createdAt": "2024-01-01T12:00:00.000Z",
"updatedAt": "2024-01-01T12:00:00.000Z"
}
],
"pagination": {
"items": 2,
"total": 1,
"current": 1,
"next": null,
"prev": null
}
}Get comment details
Request
http
GET /gentle_owl/comments/d1ff1866-6fad-545c-839e-2d972eb5729cResponse 200
json
{
"comment": {
"id": "d1ff1866-6fad-545c-839e-2d972eb5729c",
"body": "Great post!",
"authorName": "John Doe",
"commentableType": "post",
"commentableId": "96988365-65b2-5455-a8a8-491aa772ba47",
"createdAt": "2024-01-01T12:00:00.000Z",
"updatedAt": "2024-01-01T12:00:00.000Z"
}
}Create comment on post
Request
http
POST /gentle_owl/comments
Content-Type: application/json
{
"comment": {
"body": "This is a great article!",
"authorName": "Jane Doe",
"commentableType": "post",
"commentableId": "96988365-65b2-5455-a8a8-491aa772ba47"
}
}Response 201
json
{
"comment": {
"id": "d1ff1866-6fad-545c-839e-2d972eb5729c",
"body": "This is a great article!",
"authorName": "Jane Doe",
"commentableType": "post",
"commentableId": "96988365-65b2-5455-a8a8-491aa772ba47",
"createdAt": "2024-01-01T12:00:00.000Z",
"updatedAt": "2024-01-01T12:00:00.000Z"
}
}Create comment on video
Request
http
POST /gentle_owl/comments
Content-Type: application/json
{
"comment": {
"body": "Very helpful video!",
"authorName": "Bob Smith",
"commentableType": "video",
"commentableId": "df4ddc5a-953d-52f5-b5b5-7ddf16fa8f57"
}
}Response 201
json
{
"comment": {
"id": "d1ff1866-6fad-545c-839e-2d972eb5729c",
"body": "Very helpful video!",
"authorName": "Bob Smith",
"commentableType": "video",
"commentableId": "df4ddc5a-953d-52f5-b5b5-7ddf16fa8f57",
"createdAt": "2024-01-01T12:00:00.000Z",
"updatedAt": "2024-01-01T12:00:00.000Z"
}
}Filter by content type
Request
http
GET /gentle_owl/comments?filter[commentableType][eq]=postResponse 200
json
{
"comments": [
{
"id": "d1ff1866-6fad-545c-839e-2d972eb5729c",
"body": "Post comment",
"authorName": "User 1",
"commentableType": "post",
"commentableId": "96988365-65b2-5455-a8a8-491aa772ba47",
"createdAt": "2024-01-01T12:00:00.000Z",
"updatedAt": "2024-01-01T12:00:00.000Z"
}
],
"pagination": {
"items": 1,
"total": 1,
"current": 1,
"next": null,
"prev": null
}
}Generated Output
Introspection
json
{
"base_path": "/gentle_owl",
"enums": {
"comment_commentable_type": {
"deprecated": false,
"description": null,
"example": null,
"values": [
"post",
"video"
]
},
"layer": {
"deprecated": false,
"description": null,
"example": null,
"values": [
"http",
"contract",
"domain"
]
},
"sort_direction": {
"deprecated": false,
"description": null,
"example": null,
"values": [
"asc",
"desc"
]
}
},
"error_codes": {
"unprocessable_entity": {
"description": "Unprocessable Entity",
"status": 422
}
},
"info": null,
"resources": {
"comments": {
"actions": {
"index": {
"deprecated": false,
"description": null,
"method": "get",
"operation_id": null,
"path": "/comments",
"raises": [],
"request": {
"body": {},
"query": {
"filter": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "union",
"discriminator": null,
"variants": [
{
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "comment_filter"
},
{
"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": "comment_filter"
},
"shape": {}
}
]
},
"include": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "reference",
"reference": "comment_include"
},
"page": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "reference",
"reference": "comment_page"
},
"sort": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "union",
"discriminator": null,
"variants": [
{
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "comment_sort"
},
{
"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": "comment_sort"
},
"shape": {}
}
]
}
}
},
"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": "comment_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": "/comments/:id",
"raises": [],
"request": {
"body": {},
"query": {
"include": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "reference",
"reference": "comment_include"
}
}
},
"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": "comment_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": "/comments",
"raises": [
"unprocessable_entity"
],
"request": {
"body": {
"comment": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "comment_create_payload"
}
},
"query": {
"include": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "reference",
"reference": "comment_include"
}
}
},
"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": "comment_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": "/comments/:id",
"raises": [
"unprocessable_entity"
],
"request": {
"body": {
"comment": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "comment_update_payload"
}
},
"query": {
"include": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "reference",
"reference": "comment_include"
}
}
},
"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": "comment_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": "/comments/:id",
"raises": [],
"request": {
"body": {},
"query": {
"include": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "reference",
"reference": "comment_include"
}
}
},
"response": {
"body": {
"default": null,
"deprecated": null,
"description": null,
"example": null,
"nullable": null,
"optional": null,
"type": null
},
"no_content": true
},
"summary": null,
"tags": []
}
},
"identifier": "comments",
"parent_identifiers": [],
"path": "comments",
"resources": {}
}
},
"types": {
"comment": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"author_name": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": true,
"optional": false,
"type": "string",
"format": null,
"max": null,
"min": null
},
"body": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "string",
"format": null,
"max": null,
"min": null
},
"commentable": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "reference",
"reference": "comment_commentable"
},
"commentable_id": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "string",
"format": null,
"max": null,
"min": null
},
"commentable_type": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "string",
"format": null,
"max": null,
"min": null
},
"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
},
"updated_at": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "datetime"
}
},
"type": "object",
"variants": []
},
"comment_commentable": {
"deprecated": false,
"description": null,
"discriminator": "commentable_type",
"example": null,
"extends": [],
"shape": {},
"type": "union",
"variants": [
{
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "post"
},
{
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "video"
}
]
},
"comment_commentable_type_filter": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {},
"type": "union",
"variants": [
{
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "comment_commentable_type"
},
{
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "object",
"partial": true,
"shape": {
"eq": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "comment_commentable_type"
},
"in": {
"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": "comment_commentable_type"
},
"shape": {}
}
}
}
]
},
"comment_create_payload": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"author_name": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": true,
"optional": true,
"type": "string",
"format": null,
"max": null,
"min": null
},
"body": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "string",
"format": null,
"max": null,
"min": null
},
"commentable_id": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "string",
"format": null,
"max": null,
"min": null
},
"commentable_type": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "string",
"enum": [
"post",
"video"
],
"format": null,
"max": null,
"min": null
}
},
"type": "object",
"variants": []
},
"comment_create_success_response_body": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"comment": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "comment"
},
"meta": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "object",
"partial": false,
"shape": {}
}
},
"type": "object",
"variants": []
},
"comment_filter": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"AND": {
"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": "comment_filter"
},
"shape": {}
},
"NOT": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "reference",
"reference": "comment_filter"
},
"OR": {
"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": "comment_filter"
},
"shape": {}
},
"commentable_type": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "reference",
"reference": "comment_commentable_type_filter"
}
},
"type": "object",
"variants": []
},
"comment_include": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"commentable": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "boolean"
}
},
"type": "object",
"variants": []
},
"comment_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"
},
"comments": {
"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": "comment"
},
"shape": {}
},
"meta": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "object",
"partial": false,
"shape": {}
}
},
"type": "object",
"variants": []
},
"comment_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": []
},
"comment_show_success_response_body": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"comment": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "comment"
},
"meta": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "object",
"partial": false,
"shape": {}
}
},
"type": "object",
"variants": []
},
"comment_sort": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"created_at": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "reference",
"reference": "sort_direction"
},
"updated_at": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "reference",
"reference": "sort_direction"
}
},
"type": "object",
"variants": []
},
"comment_update_payload": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"author_name": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": true,
"optional": true,
"type": "string",
"format": null,
"max": null,
"min": null
},
"body": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "string",
"format": null,
"max": null,
"min": null
},
"commentable_id": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "string",
"format": null,
"max": null,
"min": null
},
"commentable_type": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "string",
"enum": [
"post",
"video"
],
"format": null,
"max": null,
"min": null
}
},
"type": "object",
"variants": []
},
"comment_update_success_response_body": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"comment": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "comment"
},
"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": []
},
"post": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"body": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": true,
"optional": false,
"type": "string",
"format": null,
"max": null,
"min": null
},
"comments": {
"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": "comment"
},
"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
},
"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": []
},
"post_create_payload": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"body": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": true,
"optional": true,
"type": "string",
"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": []
},
"post_filter": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"AND": {
"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": "post_filter"
},
"shape": {}
},
"NOT": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "reference",
"reference": "post_filter"
},
"OR": {
"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": "post_filter"
},
"shape": {}
},
"title": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "union",
"discriminator": null,
"variants": [
{
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "string",
"format": null,
"max": null,
"min": null
},
{
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "string_filter"
}
]
}
},
"type": "object",
"variants": []
},
"post_include": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"comments": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "union",
"discriminator": null,
"variants": [
{
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "boolean"
},
{
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "comment_include"
}
]
}
},
"type": "object",
"variants": []
},
"post_sort": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"created_at": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "reference",
"reference": "sort_direction"
},
"updated_at": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "reference",
"reference": "sort_direction"
}
},
"type": "object",
"variants": []
},
"post_update_payload": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"body": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": true,
"optional": true,
"type": "string",
"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": []
},
"string_filter": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"contains": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "string",
"format": null,
"max": null,
"min": null
},
"ends_with": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "string",
"format": null,
"max": null,
"min": null
},
"eq": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "string",
"format": null,
"max": null,
"min": null
},
"in": {
"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": "string",
"format": null,
"max": null,
"min": null
},
"shape": {}
},
"starts_with": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "string",
"format": null,
"max": null,
"min": null
}
},
"type": "object",
"variants": []
},
"video": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"comments": {
"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": "comment"
},
"shape": {}
},
"created_at": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "datetime"
},
"duration": {
"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
},
"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"
},
"url": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "string",
"format": null,
"max": null,
"min": null
}
},
"type": "object",
"variants": []
},
"video_create_payload": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"duration": {
"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
},
"url": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "string",
"format": null,
"max": null,
"min": null
}
},
"type": "object",
"variants": []
},
"video_filter": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"AND": {
"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": "video_filter"
},
"shape": {}
},
"NOT": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "reference",
"reference": "video_filter"
},
"OR": {
"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": "video_filter"
},
"shape": {}
},
"title": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "union",
"discriminator": null,
"variants": [
{
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "string",
"format": null,
"max": null,
"min": null
},
{
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "string_filter"
}
]
}
},
"type": "object",
"variants": []
},
"video_include": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"comments": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "union",
"discriminator": null,
"variants": [
{
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "boolean"
},
{
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": false,
"type": "reference",
"reference": "comment_include"
}
]
}
},
"type": "object",
"variants": []
},
"video_sort": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"created_at": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "reference",
"reference": "sort_direction"
},
"updated_at": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "reference",
"reference": "sort_direction"
}
},
"type": "object",
"variants": []
},
"video_update_payload": {
"deprecated": false,
"description": null,
"discriminator": null,
"example": null,
"extends": [],
"shape": {
"duration": {
"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
},
"url": {
"default": null,
"deprecated": false,
"description": null,
"example": null,
"nullable": false,
"optional": true,
"type": "string",
"format": null,
"max": null,
"min": null
}
},
"type": "object",
"variants": []
}
}
}TypeScript
ts
export interface Comment {
authorName: null | string;
body: string;
commentable?: CommentCommentable;
commentableId: string;
commentableType: string;
createdAt: string;
id: string;
updatedAt: string;
}
export type CommentCommentable = { commentableType: 'post' } & Post | { commentableType: 'video' } & Video;
export type CommentCommentableType = 'post' | 'video';
export type CommentCommentableTypeFilter = CommentCommentableType | { eq?: CommentCommentableType; in?: CommentCommentableType[] };
export interface CommentCreatePayload {
authorName?: null | string;
body: string;
commentableId: string;
commentableType: 'post' | 'video';
}
export interface CommentCreateSuccessResponseBody {
comment: Comment;
meta?: Record<string, unknown>;
}
export interface CommentFilter {
AND?: CommentFilter[];
NOT?: CommentFilter;
OR?: CommentFilter[];
commentableType?: CommentCommentableTypeFilter;
}
export interface CommentInclude {
commentable?: boolean;
}
export interface CommentIndexSuccessResponseBody {
comments: Comment[];
meta?: Record<string, unknown>;
pagination: OffsetPagination;
}
export interface CommentPage {
number?: number;
size?: number;
}
export interface CommentShowSuccessResponseBody {
comment: Comment;
meta?: Record<string, unknown>;
}
export interface CommentSort {
createdAt?: SortDirection;
updatedAt?: SortDirection;
}
export interface CommentUpdatePayload {
authorName?: null | string;
body?: string;
commentableId?: string;
commentableType?: 'post' | 'video';
}
export interface CommentUpdateSuccessResponseBody {
comment: Comment;
meta?: Record<string, unknown>;
}
export interface CommentsCreateRequest {
query: CommentsCreateRequestQuery;
body: CommentsCreateRequestBody;
}
export interface CommentsCreateRequestBody {
comment: CommentCreatePayload;
}
export interface CommentsCreateRequestQuery {
include?: CommentInclude;
}
export interface CommentsCreateResponse {
body: CommentsCreateResponseBody;
}
export type CommentsCreateResponseBody = CommentCreateSuccessResponseBody | ErrorResponseBody;
export interface CommentsDestroyRequest {
query: CommentsDestroyRequestQuery;
}
export interface CommentsDestroyRequestQuery {
include?: CommentInclude;
}
export type CommentsDestroyResponse = never;
export interface CommentsIndexRequest {
query: CommentsIndexRequestQuery;
}
export interface CommentsIndexRequestQuery {
filter?: CommentFilter | CommentFilter[];
include?: CommentInclude;
page?: CommentPage;
sort?: CommentSort | CommentSort[];
}
export interface CommentsIndexResponse {
body: CommentsIndexResponseBody;
}
export type CommentsIndexResponseBody = CommentIndexSuccessResponseBody | ErrorResponseBody;
export interface CommentsShowRequest {
query: CommentsShowRequestQuery;
}
export interface CommentsShowRequestQuery {
include?: CommentInclude;
}
export interface CommentsShowResponse {
body: CommentsShowResponseBody;
}
export type CommentsShowResponseBody = CommentShowSuccessResponseBody | ErrorResponseBody;
export interface CommentsUpdateRequest {
query: CommentsUpdateRequestQuery;
body: CommentsUpdateRequestBody;
}
export interface CommentsUpdateRequestBody {
comment: CommentUpdatePayload;
}
export interface CommentsUpdateRequestQuery {
include?: CommentInclude;
}
export interface CommentsUpdateResponse {
body: CommentsUpdateResponseBody;
}
export type CommentsUpdateResponseBody = CommentUpdateSuccessResponseBody | 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;
}
export interface Post {
body: null | string;
comments?: Comment[];
createdAt: string;
id: string;
title: string;
updatedAt: string;
}
export type SortDirection = 'asc' | 'desc';
export interface Video {
comments?: Comment[];
createdAt: string;
duration: null | number;
id: string;
title: string;
updatedAt: string;
url: string;
}Zod
ts
import { z } from 'zod';
export const CommentCommentableTypeSchema = z.enum(['post', 'video']);
export const LayerSchema = z.enum(['contract', 'domain', 'http']);
export const SortDirectionSchema = z.enum(['asc', 'desc']);
export const CommentSchema: z.ZodType<Comment> = z.lazy(() => z.object({
authorName: z.string().nullable(),
body: z.string(),
commentable: CommentCommentableSchema.optional(),
commentableId: z.string(),
commentableType: z.string(),
createdAt: z.iso.datetime(),
id: z.string(),
updatedAt: z.iso.datetime()
}));
export const CommentFilterSchema: z.ZodType<CommentFilter> = z.lazy(() => z.object({
AND: z.array(CommentFilterSchema).optional(),
NOT: CommentFilterSchema.optional(),
OR: z.array(CommentFilterSchema).optional(),
commentableType: CommentCommentableTypeFilterSchema.optional()
}));
export const CommentCommentableTypeFilterSchema = z.union([
CommentCommentableTypeSchema,
z.object({ eq: CommentCommentableTypeSchema, in: z.array(CommentCommentableTypeSchema) }).partial()
]);
export const CommentCreatePayloadSchema = z.object({
authorName: z.string().nullable().optional(),
body: z.string(),
commentableId: z.string(),
commentableType: z.enum(['post', 'video'])
});
export const CommentCreateSuccessResponseBodySchema = z.object({
comment: CommentSchema,
meta: z.record(z.string(), z.unknown()).optional()
});
export const CommentIncludeSchema = z.object({
commentable: z.boolean().optional()
});
export const CommentPageSchema = z.object({
number: z.number().int().min(1).optional(),
size: z.number().int().min(1).max(100).optional()
});
export const CommentShowSuccessResponseBodySchema = z.object({
comment: CommentSchema,
meta: z.record(z.string(), z.unknown()).optional()
});
export const CommentSortSchema = z.object({
createdAt: SortDirectionSchema.optional(),
updatedAt: SortDirectionSchema.optional()
});
export const CommentUpdatePayloadSchema = z.object({
authorName: z.string().nullable().optional(),
body: z.string().optional(),
commentableId: z.string().optional(),
commentableType: z.enum(['post', 'video']).optional()
});
export const CommentUpdateSuccessResponseBodySchema = z.object({
comment: CommentSchema,
meta: z.record(z.string(), z.unknown()).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 PostSchema = z.object({
body: z.string().nullable(),
comments: z.array(CommentSchema).optional(),
createdAt: z.iso.datetime(),
id: z.string(),
title: z.string(),
updatedAt: z.iso.datetime()
});
export const VideoSchema = z.object({
comments: z.array(CommentSchema).optional(),
createdAt: z.iso.datetime(),
duration: z.number().int().nullable(),
id: z.string(),
title: z.string(),
updatedAt: z.iso.datetime(),
url: z.string()
});
export const CommentCommentableSchema = z.discriminatedUnion('commentableType', [
PostSchema.extend({ commentableType: z.literal('post') }),
VideoSchema.extend({ commentableType: z.literal('video') })
]);
export const CommentIndexSuccessResponseBodySchema = z.object({
comments: z.array(CommentSchema),
meta: z.record(z.string(), z.unknown()).optional(),
pagination: OffsetPaginationSchema
});
export const ErrorSchema = z.object({
issues: z.array(IssueSchema),
layer: LayerSchema
});
export const ErrorResponseBodySchema = ErrorSchema;
export const CommentsIndexRequestQuerySchema = z.object({
filter: z.union([CommentFilterSchema, z.array(CommentFilterSchema)]).optional(),
include: CommentIncludeSchema.optional(),
page: CommentPageSchema.optional(),
sort: z.union([CommentSortSchema, z.array(CommentSortSchema)]).optional()
});
export const CommentsIndexRequestSchema = z.object({
query: CommentsIndexRequestQuerySchema
});
export const CommentsIndexResponseBodySchema = z.union([CommentIndexSuccessResponseBodySchema, ErrorResponseBodySchema]);
export const CommentsIndexResponseSchema = z.object({
body: CommentsIndexResponseBodySchema
});
export const CommentsShowRequestQuerySchema = z.object({
include: CommentIncludeSchema.optional()
});
export const CommentsShowRequestSchema = z.object({
query: CommentsShowRequestQuerySchema
});
export const CommentsShowResponseBodySchema = z.union([CommentShowSuccessResponseBodySchema, ErrorResponseBodySchema]);
export const CommentsShowResponseSchema = z.object({
body: CommentsShowResponseBodySchema
});
export const CommentsCreateRequestQuerySchema = z.object({
include: CommentIncludeSchema.optional()
});
export const CommentsCreateRequestBodySchema = z.object({
comment: CommentCreatePayloadSchema
});
export const CommentsCreateRequestSchema = z.object({
query: CommentsCreateRequestQuerySchema,
body: CommentsCreateRequestBodySchema
});
export const CommentsCreateResponseBodySchema = z.union([CommentCreateSuccessResponseBodySchema, ErrorResponseBodySchema]);
export const CommentsCreateResponseSchema = z.object({
body: CommentsCreateResponseBodySchema
});
export const CommentsUpdateRequestQuerySchema = z.object({
include: CommentIncludeSchema.optional()
});
export const CommentsUpdateRequestBodySchema = z.object({
comment: CommentUpdatePayloadSchema
});
export const CommentsUpdateRequestSchema = z.object({
query: CommentsUpdateRequestQuerySchema,
body: CommentsUpdateRequestBodySchema
});
export const CommentsUpdateResponseBodySchema = z.union([CommentUpdateSuccessResponseBodySchema, ErrorResponseBodySchema]);
export const CommentsUpdateResponseSchema = z.object({
body: CommentsUpdateResponseBodySchema
});
export const CommentsDestroyRequestQuerySchema = z.object({
include: CommentIncludeSchema.optional()
});
export const CommentsDestroyRequestSchema = z.object({
query: CommentsDestroyRequestQuerySchema
});
export const CommentsDestroyResponseSchema = z.never();
export interface Comment {
authorName: null | string;
body: string;
commentable?: CommentCommentable;
commentableId: string;
commentableType: string;
createdAt: string;
id: string;
updatedAt: string;
}
export type CommentCommentable = { commentableType: 'post' } & Post | { commentableType: 'video' } & Video;
export type CommentCommentableType = 'post' | 'video';
export type CommentCommentableTypeFilter = CommentCommentableType | { eq?: CommentCommentableType; in?: CommentCommentableType[] };
export interface CommentCreatePayload {
authorName?: null | string;
body: string;
commentableId: string;
commentableType: 'post' | 'video';
}
export interface CommentCreateSuccessResponseBody {
comment: Comment;
meta?: Record<string, unknown>;
}
export interface CommentFilter {
AND?: CommentFilter[];
NOT?: CommentFilter;
OR?: CommentFilter[];
commentableType?: CommentCommentableTypeFilter;
}
export interface CommentInclude {
commentable?: boolean;
}
export interface CommentIndexSuccessResponseBody {
comments: Comment[];
meta?: Record<string, unknown>;
pagination: OffsetPagination;
}
export interface CommentPage {
number?: number;
size?: number;
}
export interface CommentShowSuccessResponseBody {
comment: Comment;
meta?: Record<string, unknown>;
}
export interface CommentSort {
createdAt?: SortDirection;
updatedAt?: SortDirection;
}
export interface CommentUpdatePayload {
authorName?: null | string;
body?: string;
commentableId?: string;
commentableType?: 'post' | 'video';
}
export interface CommentUpdateSuccessResponseBody {
comment: Comment;
meta?: Record<string, unknown>;
}
export interface CommentsCreateRequest {
query: CommentsCreateRequestQuery;
body: CommentsCreateRequestBody;
}
export interface CommentsCreateRequestBody {
comment: CommentCreatePayload;
}
export interface CommentsCreateRequestQuery {
include?: CommentInclude;
}
export interface CommentsCreateResponse {
body: CommentsCreateResponseBody;
}
export type CommentsCreateResponseBody = CommentCreateSuccessResponseBody | ErrorResponseBody;
export interface CommentsDestroyRequest {
query: CommentsDestroyRequestQuery;
}
export interface CommentsDestroyRequestQuery {
include?: CommentInclude;
}
export type CommentsDestroyResponse = never;
export interface CommentsIndexRequest {
query: CommentsIndexRequestQuery;
}
export interface CommentsIndexRequestQuery {
filter?: CommentFilter | CommentFilter[];
include?: CommentInclude;
page?: CommentPage;
sort?: CommentSort | CommentSort[];
}
export interface CommentsIndexResponse {
body: CommentsIndexResponseBody;
}
export type CommentsIndexResponseBody = CommentIndexSuccessResponseBody | ErrorResponseBody;
export interface CommentsShowRequest {
query: CommentsShowRequestQuery;
}
export interface CommentsShowRequestQuery {
include?: CommentInclude;
}
export interface CommentsShowResponse {
body: CommentsShowResponseBody;
}
export type CommentsShowResponseBody = CommentShowSuccessResponseBody | ErrorResponseBody;
export interface CommentsUpdateRequest {
query: CommentsUpdateRequestQuery;
body: CommentsUpdateRequestBody;
}
export interface CommentsUpdateRequestBody {
comment: CommentUpdatePayload;
}
export interface CommentsUpdateRequestQuery {
include?: CommentInclude;
}
export interface CommentsUpdateResponse {
body: CommentsUpdateResponseBody;
}
export type CommentsUpdateResponseBody = CommentUpdateSuccessResponseBody | 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;
}
export interface Post {
body: null | string;
comments?: Comment[];
createdAt: string;
id: string;
title: string;
updatedAt: string;
}
export type SortDirection = 'asc' | 'desc';
export interface Video {
comments?: Comment[];
createdAt: string;
duration: null | number;
id: string;
title: string;
updatedAt: string;
url: string;
}OpenAPI
yml
---
openapi: 3.1.0
info:
title: "/gentle_owl"
version: 1.0.0
paths:
"/comments":
get:
operationId: commentsIndex
parameters:
- in: query
name: filter
required: false
schema:
oneOf:
- "$ref": "#/components/schemas/commentFilter"
- items:
"$ref": "#/components/schemas/commentFilter"
type: array
- in: query
name: include
required: false
schema:
"$ref": "#/components/schemas/commentInclude"
- in: query
name: page
required: false
schema:
"$ref": "#/components/schemas/commentPage"
- in: query
name: sort
required: false
schema:
oneOf:
- "$ref": "#/components/schemas/commentSort"
- items:
"$ref": "#/components/schemas/commentSort"
type: array
responses:
'200':
content:
application/json:
schema:
"$ref": "#/components/schemas/commentIndexSuccessResponseBody"
description: Successful response
post:
operationId: commentsCreate
parameters:
- in: query
name: include
required: false
schema:
"$ref": "#/components/schemas/commentInclude"
requestBody:
content:
application/json:
schema:
properties:
comment:
"$ref": "#/components/schemas/commentCreatePayload"
type: object
required:
- comment
required: true
responses:
'200':
content:
application/json:
schema:
"$ref": "#/components/schemas/commentCreateSuccessResponseBody"
description: Successful response
'422':
description: Unprocessable Entity
content:
application/json:
schema:
"$ref": "#/components/schemas/errorResponseBody"
"/comments/{id}":
get:
operationId: commentsShow
parameters:
- in: path
name: id
required: true
schema:
type: string
- in: query
name: include
required: false
schema:
"$ref": "#/components/schemas/commentInclude"
responses:
'200':
content:
application/json:
schema:
"$ref": "#/components/schemas/commentShowSuccessResponseBody"
description: Successful response
patch:
operationId: commentsUpdate
parameters:
- in: path
name: id
required: true
schema:
type: string
- in: query
name: include
required: false
schema:
"$ref": "#/components/schemas/commentInclude"
requestBody:
content:
application/json:
schema:
properties:
comment:
"$ref": "#/components/schemas/commentUpdatePayload"
type: object
required:
- comment
required: true
responses:
'200':
content:
application/json:
schema:
"$ref": "#/components/schemas/commentUpdateSuccessResponseBody"
description: Successful response
'422':
description: Unprocessable Entity
content:
application/json:
schema:
"$ref": "#/components/schemas/errorResponseBody"
delete:
operationId: commentsDestroy
parameters:
- in: path
name: id
required: true
schema:
type: string
- in: query
name: include
required: false
schema:
"$ref": "#/components/schemas/commentInclude"
responses:
'204':
description: No content
components:
schemas:
comment:
properties:
authorName:
type:
- string
- 'null'
body:
type: string
commentable:
"$ref": "#/components/schemas/commentCommentable"
commentableId:
type: string
commentableType:
type: string
createdAt:
type: string
format: date-time
id:
type: string
updatedAt:
type: string
format: date-time
type: object
required:
- authorName
- body
- commentableId
- commentableType
- createdAt
- id
- updatedAt
commentCommentable:
oneOf:
- allOf:
- "$ref": "#/components/schemas/post"
- properties:
commentableType:
const: post
type: string
required:
- commentableType
type: object
- allOf:
- "$ref": "#/components/schemas/video"
- properties:
commentableType:
const: video
type: string
required:
- commentableType
type: object
discriminator:
mapping:
post: "#/components/schemas/post"
video: "#/components/schemas/video"
propertyName: commentableType
commentCommentableTypeFilter:
oneOf:
- enum:
- post
- video
type: string
- properties:
eq:
enum:
- post
- video
type: string
in:
items:
enum:
- post
- video
type: string
type: array
type: object
required:
- eq
- in
commentCreatePayload:
properties:
authorName:
type:
- string
- 'null'
body:
type: string
commentableId:
type: string
commentableType:
enum:
- post
- video
type: string
type: object
required:
- body
- commentableId
- commentableType
commentCreateSuccessResponseBody:
properties:
comment:
"$ref": "#/components/schemas/comment"
meta:
properties: {}
type: object
type: object
required:
- comment
commentFilter:
properties:
AND:
items:
"$ref": "#/components/schemas/commentFilter"
type: array
NOT:
"$ref": "#/components/schemas/commentFilter"
OR:
items:
"$ref": "#/components/schemas/commentFilter"
type: array
commentableType:
"$ref": "#/components/schemas/commentCommentableTypeFilter"
type: object
commentInclude:
properties:
commentable:
type: boolean
type: object
commentIndexSuccessResponseBody:
properties:
pagination:
"$ref": "#/components/schemas/offsetPagination"
comments:
items:
"$ref": "#/components/schemas/comment"
type: array
meta:
properties: {}
type: object
type: object
required:
- pagination
- comments
commentPage:
properties:
number:
type: integer
minimum: 1
size:
type: integer
minimum: 1
maximum: 100
type: object
commentShowSuccessResponseBody:
properties:
comment:
"$ref": "#/components/schemas/comment"
meta:
properties: {}
type: object
type: object
required:
- comment
commentSort:
properties:
createdAt:
enum:
- asc
- desc
type: string
updatedAt:
enum:
- asc
- desc
type: string
type: object
commentUpdatePayload:
properties:
authorName:
type:
- string
- 'null'
body:
type: string
commentableId:
type: string
commentableType:
enum:
- post
- video
type: string
type: object
commentUpdateSuccessResponseBody:
properties:
comment:
"$ref": "#/components/schemas/comment"
meta:
properties: {}
type: object
type: object
required:
- comment
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
post:
properties:
body:
type:
- string
- 'null'
comments:
items:
"$ref": "#/components/schemas/comment"
type: array
createdAt:
type: string
format: date-time
id:
type: string
title:
type: string
updatedAt:
type: string
format: date-time
type: object
required:
- body
- createdAt
- id
- title
- updatedAt
video:
properties:
comments:
items:
"$ref": "#/components/schemas/comment"
type: array
createdAt:
type: string
format: date-time
duration:
type:
- integer
- 'null'
id:
type: string
title:
type: string
updatedAt:
type: string
format: date-time
url:
type: string
type: object
required:
- createdAt
- duration
- id
- title
- updatedAt
- url