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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ikonintegration/ikapi-docs-gen

v1.0.2

Published

A tool to generate OpenAPI specifications from IKApi Routes in TypeScript files.

Downloads

57

Readme

IKApi-docs-gen

A tool to generate OpenAPI specifications from IKApi Routes in TypeScript files.

Installation

You don't need to install the package globally. You can use npx to run the command directly.

Usage

To generate OpenAPI specifications, run:

npx @ikonintegration/ikapi-docs-gen

This command will:

  1. Recursively find all router.ts files in the src directory.
  2. Extract IKApi Routes from these files.
  3. Generate OpenAPI components and save them to ./docs/api.yaml.

Requirements

Ensure your project meets the following requirements:

  1. TypeScript files IKApi exported Router, named router.ts.
  2. A base.json file in the docs folder.

Configuration

The base.json file should contain your OpenAPI base configuration. Here is an example:

{
    "contact": {
        "email": "[email protected]",
        "name": "Company Inc",
        "url": "http://domain.com"
    },
    "servers": [
        {
            "url": "http://localhost:8080",
            "description": "Local server"
        },
        {
            "url": "https://example.dev.domain.com",
            "description": "Dev server"
        }
    ],
    "security": {
        "UserAuth": {
            "bearerFormat": "JWT",
            "description": "User custom JSON web token.",
            "scheme": "bearer",
            "type": "http"
        },
        "APIKey": {
            "description": "API Key",
            "type": "apiKey",
            "in": "header",
            "name": "apiKey"
        }
    }
}

Examples

Route

import { Route, HttpMethod, Response } from '@ikonintegration/ikapi'

import {
  NotesListInputType,
  NotesListInputSchema,
  NotesResponseType,
  NotesResponseSchema,
} from './types.js'
import Module from '../../core/Module.js'

interface PostRouteType extends Route<NotesListInputType, NotesResponseType> {}
export default class Post implements PostRouteType {
  public path: string = '/notes'
  public method: HttpMethod = HttpMethod.POST
  public inputSchema = NotesListInputSchema
  public openApi = {
    summary: 'List Notes',
    description: 'Paginated Notes Listing',
    outputSchema: NotesResponseSchema,
    tags: ['Notes'],
    security: [{ UserAuth: [] }],
  }
  public handler: PostRouteType['handler'] = async transaction => {
    return await new Module.Core(transaction, Module.Globals.AccessLevel.ADMIN).authenticate(
      async core => {
        const b = transaction.request.getBody()
        const resp = await core.notesService.note.list(b.nextToken || undefined)
        if (resp instanceof Response) return resp
        return Response.SuccessResponse(resp)
      }
    )
  }
}

Input Body Example

// Input Body Example
import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi'
import { z } from 'zod'

extendZodWithOpenApi(z)

/* Post */
export const NotesListInputSchema = z
  .object({
    nextToken: z.string().nullish().openapi({
      description: 'Optional next token',
    }),
  })
  .openapi({
    description: 'Notes list input body',
    name: 'NotesListInput',
  })

export type NotesListInputType = z.infer<typeof NotesListInputSchema>

Output Body Example


// Output Body Example
import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi'
import { z } from 'zod'

extendZodWithOpenApi(z)

/* Post */
export const NotesResponseSchema = z
  .object({
    notes: z.array(.....).openapi({
      description: 'List of notes',
    }),
    nextToken: z.string().optional().openapi({
      description: 'Next token for pagination',
    }),
  })
  .openapi({
    description: 'Notes list response body',
    name: 'NotesResponse',
  })

export type NotesResponseType = z.infer<typeof NotesResponseSchema>

Path Parameter Example


// Path Parameter Example
import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi'
import { z } from 'zod'

extendZodWithOpenApi(z)

/* Path */
export const NotePathSchema = z
  .object({
    noteId: z.string().openapi({
      param: {
        name: 'noteId',
        in: 'path',
      },
      example: 'Note Id',
    }),
  })
  .openapi({
    description: 'Note authorized route path parameters',
  })

export type NotePathType = z.infer<typeof NotePathSchema>