Skip to content

Commit 57ebae9

Browse files
nogatesclaude
andauthored
Fix UnmarshalJSON required check for nullable additionalProperties containers (#3762)
When a field is a nullable `map[string]interface{}` (object with additionalProperties), the template was incorrectly emitting `.IsSet()` which only works on NullableXxx wrapper types. Use `== nil` instead for additionalProperties container fields. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 8dbdab1 commit 57ebae9

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

.generator/src/generator/templates/model_simple.j2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ func (o *{{ name }}) UnmarshalJSON(bytes []byte) (err error) {
357357
}
358358
{%- for attr, spec in model.get("properties", {}).items() if attr in model.get("required", []) %}
359359
{%- set propertyName = attr|attribute_name %}
360-
{%- if not spec.nullable %}
360+
{%- set isAdditionalPropertiesContainer = spec.type == "object" and spec.additionalProperties is defined and spec.additionalProperties is not false and not spec.get("properties") %}
361+
{%- if not spec.nullable or isAdditionalPropertiesContainer %}
361362
if all.{{ propertyName }} == nil {
362363
{%- else %}
363364
if !all.{{ propertyName }}.IsSet() {

0 commit comments

Comments
 (0)