projectdiscovery/nuclei · warning
can't get example for array item: %+v
Error message
can't get example for array item: %+v
What it means
While generating example request bodies from an OpenAPI 3 schema, openAPIExample failed to build an example for the items schema of an array (schema.Items.Value) and wraps the underlying error. The inner error is usually ErrRecursive (an array that directly or indirectly contains itself, e.g. Node[] whose items are $ref Node) or a nested 'can't get example for ...' failure; the affected operation/parameter loses its generated example.
Source
Thrown at pkg/input/formats/openapi/examples.go:229
return ex, nil
}
example := "string"
for schema.MinLength > uint64(len(example)) {
example += example
}
if schema.MaxLength != nil && *schema.MaxLength < uint64(len(example)) {
example = example[:*schema.MaxLength]
}
return example, nil
case schema.Type.Is("array"), schema.Items != nil:
example := []interface{}{}
if schema.Items != nil && schema.Items.Value != nil {
ex, err := openAPIExample(schema.Items.Value, cache)
if err != nil {
return nil, fmt.Errorf("can't get example for array item: %+v", err)
}
example = append(example, ex)
for uint64(len(example)) < schema.MinItems {
example = append(example, ex)
}
}
return example, nil
case schema.Type.Is("object"), len(schema.Properties) > 0:
example := map[string]interface{}{}
for k, v := range schema.Properties {
if excludeFromMode(v.Value) {
continue
}
ex, err := openAPIExample(v.Value, cache)View on GitHub (pinned to 265b3a3dec)
Solutions
- Add an explicit `example` (or `default`/`enum`) to the array's items schema so generation short-circuits (getSchemaExample checks example/default/enum first)
- If the recursion is required, define the example at the array property level instead of per-item
- Loosen artificial recursion (e.g. inline one level instead of self-$ref) if you control the spec
- Ignore the failure if the affected endpoint is not in scope: only that operation's example is lost
Example fix
# before (recursive array item, no example)
Node:
type: object
required: [children]
properties:
children:
type: array
items:
$ref: '#/components/schemas/Node'
# after (explicit example short-circuits recursion)
children:
type: array
items:
$ref: '#/components/schemas/Node'
example: [] Defensive patterns
Strategy: fallback
Validate before calling
// in the spec (before scanning): give every array items schema an example
definitions:
Node:
type: object
properties:
children:
type: array
items: { $ref: '#/components/schemas/Node' }
example: [] # short-circuits recursive example generation Type guard
func itemExampleResolvable(schema *openapi3.Schema) bool {
if schema.Example != nil || schema.Default != nil || len(schema.Enum) > 0 {
return true
}
return schema.Type != nil && !isSelfReferencing(schema)
} Try / catch
if _, err := generateExampleFromSchema(schema); err != nil {
if strings.Contains(err.Error(), "can't get example for array item") {
// fall back: use an empty array or skip this operation instead of failing the run
}
} Prevention
- Add example/default/enum to recursive and untyped array item schemas
- Lint specs for self-referencing $refs before scanning
- Treat missing examples as per-endpoint degradation, not a fatal scan error
When it happens
Trigger: Recursive schemas: items: $ref: '#/components/schemas/Node' where Node itself has a children array of Node; an item schema with no recognizable type and no example/default/enum (ErrNoExample); an item whose nested object has a required property that is itself recursive.
Common situations: Specs for tree/graph APIs (categories, comments, org units) that model recursion with self-references; specs auto-generated from code where every type has a schema but few have examples; deeply nested DTOs.
Related errors
- can't get example for '%s': %+v
- can't get example for additional properties: %+v
- URL does not appear to be an OpenAPI JSON spec
- HTTP %d when downloading OpenAPI spec
- downloaded content is not valid JSON: %w
AI-assisted analysis of projectdiscovery/nuclei@265b3a3dec (2026-08-15).
Data as JSON: /api/errors/7f239aa5b2eee34f.
Report an issue: GitHub.