Module: Legion::API::OpenAPI

Defined in:
lib/legion/api/openapi.rb

Constant Summary collapse

META_SCHEMA =
{
  type:       'object',
  properties: {
    timestamp: { type: 'string', format: 'date-time' },
    node:      { type: 'string' }
  },
  required:   %w[timestamp node]
}.freeze
META_COLLECTION_SCHEMA =
{
  type:       'object',
  properties: {
    timestamp: { type: 'string', format: 'date-time' },
    node:      { type: 'string' },
    total:     { type: 'integer' },
    limit:     { type: 'integer' },
    offset:    { type: 'integer' }
  },
  required:   %w[timestamp node total limit offset]
}.freeze
ERROR_SCHEMA =
{
  type:       'object',
  properties: {
    error: {
      type:       'object',
      properties: {
        code:    { type: 'string' },
        message: { type: 'string' }
      },
      required:   %w[code message]
    },
    meta:  META_SCHEMA
  },
  required:   %w[error meta]
}.freeze
PAGINATION_PARAMS =
[
  {
    name:        'limit',
    in:          'query',
    description: 'Maximum number of records to return (1-100, default 25)',
    required:    false,
    schema:      { type: 'integer', minimum: 1, maximum: 100, default: 25 }
  },
  {
    name:        'offset',
    in:          'query',
    description: 'Number of records to skip',
    required:    false,
    schema:      { type: 'integer', minimum: 0, default: 0 }
  }
].freeze
NOT_FOUND_RESPONSE =
{
  description: 'Not found',
  content:     { 'application/json' => { schema: { '$ref' => '#/components/schemas/ErrorResponse' } } }
}.freeze
UNAUTH_RESPONSE =
{
  description: 'Unauthorized',
  content:     { 'application/json' => { schema: { '$ref' => '#/components/schemas/ErrorResponse' } } }
}.freeze
UNPROCESSABLE_RESPONSE =
{
  description: 'Unprocessable entity',
  content:     { 'application/json' => { schema: { '$ref' => '#/components/schemas/ErrorResponse' } } }
}.freeze
NOT_IMPL_RESPONSE =
{
  description: 'Not implemented',
  content:     { 'application/json' => { schema: { '$ref' => '#/components/schemas/ErrorResponse' } } }
}.freeze

Class Method Summary collapse

Class Method Details

.specObject



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/legion/api/openapi.rb', line 83

def self.spec
  {
    openapi:    '3.1.0',
    info:       info_block,
    servers:    [{ url: 'http://localhost:4567', description: 'Local Legion daemon' }],
    security:   [{ BearerAuth: [] }, { ApiKeyAuth: [] }],
    tags:       tags,
    paths:      paths,
    components: components
  }
end

.to_jsonObject



95
96
97
98
# File 'lib/legion/api/openapi.rb', line 95

def self.to_json
  require 'json'
  ::JSON.generate(spec)
end