From 467ae8c13d8a219251c5f835bddeb541705d7a79 Mon Sep 17 00:00:00 2001 From: Kinplemelon Date: Wed, 15 May 2024 16:25:27 +0800 Subject: [PATCH 1/2] test(script): sort enum array for try to fix ci error --- scripts/transformer/filterTagsSchema.js | 81 ++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 9 deletions(-) diff --git a/scripts/transformer/filterTagsSchema.js b/scripts/transformer/filterTagsSchema.js index 75a42c07d..eebdfbdb1 100644 --- a/scripts/transformer/filterTagsSchema.js +++ b/scripts/transformer/filterTagsSchema.js @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/no-var-requires */ -const { isObject, get } = require('lodash') +const { isObject, get, set } = require('lodash') const paramRefReg = /^#\/components\/parameters\// const schemaRefReg = /^#\/components\/schemas\// @@ -21,14 +21,28 @@ const removeAllDesc = (swaggerJSON) => { return swaggerJSON } -const getTargetRequestArr = (swaggerJSON, tags) => { +const filterUselessRequest = (swaggerJSON, tag) => { + const ret = swaggerJSON + const { paths } = swaggerJSON + Object.entries(paths).forEach(([path, methodRequestMap]) => { + Object.entries(methodRequestMap).forEach(([method, request]) => { + if (!request.tags.includes(tag)) { + Reflect.deleteProperty(methodRequestMap, method) + } + }) + if (Object.keys(methodRequestMap).length === 0) { + Reflect.deleteProperty(paths, path) + } + }) + return ret +} + +const getTargetRequestArr = (swaggerJSON) => { const { paths } = swaggerJSON const targetRequestArr = [] Object.entries(paths).forEach(([, methods]) => { Object.entries(methods).forEach(([, request]) => { - if (request.tags.includes(tags)) { - targetRequestArr.push(request) - } + targetRequestArr.push(request) }) }) return targetRequestArr @@ -136,15 +150,64 @@ const keepTargetSchema = (swaggerJSON, refs) => { return swaggerJSON } -const filterTargetSchema = (swaggerJSON, tags) => { - const targetRequestArr = getTargetRequestArr(swaggerJSON, tags) +const handleActionJSON = (swaggerJSON) => { + const path = [ + 'paths', + '/action_types', + 'get', + 'responses', + '200', + 'content', + 'application/json', + 'schema', + 'items', + 'enum', + ] + const enums = get(swaggerJSON, path) + if (enums) { + set(swaggerJSON, path, enums.sort()) + } + return swaggerJSON +} + +const handleSourceJSON = (swaggerJSON) => { + const path = [ + 'paths', + '/source_types', + 'get', + 'responses', + '200', + 'content', + 'application/json', + 'schema', + 'items', + 'enum', + ] + const enums = get(swaggerJSON, path) + if (enums) { + set(swaggerJSON, path, enums.sort()) + } + return swaggerJSON +} +const specialHandlers = new Map([ + ['Actions', handleActionJSON], + ['Sources', handleSourceJSON], +]) + +const filterTargetSchema = (swaggerJSON, tag) => { + const filteredUselessPathsJSON = filterUselessRequest(swaggerJSON, tag) + const targetRequestArr = getTargetRequestArr(filteredUselessPathsJSON, tag) const paramRefs = getParamRefsInRequestArr(targetRequestArr) const firstLevelRefs = getSchemaRefsInRequestArr(targetRequestArr) - const schemaRefs = getAllRefsByRefArr(swaggerJSON, firstLevelRefs) + const schemaRefs = getAllRefsByRefArr(filteredUselessPathsJSON, firstLevelRefs) - const ret = keepTargetParam(keepTargetSchema(swaggerJSON, schemaRefs), paramRefs) + let ret = keepTargetParam(keepTargetSchema(filteredUselessPathsJSON, schemaRefs), paramRefs) + const specialHandler = specialHandlers.get(tag) + if (specialHandler) { + ret = specialHandler(ret) + } return removeAllDesc(ret) } From d1278ec86c9f546460e8a22512be2c19cbacdd34 Mon Sep 17 00:00:00 2001 From: Kinplemelon Date: Wed, 15 May 2024 16:34:36 +0800 Subject: [PATCH 2/2] test(schemas): update schemas --- src/types/schemas/clients.schemas.ts | 2 + src/types/schemas/rules.schemas.ts | 60 +++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/types/schemas/clients.schemas.ts b/src/types/schemas/clients.schemas.ts index 4fae9706b..e46e39a30 100644 --- a/src/types/schemas/clients.schemas.ts +++ b/src/types/schemas/clients.schemas.ts @@ -352,6 +352,7 @@ export const EmqxMgmtApiClientsRequestedClientFieldsParameterOneOfItem = { inflight_max: 'inflight_max', ip_address: 'ip_address', is_bridge: 'is_bridge', + is_expired: 'is_expired', keepalive: 'keepalive', mailbox_len: 'mailbox_len', mqueue_dropped: 'mqueue_dropped', @@ -502,6 +503,7 @@ export interface EmqxMgmtApiClientsClient { inflight_max?: number ip_address?: string is_bridge?: boolean + is_expired?: boolean keepalive?: number mailbox_len?: number mqueue_dropped?: number diff --git a/src/types/schemas/rules.schemas.ts b/src/types/schemas/rules.schemas.ts index b1deca7b1..2d433b4ff 100644 --- a/src/types/schemas/rules.schemas.ts +++ b/src/types/schemas/rules.schemas.ts @@ -101,6 +101,45 @@ export type GetRules200 = { meta?: PublicMeta } +export type PostRulesIdTest412Code = + typeof PostRulesIdTest412Code[keyof typeof PostRulesIdTest412Code] + +// eslint-disable-next-line @typescript-eslint/no-redeclare +export const PostRulesIdTest412Code = { + NOT_MATCH: 'NOT_MATCH', +} as const + +export type PostRulesIdTest412 = { + code?: PostRulesIdTest412Code + message?: string +} + +export type PostRulesIdTest404Code = + typeof PostRulesIdTest404Code[keyof typeof PostRulesIdTest404Code] + +// eslint-disable-next-line @typescript-eslint/no-redeclare +export const PostRulesIdTest404Code = { + RULE_NOT_FOUND: 'RULE_NOT_FOUND', +} as const + +export type PostRulesIdTest404 = { + code?: PostRulesIdTest404Code + message?: string +} + +export type PostRulesIdTest400Code = + typeof PostRulesIdTest400Code[keyof typeof PostRulesIdTest400Code] + +// eslint-disable-next-line @typescript-eslint/no-redeclare +export const PostRulesIdTest400Code = { + BAD_REQUEST: 'BAD_REQUEST', +} as const + +export type PostRulesIdTest400 = { + code?: PostRulesIdTest400Code + message?: string +} + export type PostRuleTest412Code = typeof PostRuleTest412Code[keyof typeof PostRuleTest412Code] // eslint-disable-next-line @typescript-eslint/no-redeclare @@ -210,7 +249,7 @@ export const RuleEngineRuleEventsEvent = { '$events/message_delivered': '$events/message_delivered', '$events/message_acked': '$events/message_acked', '$events/message_dropped': '$events/message_dropped', - '$events/message_validation_failed': '$events/message_validation_failed', + '$events/schema_validation_failed': '$events/schema_validation_failed', '$events/delivery_dropped': '$events/delivery_dropped', } as const @@ -245,6 +284,11 @@ export interface RuleEngineRuleCreation { metadata?: RuleEngineRuleCreationMetadata } +export interface RuleEngineRuleApplyTest { + context?: RuleEngineRuleApplyTestContext + stop_action_after_template_rendering?: boolean +} + export interface RuleEngineRepublishMqttProperties { 'Payload-Format-Indicator'?: string 'Message-Expiry-Interval'?: string @@ -441,6 +485,20 @@ export interface RuleEngineCtxDelivered { qos?: number } +export type RuleEngineRuleApplyTestContext = + | RuleEngineCtxDeliveryDropped + | RuleEngineCtxBridgeMqtt + | RuleEngineCtxCheckAuthzComplete + | RuleEngineCtxConnack + | RuleEngineCtxDisconnected + | RuleEngineCtxConnected + | RuleEngineCtxDropped + | RuleEngineCtxAcked + | RuleEngineCtxDelivered + | RuleEngineCtxUnsub + | RuleEngineCtxSub + | RuleEngineCtxPub + export type RuleEngineCtxConnectedEventType = typeof RuleEngineCtxConnectedEventType[keyof typeof RuleEngineCtxConnectedEventType]