feat: 补充接口example

This commit is contained in:
dayjoy
2025-10-11 18:02:08 +08:00
parent 99c8fa5f2d
commit 1659d03040
4 changed files with 36 additions and 5 deletions

View File

@@ -1,4 +1,4 @@
import {Controller, Get, Route, Response, Tags, Request, Security, OperationId} from 'tsoa';
import {Controller, Get, Route, Response, Tags, Request, Security, OperationId, Example} from 'tsoa';
import {ApiError, ApiResponse} from '../types/api';
import type {Request as ExpressRequest} from 'express';
import axios from "axios";
@@ -50,6 +50,21 @@ export class GroupController extends Controller {
@Response<ApiResponse<UserInfo[]>>(200, 'Success')
@Response<ApiResponse<null>>(400, 'Bad Request')
@Response<ApiResponse<null>>(401, 'Unauthorized')
@Example<ApiResponse<UserInfo[]>>({
code: 200,
message: 'success',
data: [
{
userId: 123,
nickname: 'John Doe',
avatarUrl: 'https://example.com/avatar.jpg',
gender: 'MALE',
nimToken: 'nim_token_123',
nimAccountId: 'nim_account_123',
token: 'user_token_123',
},
],
})
public async getGroupMembers(@Request() req: ExpressRequest): Promise<ApiResponse<UserInfo[]>> {
const user = req.user;
const groupId = req.headers.groupid;

View File

@@ -1,4 +1,4 @@
import {Controller, Get, Route, Response, Tags, OperationId} from 'tsoa';
import {Controller, Get, Route, Response, Tags, OperationId, Example} from 'tsoa';
import type { ApiResponse } from '../types/api';
@Route('api')
@@ -12,6 +12,11 @@ export class TestController extends Controller {
@Get('/test')
@OperationId('Test_GetTest') // MUST: Specify operationId for better API documentation
@Response<ApiResponse>(200, 'Success')
@Example<ApiResponse>({
code: 200,
message: 'success',
data: null,
})
public async getTest(): Promise<ApiResponse> {
return {
code: 200,

View File

@@ -1,4 +1,4 @@
import {Controller, Get, Route, Response, Tags, Middlewares, Request, Security, OperationId} from 'tsoa';
import {Controller, Get, Route, Response, Tags, Example, Request, Security, OperationId} from 'tsoa';
import type { ApiResponse } from '../types/api';
import type { Request as ExpressRequest } from 'express';
import type {UserInfo} from "../types/user";
@@ -17,6 +17,19 @@ export class UserController extends Controller {
@Security('jwt')
@Response<ApiResponse<UserInfo>>(200, 'Success')
@Response(401, 'Unauthorized')
@Example<ApiResponse<UserInfo>>({
code: 200,
message: 'success',
data: {
userId: 123,
nickname: 'John Doe',
avatarUrl: 'https://example.com/avatar.jpg',
gender: 'MALE',
nimToken: 'nim_token_123',
nimAccountId: 'nim_account_123',
token: 'user_token_123',
}
})
public async getUserGroupInfo(@Request() req: ExpressRequest): Promise<ApiResponse<Omit<UserInfo, 'token'>>> {
const { token, ...rest } = req.user;
return {

View File

@@ -5,7 +5,5 @@ export interface UserInfo {
gender: 'MALE' | 'FEMALE' | 'UNKNOWN';
nimToken: string; // NetEase Cloud Communication token
nimAccountId: string; // NetEase Cloud Communication account ID
createdAt: string;
updatedAt: string;
token: string; // Authentication token
}