Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .generator/src/generator/templates/modelSimple.j2
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ public class {{ name }} {%- if model.get("x-generate-alias-as-model") %} extends
{%- set isRequired = attr in model.get("required", []) %}
{%- set isNullable = schema.nullable %}
{%- set defaultValue = schema.get("default", None) %}
{%- set isAdditionalPropertiesContainer = schema.properties is not defined and schema.additionalProperties is defined and schema.additionalProperties is not false %}
public static final String JSON_PROPERTY_{{ attr|snake_case|upper }} = "{{ attr }}";

{%- if not isRequired and isNullable %}
{%- if "items" in schema or (schema.additionalProperties is defined and schema.additionalProperties is not false) or (schema.type is not defined and "oneOf" not in schema) %}
{%- if "items" in schema or (isAdditionalPropertiesContainer) or (schema.type is not defined and "oneOf" not in schema) %}
private JsonNullable<{{ dataType }}> {{ variableName }} = JsonNullable.<{{ dataType }}>undefined();
{%- else %}
private JsonNullable<{{ dataType }}> {{ variableName }} = JsonNullable.<{{ dataType }}>{%- if defaultValue != None %}of({{ defaultValue|format_value(schema=schema, default_value=True, type_=dataType) }}){%- else %}undefined(){%- endif%};
{%- endif %}
{%- else %}
{%- if "items" in schema %}
private {{ dataType }} {{ variableName }}{%- if isRequired %} = new ArrayList<>(){%- else %} = null{%- endif %};
{%- elif (schema.additionalProperties is defined and schema.additionalProperties is not false) or (not schema.get("type") and "oneOf" not in schema) %}
{%- elif (isAdditionalPropertiesContainer) or (not schema.get("type") and "oneOf" not in schema) %}
private {{ dataType }} {{ variableName }}{%- if isRequired %} = new {{ dataType }}(){%- else %} = null{%- endif %};
{%- else %}
private {{ dataType }} {{ variableName }}{%- if defaultValue != None %} = {{ defaultValue|format_value(schema=schema, default_value=True, type_=dataType) }}{%- endif %};
Expand Down Expand Up @@ -87,6 +88,7 @@ public class {{ name }} {%- if model.get("x-generate-alias-as-model") %} extends
{%- set isArray = "items" in schema %}
{%- set isRequired = attr in model.get("required", []) %}
{%- set defaultValue = schema.get("default", None) %}
{%- set isAdditionalPropertiesContainer = schema.properties is not defined and schema.additionalProperties is defined and schema.additionalProperties is not false %}

{%- if not schema.get("readOnly", False) %}
public {{ name }} {{ variableName }}({{ dataType }} {{ variableName }}) {
Expand Down Expand Up @@ -158,7 +160,7 @@ public class {{ name }} {%- if model.get("x-generate-alias-as-model") %} extends
}
{%- endif %}

{%- if schema.additionalProperties is defined and schema.additionalProperties is not false %}
{%- if isAdditionalPropertiesContainer %}
public {{ name }} put{{ variableName|upperfirst }}Item(String key, {{ get_type(schema.additionalProperties) }} {{ variableName }}Item) {
{%- if not isRequired and isNullable %}
if (this.{{ variableName }} == null || !this.{{ variableName }}.isPresent()) {
Expand Down