wip: 稍微规划一下api的desc写法。

main
NoahLan 1 year ago
parent e50b98f420
commit 60a0b74476

@ -1,6 +1,7 @@
# Custom configuration | 独立配置
# Service name | 项目名称
SERVICE=core
FILE_SERVICE=file
TEMPLATE_REMOTE=https://git.noahlan.cn/noahlan/goctls-template.git
TEMPLATE_BRANCH=v1.5.17
@ -50,6 +51,17 @@ gen-rpc: # Generate RPC files from proto | 生成 RPC 的代码
--branch $(TEMPLATE_BRANCH)
@echo "Generate RPC files successfully"
.PHONY: gen-rpc-file
gen-rpc-file: # Generate RPC files from proto | 生成 RPC 的代码
goctls rpc protoc ./rpc/$(FILE_SERVICE)/$(FILE_SERVICE).proto \
--style=$(PROJECT_STYLE) \
--go_out=./rpc/$(FILE_SERVICE)/types \
--go-grpc_out=./rpc/$(FILE_SERVICE)/types \
--zrpc_out=./rpc/$(FILE_SERVICE) \
--remote $(TEMPLATE_REMOTE) \
--branch $(TEMPLATE_BRANCH)
@echo "Generate RPC files successfully"
.PHONY: gen-ent
gen-ent: # Generate Ent codes | 生成 Ent 的代码
go run -mod=mod entgo.io/ent/cmd/ent generate \

@ -1 +1,3 @@
import "base.api"
import "core/model.api"
import "core/user.api"

@ -42,39 +42,31 @@ type TimeInfo {
}
// Basic ID Request | 基础ID结构
type IDReq {
type BaseID {
// Id | 序号
Id uint64 `json:"id,string,optional" form:"id,string,optional"`
ID int64 `json:"id,string,optional" form:"id,string,optional"`
}
// Basic ID request (path) | 基础ID结构地址参数
type IDPathReq {
type PathID {
// ID | 序号
//
// In: path
Id uint64 `json:"id,optional,string" path:"id,optional,string"`
ID int64 `json:"id,optional,string" path:"id,optional,string"`
}
// Basic ID List request | 基础ID列表结构用于Post
// swagger:model IDsReq
type IDsReq {
// swagger:model BaseIDs
type BaseIDs {
// 主键列表
Ids []uint64 `json:"ids,optional" form:"ids,optional"`
}
// The base ID response data | 基础ID信息
type BaseIDInfo {
// Id | 序号
Id uint64 `json:"id,string,optional"`
TimeInfo
Ids []int64 `json:"ids,optional" form:"ids,optional"`
}
@server(
group: base
prefix: /api/base
)
service Test {
service api {
// Initialize database | 初始化数据库
@handler initDatabase
get /initDatabase

@ -0,0 +1,16 @@
syntax = "v1"
info(
title: "Model"
desc: "API basic"
author: "NorthLan"
email: "lan6995@gmail.com"
version: "v1.0"
)
import "../base.api"
type UserInfo {
BaseID
TimeInfo
}

@ -0,0 +1,28 @@
//import "model.api"
type (
UserReq {
BaseID
*Pagination
}
)
@server(
group: user_admin
prefix: /api/admin/user
jwt: Auth
middleware: Authority
)
service api {
// Create user | 创建用户
@handler createUserAdmin
post /create (UserInfo) returns (BaseID)
// Get user | 获取用户
@handler getUserAdmin
get / (UserReq) returns (UserInfo)
// Delete user | 删除用户
@handler deleteUserAdmin
post / (BaseID)
}

@ -2,54 +2,23 @@ basePath: /
consumes:
- application/json
definitions:
BaseIDInfo:
description: The base ID response data | 基础ID信息
properties:
createdAt:
description: Create Time | 创建时间
type: string
x-go-name: CreatedAt
id:
description: Id | 序号
format: uint64
type: string
x-go-name: Id
updatedAt:
description: Update Time | 更新时间
type: string
x-go-name: UpdatedAt
type: object
x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types
IDPathReq:
description: Basic ID request (path) | 基础ID结构地址参数
properties:
id:
description: |-
ID | 序号
In: path
format: uint64
type: string
x-go-name: Id
type: object
x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types
IDReq:
BaseID:
description: Basic ID Request | 基础ID结构
properties:
id:
description: Id | 序号
format: uint64
format: int64
type: string
x-go-name: Id
x-go-name: ID
type: object
x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types
IDsReq:
BaseIDs:
description: Basic ID List request | 基础ID列表结构用于Post
properties:
ids:
description: 主键列表
items:
format: uint64
format: int64
type: integer
type: array
x-go-name: Ids
@ -94,12 +63,107 @@ definitions:
x-go-name: UpdatedAt
type: object
x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types
UserInfo:
properties:
createdAt:
description: Create Time | 创建时间
type: string
x-go-name: CreatedAt
id:
description: Id | 序号
format: int64
type: string
x-go-name: ID
updatedAt:
description: Update Time | 更新时间
type: string
x-go-name: UpdatedAt
type: object
x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types
UserReq:
properties:
current:
description: Current Page | 当前页
example: 1
format: uint64
maximum: 100000
minimum: 1
type: integer
x-go-name: Current
id:
description: Id | 序号
format: int64
type: string
x-go-name: ID
size:
description: Page Size | 每页大小
example: 10
format: uint64
maximum: 9999
minimum: 0
type: integer
x-go-name: Size
total:
description: Total Number | 数据总数
format: uint64
type: integer
x-go-name: Total
type: object
x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types
host: localhost:0
info:
description: 'Description: test service'
title: test
description: 'Description: api service'
title: api
version: 0.0.1
paths:
/api/admin/user:
get:
description: Get user | 获取用户
operationId: GetUserAdmin
parameters:
- in: body
name: body
schema:
$ref: '#/definitions/UserReq'
type: object
responses:
"200":
description: UserInfo
schema:
$ref: '#/definitions/UserInfo'
summary: Get user | 获取用户
tags:
- user_admin
post:
description: Delete user | 删除用户
operationId: DeleteUserAdmin
parameters:
- in: body
name: body
schema:
$ref: '#/definitions/BaseID'
type: object
summary: Delete user | 删除用户
tags:
- user_admin
/api/admin/user/create:
post:
description: Create user | 创建用户
operationId: CreateUserAdmin
parameters:
- in: body
name: body
schema:
$ref: '#/definitions/UserInfo'
type: object
responses:
"200":
description: BaseID
schema:
$ref: '#/definitions/BaseID'
summary: Create user | 创建用户
tags:
- user_admin
/api/base/initDatabase:
get:
description: Initialize database | 初始化数据库

Loading…
Cancel
Save