projectdiscovery/nuclei · warning

can't get example for '%s': %+v

Error message

can't get example for '%s': %+v

What it means

During object example generation, the property named in the message returned ErrRecursive (the property's schema contains itself) AND that property is listed in the object's `required` array. Required properties cannot be skipped, so generation of the whole object example fails with the property name and the recursive-schema error.

Source

Thrown at pkg/input/formats/openapi/examples.go:250

			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)
			if err == ErrRecursive {
				if isRequired(schema, k) {
					return nil, fmt.Errorf("can't get example for '%s': %+v", k, err)
				}
			} else if err != nil {
				return nil, fmt.Errorf("can't get example for '%s': %+v", k, err)
			} else {
				example[k] = ex
			}
		}

		if schema.AdditionalProperties.Has != nil && schema.AdditionalProperties.Schema != nil {
			addl := schema.AdditionalProperties.Schema.Value

			if !excludeFromMode(addl) {
				ex, err := openAPIExample(addl, cache)
				if err == ErrRecursive {
					// We just won't add this if it's recursive.
				} else if err != nil {
					return nil, fmt.Errorf("can't get example for additional properties: %+v", err)
				} else {

View on GitHub (pinned to 265b3a3dec)

Solutions

  1. Add an `example` to that required property's schema so the recursion check is never hit
  2. If the property is not truly mandatory, remove it from the schema's required list (optional recursive properties are skipped gracefully)
  3. Restructure the recursion: inline the first level or move the self-reference behind a non-required wrapper
  4. Accept the gap: the operation relying on that body will not get a generated request

Example fix

# before (required self-reference)
Comment:
  type: object
  required: [body, replies]
  properties:
    body: { type: string }
    replies:
      type: array
      items: { $ref: '#/components/schemas/Comment' }

# after (optional recursion is skipped cleanly)
  required: [body]
  properties:
    body: { type: string }
    replies:
      type: array
      items: { $ref: '#/components/schemas/Comment' }
      example: []
Defensive patterns

Strategy: validation

Validate before calling

// spec lint: required properties must not be directly self-referencing without an example
for name, prop := range schema.Properties {
    if isRequired(schema, name) && isSelfRef(prop.Value, schemaName) && prop.Value.Example == nil {
        return fmt.Errorf("required property %s is recursive without an example", name)
    }
}

Try / catch

if _, err := generateExampleFromSchema(schema); err != nil {
    if strings.Contains(err.Error(), "can't get example for '") && strings.Contains(err.Error(), "Recursive") {
        // required self-reference: add an example in the spec or drop it from required
    }
}

Prevention

When it happens

Trigger: Tree-style schemas like Category { required: [parent], parent: $ref Category }; linked-list node schemas where next is required and self-referencing; comment threads with required children arrays referencing the same schema.

Common situations: Specs generated from ORM/domain models where back-references are mandatory; API tooling that marks every property required by default; graph APIs.

Related errors


AI-assisted analysis of projectdiscovery/nuclei@265b3a3dec (2026-08-15). Data as JSON: /api/errors/a867a62b7cd5910a. Report an issue: GitHub.