Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add Java contraints annotations at the field level #1067

Merged
merged 4 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
4 changes: 2 additions & 2 deletions src/generators/java/presets/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './CommonPreset';
export * from './DescriptionPreset';
export * from './JacksonPreset';
export * from './ConstraintsPreset';
export * from './JavaJacksonPreset';
export * from './JavaConstraintsPreset';
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