diff --git a/package.json b/package.json index 6e76f562..cb36b75c 100644 --- a/package.json +++ b/package.json @@ -119,7 +119,7 @@ "required": false } }, - "generator": ">=1.8.27 <2.0.0", + "generator": ">=1.8.27", "filters": [ "@asyncapi/generator-filters" ], diff --git a/template/src/main/java/com/asyncapi/model/$$objectSchema$$.java b/template/src/main/java/com/asyncapi/model/$$objectSchema$$.java index d08d12c7..2b4d29c1 100644 --- a/template/src/main/java/com/asyncapi/model/$$objectSchema$$.java +++ b/template/src/main/java/com/asyncapi/model/$$objectSchema$$.java @@ -147,8 +147,13 @@ public class {{allName}} { {%- if prop.deprecated() %}@Deprecated{% endif %} {%- if prop.minLength() or prop.maxLength() or prop.maxItems() or prop.minItems() %}@Size({% if prop.minLength() or prop.minItems() %}min = {{prop.minLength()}}{{prop.minItems()}}{% endif %}{% if prop.maxLength() or prop.maxItems() %}{% if prop.minLength() or prop.minItems() %},{% endif %}max = {{prop.maxLength()}}{{prop.maxItems()}}{% endif %}){% endif %} {%- if prop.pattern() %}@Pattern(regexp="{{prop.pattern() | addBackSlashToPattern}}"){% endif %} - {%- if prop.minimum() %}@Min({{prop.minimum()}}){% endif %}{% if prop.exclusiveMinimum() %}@Min({{prop.exclusiveMinimum() + 1}}){% endif %} - {%- if prop.maximum() %}@Max({{prop.maximum()}}){% endif %}{% if prop.exclusiveMaximum() %}@Max({{prop.exclusiveMaximum() + 1}}){% endif %} + {%- if prop.type() == 'number' and (prop.format() == 'float' or prop.format() == 'double') %} + {%- if prop.minimum() %}@DecimalMin(value = "{{prop.minimum()}}", inclusive = true){% endif %}{%- if prop.exclusiveMinimum() %}@DecimalMin(value = "{{prop.exclusiveMinimum()}}", inclusive = false){% endif %} + {%- if prop.maximum() %}@DecimalMax(value = "{{prop.maximum()}}", inclusive = true){% endif %}{%- if prop.exclusiveMaximum() %}@DecimalMax(value = "{{prop.exclusiveMaximum()}}", inclusive = false){% endif %} + {%- else %} + {%- if prop.minimum() %}@Min({{prop.minimum()}}){% endif %}{% if prop.exclusiveMinimum() %}@Min({{prop.exclusiveMinimum() + 1}}){% endif %} + {%- if prop.maximum() %}@Max({{prop.maximum()}}){% endif %}{% if prop.exclusiveMaximum() %}@Max({{prop.exclusiveMaximum() + 1}}){% endif %} + {%- endif %} public {{propType}} get{{className}}() { return {{varName}}; } @@ -202,4 +207,4 @@ private String toIndentedString(Object o) { } return o.toString().replace("\n", "\n "); } -} \ No newline at end of file +} diff --git a/tests/__snapshots__/additional-formats.test.js.snap b/tests/__snapshots__/additional-formats.test.js.snap index 261fd77e..ab1e7476 100644 --- a/tests/__snapshots__/additional-formats.test.js.snap +++ b/tests/__snapshots__/additional-formats.test.js.snap @@ -32,6 +32,10 @@ public class SongPayload { private @Valid Integer stars; + private @Valid Float length; + + private @Valid Double playtime; + @@ -113,6 +117,32 @@ public class SongPayload { this.stars = stars; } + + /** + * Length of the song in minutes + */ + @JsonProperty("length")@DecimalMin(value = "0.5", inclusive = true)@DecimalMax(value = "10.5", inclusive = true) + public Float getLength() { + return length; + } + + public void setLength(Float length) { + this.length = length; + } + + + /** + * Playtime of the song in minutes + */ + @JsonProperty("playtime")@DecimalMin(value = "1.5", inclusive = false)@DecimalMax(value = "11.5", inclusive = false) + public Double getPlaytime() { + return playtime; + } + + public void setPlaytime(Double playtime) { + this.playtime = playtime; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -128,12 +158,14 @@ public class SongPayload { Objects.equals(this.uri, songPayload.uri) && Objects.equals(this.email, songPayload.email) && Objects.equals(this.rating, songPayload.rating) && - Objects.equals(this.stars, songPayload.stars); + Objects.equals(this.stars, songPayload.stars) && + Objects.equals(this.length, songPayload.length) && + Objects.equals(this.playtime, songPayload.playtime); } @Override public int hashCode() { - return Objects.hash(id, title, uri, email, rating, stars); + return Objects.hash(id, title, uri, email, rating, stars, length, playtime); } @Override @@ -146,6 +178,8 @@ public class SongPayload { " email: " + toIndentedString(email) + "\\n" + " rating: " + toIndentedString(rating) + "\\n" + " stars: " + toIndentedString(stars) + "\\n" + + " length: " + toIndentedString(length) + "\\n" + + " playtime: " + toIndentedString(playtime) + "\\n" + "}"; } diff --git a/tests/mocks/additional-type-formats.yml b/tests/mocks/additional-type-formats.yml index 13ae8d82..9fe3f9d3 100644 --- a/tests/mocks/additional-type-formats.yml +++ b/tests/mocks/additional-type-formats.yml @@ -45,4 +45,16 @@ components: stars: description: "Number of stars. Deprecated: Use rating" type: integer - deprecated: true \ No newline at end of file + deprecated: true + length: + description: Length of the song in minutes + type: number + format: float + minimum: 0.5 + maximum: 10.5 + playtime: + description: Playtime of the song in minutes + type: number + format: double + exclusiveMinimum: 1.5 + exclusiveMaximum: 11.5 \ No newline at end of file