npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

openapi-to-effect

v0.9.3

Published

OpenAPI to Effect Schema code generator

Downloads

3,338

Readme

npm GitHub Actions

openapi-to-effect

Generate Effect Schema definitions from an OpenAPI document.

Features:

  • All output is TypeScript code.
  • Fully configurable using a spec file, including hooks to customize the output (e.g. support more formats).
  • Automatic detection of recursive definitions using graph analysis. In the output, the recursive references are wrapped in Schema.suspend().
  • Supports generating either one file per schema, or all schemas bundled into one file. When bundled, the schemas are sorted according to a topological sort algorithm so that schema dependencies are reflected in the output order.
  • Pretty printing using prettier. Descriptions in the schema (e.g. title, description) are output as comments in the generated code. title fields are assumed to be single line comments, which are output as // comments, whereas description results in a block comment.

Limitations:

  • We currently only support OpenAPI v3.1 documents.
  • Only JSON is supported for the OpenAPI document format. For other formats like YAML, run it through a converter first.
  • The input must be a single OpenAPI document. Cross-document references are not currently supported.
  • The $allOf operator currently only supports schemas of type object. Generic intersections are not currently supported.

Usage

This package exposes an openapi-to-effect command:

npx openapi-to-effect <command> <args>

Generating Effect Schema code with the gen command

The gen command takes the path to an OpenAPI v3.1 document (in JSON format), the path to the output directory, and optionally a spec file to configure the output:

npx openapi-to-effect gen ./api.json ./output --spec=./spec.ts

Example

npx openapi-to-effect gen ./example_api.json ./output --spec=./example_spec.ts

example_api.json

{
  "openapi": "3.1.0",
  "info": {
    "title": "Example API",
    "version": "0.1.0"
  },
  "components": {
    "schemas": {
      "Category": {
        "type": "object",
        "properties": {
          "name": { "type": "string" },
          "subcategories": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/components/schemas/Category"
            },
            "default": {}
          }
        },
        "required": ["name"]
      },
      "User": {
        "type": "object",
        "properties": {
          "id": {
            "title": "Unique ID",
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "title": "The user's full name.",
            "type": "string"
          },
          "last_logged_in": {
            "title": "When the user last logged in.",
            "type": "string", "format": "date-time"
          },
          "role": {
            "title": "The user's role within the system.",
            "description": "Roles:\n- ADMIN: Administrative permissions\n- USER: Normal permissions\n- AUDITOR: Read only permissions",
            "type": "string",
            "enum": ["ADMIN", "USER", "AUDITOR"]
          },
          "interests": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/Category" },
            "default": []
          }
        },
        "required": ["id", "name", "last_logged_in", "role"]
      }
    }
  }
}

example_spec.ts

import { type GenerationSpec } from '../../src/generation/generationSpec.ts';


export default {
  generationMethod: { method: 'bundled', bundleName: 'example' },
  hooks: {},
  runtime: {},
  modules: {
    './Category.ts': {
      definitions: [
        {
          action: 'generate-schema',
          schemaId: 'Category',
          typeDeclarationEncoded: `{
            readonly name: string,
            readonly subcategories?: undefined | { readonly [key: string]: _CategoryEncoded }
          }`,
          typeDeclaration: `{
            readonly name: string,
            readonly subcategories: { readonly [key: string]: _Category }
          }`,
        },
      ],
    },
  },
} satisfies GenerationSpec;

output/example.ts

import { Schema as S } from 'effect';

/* Category */

type _Category = {
  readonly name: string;
  readonly subcategories: { readonly [key: string]: _Category };
};
type _CategoryEncoded = {
  readonly name: string;
  readonly subcategories?: undefined | { readonly [key: string]: _CategoryEncoded };
};
export const Category = S.Struct({
  name: S.String,
  subcategories: S.optionalWith(
    S.Record({
      key: S.String,
      value: S.suspend((): S.Schema<_Category, _CategoryEncoded> => Category),
    }),
    {
      default: () => ({}),
    },
  ),
}).annotations({ identifier: 'Category' });
export type Category = S.Schema.Type<typeof Category>;
export type CategoryEncoded = S.Schema.Encoded<typeof Category>;

/* User */

export const User = S.Struct({
  id: S.UUID, // Unique ID
  name: S.String, // The user's full name.
  last_logged_in: S.Date, // When the user last logged in.
  /**
   * Roles:
   *
   * - ADMIN: Administrative permissions
   * - USER: Normal permissions
   * - AUDITOR: Read only permissions
   */
  role: S.Literal('ADMIN', 'USER', 'AUDITOR'), // The user's role within the system.
  interests: S.optionalWith(S.Array(Category), {
    default: () => [],
  }),
}).annotations({ identifier: 'User' });
export type User = S.Schema.Type<typeof User>;
export type UserEncoded = S.Schema.Encoded<typeof User>;

Contributing

We gratefully accept bug reports and contributions from the community. By participating in this community, you agree to abide by Code of Conduct. All contributions are covered under the Developer's Certificate of Origin (DCO).

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or

(b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or

(c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it.

(d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved.

License

This project is primarily distributed under the terms of the Mozilla Public License (MPL) 2.0, see LICENSE for details.