Skip to content

Commit

Permalink
Ensures a JsonCreator annotated constructor is present if there are r…
Browse files Browse the repository at this point in the history
…equired fields, and ensure the getters and setters are properly annotated with required=true / required=false for jaxrs-spec generator. (#19578)
  • Loading branch information
kevinferrare authored Nov 24, 2024
1 parent 6399a7a commit 5ae8c03
Show file tree
Hide file tree
Showing 146 changed files with 1,150 additions and 221 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#vendorExtens
{{/vendorExtensions.x-field-extra-annotation}}
private {{#isContainer}}{{#useBeanValidation}}@Valid {{/useBeanValidation}}{{/isContainer}}{{{datatypeWithEnum}}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};
{{/vars}}

{{#generateBuilders}}
{{^additionalProperties}}

protected {{classname}}({{classname}}Builder<?, ?> b) {
{{#parent}}
super(b);
Expand All @@ -46,11 +46,33 @@ public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#vendorExtens
{{/vars}}
}

public {{classname}}() {
}
{{/additionalProperties}}
{{/generateBuilders}}
public {{classname}}() {
}

{{#hasRequired}}
@JsonCreator
public {{classname}}(
{{#requiredVars}}
@JsonProperty(required = {{required}}, value = "{{baseName}}") {{>beanValidatedType}} {{name}}{{^-last}},{{/-last}}
{{/requiredVars}}
) {
{{#parent}}
super(
{{#parentRequiredVars}}
{{name}}{{^-last}},{{/-last}}
{{/parentRequiredVars}}
);
{{/parent}}
{{#vars}}
{{#required}}
this.{{name}} = {{name}};
{{/required}}
{{/vars}}
}

{{/hasRequired}}
{{#vars}}
/**
{{#description}}
Expand All @@ -71,12 +93,12 @@ public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#vendorExtens
{{#vendorExtensions.x-extra-annotation}}{{{vendorExtensions.x-extra-annotation}}}{{/vendorExtensions.x-extra-annotation}}{{#useSwaggerAnnotations}}
@ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}"){{/useSwaggerAnnotations}}{{#useMicroProfileOpenAPIAnnotations}}
@org.eclipse.microprofile.openapi.annotations.media.Schema({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}description = "{{{description}}}"){{/useMicroProfileOpenAPIAnnotations}}
@JsonProperty("{{baseName}}")
@JsonProperty({{#required}}required = {{required}}, value = {{/required}}"{{baseName}}")
{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}}public {{>beanValidatedType}} {{getter}}() {
return {{name}};
}

@JsonProperty("{{baseName}}")
@JsonProperty({{#required}}required = {{required}}, value = {{/required}}"{{baseName}}")
{{#vendorExtensions.x-setter-extra-annotation}}{{{vendorExtensions.x-setter-extra-annotation}}}
{{/vendorExtensions.x-setter-extra-annotation}}public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
this.{{name}} = {{name}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
public class AdditionalPropertiesAnyType extends HashMap<String, Object> implements Serializable {
private String name;

public AdditionalPropertiesAnyType() {
}

/**
**/
public AdditionalPropertiesAnyType name(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
public class AdditionalPropertiesArray extends HashMap<String, List> implements Serializable {
private String name;

public AdditionalPropertiesArray() {
}

/**
**/
public AdditionalPropertiesArray name(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
public class AdditionalPropertiesBoolean extends HashMap<String, Boolean> implements Serializable {
private String name;

public AdditionalPropertiesBoolean() {
}

/**
**/
public AdditionalPropertiesBoolean name(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public class AdditionalPropertiesClass implements Serializable {
private Object anytype2;
private Object anytype3;

public AdditionalPropertiesClass() {
}

/**
**/
public AdditionalPropertiesClass mapString(Map<String, String> mapString) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
public class AdditionalPropertiesInteger extends HashMap<String, Integer> implements Serializable {
private String name;

public AdditionalPropertiesInteger() {
}

/**
**/
public AdditionalPropertiesInteger name(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
public class AdditionalPropertiesNumber extends HashMap<String, BigDecimal> implements Serializable {
private String name;

public AdditionalPropertiesNumber() {
}

/**
**/
public AdditionalPropertiesNumber name(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
public class AdditionalPropertiesObject extends HashMap<String, Map> implements Serializable {
private String name;

public AdditionalPropertiesObject() {
}

/**
**/
public AdditionalPropertiesObject name(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
public class AdditionalPropertiesString extends HashMap<String, String> implements Serializable {
private String name;

public AdditionalPropertiesString() {
}

/**
**/
public AdditionalPropertiesString name(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ public class Animal implements Serializable {
private String className;
private String color = "red";

public Animal() {
}

@JsonCreator
public Animal(
@JsonProperty(required = true, value = "className") String className
) {
this.className = className;
}

/**
**/
public Animal className(String className) {
Expand All @@ -39,12 +49,12 @@ public Animal className(String className) {


@ApiModelProperty(required = true, value = "")
@JsonProperty("className")
@JsonProperty(required = true, value = "className")
@NotNull public String getClassName() {
return className;
}

@JsonProperty("className")
@JsonProperty(required = true, value = "className")
public void setClassName(String className) {
this.className = className;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
public class ArrayOfArrayOfNumberOnly implements Serializable {
private @Valid List<List<BigDecimal>> arrayArrayNumber = new ArrayList<>();

public ArrayOfArrayOfNumberOnly() {
}

/**
**/
public ArrayOfArrayOfNumberOnly arrayArrayNumber(List<List<BigDecimal>> arrayArrayNumber) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
public class ArrayOfNumberOnly implements Serializable {
private @Valid List<BigDecimal> arrayNumber = new ArrayList<>();

public ArrayOfNumberOnly() {
}

/**
**/
public ArrayOfNumberOnly arrayNumber(List<BigDecimal> arrayNumber) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class ArrayTest implements Serializable {
private @Valid List<List<Long>> arrayArrayOfInteger = new ArrayList<>();
private @Valid List<List<@Valid ReadOnlyFirst>> arrayArrayOfModel = new ArrayList<>();

public ArrayTest() {
}

/**
**/
public ArrayTest arrayOfString(List<String> arrayOfString) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ public static KindEnum fromValue(String value) {

private KindEnum kind;

public BigCat() {
}

@JsonCreator
public BigCat(
@JsonProperty(required = true, value = "className") String className
) {
super(
className
);
}

/**
**/
public BigCat kind(KindEnum kind) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class Capitalization implements Serializable {
private String scAETHFlowPoints;
private String ATT_NAME;

public Capitalization() {
}

/**
**/
public Capitalization smallCamel(String smallCamel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@
public class Cat extends Animal implements Serializable {
private Boolean declawed;

public Cat() {
}

@JsonCreator
public Cat(
@JsonProperty(required = true, value = "className") String className
) {
super(
className
);
}

/**
**/
public Cat declawed(Boolean declawed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ public class Category implements Serializable {
private Long id;
private String name = "default-name";

public Category() {
}

@JsonCreator
public Category(
@JsonProperty(required = true, value = "name") String name
) {
this.name = name;
}

/**
**/
public Category id(Long id) {
Expand Down Expand Up @@ -49,12 +59,12 @@ public Category name(String name) {


@ApiModelProperty(required = true, value = "")
@JsonProperty("name")
@JsonProperty(required = true, value = "name")
@NotNull public String getName() {
return name;
}

@JsonProperty("name")
@JsonProperty(required = true, value = "name")
public void setName(String name) {
this.name = name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
public class ClassModel implements Serializable {
private String propertyClass;

public ClassModel() {
}

/**
**/
public ClassModel propertyClass(String propertyClass) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
public class Client implements Serializable {
private String client;

public Client() {
}

/**
**/
public Client client(String client) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@
public class Dog extends Animal implements Serializable {
private String breed;

public Dog() {
}

@JsonCreator
public Dog(
@JsonProperty(required = true, value = "className") String className
) {
super(
className
);
}

/**
**/
public Dog breed(String breed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ public static ArrayEnumEnum fromValue(String value) {

private @Valid List<ArrayEnumEnum> arrayEnum = new ArrayList<>();

public EnumArrays() {
}

/**
**/
public EnumArrays justSymbol(JustSymbolEnum justSymbol) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,16 @@ public static EnumNumberEnum fromValue(Double value) {
private EnumNumberEnum enumNumber;
private OuterEnum outerEnum;

public EnumTest() {
}

@JsonCreator
public EnumTest(
@JsonProperty(required = true, value = "enum_string_required") EnumStringRequiredEnum enumStringRequired
) {
this.enumStringRequired = enumStringRequired;
}

/**
**/
public EnumTest enumString(EnumStringEnum enumString) {
Expand Down Expand Up @@ -242,12 +252,12 @@ public EnumTest enumStringRequired(EnumStringRequiredEnum enumStringRequired) {


@ApiModelProperty(required = true, value = "")
@JsonProperty("enum_string_required")
@JsonProperty(required = true, value = "enum_string_required")
@NotNull public EnumStringRequiredEnum getEnumStringRequired() {
return enumStringRequired;
}

@JsonProperty("enum_string_required")
@JsonProperty(required = true, value = "enum_string_required")
public void setEnumStringRequired(EnumStringRequiredEnum enumStringRequired) {
this.enumStringRequired = enumStringRequired;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class FileSchemaTestClass implements Serializable {
private ModelFile _file;
private @Valid List<@Valid ModelFile> files = new ArrayList<>();

public FileSchemaTestClass() {
}

/**
**/
public FileSchemaTestClass _file(ModelFile _file) {
Expand Down
Loading

0 comments on commit 5ae8c03

Please sign in to comment.