feat(api): rules playground API

- updated swagger
This commit is contained in:
yusing
2025-10-26 15:56:18 +08:00
parent 8778f4ea73
commit f76d86dfa2
5 changed files with 1392 additions and 185 deletions

View File

@@ -105,12 +105,6 @@
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
}
},
"x-id": "list",
@@ -2135,6 +2129,54 @@
"operationId": "routes"
}
},
"/route/playground": {
"post": {
"description": "Test rules against mock request/response",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"route"
],
"summary": "Rule Playground",
"parameters": [
{
"description": "Playground request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/PlaygroundRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/PlaygroundResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
}
},
"x-id": "playground",
"operationId": "playground"
}
},
"/route/providers": {
"get": {
"description": "List route providers",
@@ -2726,6 +2768,83 @@
"x-nullable": false,
"x-omitempty": false
},
"FinalRequest": {
"type": "object",
"properties": {
"body": {
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"headers": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "string"
}
},
"x-nullable": false,
"x-omitempty": false
},
"host": {
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"method": {
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"path": {
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"query": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "string"
}
},
"x-nullable": false,
"x-omitempty": false
}
},
"x-nullable": false,
"x-omitempty": false
},
"FinalResponse": {
"type": "object",
"properties": {
"body": {
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"headers": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "string"
}
},
"x-nullable": false,
"x-omitempty": false
},
"statusCode": {
"type": "integer",
"x-nullable": false,
"x-omitempty": false
}
},
"x-nullable": false,
"x-omitempty": false
},
"HTTPHeader": {
"type": "object",
"properties": {
@@ -2799,6 +2918,75 @@
"x-nullable": false,
"x-omitempty": false
},
"HealthInfo": {
"type": "object",
"properties": {
"detail": {
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"latency": {
"description": "latency in microseconds",
"type": "number",
"x-nullable": false,
"x-omitempty": false
},
"status": {
"type": "string",
"enum": [
"healthy",
"unhealthy",
"napping",
"starting",
"error",
"unknown"
],
"x-nullable": false,
"x-omitempty": false
},
"uptime": {
"description": "uptime in milliseconds",
"type": "number",
"x-nullable": false,
"x-omitempty": false
}
},
"x-nullable": false,
"x-omitempty": false
},
"HealthInfoWithoutDetail": {
"type": "object",
"properties": {
"latency": {
"description": "latency in microseconds",
"type": "number",
"x-nullable": false,
"x-omitempty": false
},
"status": {
"type": "string",
"enum": [
"healthy",
"unhealthy",
"napping",
"starting",
"error",
"unknown"
],
"x-nullable": false,
"x-omitempty": false
},
"uptime": {
"description": "uptime in milliseconds",
"type": "number",
"x-nullable": false,
"x-omitempty": false
}
},
"x-nullable": false,
"x-omitempty": false
},
"HealthJSON": {
"type": "object",
"properties": {
@@ -2882,7 +3070,7 @@
"HealthMap": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/routes.HealthInfo"
"$ref": "#/definitions/HealthInfo"
},
"x-nullable": false,
"x-omitempty": false
@@ -3494,6 +3682,113 @@
"x-nullable": false,
"x-omitempty": false
},
"MockCookie": {
"type": "object",
"properties": {
"name": {
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"value": {
"type": "string",
"x-nullable": false,
"x-omitempty": false
}
},
"x-nullable": false,
"x-omitempty": false
},
"MockRequest": {
"type": "object",
"properties": {
"body": {
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"cookies": {
"type": "array",
"items": {
"$ref": "#/definitions/MockCookie"
},
"x-nullable": false,
"x-omitempty": false
},
"headers": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "string"
}
},
"x-nullable": false,
"x-omitempty": false
},
"host": {
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"method": {
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"path": {
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"query": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "string"
}
},
"x-nullable": false,
"x-omitempty": false
},
"remoteIP": {
"type": "string",
"x-nullable": false,
"x-omitempty": false
}
},
"x-nullable": false,
"x-omitempty": false
},
"MockResponse": {
"type": "object",
"properties": {
"body": {
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"headers": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "string"
}
},
"x-nullable": false,
"x-omitempty": false
},
"statusCode": {
"type": "integer",
"x-nullable": false,
"x-omitempty": false
}
},
"x-nullable": false,
"x-omitempty": false
},
"NewAgentRequest": {
"type": "object",
"required": [
@@ -3589,6 +3884,120 @@
"x-nullable": false,
"x-omitempty": false
},
"ParsedRule": {
"type": "object",
"properties": {
"do": {
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"isResponseRule": {
"type": "boolean",
"x-nullable": false,
"x-omitempty": false
},
"name": {
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"on": {
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"validationError": {
"x-nullable": false,
"x-omitempty": false
}
},
"x-nullable": false,
"x-omitempty": false
},
"PlaygroundRequest": {
"type": "object",
"required": [
"rules"
],
"properties": {
"mockRequest": {
"$ref": "#/definitions/MockRequest"
},
"mockResponse": {
"$ref": "#/definitions/MockResponse"
},
"rules": {
"type": "array",
"items": {
"$ref": "#/definitions/routeApi.RawRule"
},
"x-nullable": false,
"x-omitempty": false
}
},
"x-nullable": false,
"x-omitempty": false
},
"PlaygroundResponse": {
"type": "object",
"properties": {
"executionError": {
"x-nullable": false,
"x-omitempty": false
},
"finalRequest": {
"$ref": "#/definitions/FinalRequest",
"x-nullable": false,
"x-omitempty": false
},
"finalResponse": {
"$ref": "#/definitions/FinalResponse",
"x-nullable": false,
"x-omitempty": false
},
"matchedRules": {
"type": "array",
"items": {
"type": "string"
},
"x-nullable": false,
"x-omitempty": false
},
"parsedRules": {
"type": "array",
"items": {
"$ref": "#/definitions/ParsedRule"
},
"x-nullable": false,
"x-omitempty": false
},
"upstreamCalled": {
"type": "boolean",
"x-nullable": false,
"x-omitempty": false
}
},
"x-nullable": false,
"x-omitempty": false
},
"Port": {
"type": "object",
"properties": {
"listening": {
"type": "integer",
"x-nullable": false,
"x-omitempty": false
},
"proxy": {
"type": "integer",
"x-nullable": false,
"x-omitempty": false
}
},
"x-nullable": false,
"x-omitempty": false
},
"ProviderStats": {
"type": "object",
"properties": {
@@ -3844,7 +4253,7 @@
"x-nullable": true
},
"port": {
"$ref": "#/definitions/github_com_yusing_go-proxy_internal_route_types.Port",
"$ref": "#/definitions/Port",
"x-nullable": false,
"x-omitempty": false
},
@@ -3868,9 +4277,12 @@
"x-nullable": false,
"x-omitempty": false
},
"rule_file": {
"type": "string",
"x-nullable": true
},
"rules": {
"type": "array",
"uniqueItems": true,
"items": {
"$ref": "#/definitions/rules.Rule"
},
@@ -3878,7 +4290,47 @@
"x-omitempty": false
},
"scheme": {
"$ref": "#/definitions/route.Scheme",
"type": "string",
"enum": [
"http",
"https",
"tcp",
"udp",
"fileserver"
],
"x-nullable": false,
"x-omitempty": false
},
"ssl_certificate": {
"description": "Path to client certificate",
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"ssl_certificate_key": {
"description": "Path to client certificate key",
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"ssl_protocols": {
"description": "Allowed TLS protocols",
"type": "array",
"items": {
"type": "string"
},
"x-nullable": false,
"x-omitempty": false
},
"ssl_server_name": {
"description": "SSL/TLS proxy options (nginx-like)",
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"ssl_trusted_certificate": {
"description": "Path to trusted CA certificates",
"type": "string",
"x-nullable": false,
"x-omitempty": false
}
@@ -3975,7 +4427,7 @@
"statuses": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/routes.HealthInfo"
"$ref": "#/definitions/HealthInfoWithoutDetail"
},
"x-nullable": false,
"x-omitempty": false
@@ -4499,7 +4951,6 @@
"type": "object",
"properties": {
"iops": {
"description": "godoxy",
"type": "integer",
"x-nullable": false,
"x-omitempty": false
@@ -4522,7 +4973,6 @@
"x-omitempty": false
},
"read_speed": {
"description": "godoxy",
"type": "number",
"x-nullable": false,
"x-omitempty": false
@@ -4538,7 +4988,6 @@
"x-omitempty": false
},
"write_speed": {
"description": "godoxy",
"type": "number",
"x-nullable": false,
"x-omitempty": false
@@ -4566,7 +5015,7 @@
"x-omitempty": false
},
"total": {
"type": "integer",
"type": "number",
"x-nullable": false,
"x-omitempty": false
},
@@ -4628,31 +5077,9 @@
"x-nullable": false,
"x-omitempty": false
},
"github_com_yusing_go-proxy_internal_route_types.Port": {
"type": "object",
"properties": {
"listening": {
"type": "integer",
"x-nullable": false,
"x-omitempty": false
},
"proxy": {
"type": "integer",
"x-nullable": false,
"x-omitempty": false
}
},
"x-nullable": false,
"x-omitempty": false
},
"homepage.FetchResult": {
"type": "object",
"properties": {
"errMsg": {
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"icon": {
"type": "array",
"items": {
@@ -4739,29 +5166,11 @@
"x-nullable": false,
"x-omitempty": false
},
"free": {
"description": "This is the kernel's notion of free memory; RAM chips whose bits nobody\ncares about the value of right now. For a human consumable number,\nAvailable is what you really want.",
"type": "integer",
"x-nullable": false,
"x-omitempty": false
},
"total": {
"description": "Total amount of RAM on this system",
"type": "integer",
"x-nullable": false,
"x-omitempty": false
},
"used": {
"description": "RAM used by programs\n\nThis value is computed from the kernel specific values.",
"type": "integer",
"x-nullable": false,
"x-omitempty": false
},
"used_percent": {
"description": "Percentage of RAM used by programs\n\nThis value is computed from the kernel specific values.",
"type": "number",
"x-nullable": false,
"x-omitempty": false
}
},
"x-nullable": false,
@@ -4907,7 +5316,7 @@
"x-nullable": true
},
"port": {
"$ref": "#/definitions/github_com_yusing_go-proxy_internal_route_types.Port",
"$ref": "#/definitions/Port",
"x-nullable": false,
"x-omitempty": false
},
@@ -4931,9 +5340,12 @@
"x-nullable": false,
"x-omitempty": false
},
"rule_file": {
"type": "string",
"x-nullable": true
},
"rules": {
"type": "array",
"uniqueItems": true,
"items": {
"$ref": "#/definitions/rules.Rule"
},
@@ -4941,7 +5353,47 @@
"x-omitempty": false
},
"scheme": {
"$ref": "#/definitions/route.Scheme",
"type": "string",
"enum": [
"http",
"https",
"tcp",
"udp",
"fileserver"
],
"x-nullable": false,
"x-omitempty": false
},
"ssl_certificate": {
"description": "Path to client certificate",
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"ssl_certificate_key": {
"description": "Path to client certificate key",
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"ssl_protocols": {
"description": "Allowed TLS protocols",
"type": "array",
"items": {
"type": "string"
},
"x-nullable": false,
"x-omitempty": false
},
"ssl_server_name": {
"description": "SSL/TLS proxy options (nginx-like)",
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"ssl_trusted_certificate": {
"description": "Path to trusted CA certificates",
"type": "string",
"x-nullable": false,
"x-omitempty": false
}
@@ -4949,22 +5401,25 @@
"x-nullable": false,
"x-omitempty": false
},
"route.Scheme": {
"type": "string",
"enum": [
"http",
"https",
"tcp",
"udp",
"fileserver"
],
"x-enum-varnames": [
"SchemeHTTP",
"SchemeHTTPS",
"SchemeTCP",
"SchemeUDP",
"SchemeFileServer"
],
"routeApi.RawRule": {
"type": "object",
"properties": {
"do": {
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"name": {
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"on": {
"type": "string",
"x-nullable": false,
"x-omitempty": false
}
},
"x-nullable": false,
"x-omitempty": false
},
@@ -4979,43 +5434,6 @@
"x-nullable": false,
"x-omitempty": false
},
"routes.HealthInfo": {
"type": "object",
"properties": {
"detail": {
"type": "string",
"x-nullable": false,
"x-omitempty": false
},
"latency": {
"description": "latency in microseconds",
"type": "number",
"x-nullable": false,
"x-omitempty": false
},
"status": {
"type": "string",
"enum": [
"healthy",
"unhealthy",
"napping",
"starting",
"error",
"unknown"
],
"x-nullable": false,
"x-omitempty": false
},
"uptime": {
"description": "uptime in milliseconds",
"type": "number",
"x-nullable": false,
"x-omitempty": false
}
},
"x-nullable": false,
"x-omitempty": false
},
"rules.Rule": {
"type": "object",
"properties": {

View File

@@ -217,6 +217,42 @@ definitions:
- FileTypeConfig
- FileTypeProvider
- FileTypeMiddleware
FinalRequest:
properties:
body:
type: string
headers:
additionalProperties:
items:
type: string
type: array
type: object
host:
type: string
method:
type: string
path:
type: string
query:
additionalProperties:
items:
type: string
type: array
type: object
type: object
FinalResponse:
properties:
body:
type: string
headers:
additionalProperties:
items:
type: string
type: array
type: object
statusCode:
type: integer
type: object
HTTPHeader:
properties:
key:
@@ -248,6 +284,44 @@ definitions:
additionalProperties: {}
type: object
type: object
HealthInfo:
properties:
detail:
type: string
latency:
description: latency in microseconds
type: number
status:
enum:
- healthy
- unhealthy
- napping
- starting
- error
- unknown
type: string
uptime:
description: uptime in milliseconds
type: number
type: object
HealthInfoWithoutDetail:
properties:
latency:
description: latency in microseconds
type: number
status:
enum:
- healthy
- unhealthy
- napping
- starting
- error
- unknown
type: string
uptime:
description: uptime in milliseconds
type: number
type: object
HealthJSON:
properties:
config:
@@ -283,7 +357,7 @@ definitions:
type: object
HealthMap:
additionalProperties:
$ref: '#/definitions/routes.HealthInfo'
$ref: '#/definitions/HealthInfo'
type: object
HomepageCategory:
properties:
@@ -564,6 +638,55 @@ definitions:
- MetricsPeriod1h
- MetricsPeriod1d
- MetricsPeriod1mo
MockCookie:
properties:
name:
type: string
value:
type: string
type: object
MockRequest:
properties:
body:
type: string
cookies:
items:
$ref: '#/definitions/MockCookie'
type: array
headers:
additionalProperties:
items:
type: string
type: array
type: object
host:
type: string
method:
type: string
path:
type: string
query:
additionalProperties:
items:
type: string
type: array
type: object
remoteIP:
type: string
type: object
MockResponse:
properties:
body:
type: string
headers:
additionalProperties:
items:
type: string
type: array
type: object
statusCode:
type: integer
type: object
NewAgentRequest:
properties:
container_runtime:
@@ -612,6 +735,56 @@ definitions:
format: base64
type: string
type: object
ParsedRule:
properties:
do:
type: string
isResponseRule:
type: boolean
name:
type: string
"on":
type: string
validationError: {}
type: object
PlaygroundRequest:
properties:
mockRequest:
$ref: '#/definitions/MockRequest'
mockResponse:
$ref: '#/definitions/MockResponse'
rules:
items:
$ref: '#/definitions/routeApi.RawRule'
type: array
required:
- rules
type: object
PlaygroundResponse:
properties:
executionError: {}
finalRequest:
$ref: '#/definitions/FinalRequest'
finalResponse:
$ref: '#/definitions/FinalResponse'
matchedRules:
items:
type: string
type: array
parsedRules:
items:
$ref: '#/definitions/ParsedRule'
type: array
upstreamCalled:
type: boolean
type: object
Port:
properties:
listening:
type: integer
proxy:
type: integer
type: object
ProviderStats:
properties:
reverse_proxies:
@@ -738,7 +911,7 @@ definitions:
type: array
x-nullable: true
port:
$ref: '#/definitions/github_com_yusing_go-proxy_internal_route_types.Port'
$ref: '#/definitions/Port'
provider:
description: for backward compatibility
type: string
@@ -749,13 +922,38 @@ definitions:
type: integer
root:
type: string
rule_file:
type: string
x-nullable: true
rules:
items:
$ref: '#/definitions/rules.Rule'
type: array
uniqueItems: true
scheme:
$ref: '#/definitions/route.Scheme'
enum:
- http
- https
- tcp
- udp
- fileserver
type: string
ssl_certificate:
description: Path to client certificate
type: string
ssl_certificate_key:
description: Path to client certificate key
type: string
ssl_protocols:
description: Allowed TLS protocols
items:
type: string
type: array
ssl_server_name:
description: SSL/TLS proxy options (nginx-like)
type: string
ssl_trusted_certificate:
description: Path to trusted CA certificates
type: string
type: object
RouteProvider:
properties:
@@ -798,7 +996,7 @@ definitions:
properties:
statuses:
additionalProperties:
$ref: '#/definitions/routes.HealthInfo'
$ref: '#/definitions/HealthInfoWithoutDetail'
type: object
timestamp:
type: integer
@@ -1072,7 +1270,6 @@ definitions:
disk.IOCountersStat:
properties:
iops:
description: godoxy
type: integer
name:
description: |-
@@ -1096,14 +1293,12 @@ definitions:
read_count:
type: integer
read_speed:
description: godoxy
type: number
write_bytes:
type: integer
write_count:
type: integer
write_speed:
description: godoxy
type: number
type: object
disk.UsageStat:
@@ -1115,7 +1310,7 @@ definitions:
path:
type: string
total:
type: integer
type: number
used:
type: integer
used_percent:
@@ -1156,17 +1351,8 @@ definitions:
required:
- id
type: object
github_com_yusing_go-proxy_internal_route_types.Port:
properties:
listening:
type: integer
proxy:
type: integer
type: object
homepage.FetchResult:
properties:
errMsg:
type: string
icon:
items:
format: int32
@@ -1212,27 +1398,12 @@ definitions:
This value is computed from the kernel specific values.
type: integer
free:
description: |-
This is the kernel's notion of free memory; RAM chips whose bits nobody
cares about the value of right now. For a human consumable number,
Available is what you really want.
type: integer
total:
description: Total amount of RAM on this system
type: integer
used:
description: |-
RAM used by programs
This value is computed from the kernel specific values.
type: integer
used_percent:
description: |-
Percentage of RAM used by programs
This value is computed from the kernel specific values.
type: number
type: object
net.IOCountersStat:
properties:
@@ -1307,7 +1478,7 @@ definitions:
type: array
x-nullable: true
port:
$ref: '#/definitions/github_com_yusing_go-proxy_internal_route_types.Port'
$ref: '#/definitions/Port'
provider:
description: for backward compatibility
type: string
@@ -1318,54 +1489,54 @@ definitions:
type: integer
root:
type: string
rule_file:
type: string
x-nullable: true
rules:
items:
$ref: '#/definitions/rules.Rule'
type: array
uniqueItems: true
scheme:
$ref: '#/definitions/route.Scheme'
enum:
- http
- https
- tcp
- udp
- fileserver
type: string
ssl_certificate:
description: Path to client certificate
type: string
ssl_certificate_key:
description: Path to client certificate key
type: string
ssl_protocols:
description: Allowed TLS protocols
items:
type: string
type: array
ssl_server_name:
description: SSL/TLS proxy options (nginx-like)
type: string
ssl_trusted_certificate:
description: Path to trusted CA certificates
type: string
type: object
routeApi.RawRule:
properties:
do:
type: string
name:
type: string
"on":
type: string
type: object
route.Scheme:
enum:
- http
- https
- tcp
- udp
- fileserver
type: string
x-enum-varnames:
- SchemeHTTP
- SchemeHTTPS
- SchemeTCP
- SchemeUDP
- SchemeFileServer
routeApi.RoutesByProvider:
additionalProperties:
items:
$ref: '#/definitions/route.Route'
type: array
type: object
routes.HealthInfo:
properties:
detail:
type: string
latency:
description: latency in microseconds
type: number
status:
enum:
- healthy
- unhealthy
- napping
- starting
- error
- unknown
type: string
uptime:
description: uptime in milliseconds
type: number
type: object
rules.Rule:
properties:
do:
@@ -1494,10 +1665,6 @@ paths:
description: Forbidden
schema:
$ref: '#/definitions/ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/ErrorResponse'
summary: List agents
tags:
- agent
@@ -2878,6 +3045,37 @@ paths:
- route
- websocket
x-id: routes
/route/playground:
post:
consumes:
- application/json
description: Test rules against mock request/response
parameters:
- description: Playground request
in: body
name: request
required: true
schema:
$ref: '#/definitions/PlaygroundRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/PlaygroundResponse'
"400":
description: Bad Request
schema:
$ref: '#/definitions/ErrorResponse'
"403":
description: Forbidden
schema:
$ref: '#/definitions/ErrorResponse'
summary: Rule Playground
tags:
- route
x-id: playground
/route/providers:
get:
consumes: