1.0.21 • Published 4 years ago

xxd-smartdoc-middleware v1.0.21

Weekly downloads
35
License
ISC
Repository
github
Last release
4 years ago

Smartdoc Middleware (For XXD) v1.x

* It's an project specific version, maybe not suitable for other projects.

Usage

npm i koa-mount xxd-smartdoc-middleware@^1
const app = new Koa();
const smartdoc = require('xxd-smartdoc-middleware');
//...
const spec = require('./spec.json'); // The API specification of your web application
// const spec = require.resolve('./spec.json'); // Path to a JSON file is also acceptable
const prefix = '/docs'; // The prefix you want to serve smartdoc.
const docsDir = `${__dirname}/docs`; // The directory of markdown documents.
app.use(mount(prefix, smartdoc({ prefix, spec, docsDir })));

Note: Must use koa-mount instead of koa-router, because koa-mount will strip the prefix off but koa-router wont.

Options

  • options.prefix: The prefix defined here will be treat as relative path of the document page from the api root.
  • options.spec: API specification, describes your application, modules and actions.
  • options.docs: The directory you put markdown documents, this module will parse them to generate the catalog and search index.

API Specification

ApplicationSpecification

FieldTypeDescription
typestringMust be "application"
titlestringDisplay name of the application
namestringInner name of the application, generally the name in package.json
descriptionstringDescription of the application, supports markdown
notesstring[]Notes of the application, supports markdown
addressstringThe url of the application
contactstringContact messages of the developer.
versionstringVersion of the application, generally the version in package.json
modulesModuleSpecification[]Modules in the application

ModuleSpecification

FieldTypeDescription
typestringMust be "module"
titlestringDisplay name of the module
namestringInner name of the module, generally the name in package.json
descriptionstringDescription of the module, supports markdown
notesstring[]Notes of the module, supports markdown
pathstringThe path prefix of the module
middlewaresMiddlewareSpecification[]Middlewares applied to every actions of the module
filenamestringFilename of the module
actionsActionSpecification[]Actions of the module

Note: According to the implementation of XXD:

  • Path of module spec doesn't affect path of actions, but must be prefix of those paths.

ActionSpecification

FieldTypeDescription
typestringMust be "action"
titlestringDisplay name of the module
namestringInner name of the module, generally the name in package.json
descriptionstringDescription of the module, supports markdown
notesstring[]Notes of the module, supports markdown
route.methodstringRequest method of the action, one of "GET", "POST", "PUT", "DELETE","HEAD","OPTIONS","PATCH"
route.pathstringRequest path of the action, if module has prefix, route.path must be prefixed by that
paramsParameterSpecification[]Request parameters of the action
middlewaresMiddlewareSpecification[]Middlewares applied to the action
filenamestringFilename of the module
funcnamestringFunction name of the action

Note: According to the implementation of XXD:

  • Path of module spec doesn't affect path of actions, but must be prefix of those paths.

ParameterSpecification

FieldTypeDescription
typestringType of the parameter
namestringName of the parameter, generally the name in package.json
descriptionstringDescription of the parameter, supports markdown

Note: According to the implementation of XXD:

  • Parameter can be transferred by route parameters, query, request body (if possible, support json, urlencoded)
  • Type "Upload" is representing a multipart file parameter.
  • Multipart body is only supported when an Upload parameter is declared in the action.
  • There will be some "mismatch parameter" if a @param annotation cannot be parsed correctly, these will be ignored in this module.

MiddlewareSpecification

FieldTypeDescription
namestringName of the parameter, generally the name in package.json
argsstringArguments of the parameter, in the same format of query string

Note: According to the implementation of XXD:

  • Args of middlewares is a querystring.
1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.9

4 years ago

1.0.10

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago