Skip to content

Support keeping typed fields in AdditionalProperties via x-keep-typed-in-additional-properties#4224

Open
charlie-zhang109 wants to merge 2 commits into
masterfrom
czhang/typed-fields-in-additional-properties
Open

Support keeping typed fields in AdditionalProperties via x-keep-typed-in-additional-properties#4224
charlie-zhang109 wants to merge 2 commits into
masterfrom
czhang/typed-fields-in-additional-properties

Conversation

@charlie-zhang109

@charlie-zhang109 charlie-zhang109 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds a x-keep-typed-in-additional-properties flag to model_simple.j2. When set on a schema, the generated UnmarshalJSON skips the DeleteKeys call that normally strips typed property keys out of the AdditionalProperties map. The MarshalJSON path is updated symmetrically to skip typed keys in the AdditionalProperties range loop, so the formatted typed-field path always wins.

This enables a single unified access pattern for SDK users: instead of needing to know whether a field has a typed getter or must be read from AdditionalProperties, every field on the annotated model is accessible from AdditionalProperties regardless of when it was added to the spec. Typed getters continue to work unchanged — this is additive only.

The first consumer is the UsageSummary family (UsageSummaryDate, UsageSummaryDateOrg, UsageSummaryResponse), which receive the annotation in the companion spec PR: DataDog/datadog-api-spec#5941.

Behavioral note: len(AdditionalProperties) == 0 sentinel

Before this change, len(o.AdditionalProperties) == 0 could be used to test whether an API response contained any unknown/extra fields. After this change, AdditionalProperties is guaranteed non-empty for any non-trivial response on annotated models, because all typed field values are retained in the map. Callers relying on the zero-length sentinel to detect "no unknown fields" should switch to checking for unexpected keys explicitly.

Additional Notes

This is a Draft PR pending the spec change. Once DataDog/datadog-api-spec#5941 merges and triggers regeneration, the generated model files will reflect the new behavior.

Review checklist

Please check relevant items below:

  • This PR includes all newly recorded cassettes for any modified tests.

  • This PR does not rely on API client schema changes.

    • The CI should be fully passing.
  • Or, this PR relies on API schema changes and this is a Draft PR to include tests for that new functionality.

    • Note: CI shouldn't be run on this Draft PR, as its expected to fail without the corresponding schema changes.

…-in-additional-properties

When a schema sets `x-keep-typed-in-additional-properties: true`, skip the
DeleteKeys call so typed property keys are also present in AdditionalProperties,
giving callers a single unified entry point for all fields.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
charlie-zhang109

This comment was marked as resolved.

…ed-in-additional-properties

When the flag is set, AdditionalProperties already contains typed keys from
deserialization. Skip those keys in the MarshalJSON range loop so typed fields
are serialized only through their own formatted path (e.g. time.Time date-time).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@charlie-zhang109 charlie-zhang109 marked this pull request as ready for review June 8, 2026 15:23
@charlie-zhang109 charlie-zhang109 requested review from a team as code owners June 8, 2026 15:23
@datadog-datadog-prod-us1

Copy link
Copy Markdown

Pipelines

Fix all issues with BitsAI

⚠️ Warnings

🚦 1 Pipeline job failed

Ensure labels | changelog   View in Datadog   GitHub Actions

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 546852a | Docs | Datadog PR Page | Give us feedback!

@charlie-zhang109 charlie-zhang109 added the changelog/Added Added features results into a minor version bump label Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/Added Added features results into a minor version bump

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant