Skip to content

Commit

Permalink
[Jaxrs-cxf] Add bean-level cascaded beanvalidation for pojos (@Valid) f…
Browse files Browse the repository at this point in the history
…ix #4738 (#7807)

* add valid for pojos #4738

* add Valid to imports for pojos #4738

* Do not generate Valid-annotation for Date-types and UUID

* * add Valid-annotation to Containers.  #4738

Collection-valued, array-valued and generally Iterable fields and properties may also be decorated with the @Valid annotation. This causes the contents of the iterator to be validated.
Quoted from: http://beanvalidation.org/1.1/spec/

* add equivalent windows-bat-script for jaxrs-cxf-petstore-server.sh

* differences on jaxrs-cxf-generated-classes introduced by other changes (not related to this PR)
  • Loading branch information
fabian-braun authored and wing328 committed Apr 7, 2018
1 parent d2bd41d commit ce930e7
Show file tree
Hide file tree
Showing 39 changed files with 128 additions and 8 deletions.
10 changes: 10 additions & 0 deletions bin/windows/jaxrs-cxf-petstore-server.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar

If Not Exist %executable% (
mvn clean package
)

REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties
set ags=generate -t modules\swagger-codegen\src\main\resources\JavaJaxRS\cxf -i modules\swagger-codegen\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -l jaxrs-cxf -o samples\server\petstore\jaxrs-cxf -DhideGenerationTimestamp=true

java %JAVA_OPTS% -jar %executable% %ags%
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package {{package}};
{{/imports}}
{{#useBeanValidation}}
import javax.validation.constraints.*;
import javax.validation.Valid;
{{/useBeanValidation}}

{{#models}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {
{{#withXml}}
@XmlElement(name="{{baseName}}"{{#required}}, required = {{required}}{{/required}})
{{/withXml}}
@ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
@ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}"){{^isPrimitiveType}}{{^isDate}}{{^isDateTime}}{{^isString}}{{^isFile}}{{#useBeanValidation}}
@Valid{{/useBeanValidation}}{{/isFile}}{{/isString}}{{/isDateTime}}{{/isDate}}{{/isPrimitiveType}}
{{#description}}
/**
* {{{description}}}
* {{{description}}}
**/
{{/description}}
{{#isContainer}}
Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/jaxrs-cxf/.swagger-codegen/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.0-SNAPSHOT
2.4.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
public interface FakeClassnameTags123Api {

/**
* To test class name in snake case
*
* To test class name in snake case
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public interface StoreApi {
@ApiResponse(code = 200, message = "successful operation", response = Order.class),
@ApiResponse(code = 400, message = "Invalid ID supplied"),
@ApiResponse(code = 404, message = "Order not found") })
public Order getOrderById(@PathParam("order_id") @Min(1) @Max(5) Long orderId);
public Order getOrderById(@PathParam("order_id") @Min(1L) @Max(5L) Long orderId);

/**
* Place an order for a pet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;
import java.util.Map;
import javax.validation.constraints.*;
import javax.validation.Valid;

import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement;
Expand All @@ -21,6 +22,7 @@ public class AdditionalPropertiesClass {
private Map<String, String> mapProperty = null;

@ApiModelProperty(value = "")
@Valid
private Map<String, Map<String, String>> mapOfMapProperty = null;
/**
* Get mapProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import javax.validation.constraints.*;
import javax.validation.Valid;

import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.List;
import javax.validation.constraints.*;
import javax.validation.Valid;

import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.List;
import javax.validation.constraints.*;
import javax.validation.Valid;

import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement;
Expand All @@ -18,6 +19,7 @@
public class ArrayOfArrayOfNumberOnly {

@ApiModelProperty(value = "")
@Valid
private List<List<BigDecimal>> arrayArrayNumber = null;
/**
* Get arrayArrayNumber
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.List;
import javax.validation.constraints.*;
import javax.validation.Valid;

import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement;
Expand All @@ -18,6 +19,7 @@
public class ArrayOfNumberOnly {

@ApiModelProperty(value = "")
@Valid
private List<BigDecimal> arrayNumber = null;
/**
* Get arrayNumber
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.List;
import javax.validation.constraints.*;
import javax.validation.Valid;

import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement;
Expand All @@ -21,9 +22,11 @@ public class ArrayTest {
private List<String> arrayOfString = null;

@ApiModelProperty(value = "")
@Valid
private List<List<Long>> arrayArrayOfInteger = null;

@ApiModelProperty(value = "")
@Valid
private List<List<ReadOnlyFirst>> arrayArrayOfModel = null;
/**
* Get arrayOfString
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.swagger.model;

import javax.validation.constraints.*;
import javax.validation.Valid;

import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement;
Expand Down Expand Up @@ -31,7 +32,7 @@ public class Capitalization {

@ApiModelProperty(value = "Name of the pet ")
/**
* Name of the pet
* Name of the pet
**/
private String ATT_NAME = null;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.swagger.model.Animal;
import javax.validation.constraints.*;
import javax.validation.Valid;

import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.swagger.model;

import javax.validation.constraints.*;
import javax.validation.Valid;

import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.swagger.annotations.ApiModel;
import javax.validation.constraints.*;
import javax.validation.Valid;

import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.swagger.model;

import javax.validation.constraints.*;
import javax.validation.Valid;

import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.swagger.model.Animal;
import javax.validation.constraints.*;
import javax.validation.Valid;

import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;
import javax.validation.constraints.*;
import javax.validation.Valid;

import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.swagger.model;

import javax.validation.constraints.*;
import javax.validation.Valid;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.swagger.model.OuterEnum;
import javax.validation.constraints.*;
import javax.validation.Valid;

import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement;
Expand Down Expand Up @@ -52,6 +53,42 @@ public static EnumStringEnum fromValue(String v) {
private EnumStringEnum enumString = null;


@XmlType(name="EnumStringRequiredEnum")
@XmlEnum(String.class)
public enum EnumStringRequiredEnum {

@XmlEnumValue("UPPER") UPPER(String.valueOf("UPPER")), @XmlEnumValue("lower") LOWER(String.valueOf("lower")), @XmlEnumValue("") EMPTY(String.valueOf(""));


private String value;

EnumStringRequiredEnum (String v) {
value = v;
}

public String value() {
return value;
}

@Override
public String toString() {
return String.valueOf(value);
}

public static EnumStringRequiredEnum fromValue(String v) {
for (EnumStringRequiredEnum b : EnumStringRequiredEnum.values()) {
if (String.valueOf(b.value).equals(v)) {
return b;
}
}
return null;
}
}

@ApiModelProperty(required = true, value = "")
private EnumStringRequiredEnum enumStringRequired = null;


@XmlType(name="EnumIntegerEnum")
@XmlEnum(Integer.class)
public enum EnumIntegerEnum {
Expand Down Expand Up @@ -124,6 +161,7 @@ public static EnumNumberEnum fromValue(String v) {
private EnumNumberEnum enumNumber = null;

@ApiModelProperty(value = "")
@Valid
private OuterEnum outerEnum = null;
/**
* Get enumString
Expand All @@ -146,6 +184,28 @@ public EnumTest enumString(EnumStringEnum enumString) {
return this;
}

/**
* Get enumStringRequired
* @return enumStringRequired
**/
@JsonProperty("enum_string_required")
@NotNull
public String getEnumStringRequired() {
if (enumStringRequired == null) {
return null;
}
return enumStringRequired.value();
}

public void setEnumStringRequired(EnumStringRequiredEnum enumStringRequired) {
this.enumStringRequired = enumStringRequired;
}

public EnumTest enumStringRequired(EnumStringRequiredEnum enumStringRequired) {
this.enumStringRequired = enumStringRequired;
return this;
}

/**
* Get enumInteger
* @return enumInteger
Expand Down Expand Up @@ -213,6 +273,7 @@ public String toString() {
sb.append("class EnumTest {\n");

sb.append(" enumString: ").append(toIndentedString(enumString)).append("\n");
sb.append(" enumStringRequired: ").append(toIndentedString(enumStringRequired)).append("\n");
sb.append(" enumInteger: ").append(toIndentedString(enumInteger)).append("\n");
sb.append(" enumNumber: ").append(toIndentedString(enumNumber)).append("\n");
sb.append(" outerEnum: ").append(toIndentedString(outerEnum)).append("\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.UUID;
import org.joda.time.LocalDate;
import javax.validation.constraints.*;
import javax.validation.Valid;

import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement;
Expand All @@ -28,6 +29,7 @@ public class FormatTest {
private Long int64 = null;

@ApiModelProperty(required = true, value = "")
@Valid
private BigDecimal number = null;

@ApiModelProperty(value = "")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.swagger.model;

import javax.validation.constraints.*;
import javax.validation.Valid;

import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;
import java.util.Map;
import javax.validation.constraints.*;
import javax.validation.Valid;

import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement;
Expand All @@ -18,6 +19,7 @@
public class MapTest {

@ApiModelProperty(value = "")
@Valid
private Map<String, Map<String, String>> mapMapOfString = null;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Map;
import java.util.UUID;
import javax.validation.constraints.*;
import javax.validation.Valid;

import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement;
Expand All @@ -27,6 +28,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
private Date dateTime = null;

@ApiModelProperty(value = "")
@Valid
private Map<String, Animal> map = null;
/**
* Get uuid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.swagger.annotations.ApiModel;
import javax.validation.constraints.*;
import javax.validation.Valid;

import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.swagger.model;

import javax.validation.constraints.*;
import javax.validation.Valid;

import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.swagger.annotations.ApiModel;
import javax.validation.constraints.*;
import javax.validation.Valid;

import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.swagger.annotations.ApiModel;
import javax.validation.constraints.*;
import javax.validation.Valid;

import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement;
Expand Down
Loading

0 comments on commit ce930e7

Please sign in to comment.