# aldabra

> OpenAPI(Swagger)规范是一种用于描述 RESTful API 的强大定义格式。 aldabra 提供了声明式的 api 及参数验证。

Latest version **1.1.0** (published 2022-01-14) · 0 weekly downloads

## Install

```sh
npm install aldabra
pnpm add aldabra
yarn add aldabra
bun add aldabra
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2022-01-14 |
| First published | 2021-12-03 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 50.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | vencel |
| Maintainers | candoudashu |

## Links

- npm: https://www.npmjs.com/package/aldabra
- Repository: https://github.com/CanDouDaShu/aldabra
- Homepage: https://github.com/CanDouDaShu/aldabra#readme
- Issues: https://github.com/CanDouDaShu/aldabra/issues
- npm.io page: https://npm.io/package/aldabra

## Recent versions

- 1.1.0 (latest) — 2022-01-14
- 1.0.0 — 2021-12-03

## README

# aldabra

OpenAPI(Swagger)规范是一种用于描述 RESTful API 的强大定义格式。 aldabra 提供了声明式的 api 及参数验证。

## 快速开始


```
npm i midway-init -g
midway-init --package=aldabra
```

## 配置 swagger (open api)

进入 `src/app.ts`

```ts
/**
 * open api 文档配置
 */
document
    .setTitle('midway openApi')
    .setVersion(process.env.npm_package_version)
    .setDescription('支持基于 interface 的验证')
    // api 认证方式
    .setSecuritySchemes({
        ApiKeyAuth: {
            type: 'apiKey',
            in: 'header',
            name: 'authorization',
        },
    })
```

## 配置 swagger ui

进入 `src/app.ts`

```ts
await openApi(app, {
    /**
     * 是否开启 swagger ui
     */
    enable: true,
    /**
     * swagger ui 路由前缀
     */
    routerPrefix: '/swagger-ui',

    /**
     * swagger ui version
     */
    swaggerUiVersion: '3.30.2',
})
```

## 声明 API

```ts
import { provide, inject, Context } from 'midway'
import { get, Param, controller } from '../../decorator/openApi'

@provide()
@controller('/user', {
    description: '用户模块'
})
export class UserController {
    @inject()
    ctx: Context

    @get('/:id', {
        description: '用户信息',
        responses: 'API.UserRes',
    })
    async getUser(
        @Param('number', {
            minimum: 1,
            description: '用户id',
        })
        id: number
    ) {
        return {
            id,
            username: 'string',
            phone: '13800138000',
        }
    }
}

```

### 路由参数

在路由处理程序中查找所有使用的
`@Body()` ， `@Query()` 和 `@Param()` 等装饰器来生成 API 文档。该模块利用反射创建相应的模型定义。

---
_Source: https://npm.io/package/aldabra · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
