diff --git a/packages/worma/src/core/loader/astLoader/parsers/array.ts b/packages/worma/src/core/loader/astLoader/parsers/array.ts index 211e5837..e47c2707 100644 --- a/packages/worma/src/core/loader/astLoader/parsers/array.ts +++ b/packages/worma/src/core/loader/astLoader/parsers/array.ts @@ -1,12 +1,12 @@ import type { ASTParser, ParserCtx } from './type' import type { ArraySchemaObject, TArray } from '@/type' -import { CommentHelper } from '@/helper' +import { CommentHelper } from '@/helper' import { ASTType } from '@/type' import { initAST } from './utils' export function arrayTypeParser(schema: ArraySchemaObject, ctx: ParserCtx) { ctx.pathKey = '[]' - const itemsAst = ctx.next(schema.items, ctx.options) + const itemsAst = ctx.next(schema.items ?? {}, ctx.options) const result: TArray = { ...initAST(schema, ctx), type: ASTType.ARRAY, diff --git a/packages/worma/test/parsers/array.spec.ts b/packages/worma/test/parsers/array.spec.ts index d8d8420b..6db10a24 100644 --- a/packages/worma/test/parsers/array.spec.ts +++ b/packages/worma/test/parsers/array.spec.ts @@ -274,5 +274,26 @@ describe('array Type Parser', () => { expect(result.deepComment).toContain('[items] start') expect(result.deepComment).toContain('[items] end') }) + + it('should handle array without items', () => { + const schema = { + type: 'array', + description: 'Array without items', + } as ArraySchemaObject + + const mockItemAST: AST = { + type: ASTType.ANY, + keyName: '', + } + + const ctx = createMockCtx('itemlessArray') + ctx.next = vi.fn().mockReturnValue(mockItemAST) + + const result = arrayTypeParser(schema, ctx) + + expect(result.type).toBe(ASTType.ARRAY) + expect(result.params).toBe(mockItemAST) + expect(ctx.next).toHaveBeenCalledWith({}, ctx.options) + }) }) })