Skip to content
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"required": false
}
},
"generator": ">=1.8.27 <2.0.0",
"generator": ">=1.8.27",
"filters": [
"@asyncapi/generator-filters"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}};
}
Expand Down Expand Up @@ -202,4 +207,4 @@ private String toIndentedString(Object o) {
}
return o.toString().replace("\n", "\n ");
}
}
}
38 changes: 36 additions & 2 deletions tests/__snapshots__/additional-formats.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public class SongPayload {

private @Valid Integer stars;

private @Valid Float length;

private @Valid Double playtime;




Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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" +
"}";
}

Expand Down
14 changes: 13 additions & 1 deletion tests/mocks/additional-type-formats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,16 @@ components:
stars:
description: "Number of stars. Deprecated: Use rating"
type: integer
deprecated: true
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