Skip to content

Commit

Permalink
feat(core): update custom id schema (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
bzp2010 authored Nov 11, 2024
1 parent a78ab95 commit fcbd0fd
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
11 changes: 11 additions & 0 deletions apps/cli/src/linter/schema.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -178,6 +183,7 @@ const upstreamSchema = z

const routeSchema = z
.object({
id: idSchema.optional(),
name: nameSchema,
description: descriptionSchema.optional(),
labels: labelsSchema.optional(),
Expand Down Expand Up @@ -213,6 +219,7 @@ const routeSchema = z

const streamRouteSchema = z
.object({
id: idSchema.optional(),
name: nameSchema,
description: descriptionSchema.optional(),
labels: labelsSchema.optional(),
Expand All @@ -228,6 +235,7 @@ const streamRouteSchema = z

const serviceSchema = z
.object({
id: idSchema.optional(),
name: nameSchema,
description: descriptionSchema.optional(),
labels: labelsSchema.optional(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -294,6 +303,7 @@ const sslSchema = z

const consumerCredentialSchema = z
.object({
id: idSchema.optional(),
name: nameSchema,
description: descriptionSchema.optional(),
labels: labelsSchema.optional(),
Expand Down Expand Up @@ -324,6 +334,7 @@ const consumerSchema = z

const consumerGroupSchema = z
.object({
id: idSchema.optional(),
name: nameSchema,
description: descriptionSchema.optional(),
labels: labelsSchema.optional(),
Expand Down
19 changes: 19 additions & 0 deletions apps/cli/src/linter/specs/common.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -397,6 +403,9 @@
"items": {
"type": "object",
"properties": {
"id": {
"$ref": "#/properties/services/items/properties/id"
},
"name": {
"$ref": "#/properties/services/items/properties/name"
},
Expand Down Expand Up @@ -483,6 +492,9 @@
"items": {
"type": "object",
"properties": {
"id": {
"$ref": "#/properties/services/items/properties/id"
},
"name": {
"$ref": "#/properties/services/items/properties/name"
},
Expand Down Expand Up @@ -526,6 +538,9 @@
"items": {
"type": "object",
"properties": {
"id": {
"$ref": "#/properties/services/items/properties/id"
},
"labels": {
"$ref": "#/properties/services/items/properties/labels"
},
Expand Down Expand Up @@ -648,6 +663,9 @@
"items": {
"type": "object",
"properties": {
"id": {
"$ref": "#/properties/services/items/properties/id"
},
"name": {
"$ref": "#/properties/services/items/properties/name"
},
Expand Down Expand Up @@ -684,6 +702,9 @@
"items": {
"type": "object",
"properties": {
"id": {
"$ref": "#/properties/services/items/properties/id"
},
"name": {
"$ref": "#/properties/services/items/properties/name"
},
Expand Down

0 comments on commit fcbd0fd

Please sign in to comment.