From 17222be9d8e408a512fb7e2d61d9bd8ee16e2988 Mon Sep 17 00:00:00 2001 From: bzp2010 Date: Mon, 11 Nov 2024 10:45:32 +0800 Subject: [PATCH 1/2] feat(core): update custom id schema --- apps/cli/src/linter/schema.ts | 11 +++++++++++ schema.json | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/apps/cli/src/linter/schema.ts b/apps/cli/src/linter/schema.ts index da484a3..1ddd63a 100644 --- a/apps/cli/src/linter/schema.ts +++ b/apps/cli/src/linter/schema.ts @@ -1,5 +1,10 @@ import { z } from 'zod'; +const idSchema = z + .string() + .min(1) + .max(64) + .regex(/^[a-zA-Z0-9-_.]+$/); const nameSchema = z .string() .min(1) @@ -178,6 +183,7 @@ const upstreamSchema = z const routeSchema = z .object({ + id: idSchema.optional(), name: nameSchema, description: descriptionSchema.optional(), labels: labelsSchema.optional(), @@ -213,6 +219,7 @@ const routeSchema = z const streamRouteSchema = z .object({ + id: idSchema.optional(), name: nameSchema, description: descriptionSchema.optional(), labels: labelsSchema.optional(), @@ -228,6 +235,7 @@ const streamRouteSchema = z const serviceSchema = z .object({ + id: idSchema.optional(), name: nameSchema, description: descriptionSchema.optional(), labels: labelsSchema.optional(), @@ -261,6 +269,7 @@ const serviceSchema = z const sslSchema = z .object({ + id: idSchema.optional(), labels: labelsSchema.optional(), type: z.enum(['server', 'client']).default('server').optional(), @@ -294,6 +303,7 @@ const sslSchema = z const consumerCredentialSchema = z .object({ + id: idSchema.optional(), name: nameSchema, description: descriptionSchema.optional(), labels: labelsSchema.optional(), @@ -324,6 +334,7 @@ const consumerSchema = z const consumerGroupSchema = z .object({ + id: idSchema.optional(), name: nameSchema, description: descriptionSchema.optional(), labels: labelsSchema.optional(), diff --git a/schema.json b/schema.json index efed54a..8619cab 100644 --- a/schema.json +++ b/schema.json @@ -6,6 +6,12 @@ "items": { "type": "object", "properties": { + "id": { + "type": "string", + "minLength": 1, + "maxLength": 64, + "pattern": "^[a-zA-Z0-9-_.]+$" + }, "name": { "type": "string", "minLength": 1, @@ -397,6 +403,9 @@ "items": { "type": "object", "properties": { + "id": { + "$ref": "#/properties/services/items/properties/id" + }, "name": { "$ref": "#/properties/services/items/properties/name" }, @@ -483,6 +492,9 @@ "items": { "type": "object", "properties": { + "id": { + "$ref": "#/properties/services/items/properties/id" + }, "name": { "$ref": "#/properties/services/items/properties/name" }, @@ -526,6 +538,9 @@ "items": { "type": "object", "properties": { + "id": { + "$ref": "#/properties/services/items/properties/id" + }, "labels": { "$ref": "#/properties/services/items/properties/labels" }, @@ -648,6 +663,9 @@ "items": { "type": "object", "properties": { + "id": { + "$ref": "#/properties/services/items/properties/id" + }, "name": { "$ref": "#/properties/services/items/properties/name" }, @@ -684,6 +702,9 @@ "items": { "type": "object", "properties": { + "id": { + "$ref": "#/properties/services/items/properties/id" + }, "name": { "$ref": "#/properties/services/items/properties/name" }, From 075e8e3a542e699777483ef56315b14c5f3fcd1a Mon Sep 17 00:00:00 2001 From: bzp2010 Date: Mon, 11 Nov 2024 10:49:04 +0800 Subject: [PATCH 2/2] test --- apps/cli/src/linter/specs/common.spec.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/apps/cli/src/linter/specs/common.spec.ts b/apps/cli/src/linter/specs/common.spec.ts index c3fcdd1..3570dbe 100644 --- a/apps/cli/src/linter/specs/common.spec.ts +++ b/apps/cli/src/linter/specs/common.spec.ts @@ -51,6 +51,25 @@ describe('Common Linter', () => { }, ], }, + { + name: 'should check custom resource id', + input: { + services: [ + { + id: 'custom-service', + name: 'test', + routes: [ + { + id: 'custom-route', + name: 'test', + uris: ['/test'], + }, + ], + }, + ], + } as ADCSDK.Configuration, + expect: true, + }, ]; // test cases runner