Support keeping typed fields in AdditionalProperties via x-keep-typed-in-additional-properties#4224
Open
charlie-zhang109 wants to merge 2 commits into
Open
Support keeping typed fields in AdditionalProperties via x-keep-typed-in-additional-properties#4224charlie-zhang109 wants to merge 2 commits into
charlie-zhang109 wants to merge 2 commits into
Conversation
…-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>
This was referenced Jun 8, 2026
…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>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds a
x-keep-typed-in-additional-propertiesflag tomodel_simple.j2. When set on a schema, the generatedUnmarshalJSONskips theDeleteKeyscall that normally strips typed property keys out of theAdditionalPropertiesmap. TheMarshalJSONpath is updated symmetrically to skip typed keys in theAdditionalPropertiesrange 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 fromAdditionalPropertiesregardless of when it was added to the spec. Typed getters continue to work unchanged — this is additive only.The first consumer is the
UsageSummaryfamily (UsageSummaryDate,UsageSummaryDateOrg,UsageSummaryResponse), which receive the annotation in the companion spec PR: DataDog/datadog-api-spec#5941.Behavioral note:
len(AdditionalProperties) == 0sentinelBefore this change,
len(o.AdditionalProperties) == 0could be used to test whether an API response contained any unknown/extra fields. After this change,AdditionalPropertiesis 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.
Or, this PR relies on API schema changes and this is a Draft PR to include tests for that new functionality.