Automatically document all of your Remix loaders and actions typings per each route. 📚

Overview

remix-docs-gen License Twitter

About

remix-docs-gen parses all of your Remix loaders and actions and automatically documents all the typings per each route.

Installation

First, you have to install the package itself:

yarn add -D remix-docs-gen

Note that you need @remix-run/server-runtime to be at least ^1.7.0.

Usage Example

You can simply run:

yarn remix-docs-gen -o api-docs.ts

It will magically parse all of your routes and extract all the return types of your loaders and actions.

CLI Options

Option Alias Description
--help Print the help message and exit
--version -v Print the CLI version and exit
--output -o The path for docs export
--regex -r The regex to filter routes
--watch -w Watch for changes
--post-export Execute a command after docs export

Loader output documentation

For example having a route in app/routes/articles with the following content:

export const loader = () => {
  return {
    articles: db.articles.findMany(),
  };
};

The package will fully infer the return type of the loader and produce the following example output:

export interface RemixDocs {
  "/articles": {
    loader: { output: { articles: { id: string; title: string }[] } };
  };
}

Action output documentation

For example having a route in app/routes/articles with the following content:

export const action = () => {
  return {
    myNewArticle: db.articles.create(),
  };
};

The package will fully infer the return type of the action and produce the following example output:

export interface RemixDocs {
  "/articles": {
    action: { output: { myNewArticle: { id: string; title: string } } };
  };
}

Output typings customization

If you'd like to manually define the typings of the loader's or action's output, in your route simply export your custom LoaderOutput or ActionOutput types as needed:

export type LoaderOutput = {
  articles: { custom: string }[];
};

export type ActionOutput = {
  myNewArticle: { custom: string };
};

Which will produce the following result:

export interface RemixDocs {
  "/articles": {
    loader: { output: { articles: { custom: string }[] } };
    action: { output: { myNewArticle: { custom: string } } };
  };
}

Documenting input typings

Besides returing data, loaders and actions usually also expect data to be coming in from the client. To document that, in your route simply export the LoaderInput or ActionInput types as needed:

export type ActionInput = {
  articleData: { title: string };
};

Which will produce the following result:

export interface RemixDocs {
  "/articles": {
    action: { input: { articleData: { title: string } } };
  };
}

This can be very convenient when working with tools like Zod, for example:

const articleSchema = z.object({
  title: z.string().min(1),
});

export type ActionInput = z.infer<typeof articleSchema>;

Route documentation override

If you'd like to fully override the generated documentation typings of a specific route, simply export a Docs type:

export type Docs = {
  my: {
    custom: {
      documentation: string;
    };
  };
};

Which will produce the following output:

export interface RemixDocs {
  "/articles": { my: { custom: { documentation: string } } };
}

Generating typings for specific routes only

You can leverage the --regex or --r flag to only generate typings for the desired routes. For example, that's how you'd document only the routes starting with /api.

yarn remix-docs-gen --output api-docs.ts --regex /api

Dynamic segments

For routes with dynamic segments, the following pattern is being output:

export interface RemixDocs {
  "/reset-password/:token": {
    // ...
  };
}

Generating typings for other languages

For generating typings for other languages besides Typescript, you can use tools like quicktype on top of the generated Typescript file.

You might also like...

End-to-End type safety for REST APIs written in Fastify. Only problem is you have to explicity export and register route handlers. LOL

Chino intelligence in japaneese End-to-End type safety for REST APIs written in Fastify. Only problem is you have to explicity export and register rou

Sep 12, 2022

simple-remix-blog is a blog template built using Remix and TailwindCSS. Create your own blog in just a few minutes!

simple-remix-blog is a blog template built using Remix and TailwindCSS. Create your own blog in just a few minutes!

simple-remix-blog is a blog template built using remix.run and TailwindCSS. It supports markdown and MDX for the blog posts. You can clone it and star

Dec 8, 2022

Check if a url is a known route to a next.js application ahead of time

next-known-route Check if a url is a known route to a next.js application ahead of time. https://www.npmjs.com/package/next-known-route Use Case Why d

Jul 17, 2022

A vanilla JavaScript library that automatically generates the "Table of Contents" of an HTML document.

DocumentOutline.js DocumentOutline is a vanilla JavaScript library that automatically generates the "Table of Contents" of an HTML document. See a liv

Jul 12, 2021

Use this project as a tool for remembering your daily tasks, confirming, editing, remove are actions you can do to tasks, your data is saved in the LocalStorage so every time you open or refresh the page all changes will be present.

To-do-list The porpuse for this project is show You, the way how to implement webpack in a project creating a To-Do list in for add a template to crea

Nov 18, 2022

Zenload - "Load couple loaders and apply transform one-by-one

Zenload Load couple loaders and apply transforms one-by-one. Install npm i zenload -g How to use? With env vairable ZENLOAD: NODE_OPTIONS='"--loader

Jan 25, 2022

Node.js ESM loader for chaining multiple custom loaders.

ESMultiloader Node.js ESM loader for chaining multiple custom loaders. Fast and lightweight No configuration required, but configurable if needed Usag

Sep 12, 2022

Remix enables you to build fantastic user experiences for the web and feel happy with the code that got you there. In this workshop, we'll look at some more advanced use cases when building Remix applications.

💿 Advanced Remix Workshop Remix enables you to build fantastic user experiences for the web and feel happy with the code that got you there. In this

Dec 9, 2022

Remix enables you to build fantastic user experiences for the web and feel happy with the code that got you there. Get a jumpstart on Remix with this workshop.

💿 Remix Fundamentals Build Better websites with Remix Remix enables you to build fantastic user experiences for the web and feel happy with the code

Dec 25, 2022
Releases(v0.1.4)
Owner
Stratulat Alexandru
Married to React & Typescript — In love with Tailwind — CTO / Co-founder https://coltorapps.com/
Stratulat Alexandru
Zod utilities for Remix loaders and actions.

Zodix Zodix is a collection of Zod utilities for Remix loaders and actions. It abstracts the complexity of parsing and validating FormData and URLSear

Riley Tomasek 172 Dec 22, 2022
Një projekt open source për komunitetin që shërben për të gjeneruar fjalëkalime me nivele të sigurisë të ndryshme.

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

Benjamin Fazli 4 Mar 7, 2022
Keep your Business Logic appart from your actions/loaders plumbing

Remix Domains Remix Domains helps you to keep your Business Logic appart from your actions/loaders plumbing. It does this by enforcing the parameters'

Seasoned 290 Jan 2, 2023
Framework agnostic CLI tool for routes parsing and generation of a type-safe helper for safe route usage. 🗺️ Remix driver included. 🤟

About routes-gen is a framework agnostic CLI tool for routes parsing and generation of a type-safe helper for safe route usage. Think of it as Prisma,

Stratulat Alexandru 192 Jan 2, 2023
Unlocks all brainly answers and bypasses one answer per day limit. Gives infinite free answers & unlocks all textbooks 🔐 ∞

Brainly-LockPick ?? Unlocks all brainly answers and bypasses one answer per day limit. Gives infinite free answers & unlocks textbooks ?? ∞ Note: refr

null 7 Dec 9, 2022
A complete and heavily tested wrapper with typings for the zapper.fi API.

Zapperfi API Unofficial wrapper for the Zapperfi API Don't forget to leave a ⭐ if you found this useful. Install # use npm $ npm i zapperfi-api # use

izayl 6 Sep 4, 2022
Elegant jest.expect typings for a more civilized age

typed-jest-expect Elegant jest.expect typings for a more civilized age Why? By default, the expect utility of jest is very broadly typed, which makes

Elie Rotenberg 4 Feb 25, 2022
Deploy an Architect project from GitHub Actions with keys gathered from aws-actions/configure-aws-credentials

Deploy an Architect project from GitHub Actions with keys gathered from a specific AWS IAM Role federated by an IAM OIDCProvider. CloudFormation to cr

Taylor Beseda 4 Apr 6, 2022
This is a simple web application of a To-do List in which you can add, remove and edit all your tasks and also you can mark each task as completed and delete all completed ones.

To-Do List A simple web application of a to do list Built With HTML, CSS, JS, ES6 & Webpack Getting Started In this repository I created To-Do List SP

Juan Sebastian Sotomayor 12 Apr 11, 2022
Magically create forms + actions in Remix!

Welcome to Remix Forms! This repository contains the Remix Forms source code. We're just getting started and the APIs are unstable, so we appreciate y

Seasoned 321 Dec 29, 2022