Skip to content

Fix example generator wrapping named number types in non-existent constructors#3440

Merged
MintsInc merged 1 commit into
masterfrom
fix/named-number-type-example-generator
Apr 24, 2026
Merged

Fix example generator wrapping named number types in non-existent constructors#3440
MintsInc merged 1 commit into
masterfrom
fix/named-number-type-example-generator

Conversation

@MintsInc
Copy link
Copy Markdown
Member

Summary

  • Named OpenAPI schemas with type: number (e.g. RumRetentionFilterSampleRate) don't generate Python classes, but the example generator was emitting broken code: a constructor call and import for a module that doesn't exist
  • Root cause: formatter.py:280 excluded {"string", "integer", "boolean"} from constructor wrapping but was missing "number", so any named type: number schema with a $ref was treated as a class type
  • Fix: add "number" to the exclusion set — consistent with the existing PRIMITIVE_TYPES constant. The or schema.get("enum") guard is preserved, so enum-typed number schemas remain unaffected
  • Regenerated both broken RUM retention filter examples (CreateRetentionFilter.py, UpdateRetentionFilter.py)
  • Added 3 test cases: regression for the fix, guard for named integers (already worked), and guard for named number enums (must still use constructor)

Affected examples (broken → fixed)

# Before (broken — module does not exist)
from datadog_api_client.v2.model.rum_retention_filter_sample_rate import RumRetentionFilterSampleRate
sample_rate=RumRetentionFilterSampleRate(50.0),

# After (correct)
sample_rate=50.0,

Test plan

  • cd .generator && poetry run pytest tests/test_formatter.py -v — all 17 tests pass
  • poetry run pytest tests/test_scenarios.py — all 3432 scenarios pass
  • find examples/ -name "*.py" | xargs python3 -m py_compile — all examples compile cleanly

🤖 Generated with Claude Code

…structors

Named OpenAPI schemas with `type: number` (e.g. RumRetentionFilterSampleRate)
don't generate Python classes, but the example generator was emitting broken
constructor calls like `RumRetentionFilterSampleRate(50.0)` and a matching
import for a module that doesn't exist.

Root cause: the primitive-type exclusion set on formatter.py:280 was missing
"number", causing any named number schema with a $ref to be treated as a class.

Fix: add "number" to the exclusion set, matching the existing PRIMITIVE_TYPES
constant. Enum-typed number schemas are unaffected (the `or schema.get("enum")`
branch still fires). Also regenerates the two broken RUM retention filter
examples.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@MintsInc MintsInc marked this pull request as ready for review April 23, 2026 11:22
@MintsInc MintsInc requested review from a team as code owners April 23, 2026 11:22
@MintsInc MintsInc merged commit a3384aa into master Apr 24, 2026
19 checks passed
@MintsInc MintsInc deleted the fix/named-number-type-example-generator branch April 24, 2026 12:16
github-actions Bot pushed a commit that referenced this pull request Apr 24, 2026
…structors (#3440)

Named OpenAPI schemas with `type: number` (e.g. RumRetentionFilterSampleRate)
don't generate Python classes, but the example generator was emitting broken
constructor calls like `RumRetentionFilterSampleRate(50.0)` and a matching
import for a module that doesn't exist.

Root cause: the primitive-type exclusion set on formatter.py:280 was missing
"number", causing any named number schema with a $ref to be treated as a class.

Fix: add "number" to the exclusion set, matching the existing PRIMITIVE_TYPES
constant. Enum-typed number schemas are unaffected (the `or schema.get("enum")`
branch still fires). Also regenerates the two broken RUM retention filter
examples.

Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> a3384aa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants