Skip to content

Commit

Permalink
Improve array item check
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-balitskyi committed Sep 26, 2024
1 parent 9dc2687 commit b0fa535
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/lib/code-sample/go.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,14 @@ const formatGoValue = ({

const formattedItems = value.map((v) => formatGoValue({ value: v, key }))
const item = value[0]
const arrayType = item
? isPrimitiveValue(item)
? getPrimitiveTypeName(item)
: `api.${pascalCase(key)}`
: ''
if (item == null) {
throw new Error(`Null value in response array for '${key}'`)
}

const arrayType = isPrimitiveValue(item)
? getPrimitiveTypeName(item)
: `api.${pascalCase(key)}`

return `[${value.length}]${arrayType}{${formattedItems.join(', ')}}`
}

Expand Down

0 comments on commit b0fa535

Please sign in to comment.