Skip to content

Commit

Permalink
fix: add Java contraints annotations at the field level (#1067)
Browse files Browse the repository at this point in the history
Co-authored-by: Artur Ciocanu <ciocanu@adobe.com>
  • Loading branch information
artur-ciocanu and Artur Ciocanu authored Dec 21, 2022
1 parent 13edf11 commit cc1890a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
exports[`Should be able to generate models with javax.validation.constraints annotations and should log expected output to console 1`] = `
Array [
"public class JavaxAnnotation {
@NotNull
@Min(0)
private Double minNumberProp;
@NotNull
@Max(99)
private Double maxNumberProp;
@Size(min=2, max=3)
private Object[] arrayProp;
@Pattern(regexp=\\"^I_\\")
@Size(min=3)
private String stringProp;
private Map<String, Object> additionalProperties;
@NotNull
@Min(0)
public Double getMinNumberProp() { return this.minNumberProp; }
public void setMinNumberProp(Double minNumberProp) { this.minNumberProp = minNumberProp; }
@NotNull
@Max(99)
public Double getMaxNumberProp() { return this.maxNumberProp; }
public void setMaxNumberProp(Double maxNumberProp) { this.maxNumberProp = maxNumberProp; }
@Size(min=2, max=3)
public Object[] getArrayProp() { return this.arrayProp; }
public void setArrayProp(Object[] arrayProp) { this.arrayProp = arrayProp; }
@Pattern(regexp=\\"^I_\\")
@Size(min=3)
public String getStringProp() { return this.stringProp; }
public void setStringProp(String stringProp) { this.stringProp = stringProp; }
Expand Down
2 changes: 1 addition & 1 deletion src/generators/java/presets/ConstraintsPreset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const JAVA_CONSTRAINTS_PRESET: JavaPreset = {
return content;
},
// eslint-disable-next-line sonarjs/cognitive-complexity
getter({ renderer, property, content }) {
property({ renderer, property, content }) {
const annotations: string[] = [];

if (property.required) {
Expand Down
2 changes: 1 addition & 1 deletion test/generators/java/presets/ConstraintsPreset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('JAVA_CONSTRAINTS_PRESET', () => {
generator = new JavaGenerator({ presets: [JAVA_CONSTRAINTS_PRESET] });
});

test('should render constaints annotations', async () => {
test('should render constraints annotations', async () => {
const doc = {
$id: 'Clazz',
type: 'object',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`JAVA_CONSTRAINTS_PRESET should render constaints annotations 1`] = `
exports[`JAVA_CONSTRAINTS_PRESET should render constraints annotations 1`] = `
"public class Clazz {
@NotNull
@Min(0)
private Double minNumberProp;
@NotNull
@Max(99)
private Double maxNumberProp;
@Size(min=2, max=3)
private Object[] arrayProp;
@Pattern(regexp=\\"^I_\\")
@Size(min=3)
private String stringProp;
private Map<String, Object> additionalProperties;
@NotNull
@Min(0)
public Double getMinNumberProp() { return this.minNumberProp; }
public void setMinNumberProp(Double minNumberProp) { this.minNumberProp = minNumberProp; }
@NotNull
@Max(99)
public Double getMaxNumberProp() { return this.maxNumberProp; }
public void setMaxNumberProp(Double maxNumberProp) { this.maxNumberProp = maxNumberProp; }
@Size(min=2, max=3)
public Object[] getArrayProp() { return this.arrayProp; }
public void setArrayProp(Object[] arrayProp) { this.arrayProp = arrayProp; }
@Pattern(regexp=\\"^I_\\")
@Size(min=3)
public String getStringProp() { return this.stringProp; }
public void setStringProp(String stringProp) { this.stringProp = stringProp; }
Expand Down

0 comments on commit cc1890a

Please sign in to comment.