koa-openapiv3
this is a koa middleware ,that validates header&cookie&params&body&parameters based on openapiv3 and displays doc and cli print routing information
Last updated 5 months ago by lynn.wang .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install koa-openapiv3 
SYNC missed versions from official npm registry.

koa-openapiv3

this is a koa middleware ,that validates header&cookie&params&body&parameters based on openapiv3 and displays doc and cli print routing information

install

npm install koa-openapiv3
yarn add koa-openapiv3

require

"koa": "^2.7.0",
"koa-body": "^4.1.1",
"koa-router": "^7.4.0"

tips

requestBody.content.mime the request content-type field without parameters, such as charset.
e.g. `application/json` `text/plain`   `application/x-www-form-urlencoded`
if you do not like this ui ,you can use swagger json path custom ui

errors tips cli print routes swagger api json swagger api ui

test

cd test
yarn
npm run dev

method


interface Api {
    path: string
    path: string
    method: string
    operation: IOpenAPIOperation
    schema: IOpenAPI
    paramsSchema?: Dict<IOpenAPISchema>
    querySchema?: Dict<IOpenAPISchema>
    headerSchema?: Dict<IOpenAPISchema>
    cookieSchema?: Dict<IOpenAPISchema>
    payloadSchema?: Dict<IOpenAPISchema>
    constructor (schema: IOpenAPI, path: string, method: ApiMethod, option: IOpenAPIOperation)
    validate (data: any, schema: IOpenAPISchema, name: string): boolean
    getParams (ctx: Koa.ParameterizedContext, at: IOpenAPIParameterLocation): any
    addParamMetaSchema (params: IOpenAPIParameter, schema: IOpenAPISchema | undefined, root: IOpenAPISchema): IOpenAPISchema
    async getParamsSchema (at: IOpenAPIParameterLocation): Promise<Dict<IOpenAPISchema>>
    async getPayloadSchema (): Promise<Dict<IOpenAPISchema>>
    getPayload (ctx: Koa.ParameterizedContext): any
    verify (
        paramMetaType: string = 'default',
        headerMetaType: string = 'default',
        cookieMetaType: string = 'default',
        queryMetaType: string = 'default'
    ): Middleware
}

interface Swagger{
    apis: Api[]
    schema: IOpenAPI
    constructor (schema: Omit<IOpenAPI, 'paths'>)
    // show ui 
    static ui (config: IOpenAPI, json_path?: string, ui_path?: string, web_index_path?: string, web_static_path?: string): Koa.Middleware
    // cli print all routes
    print () void
    // add one router
    add (path: string, method: ApiMethod, option: IOpenAPIOperation, components?: IOpenAPIComponent): Api
} 

Current Tags

  • 2.0.2                                ...           latest (5 months ago)

11 Versions

  • 2.0.2                                ...           5 months ago
  • 2.0.1                                ...           8 months ago
  • 2.0.0                                ...           8 months ago
  • 1.0.8                                ...           10 months ago
  • 1.0.7                                ...           a year ago
  • 1.0.5                                ...           a year ago
  • 1.0.4                                ...           a year ago
  • 1.0.3                                ...           a year ago
  • 1.0.2                                ...           a year ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (22)
Dev Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |