1.0.5 • Published 4 months ago

@tealina/doc-ui v1.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

Automatic generate modern UI for visualize and interact API's resources.

The document resouces should be json file in @tealina/doc-types format.

Install

pnpm add @tealina/doc-ui

yarn add @tealina/doc-ui

npm i @tealina/doc-ui

Usage

  1. Build the route whith recourses
// buildDocRoute.ts
import express, { Router } from 'express'
import path from 'node:path'
import {
  TealinaVdocWebConfig,
  getAssetsPath,
  assembleHTML,
  VDOC_BASENAME,
} from '@tealina/doc-ui'

const vDocCofig: TealinaVdocWebConfig = {
  sources: [
    {
      baseURL: '/api/v1',
      jsonURL: `${VDOC_BASENAME}/v1.json`,
      name: 'v1',
    },
  ],
  errorMessageKey: 'message',
  features: {
    playground: {
      //...
    },
  },
}

const docRouter = Router({ caseSensitive: true })
  .get('/index.html', (req, res, next) => {
    assembleHTML(vDocCofig).then(html => res.send(html))
  })
  .get('/v1.json', (req, res, next) => {
    res.sendFile(path.resolve('docs/api-v1.json'))
  })
  .use(express.static(getAssetsPath()))

export { docRouter, VDOC_BASENAME }
  1. Regitst Route
// server.ts
import { VDOC_BASENAME, docRouter } from './buildDocRoute.ts'
express().use(VDOC_BASENAME, docRouter).listen(5000)
  1. Open the link after server started.
http://localhost:5000/api-doc/index.html
1.0.5

4 months ago

1.0.4

4 months ago

1.0.3

5 months ago

1.0.2

5 months ago

1.0.1

6 months ago

1.0.0

6 months ago

0.0.5

6 months ago

0.0.4

6 months ago

0.0.3

6 months ago

0.0.2

6 months ago

0.0.1

7 months ago