From 1a83c739d4da706ae98b4f57aac8f51253c56aca Mon Sep 17 00:00:00 2001 From: yusing Date: Fri, 17 Jan 2025 14:33:47 +0800 Subject: [PATCH] fix middleware schemas --- schemas/config.schema.json | 191 +----------------------- schemas/middleware_compose.schema.json | 191 +----------------------- schemas/middlewares/middlewares.ts | 36 ++--- schemas/providers/homepage.ts | 7 +- schemas/providers/routes.ts | 2 +- schemas/routes.schema.json | 192 ++++++++++--------------- schemas/types.ts | 8 +- 7 files changed, 112 insertions(+), 515 deletions(-) diff --git a/schemas/config.schema.json b/schemas/config.schema.json index d671eeb..12f6a35 100644 --- a/schemas/config.schema.json +++ b/schemas/config.schema.json @@ -406,12 +406,6 @@ }, "type": "object" }, - "Partial": { - "type": "object" - }, - "Partial": { - "type": "object" - }, "Partial": { "properties": { "add_headers": { @@ -438,6 +432,9 @@ }, "type": "object" }, + "Partial": { + "type": "object" + }, "Partial": { "properties": { "allowed_groups": { @@ -499,12 +496,6 @@ }, "type": "object" }, - "Partial": { - "type": "object" - }, - "Partial": { - "type": "object" - }, "StatusCode": { "anyOf": [ { @@ -949,7 +940,7 @@ "type": "object" }, { - "$ref": "#/definitions/Partial" + "$ref": "#/definitions/Partial" } ] }, @@ -1069,180 +1060,6 @@ } ] }, - { - "allOf": [ - { - "properties": { - "use": { - "enum": [ - "CIDRWhitelist", - "CloudflareRealIP", - "CustomErrorPage", - "HideXForwarded", - "ModifyRequest", - "ModifyResponse", - "OIDC", - "RateLimit", - "RealIP", - "RedirectHTTP", - "Request", - "Response", - "SetXForwarded", - "cidrWhitelist", - "cidr_whitelist", - "cloudflareRealIP", - "cloudflare_real_ip", - "customErrorPage", - "custom_error_page", - "errorPage", - "error_page", - "hideXForwarded", - "hide_x_forwarded", - "modifyRequest", - "modifyResponse", - "modify_request", - "modify_response", - "oidc", - "rateLimit", - "rate_limit", - "realIP", - "real_ip", - "redirectHTTP", - "redirect_http", - "request", - "response", - "setXForwarded", - "set_x_forwarded" - ], - "type": "string" - } - }, - "required": [ - "use" - ], - "type": "object" - }, - { - "$ref": "#/definitions/Partial" - } - ] - }, - { - "allOf": [ - { - "properties": { - "use": { - "enum": [ - "CIDRWhitelist", - "CloudflareRealIP", - "CustomErrorPage", - "HideXForwarded", - "ModifyRequest", - "ModifyResponse", - "OIDC", - "RateLimit", - "RealIP", - "RedirectHTTP", - "Request", - "Response", - "SetXForwarded", - "cidrWhitelist", - "cidr_whitelist", - "cloudflareRealIP", - "cloudflare_real_ip", - "customErrorPage", - "custom_error_page", - "errorPage", - "error_page", - "hideXForwarded", - "hide_x_forwarded", - "modifyRequest", - "modifyResponse", - "modify_request", - "modify_response", - "oidc", - "rateLimit", - "rate_limit", - "realIP", - "real_ip", - "redirectHTTP", - "redirect_http", - "request", - "response", - "setXForwarded", - "set_x_forwarded" - ], - "type": "string" - } - }, - "required": [ - "use" - ], - "type": "object" - }, - { - "$ref": "#/definitions/Partial" - } - ] - }, - { - "allOf": [ - { - "properties": { - "use": { - "enum": [ - "CIDRWhitelist", - "CloudflareRealIP", - "CustomErrorPage", - "HideXForwarded", - "ModifyRequest", - "ModifyResponse", - "OIDC", - "RateLimit", - "RealIP", - "RedirectHTTP", - "Request", - "Response", - "SetXForwarded", - "cidrWhitelist", - "cidr_whitelist", - "cloudflareRealIP", - "cloudflare_real_ip", - "customErrorPage", - "custom_error_page", - "errorPage", - "error_page", - "hideXForwarded", - "hide_x_forwarded", - "modifyRequest", - "modifyResponse", - "modify_request", - "modify_response", - "oidc", - "rateLimit", - "rate_limit", - "realIP", - "real_ip", - "redirectHTTP", - "redirect_http", - "request", - "response", - "setXForwarded", - "set_x_forwarded" - ], - "type": "string" - } - }, - "required": [ - "use" - ], - "type": "object" - }, - { - "$ref": "#/definitions/Partial" - } - ] - }, { "allOf": [ { diff --git a/schemas/middleware_compose.schema.json b/schemas/middleware_compose.schema.json index 1b143e8..5017ed3 100644 --- a/schemas/middleware_compose.schema.json +++ b/schemas/middleware_compose.schema.json @@ -61,12 +61,6 @@ }, "type": "object" }, - "Partial": { - "type": "object" - }, - "Partial": { - "type": "object" - }, "Partial": { "properties": { "add_headers": { @@ -93,6 +87,9 @@ }, "type": "object" }, + "Partial": { + "type": "object" + }, "Partial": { "properties": { "allowed_groups": { @@ -154,12 +151,6 @@ }, "type": "object" }, - "Partial": { - "type": "object" - }, - "Partial": { - "type": "object" - }, "StatusCode": { "anyOf": [ { @@ -228,7 +219,7 @@ "type": "object" }, { - "$ref": "#/definitions/Partial" + "$ref": "#/definitions/Partial" } ] }, @@ -348,180 +339,6 @@ } ] }, - { - "allOf": [ - { - "properties": { - "use": { - "enum": [ - "CIDRWhitelist", - "CloudflareRealIP", - "CustomErrorPage", - "HideXForwarded", - "ModifyRequest", - "ModifyResponse", - "OIDC", - "RateLimit", - "RealIP", - "RedirectHTTP", - "Request", - "Response", - "SetXForwarded", - "cidrWhitelist", - "cidr_whitelist", - "cloudflareRealIP", - "cloudflare_real_ip", - "customErrorPage", - "custom_error_page", - "errorPage", - "error_page", - "hideXForwarded", - "hide_x_forwarded", - "modifyRequest", - "modifyResponse", - "modify_request", - "modify_response", - "oidc", - "rateLimit", - "rate_limit", - "realIP", - "real_ip", - "redirectHTTP", - "redirect_http", - "request", - "response", - "setXForwarded", - "set_x_forwarded" - ], - "type": "string" - } - }, - "required": [ - "use" - ], - "type": "object" - }, - { - "$ref": "#/definitions/Partial" - } - ] - }, - { - "allOf": [ - { - "properties": { - "use": { - "enum": [ - "CIDRWhitelist", - "CloudflareRealIP", - "CustomErrorPage", - "HideXForwarded", - "ModifyRequest", - "ModifyResponse", - "OIDC", - "RateLimit", - "RealIP", - "RedirectHTTP", - "Request", - "Response", - "SetXForwarded", - "cidrWhitelist", - "cidr_whitelist", - "cloudflareRealIP", - "cloudflare_real_ip", - "customErrorPage", - "custom_error_page", - "errorPage", - "error_page", - "hideXForwarded", - "hide_x_forwarded", - "modifyRequest", - "modifyResponse", - "modify_request", - "modify_response", - "oidc", - "rateLimit", - "rate_limit", - "realIP", - "real_ip", - "redirectHTTP", - "redirect_http", - "request", - "response", - "setXForwarded", - "set_x_forwarded" - ], - "type": "string" - } - }, - "required": [ - "use" - ], - "type": "object" - }, - { - "$ref": "#/definitions/Partial" - } - ] - }, - { - "allOf": [ - { - "properties": { - "use": { - "enum": [ - "CIDRWhitelist", - "CloudflareRealIP", - "CustomErrorPage", - "HideXForwarded", - "ModifyRequest", - "ModifyResponse", - "OIDC", - "RateLimit", - "RealIP", - "RedirectHTTP", - "Request", - "Response", - "SetXForwarded", - "cidrWhitelist", - "cidr_whitelist", - "cloudflareRealIP", - "cloudflare_real_ip", - "customErrorPage", - "custom_error_page", - "errorPage", - "error_page", - "hideXForwarded", - "hide_x_forwarded", - "modifyRequest", - "modifyResponse", - "modify_request", - "modify_response", - "oidc", - "rateLimit", - "rate_limit", - "realIP", - "real_ip", - "redirectHTTP", - "redirect_http", - "request", - "response", - "setXForwarded", - "set_x_forwarded" - ], - "type": "string" - } - }, - "required": [ - "use" - ], - "type": "object" - }, - { - "$ref": "#/definitions/Partial" - } - ] - }, { "allOf": [ { diff --git a/schemas/middlewares/middlewares.ts b/schemas/middlewares/middlewares.ts index 3530686..3ee098d 100644 --- a/schemas/middlewares/middlewares.ts +++ b/schemas/middlewares/middlewares.ts @@ -1,11 +1,14 @@ import * as types from "../types"; +/** + * @additionalProperties false + */ export type MiddlewaresMap = { redirect_http?: RedirectHTTP; redirectHTTP?: RedirectHTTP; RedirectHTTP?: RedirectHTTP; - oidc?: OIDC; - OIDC?: OIDC; + oidc?: types.Nullable; + OIDC?: types.Nullable; request?: ModifyRequest; Request?: ModifyRequest; modify_request?: ModifyRequest; @@ -30,9 +33,9 @@ export type MiddlewaresMap = { real_ip?: RealIP; realIP?: RealIP; RealIP?: RealIP; - cloudflare_real_ip?: CloudflareRealIP; - cloudflareRealIP?: CloudflareRealIP; - CloudflareRealIP?: CloudflareRealIP; + cloudflare_real_ip?: types.Nullable; + cloudflareRealIP?: types.Nullable; + CloudflareRealIP?: types.Nullable; rate_limit?: RateLimit; rateLimit?: RateLimit; RateLimit?: RateLimit; @@ -41,10 +44,10 @@ export type MiddlewaresMap = { CIDRWhitelist?: CIDRWhitelist; }; -/** - * @additionalProperties false - */ -export type CustomErrorPage = {}; +export type CustomErrorPage = types.Null; +export type RedirectHTTP = types.Null; +export type SetXForwarded = types.Null; +export type HideXForwarded = types.Null; /** * @additionalProperties false @@ -144,18 +147,3 @@ export type RealIP = { */ recursive: boolean; }; - -/** - * @additionalProperties false - */ -export type RedirectHTTP = {}; - -/** - * @additionalProperties false - */ -export type SetXForwarded = {}; - -/** - * @additionalProperties false - */ -export type HideXForwarded = {}; diff --git a/schemas/providers/homepage.ts b/schemas/providers/homepage.ts index 288807e..20e499c 100644 --- a/schemas/providers/homepage.ts +++ b/schemas/providers/homepage.ts @@ -4,8 +4,13 @@ import { URL } from "../types"; * @additionalProperties false */ export type HomepageConfig = { + /** Whether show in dashboard + * + * @default true + */ + show?: boolean; /* Display name on dashboard */ - name: string; + name?: string; /* Display icon on dashboard */ icon?: URL | WalkxcodeIcon | TargetRelativeIconPath; /* App description */ diff --git a/schemas/providers/routes.ts b/schemas/providers/routes.ts index b21882f..6135600 100644 --- a/schemas/providers/routes.ts +++ b/schemas/providers/routes.ts @@ -79,7 +79,7 @@ export type StreamRoute = { * * @default tcp */ - scheme?: StreamScheme; + scheme: StreamScheme; /** Stream host * * @default localhost diff --git a/schemas/routes.schema.json b/schemas/routes.schema.json index 5409455..29d4c4a 100644 --- a/schemas/routes.schema.json +++ b/schemas/routes.schema.json @@ -199,6 +199,56 @@ } ] }, + "Null": { + "type": "null" + }, + "Nullable": { + "anyOf": [ + { + "$ref": "#/definitions/Null" + }, + { + "additionalProperties": false, + "properties": { + "recursive": { + "default": false, + "description": "Recursively resolve the IP", + "type": "boolean" + } + }, + "type": "object" + } + ] + }, + "Nullable": { + "anyOf": [ + { + "$ref": "#/definitions/Null" + }, + { + "additionalProperties": false, + "properties": { + "allowed_groups": { + "description": "Allowed groups", + "items": { + "type": "string" + }, + "minItems": 1, + "type": "array" + }, + "allowed_users": { + "description": "Allowed users", + "items": { + "type": "string" + }, + "minItems": 1, + "type": "array" + } + }, + "type": "object" + } + ] + }, "ProxyScheme": { "enum": [ "http", @@ -506,6 +556,11 @@ "name": { "type": "string" }, + "show": { + "default": true, + "description": "Whether show in dashboard", + "type": "boolean" + }, "url": { "format": "uri", "type": "string" @@ -515,9 +570,6 @@ "type": "object" } }, - "required": [ - "name" - ], "type": "object" }, "host": { @@ -530,6 +582,7 @@ "description": "Load balance config" }, "middlewares": { + "additionalProperties": false, "description": "Middlewares", "properties": { "CIDRWhitelist": { @@ -558,25 +611,13 @@ "type": "object" }, "CloudflareRealIP": { - "additionalProperties": false, - "properties": { - "recursive": { - "default": false, - "description": "Recursively resolve the IP", - "type": "boolean" - } - }, - "type": "object" + "$ref": "#/definitions/Nullable" }, "CustomErrorPage": { - "additionalProperties": false, - "properties": {}, - "type": "object" + "$ref": "#/definitions/Null" }, "HideXForwarded": { - "additionalProperties": false, - "properties": {}, - "type": "object" + "$ref": "#/definitions/Null" }, "ModifyRequest": { "additionalProperties": false, @@ -633,26 +674,7 @@ "type": "object" }, "OIDC": { - "additionalProperties": false, - "properties": { - "allowed_groups": { - "description": "Allowed groups", - "items": { - "type": "string" - }, - "minItems": 1, - "type": "array" - }, - "allowed_users": { - "description": "Allowed users", - "items": { - "type": "string" - }, - "minItems": 1, - "type": "array" - } - }, - "type": "object" + "$ref": "#/definitions/Nullable" }, "RateLimit": { "additionalProperties": false, @@ -706,9 +728,7 @@ "type": "object" }, "RedirectHTTP": { - "additionalProperties": false, - "properties": {}, - "type": "object" + "$ref": "#/definitions/Null" }, "Request": { "additionalProperties": false, @@ -765,9 +785,7 @@ "type": "object" }, "SetXForwarded": { - "additionalProperties": false, - "properties": {}, - "type": "object" + "$ref": "#/definitions/Null" }, "cidrWhitelist": { "additionalProperties": false, @@ -820,56 +838,28 @@ "type": "object" }, "cloudflareRealIP": { - "additionalProperties": false, - "properties": { - "recursive": { - "default": false, - "description": "Recursively resolve the IP", - "type": "boolean" - } - }, - "type": "object" + "$ref": "#/definitions/Nullable" }, "cloudflare_real_ip": { - "additionalProperties": false, - "properties": { - "recursive": { - "default": false, - "description": "Recursively resolve the IP", - "type": "boolean" - } - }, - "type": "object" + "$ref": "#/definitions/Nullable" }, "customErrorPage": { - "additionalProperties": false, - "properties": {}, - "type": "object" + "$ref": "#/definitions/Null" }, "custom_error_page": { - "additionalProperties": false, - "properties": {}, - "type": "object" + "$ref": "#/definitions/Null" }, "errorPage": { - "additionalProperties": false, - "properties": {}, - "type": "object" + "$ref": "#/definitions/Null" }, "error_page": { - "additionalProperties": false, - "properties": {}, - "type": "object" + "$ref": "#/definitions/Null" }, "hideXForwarded": { - "additionalProperties": false, - "properties": {}, - "type": "object" + "$ref": "#/definitions/Null" }, "hide_x_forwarded": { - "additionalProperties": false, - "properties": {}, - "type": "object" + "$ref": "#/definitions/Null" }, "modifyRequest": { "additionalProperties": false, @@ -980,26 +970,7 @@ "type": "object" }, "oidc": { - "additionalProperties": false, - "properties": { - "allowed_groups": { - "description": "Allowed groups", - "items": { - "type": "string" - }, - "minItems": 1, - "type": "array" - }, - "allowed_users": { - "description": "Allowed users", - "items": { - "type": "string" - }, - "minItems": 1, - "type": "array" - } - }, - "type": "object" + "$ref": "#/definitions/Nullable" }, "rateLimit": { "additionalProperties": false, @@ -1104,14 +1075,10 @@ "type": "object" }, "redirectHTTP": { - "additionalProperties": false, - "properties": {}, - "type": "object" + "$ref": "#/definitions/Null" }, "redirect_http": { - "additionalProperties": false, - "properties": {}, - "type": "object" + "$ref": "#/definitions/Null" }, "request": { "additionalProperties": false, @@ -1168,14 +1135,10 @@ "type": "object" }, "setXForwarded": { - "additionalProperties": false, - "properties": {}, - "type": "object" + "$ref": "#/definitions/Null" }, "set_x_forwarded": { - "additionalProperties": false, - "properties": {}, - "type": "object" + "$ref": "#/definitions/Null" } }, "type": "object" @@ -1256,7 +1219,7 @@ "type": "string" }, "port": { - "pattern": "^\\d+\\:\\d+$", + "pattern": "^\\d+:\\d+$", "type": "string" }, "scheme": { @@ -1266,7 +1229,8 @@ } }, "required": [ - "port" + "port", + "scheme" ], "type": "object" } diff --git a/schemas/types.ts b/schemas/types.ts index 6823f67..6a7b0db 100644 --- a/schemas/types.ts +++ b/schemas/types.ts @@ -1,3 +1,9 @@ +/** + * @type "null" + */ +export interface Null {} +export type Nullable = T | Null; + export const HTTP_METHODS = [ "GET", "POST", @@ -69,7 +75,7 @@ export type CIDR = export type Port = number; /** - * @pattern ^\d+\:\d+$ + * @pattern ^\d+:\d+$ */ export type StreamPort = string;