Skip to content

Commit

Permalink
#270 Fix Custom Validators (#275)
Browse files Browse the repository at this point in the history
* #270 Fix Custom Validators

* #270 Fix Custom Validators
  • Loading branch information
jemacineiras committed Aug 22, 2023
1 parent 370ac0c commit f30f692
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 10 deletions.
2 changes: 1 addition & 1 deletion multiapi-engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.sngular</groupId>
<artifactId>multiapi-engine</artifactId>
<version>4.9.7</version>
<version>4.9.8</version>
<packaging>jar</packaging>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ public class MaxValidator implements ConstraintValidator<Max, BigDecimal> {
public class MaxValidator implements ConstraintValidator<Max, Integer> {

private int maximum;
<#break>
<#elseif field.dataType.baseType?has_content && (field.dataType.baseType == "Float" || field.dataType.baseType == "float")>
public class MaxValidator implements ConstraintValidator<Max, Float> {

private float maximum;
<#break>
<#elseif field.dataType.baseType?has_content && (field.dataType.baseType == "Double" || field.dataType.baseType == "double")>
public class MaxValidator implements ConstraintValidator<Max, Double> {

private double maximum;
<#break>
</#if>
</#list>
private boolean exclusive;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ public class MaxValidator implements ConstraintValidator<Max, BigDecimal> {
public class MaxValidator implements ConstraintValidator<Max, Integer> {

private int maximum;
<#break>
<#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Float" || field.dataTypeSimple == "float")>
public class MaxValidator implements ConstraintValidator<Max, Float> {

private float maximum;
<#break>
<#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Double" || field.dataTypeSimple == "double")>
public class MaxValidator implements ConstraintValidator<Max, Double> {

private double maximum;
<#break>
</#if>
</#list>
private boolean exclusive;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ public class MinValidator implements ConstraintValidator<Min, BigDecimal> {
public class MinValidator implements ConstraintValidator<Min, Integer> {

private int minimum;
<#break>
<#elseif field.dataType.baseType?has_content && (field.dataType.baseType == "Float" || field.dataType.baseType == "float")>
public class MinValidator implements ConstraintValidator<Min, Float> {

private float minimum;
<#break>
<#elseif field.dataType.baseType?has_content && (field.dataType.baseType == "Double" || field.dataType.baseType == "double")>
public class MinValidator implements ConstraintValidator<Min, Double> {

private double minimum;
<#break>
</#if>
</#list>
private boolean exclusive;
Expand All @@ -47,6 +50,7 @@ public class MinValidator implements ConstraintValidator<Min, Double> {
<#break>
<#elseif field.dataType.baseType?has_content && (field.dataType.baseType == "Double" || field.dataType.baseType == "double")>
this.minimum = Double.parseDouble(constraintAnnotation.minimum());
<#break>
</#if>
</#list>
this.exclusive = constraintAnnotation.exclusive();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ public class MinValidator implements ConstraintValidator<Min, BigDecimal> {
public class MinValidator implements ConstraintValidator<Min, Integer> {

private int minimum;
<#break>
<#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Float" || field.dataTypeSimple == "float")>
public class MinValidator implements ConstraintValidator<Min, Float> {

private float minimum;
<#break>
<#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Double" || field.dataTypeSimple == "double")>
public class MinValidator implements ConstraintValidator<Min, Double> {

private double minimum;
<#break>
</#if>
</#list>
private boolean exclusive;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ public class MultipleOfValidator implements ConstraintValidator<MultipleOf, BigD
public class MultipleOfValidator implements ConstraintValidator<MultipleOf, Integer> {

private int multiple;
<#break>
<#elseif field.dataType.baseType?has_content && (field.dataType.baseType == "Float" || field.dataType.baseType == "float")>
public class MultipleOfValidator implements ConstraintValidator<MultipleOf, Float> {

private float multiple;
<#break>
<#elseif field.dataType.baseType?has_content && (field.dataType.baseType == "Double" || field.dataType.baseType == "double")>
public class MultipleOfValidator implements ConstraintValidator<MultipleOf, Double> {

private double multiple;
<#break>
</#if>
</#list>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ public class MultipleOfValidator implements ConstraintValidator<MultipleOf, BigD
public class MultipleOfValidator implements ConstraintValidator<MultipleOf, Integer> {

private int multiple;
<#break>
<#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Float" || field.dataTypeSimple == "float")>
public class MultipleOfValidator implements ConstraintValidator<MultipleOf, Float> {

private float multiple;
<#break>
<#elseif field.dataTypeSimple?has_content && (field.dataTypeSimple == "Double" || field.dataTypeSimple == "double")>
public class MultipleOfValidator implements ConstraintValidator<MultipleOf, Double> {

private double multiple;
<#break>
</#if>
</#list>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.CleanupMode;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
Expand All @@ -26,7 +27,7 @@
@Slf4j
class OpenApiGeneratorTest {

@TempDir
@TempDir(cleanup = CleanupMode.NEVER)
static Path baseDir;

private static OpenApiGenerator openApiGenerator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ components:
maximum: 200
exclusiveMaximum: true
multipleOf: 10.55
intCode:
type: integer
message:
type: string
minLength: 50
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
@Data
public class ApiErrorDTO {

@JsonProperty(value ="intCode")
private Integer intCode;

@JsonProperty(value ="code")
@Min(minimum = "10", exclusive = false)
@Max(maximum = "200", exclusive = true)
Expand All @@ -41,7 +44,8 @@ public class ApiErrorDTO {

@Builder
@Jacksonized
private ApiErrorDTO(@NonNull Integer code, @NonNull String message, List<Integer> test) {
private ApiErrorDTO(Integer intCode, @NonNull Integer code, @NonNull String message, List<Integer> test) {
this.intCode = intCode;
this.code = code;
this.message = message;
this.test = test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
@JsonDeserialize(builder = ApiErrorDTO.ApiErrorDTOBuilder.class)
public class ApiErrorDTO {

@JsonProperty(value ="intCode")
private Integer intCode;
@JsonProperty(value ="code")
@Min(minimum = "10", exclusive = false)
@Max(maximum = "200", exclusive = true)
Expand All @@ -39,7 +41,8 @@ public class ApiErrorDTO {
@UniqueItems
private List<Integer> test = new ArrayList<Integer>();

private ApiErrorDTO(Integer code, String message, List<Integer> test) {
private ApiErrorDTO(Integer intCode, Integer code, String message, List<Integer> test) {
this.intCode = intCode;
this.code = code;
this.message = message;
this.test = test;
Expand All @@ -48,6 +51,7 @@ private ApiErrorDTO(Integer code, String message, List<Integer> test) {
}

private ApiErrorDTO(ApiErrorDTOBuilder builder) {
this.intCode = builder.intCode;
this.code = builder.code;
this.message = builder.message;
this.test = builder.test;
Expand All @@ -62,10 +66,16 @@ public static ApiErrorDTO.ApiErrorDTOBuilder builder() {
@JsonPOJOBuilder(buildMethodName = "build", withPrefix = "")
public static class ApiErrorDTOBuilder {

private Integer intCode;
private Integer code;
private String message;
private List<Integer> test = new ArrayList<Integer>();

public ApiErrorDTO.ApiErrorDTOBuilder intCode(Integer intCode) {
this.intCode = intCode;
return this;
}

public ApiErrorDTO.ApiErrorDTOBuilder code(Integer code) {
this.code = code;
return this;
Expand Down Expand Up @@ -95,6 +105,14 @@ public ApiErrorDTO build() {
}
}

@Schema(name = "intCode", required = false)
public Integer getIntCode() {
return intCode;
}
public void setIntCode(Integer intCode) {
this.intCode = intCode;
}

@Schema(name = "code", required = true)
public Integer getCode() {
return code;
Expand Down Expand Up @@ -122,18 +140,19 @@ public boolean equals(Object o) {
return false;
}
ApiErrorDTO apiErrorDTO = (ApiErrorDTO) o;
return Objects.equals(this.code, apiErrorDTO.code) && Objects.equals(this.message, apiErrorDTO.message) && Objects.equals(this.test, apiErrorDTO.test);
return Objects.equals(this.intCode, apiErrorDTO.intCode) && Objects.equals(this.code, apiErrorDTO.code) && Objects.equals(this.message, apiErrorDTO.message) && Objects.equals(this.test, apiErrorDTO.test);
}

@Override
public int hashCode() {
return Objects.hash(code, message, test);
return Objects.hash(intCode, code, message, test);
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("ApiErrorDTO{");
sb.append(" intCode:").append(intCode).append(",");
sb.append(" code:").append(code).append(",");
sb.append(" message:").append(message).append(",");
sb.append(" test:").append(test);
Expand Down
4 changes: 2 additions & 2 deletions scs-multiapi-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repositories {
}

group = 'com.sngular'
version = '4.9.7'
version = '4.9.8'

def SCSMultiApiPluginGroupId = group
def SCSMultiApiPluginVersion = version
Expand All @@ -30,7 +30,7 @@ dependencies {
shadow localGroovy()
shadow gradleApi()

implementation 'com.sngular:multiapi-engine:4.9.7'
implementation 'com.sngular:multiapi-engine:4.9.8'
testImplementation 'org.assertj:assertj-core:3.23.1'
testImplementation 'com.puppycrawl.tools:checkstyle:10.3.1'
}
Expand Down
4 changes: 2 additions & 2 deletions scs-multiapi-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.sngular</groupId>
<artifactId>scs-multiapi-maven-plugin</artifactId>
<version>4.9.7</version>
<version>4.9.8</version>
<packaging>maven-plugin</packaging>

<name>AsyncApi - OpenApi Code Generator Maven Plugin</name>
Expand Down Expand Up @@ -233,7 +233,7 @@
<dependency>
<groupId>com.sngular</groupId>
<artifactId>multiapi-engine</artifactId>
<version>4.9.7</version>
<version>4.9.8</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
Expand Down

0 comments on commit f30f692

Please sign in to comment.