Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/worma/src/core/loader/astLoader/parsers/array.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
21 changes: 21 additions & 0 deletions packages/worma/test/parsers/array.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
})
Loading