Project

mortymer

0.0
The project is in a healthy, maintained state
A simple DSL to describe metadata for endpoints and automatic params construction based on dry-struct schemas. Support for openapi
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 8.0

Runtime

 Project Readme

Mortymer

███╗   ███╗ ██████╗ ██████╗ ████████╗██╗   ██╗███╗   ███╗███████╗██████╗ 
████╗ ████║██╔═══██╗██╔══██╗╚══██╔══╝╚██╗ ██╔╝████╗ ████║██╔════╝██╔══██╗
██╔████╔██║██║   ██║██████╔╝   ██║    ╚████╔╝ ██╔████╔██║█████╗  ██████╔╝
██║╚██╔╝██║██║   ██║██╔══██╗   ██║     ╚██╔╝  ██║╚██╔╝██║██╔══╝  ██╔══██╗
██║ ╚═╝ ██║╚██████╔╝██║  ██║   ██║      ██║   ██║ ╚═╝ ██║███████╗██║  ██║

Mortymer is a Ruby gem that simplifies API endpoint management and documentation for Ruby on Rails applications. It provides a clean DSL for defining API endpoints with input/output contracts and automatically generates OpenAPI documentation. It provides a really convenient way to handle dependency Injection in Ruby, with an explicit approach but a really easy setup. No complex container initialization or registration (although it is supported). Fully compatible with ruby constructors.

Gem Version License: MIT

!IMPORTANT

This gem is going under rapid development and as new features are added it might brake compatibility from one version to another. I plan to give a stable release with version 0.1.0 and from there, follow semantic versioning.

Features

  • 🚀 Simple DSL for defining API endpoints
  • 📝 Automatic OpenAPI documentation generation
  • ✨ Input/Output contract validation
  • 🎯 Dependency injection support
  • 🛣️ Seamless Rails integration

Installation

Add this line to your application's Gemfile:

gem 'mortymer'

And then execute:

bundle install

Usage

Basic Example

class UserProfileEndpoint < ApplicationController
  include Mortymer::ApiMetadata

  # Define an endpoint with input/output contracts
  get input: UserProfileInput, output: UserProfileOutput, path: '/api/v1/users/:id/profile'
  def call(input)
    user = User.find(input.id)
    UserProfileOutput.new(
      id: user.id,
      name: user.name,
      email: user.email
    )
  end
end

Input/Output Contracts

class UserProfileInput < Mortymer::Model
  attribute :id, Types::Integer
  attribute :include_details, Types::Bool.optional.default(false)
end

class UserProfileOutput < Mortymer::Model
  attribute :id, Types::Integer
  attribute :name, Types::String
  attribute :email, Types::String
end

Dependency Injection

class UserService
  include Mortymer::DependenciesDsl

  # Inject dependencies
  inject UserRepository
  inject EmailService, as: :mailer

  def process_user(id)
    user = @user_repository.find_user(id)
    @email_service.send_email(user.email, "Welcome!")
  end
end

Rails Integration

In your config/routes.rb:

Rails.application.routes.draw do
  Mortymer::Rails::Routes.new(self).mount_controllers
end

OpenAPI Documentation

Mortymer automatically generates OpenAPI documentation for your API endpoints. The documentation includes:

  • Endpoint paths and HTTP methods
  • Request/response schemas
  • Input validation rules
  • Error responses

To generate the OpenAPI documentation:

generator = Mortymer::OpenapiGenerator.new(
  prefix: "/api",
  title: "My API",
  version: "v1"
)
generator.generate

Contributing

We love your input! We want to make contributing to Mortymer as easy and transparent as possible, whether it's:

  • Reporting a bug
  • Discussing the current state of the code
  • Submitting a fix
  • Proposing new features
  • Becoming a maintainer

Development Process

  1. Fork the repo and create your branch from master
  2. If you've added code, please, add some tests to contribute to gem health
  3. If you've changed APIs, update the documentation accordingly
  4. Ensure the test suite passes
  5. Make sure your code lints
  6. Issue that pull request!

Running Tests

bundle install
bundle exec rspec

License

MIT License. See LICENSE for details.

Code of Conduct

This project follows the Contributor Covenant Code of Conduct.

Support

If you have any questions or need help with Mortymer:

  • Open an issue
  • Join our Discord community (coming soon)

Credits

Mortymer is maintained by [Adrian Gonzalez] and was inspired by the need for a simple, yet powerful API management solution in the Ruby ecosystem, that integrates well with existing frameworks. We deserve a FastAPI experience within the ruby side.