From 6d593c887ca88c4ff78d4f3d0f6901583c189676 Mon Sep 17 00:00:00 2001 From: Semen Date: Mon, 2 Oct 2023 13:40:38 +0300 Subject: [PATCH] feat: use BigDecimal for decimal format (#324) * add BigDecimal support * update snapshot --- filters/all.js | 2 ++ .../additional-formats.test.js.snap | 21 +++++++++++++++++-- tests/mocks/additional-type-formats.yml | 6 +++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/filters/all.js b/filters/all.js index b92d701e9..90462a960 100644 --- a/filters/all.js +++ b/filters/all.js @@ -93,6 +93,8 @@ function toJavaType(str, isRequired) { case 'number': case 'double': resultType = 'double'; break; + case 'decimal': + resultType = 'java.math.BigDecimal'; break; case 'binary': resultType = 'byte[]'; break; default: diff --git a/tests/__snapshots__/additional-formats.test.js.snap b/tests/__snapshots__/additional-formats.test.js.snap index 9b28d637a..d2bb1854c 100644 --- a/tests/__snapshots__/additional-formats.test.js.snap +++ b/tests/__snapshots__/additional-formats.test.js.snap @@ -27,6 +27,8 @@ public class SongPayload { private @Valid String email; + private @Valid java.math.BigDecimal rating; + @@ -81,6 +83,19 @@ public class SongPayload { this.email = email; } + + /** + * Title rating + */ + @JsonProperty("rating") + public java.math.BigDecimal getRating() { + return rating; + } + + public void setRating(java.math.BigDecimal rating) { + this.rating = rating; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -94,12 +109,13 @@ public class SongPayload { Objects.equals(this.id, songPayload.id) && Objects.equals(this.title, songPayload.title) && Objects.equals(this.uri, songPayload.uri) && - Objects.equals(this.email, songPayload.email); + Objects.equals(this.email, songPayload.email) && + Objects.equals(this.rating, songPayload.rating); } @Override public int hashCode() { - return Objects.hash(id, title, uri, email); + return Objects.hash(id, title, uri, email, rating); } @Override @@ -110,6 +126,7 @@ public class SongPayload { " title: " + toIndentedString(title) + "\\n" + " uri: " + toIndentedString(uri) + "\\n" + " email: " + toIndentedString(email) + "\\n" + + " rating: " + toIndentedString(rating) + "\\n" + "}"; } diff --git a/tests/mocks/additional-type-formats.yml b/tests/mocks/additional-type-formats.yml index 91e29f37b..1d4c572a9 100644 --- a/tests/mocks/additional-type-formats.yml +++ b/tests/mocks/additional-type-formats.yml @@ -37,4 +37,8 @@ components: email: description: Author email type: string - format: email \ No newline at end of file + format: email + rating: + description: Title rating + type: string + format: decimal \ No newline at end of file