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

strapi-swagger-custom-paths

v1.0.2

Published

Generate OpenAPI paths for Strapi custom routes from 01-custom.js files. Supports JS and TS.

Readme

strapi-swagger-custom-paths

NPM Version GitHub stars Node.js TypeScript Strapi OpenAPI


Easily generate OpenAPI paths for the Strapi documentation plugin by automatically reading all your custom route definitions (01-custom.js) from each API. Supports both TypeScript and JavaScript Strapi projects.


Features

  • Reads all src/api/<content-type>/routes/01-custom.js files in your Strapi project.
  • Returns a valid OpenAPI paths object for use in Strapi's documentation plugin.
  • Works with both TypeScript and JavaScript projects.
  • Minimal configuration: just add your custom route files and reference the utility in your documentation config.

Installation

Install with your favorite package manager:

# npm
npm install strapi-swagger-custom-paths
# yarn
yarn add strapi-swagger-custom-paths
# pnpm
pnpm add strapi-swagger-custom-paths
# bun
bun add strapi-swagger-custom-paths

More information about Strapi documentation

For more details about how Strapi's documentation plugin works, see the official docs: https://docs.strapi.io/cms/plugins/documentation


How it works

  • The function getCustomSwaggerPaths() will scan your Strapi project's src/api folder for all routes/01-custom.js files.
  • It will merge all Swagger/OpenAPI route definitions and return a single paths object ready to use in your documentation plugin config.

Where does the Swagger data come from?

This package automatically collects Swagger/OpenAPI documentation from each custom route file in your Strapi project.

  • It looks for files named 01-custom.js or 01-custom.ts inside each API folder: src/api/<content-type>/routes/01-custom.js.
  • Each route object should include a config.swagger property, which follows the OpenAPI specification for that HTTP method and path.
  • All swagger objects are merged into the paths section of your final OpenAPI documentation.

You can include any valid OpenAPI fields (summary, description, parameters, requestBody, responses, etc.) inside config.swagger.


Example: Custom Route File

JavaScript (src/api/my-content-type/routes/01-custom.js)

module.exports = {
  routes: [
    {
      method: 'GET',
      path: '/my-content-type/current',
      handler: 'my-content-type.getCurrent',
      config: {
        tags: ['MyContentType'],
        swagger: {
          summary: 'Get current MyContentType',
          description: 'Retrieve the current MyContentType',
          operationId: 'getCurrent',
          tags: ['MyContentType'],
        },
      },
    },
  ],
};

TypeScript (src/api/my-content-type/routes/01-custom.ts)

export default {
  routes: [
    {
      method: 'GET',
      path: '/my-content-type/current',
      handler: 'my-content-type.getCurrent',
      config: {
        tags: ['MyContentType'],
        swagger: {
          summary: 'Get current MyContentType',
          description: 'Retrieve the current MyContentType',
          operationId: 'getCurrent',
          tags: ['MyContentType'],
        },
      },
    },
  ],
};

Usage in Strapi plugins config

TypeScript Example (config/plugins.ts)

import { getCustomSwaggerPaths } from 'strapi-swagger-custom-paths'; // Add this line

export default () => ({
  documentation: {
    enabled: true,
    config: {
      openapi: "3.0.0",
      info: {
        version: "1.0.0",
        title: "Documentation",
        description: "",
        termsOfService: "YOUR_TERMS_OF_SERVICE_URL",
        contact: {
          name: "Team",
          email: "[email protected]",
          url: "mywebsite.io"
        },
        license: {
          name: "Apache 2.0",
          url: "https://www.apache.org/licenses/LICENSE-2.0.html"
        }
      },
      "x-strapi-config": {
        plugins: ["upload", "users-permissions"],
        path: "/documentation"
      },
      servers: [
        {
          url: "http://localhost:1337/api",
          description: "Development server"
        }
      ],
      externalDocs: {
        description: "Find out more",
        url: "https://docs.strapi.io/developer-docs/latest/getting-started/introduction.html"
      },
      security: [
        {
          bearerAuth: []
        }
      ],
      paths: getCustomSwaggerPaths(), // Add this line
    }
  },
});

JavaScript Example (config/plugins.js)

const { getCustomSwaggerPaths } = require('strapi-swagger-custom-paths'); // Add this line

module.exports = () => ({
  documentation: {
    enabled: true,
    config: {
      openapi: "3.0.0",
      info: {
        version: "1.0.0",
        title: "Documentation",
        description: "",
        termsOfService: "YOUR_TERMS_OF_SERVICE_URL",
        contact: {
          name: "Team",
          email: "[email protected]",
          url: "mywebsite.io"
        },
        license: {
          name: "Apache 2.0",
          url: "https://www.apache.org/licenses/LICENSE-2.0.html"
        }
      },
      "x-strapi-config": {
        plugins: ["upload", "users-permissions"],
        path: "/documentation"
      },
      servers: [
        {
          url: "http://localhost:1337/api",
          description: "Development server"
        }
      ],
      externalDocs: {
        description: "Find out more",
        url: "https://docs.strapi.io/developer-docs/latest/getting-started/introduction.html"
      },
      security: [
        {
          bearerAuth: []
        }
      ],
      paths: getCustomSwaggerPaths(), // Add this line
    }
  },
});

Requirements

  • Node.js: >= 16.x
  • Strapi: v4.x or v5.x
  • Works with both JavaScript and TypeScript Strapi projects.

Tested versions

  • Node.js: 16.x, 18.x, 20.x
  • Strapi: 4.15.0, 5.12.5

License

MIT


Contributing

Pull requests and issues are welcome! Please open an issue or PR on GitHub.


You can include any valid OpenAPI fields (summary, description, parameters, requestBody, responses, etc.) inside config.swagger.


Author

DanSP89 (https://github.com/dansp89)