@sojs/openapi
TypeScript icon, indicating that this package has built-in type declarations

0.3.1-alpha.0 • Public • Published

@sojs/openapi

OpenAPI v3.0 Specification Implementation

See https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md

Usage

Define Api

import {
  ApiTag,
  ApiPost,
  ApiGet,
  ApiOkResponse,
  ApiRequestBody,
  ApiRequestQuery,
} from '@sojs/openapi';
import { UserSchema } from '../schema/user.schame';

// optional tag, default is class name
@ApiTag('User')
export class UserController {
  @ApiPost({ description: 'create a new user' })
  @ApiOkResponse({ type: Number, description: 'return created user id' })
  async createUser(
    @ApiRequestBody({ description: 'user schema' }) userSchema: UserSchema,
  ): Promise<number> {
    return 1;
  }

  @ApiGet()
  @ApiOkResponse({ type: UserSchema })
  async getUser(@ApiRequestQuery() id: number) {
    return new UserSchema();
  }
}

Define Schema

import { ApiSchema } from '@sojs/openapi';

@ApiSchema({ description: 'user' })
export class UserSchema {
  @ApiSchema({
    description: 'user id, required if update',
    required: false,
  })
  id?: number;

  @ApiSchema()
  username: string;

  @ApiSchema()
  password: string;
}

Readme

Keywords

none

Package Sidebar

Install

npm i @sojs/openapi

Weekly Downloads

0

Version

0.3.1-alpha.0

License

MIT

Unpacked Size

296 kB

Total Files

118

Last publish

Collaborators

  • metauro