From 7e893c3e7cf7bc90fff4d2ca8e0067b158dd4490 Mon Sep 17 00:00:00 2001 From: Charlie Zhang Date: Mon, 8 Jun 2026 09:47:29 -0400 Subject: [PATCH 1/2] Support x-keep-typed-in-additional-properties in Java model generator When a schema sets `x-keep-typed-in-additional-properties: true`, each typed property setter also calls putAdditionalProperty so all fields are accessible via getAdditionalProperties() alongside untyped fields. Co-Authored-By: Claude Sonnet 4.6 --- .generator/src/generator/templates/modelSimple.j2 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.generator/src/generator/templates/modelSimple.j2 b/.generator/src/generator/templates/modelSimple.j2 index 7d8a556535e..becccff46dd 100644 --- a/.generator/src/generator/templates/modelSimple.j2 +++ b/.generator/src/generator/templates/modelSimple.j2 @@ -258,6 +258,9 @@ public class {{ name }} {%- if model.get("x-generate-alias-as-model") %} extends {%- else %} this.{{ variableName }} = {{ variableName }}; {%- endif %} + {%- if model.get("x-keep-typed-in-additional-properties") %} + putAdditionalProperty(JSON_PROPERTY_{{ attr|snake_case|upper }}, {%- if not isRequired and isNullable %} this.{{ variableName }}.orElse(null){%- else %} {{ variableName }}{%- endif %}); + {%- endif %} } {%- endif %} {%- endfor %} From f30eacb461b3fab80f0b66aaafca76461ec41b33 Mon Sep 17 00:00:00 2001 From: Charlie Zhang Date: Mon, 8 Jun 2026 10:11:05 -0400 Subject: [PATCH 2/2] fix: guard putAdditionalProperty in setter against models without additionalProperties Generating the putAdditionalProperty call when additionalProperties is false would cause a compile error because putAdditionalProperty is only generated for models that have an additionalProperties schema. Co-Authored-By: Claude Sonnet 4.6 --- .generator/src/generator/templates/modelSimple.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.generator/src/generator/templates/modelSimple.j2 b/.generator/src/generator/templates/modelSimple.j2 index becccff46dd..60e2acc14ce 100644 --- a/.generator/src/generator/templates/modelSimple.j2 +++ b/.generator/src/generator/templates/modelSimple.j2 @@ -258,7 +258,7 @@ public class {{ name }} {%- if model.get("x-generate-alias-as-model") %} extends {%- else %} this.{{ variableName }} = {{ variableName }}; {%- endif %} - {%- if model.get("x-keep-typed-in-additional-properties") %} + {%- if model.get("x-keep-typed-in-additional-properties") and model.additionalProperties is not false %} putAdditionalProperty(JSON_PROPERTY_{{ attr|snake_case|upper }}, {%- if not isRequired and isNullable %} this.{{ variableName }}.orElse(null){%- else %} {{ variableName }}{%- endif %}); {%- endif %} }