doc-generate/example/test_all_params.api

52 lines
1.4 KiB
Plaintext
Raw Normal View History

2025-10-01 09:44:41 +00:00
syntax = "v1"
info (
title: "Test All Parameter Types"
version: "v1"
)
type (
// 同時包含所有類型的參數
AllParamsReq {
// Header 參數
Authorization string `header:"Authorization" validate:"required"`
XRequestID string `header:"X-Request-ID,optional"`
// Path 參數
UserID string `path:"userId" validate:"required"`
ItemID string `path:"itemId" validate:"required"`
// Query 參數 (form)
Page int `form:"page,optional"`
PageSize int `form:"pageSize,optional"`
Filter string `form:"filter,optional"`
// JSON Body 參數
Name string `json:"name" validate:"required"`
Description string `json:"description,optional"`
Tags []string `json:"tags,optional"`
}
Response {
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
}
)
@server (
prefix: /api/v1
)
service test {
// 測試所有參數類型同時存在
@handler UpdateWithAllParams
put /users/:userId/items/:itemId (AllParamsReq) returns (Response)
// 測試只有 path + query
@handler GetWithPathQuery
get /users/:userId/items/:itemId (AllParamsReq) returns (Response)
// 測試 path + header + body (POST)
@handler CreateWithPathHeaderBody
post /users/:userId/items (AllParamsReq) returns (Response)
}