Skip to content

Commit

Permalink
Adjusted Min/Max Values in the Schema to be BigDecimal instead of Int…
Browse files Browse the repository at this point in the history
…eger for Draft-07 Compliance solving issue asyncapi#99 and asyncapi#97
  • Loading branch information
Ivan Julius Alayan committed May 7, 2022
1 parent 8e2cbb0 commit 75b6099
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import lombok.NoArgsConstructor;

import javax.annotation.CheckForNull;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -261,31 +262,31 @@ Validation Keywords for Numeric Instances (number and integer)
* If the instance is a number, then this keyword validates only if the instance is less than or exactly equal to "maximum".
*/
@CheckForNull
public Integer maximum;
public BigDecimal maximum;

/**
* The value of "exclusiveMaximum" MUST be number, representing an exclusive upper limit for a numeric instance.
* <br>
* If the instance is a number, then the instance is valid only if it has a value strictly less than (not equal to) "exclusiveMaximum".
*/
@CheckForNull
public Integer exclusiveMaximum;
public BigDecimal exclusiveMaximum;

/**
* The value of "minimum" MUST be a number, representing an inclusive lower limit for a numeric instance.
* <br>
* If the instance is a number, then this keyword validates only if the instance is greater than or exactly equal to "minimum".
*/
@CheckForNull
public Integer minimum;
public BigDecimal minimum;

/**
* The value of "exclusiveMinimum" MUST be number, representing an exclusive lower limit for a numeric instance.
* <br>
* If the instance is a number, then the instance is valid only if it has a value strictly greater than (not equal to) "exclusiveMinimum".
*/
@CheckForNull
public Integer exclusiveMinimum;
public BigDecimal exclusiveMinimum;

/*
Validation Keywords for Strings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import java.math.BigDecimal

/**
* @author Pavel Bodiachevskii
Expand Down Expand Up @@ -98,8 +99,8 @@ class ComponentsTest {
.type(Type.OBJECT)
.properties(mapOf(Pair("my-app-header", Schema.builder()
.type(Type.INTEGER)
.minimum(0)
.maximum(100)
.minimum(BigDecimal.ZERO)
.maximum(BigDecimal.valueOf(100))
.build()))
)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -160,14 +161,14 @@ private Map<String, Object> getSchemas() {
Map<String, Schema> lampInfoPayloadProperties = new HashMap<>();
lampInfoPayloadProperties.put("lumens", Schema.builder()
.type(Type.INTEGER)
.minimum(0)
.minimum(BigDecimal.ZERO)
.description("Lamp intensity measured in lumens.")
.build()
);
lampInfoPayloadProperties.put("watts", Schema.builder()
.type(Type.INTEGER)
.minimum(0)
.maximum(100)
.minimum( BigDecimal.ZERO )
.maximum( BigDecimal.valueOf( 100 ) )
.description("Lamp watt consumption.")
.build()
);
Expand Down Expand Up @@ -214,8 +215,8 @@ private Map<String, MessageTrait> getMessageTraits() {
Map<String, Schema> commonHeadersProperties = new HashMap<>();
commonHeadersProperties.put("my-app-header", Schema.builder()
.type(Type.INTEGER)
.minimum(0)
.maximum(100)
.minimum(BigDecimal.ONE)
.maximum(BigDecimal.valueOf( 100 ))
.build()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -210,7 +211,7 @@ private Map<String, Object> getSchemas() {
Map<String, Schema> lightMeasuredPayloadProperties = new HashMap<>();
lightMeasuredPayloadProperties.put("lumens", Schema.builder()
.type(Type.INTEGER)
.minimum(0)
.minimum(BigDecimal.ZERO)
.description("Light intensity measured in lumens.")
.build()
);
Expand Down Expand Up @@ -248,8 +249,8 @@ private Map<String, Object> getSchemas() {
Map<String, Schema> dimLightPayloadProperties = new HashMap<>();
dimLightPayloadProperties.put("command", Schema.builder()
.type(Type.INTEGER)
.minimum(0)
.maximum(100)
.minimum( BigDecimal.ONE )
.maximum(BigDecimal.valueOf( 100 ))
.build()
);
dimLightPayloadProperties.put("sentAt", Schema.builder()
Expand Down Expand Up @@ -360,8 +361,8 @@ private Map<String, MessageTrait> getMessageTraits() {
Map<String, Schema> commonHeadersProperties = new HashMap<>();
commonHeadersProperties.put("my-app-header", Schema.builder()
.type(Type.INTEGER)
.minimum(0)
.maximum(100)
.minimum(BigDecimal.ZERO)
.maximum(BigDecimal.valueOf( 100 ))
.build()
);

Expand Down

0 comments on commit 75b6099

Please sign in to comment.