Skip to content

Commit fcbd0fd

Browse files
authored
feat(core): update custom id schema (#204)
1 parent a78ab95 commit fcbd0fd

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

apps/cli/src/linter/schema.ts

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { z } from 'zod';
22

3+
const idSchema = z
4+
.string()
5+
.min(1)
6+
.max(64)
7+
.regex(/^[a-zA-Z0-9-_.]+$/);
38
const nameSchema = z
49
.string()
510
.min(1)
@@ -178,6 +183,7 @@ const upstreamSchema = z
178183

179184
const routeSchema = z
180185
.object({
186+
id: idSchema.optional(),
181187
name: nameSchema,
182188
description: descriptionSchema.optional(),
183189
labels: labelsSchema.optional(),
@@ -213,6 +219,7 @@ const routeSchema = z
213219

214220
const streamRouteSchema = z
215221
.object({
222+
id: idSchema.optional(),
216223
name: nameSchema,
217224
description: descriptionSchema.optional(),
218225
labels: labelsSchema.optional(),
@@ -228,6 +235,7 @@ const streamRouteSchema = z
228235

229236
const serviceSchema = z
230237
.object({
238+
id: idSchema.optional(),
231239
name: nameSchema,
232240
description: descriptionSchema.optional(),
233241
labels: labelsSchema.optional(),
@@ -261,6 +269,7 @@ const serviceSchema = z
261269

262270
const sslSchema = z
263271
.object({
272+
id: idSchema.optional(),
264273
labels: labelsSchema.optional(),
265274

266275
type: z.enum(['server', 'client']).default('server').optional(),
@@ -294,6 +303,7 @@ const sslSchema = z
294303

295304
const consumerCredentialSchema = z
296305
.object({
306+
id: idSchema.optional(),
297307
name: nameSchema,
298308
description: descriptionSchema.optional(),
299309
labels: labelsSchema.optional(),
@@ -324,6 +334,7 @@ const consumerSchema = z
324334

325335
const consumerGroupSchema = z
326336
.object({
337+
id: idSchema.optional(),
327338
name: nameSchema,
328339
description: descriptionSchema.optional(),
329340
labels: labelsSchema.optional(),

apps/cli/src/linter/specs/common.spec.ts

+19
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,25 @@ describe('Common Linter', () => {
5151
},
5252
],
5353
},
54+
{
55+
name: 'should check custom resource id',
56+
input: {
57+
services: [
58+
{
59+
id: 'custom-service',
60+
name: 'test',
61+
routes: [
62+
{
63+
id: 'custom-route',
64+
name: 'test',
65+
uris: ['/test'],
66+
},
67+
],
68+
},
69+
],
70+
} as ADCSDK.Configuration,
71+
expect: true,
72+
},
5473
];
5574

5675
// test cases runner

schema.json

+21
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
"items": {
77
"type": "object",
88
"properties": {
9+
"id": {
10+
"type": "string",
11+
"minLength": 1,
12+
"maxLength": 64,
13+
"pattern": "^[a-zA-Z0-9-_.]+$"
14+
},
915
"name": {
1016
"type": "string",
1117
"minLength": 1,
@@ -397,6 +403,9 @@
397403
"items": {
398404
"type": "object",
399405
"properties": {
406+
"id": {
407+
"$ref": "#/properties/services/items/properties/id"
408+
},
400409
"name": {
401410
"$ref": "#/properties/services/items/properties/name"
402411
},
@@ -483,6 +492,9 @@
483492
"items": {
484493
"type": "object",
485494
"properties": {
495+
"id": {
496+
"$ref": "#/properties/services/items/properties/id"
497+
},
486498
"name": {
487499
"$ref": "#/properties/services/items/properties/name"
488500
},
@@ -526,6 +538,9 @@
526538
"items": {
527539
"type": "object",
528540
"properties": {
541+
"id": {
542+
"$ref": "#/properties/services/items/properties/id"
543+
},
529544
"labels": {
530545
"$ref": "#/properties/services/items/properties/labels"
531546
},
@@ -648,6 +663,9 @@
648663
"items": {
649664
"type": "object",
650665
"properties": {
666+
"id": {
667+
"$ref": "#/properties/services/items/properties/id"
668+
},
651669
"name": {
652670
"$ref": "#/properties/services/items/properties/name"
653671
},
@@ -684,6 +702,9 @@
684702
"items": {
685703
"type": "object",
686704
"properties": {
705+
"id": {
706+
"$ref": "#/properties/services/items/properties/id"
707+
},
687708
"name": {
688709
"$ref": "#/properties/services/items/properties/name"
689710
},

0 commit comments

Comments
 (0)