Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/generate optionals for dtos 3176 #3214

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{^useOptional}}{{>nullableDataType}}{{/useOptional}}{{#useOptional}}{{>optionalDataTypeGetter}}{{/useOptional}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{^useOptional}}{{>nullableDataType}}{{/useOptional}}{{#useOptional}}{{>optionalPojoDataType}}{{/useOptional}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{^useOptional}}{{>nullableDefaultValue}}{{/useOptional}}{{#useOptional}}{{>optionalDefaultValue}}{{/useOptional}}
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@
<version>2.6.4</version>
</dependency>
{{/threetenbp}}
{{^useOptional}}
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
<version>0.1.0</version>
</dependency>
{{/useOptional}}
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package {{package}};
import java.util.Objects;
{{#imports}}import {{import}};
{{/imports}}
{{^useOptional}}
import org.openapitools.jackson.nullable.JsonNullable;
{{/useOptional}}
{{#serializableModel}}
import java.io.Serializable;
{{/serializableModel}}
Expand All @@ -14,6 +16,9 @@ import javax.validation.constraints.*;
{{#performBeanValidation}}
import org.hibernate.validator.constraints.*;
{{/performBeanValidation}}
{{#useOptional}}
import java.util.Optional;
{{/useOptional}}
{{#jackson}}
{{#withXml}}
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{#isNullable}} = JsonNullable.undefined(){{/isNullable}}{{^isNullable}}{{#defaultValue}} = {{{.}}}{{/defaultValue}}{{/isNullable}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{^isContainer}}{{^isPrimitiveType}}@Valid {{/isPrimitiveType}}{{/isContainer}}{{>beanValidationCore}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{#isContainer}}{{{datatypeWithEnum}}}{{/isContainer}}{{^isContainer}}{{#required}}{{{dataType}}}{{/required}}{{^required}}{{#useBeanValidation}}Optional<{{>optionalBeanValidation}}{{{dataType}}}>{{/useBeanValidation}}{{^useBeanValidation}}Optional<{{{dataType}}}>{{/useBeanValidation}}{{/required}}{{/isContainer}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{^isContainer}}{{^required}} = Optional.empty(){{/required}}{{/isContainer}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{#isContainer}}{{{datatypeWithEnum}}}{{/isContainer}}{{^isContainer}}{{>optionalDataType}}{{/isContainer}}
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}}{{^parent}}
{{/gson}}
{{#isContainer}}
{{#useBeanValidation}}@Valid{{/useBeanValidation}}
private {{>nullableDataType}} {{name}} = {{#isNullable}}JsonNullable.undefined(){{/isNullable}}{{^isNullable}}{{#required}}{{{defaultValue}}}{{/required}}{{^required}}null{{/required}}{{/isNullable}};
private {{>dataTypePojo}} {{name}} = {{#isNullable}}JsonNullable.undefined(){{/isNullable}}{{^isNullable}}{{#required}}{{{defaultValue}}}{{/required}}{{^required}}null{{/required}}{{/isNullable}};
{{/isContainer}}
{{^isContainer}}
private {{>nullableDataType}} {{name}}{{#isNullable}} = JsonNullable.undefined(){{/isNullable}}{{^isNullable}}{{#defaultValue}} = {{{.}}}{{/defaultValue}}{{/isNullable}};
private {{>dataTypePojo}} {{name}}{{>defaultValuePojo}};
{{/isContainer}}

{{/vars}}
{{#vars}}
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
public {{classname}} {{name}}({{>dataTypePojo}} {{name}}) {
this.{{name}} = {{#isNullable}}JsonNullable.of({{name}}){{/isNullable}}{{^isNullable}}{{name}}{{/isNullable}};
return this;
}
Expand Down Expand Up @@ -84,11 +84,11 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}}{{^parent}}
{{{vendorExtensions.extraAnnotation}}}
{{/vendorExtensions.extraAnnotation}}
@ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}")
{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} public {{>nullableDataType}} {{getter}}() {
{{#useBeanValidation}}{{#useOptional}}{{#required}}{{>beanValidation}}{{/required}}{{/useOptional}}{{/useBeanValidation}}{{#useBeanValidation}}{{^useOptional}}{{>beanValidation}}{{/useOptional}}{{/useBeanValidation}} public {{>dataTypeGetter}} {{getter}}() {
return {{name}};
}

public void {{setter}}({{>nullableDataType}} {{name}}) {
public void {{setter}}({{>dataTypePojo}} {{name}}) {
this.{{name}} = {{name}};
}

Expand Down