From 5136ff41349fcc3a24c5f747829e7c5274ff5fdc Mon Sep 17 00:00:00 2001 From: Artur Ciocanu Date: Tue, 20 Dec 2022 11:04:53 +0200 Subject: [PATCH 1/4] fix: add Java contraints annotations at the field level --- ...traintsPreset.ts => JavaConstraintsPreset.ts} | 2 +- .../{JacksonPreset.ts => JavaJacksonPreset.ts} | 0 src/generators/java/presets/index.ts | 4 ++-- ...set.spec.ts => JavaConstraintsPreset.spec.ts} | 4 ++-- ...nPreset.spec.ts => JavaJacksonPreset.spec.ts} | 0 ...s.snap => JavaConstraintsPreset.spec.ts.snap} | 16 ++++++++-------- ...ec.ts.snap => JavaJacksonPreset.spec.ts.snap} | 0 7 files changed, 13 insertions(+), 13 deletions(-) rename src/generators/java/presets/{ConstraintsPreset.ts => JavaConstraintsPreset.ts} (98%) rename src/generators/java/presets/{JacksonPreset.ts => JavaJacksonPreset.ts} (100%) rename test/generators/java/presets/{ConstraintsPreset.spec.ts => JavaConstraintsPreset.spec.ts} (89%) rename test/generators/java/presets/{JacksonPreset.spec.ts => JavaJacksonPreset.spec.ts} (100%) rename test/generators/java/presets/__snapshots__/{ConstraintsPreset.spec.ts.snap => JavaConstraintsPreset.spec.ts.snap} (93%) rename test/generators/java/presets/__snapshots__/{JacksonPreset.spec.ts.snap => JavaJacksonPreset.spec.ts.snap} (100%) diff --git a/src/generators/java/presets/ConstraintsPreset.ts b/src/generators/java/presets/JavaConstraintsPreset.ts similarity index 98% rename from src/generators/java/presets/ConstraintsPreset.ts rename to src/generators/java/presets/JavaConstraintsPreset.ts index 9f0668e03e..5ed4349d61 100644 --- a/src/generators/java/presets/ConstraintsPreset.ts +++ b/src/generators/java/presets/JavaConstraintsPreset.ts @@ -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) { diff --git a/src/generators/java/presets/JacksonPreset.ts b/src/generators/java/presets/JavaJacksonPreset.ts similarity index 100% rename from src/generators/java/presets/JacksonPreset.ts rename to src/generators/java/presets/JavaJacksonPreset.ts diff --git a/src/generators/java/presets/index.ts b/src/generators/java/presets/index.ts index 77b298ecab..479d5dde65 100644 --- a/src/generators/java/presets/index.ts +++ b/src/generators/java/presets/index.ts @@ -1,4 +1,4 @@ export * from './CommonPreset'; export * from './DescriptionPreset'; -export * from './JacksonPreset'; -export * from './ConstraintsPreset'; +export * from './JavaJacksonPreset'; +export * from './JavaConstraintsPreset'; diff --git a/test/generators/java/presets/ConstraintsPreset.spec.ts b/test/generators/java/presets/JavaConstraintsPreset.spec.ts similarity index 89% rename from test/generators/java/presets/ConstraintsPreset.spec.ts rename to test/generators/java/presets/JavaConstraintsPreset.spec.ts index 6b19638b2a..53d090f250 100644 --- a/test/generators/java/presets/ConstraintsPreset.spec.ts +++ b/test/generators/java/presets/JavaConstraintsPreset.spec.ts @@ -1,12 +1,12 @@ import { JavaGenerator, JAVA_CONSTRAINTS_PRESET } from '../../../../src/generators'; -describe('JAVA_CONSTRAINTS_PRESET', () => { +fdescribe('JAVA_CONSTRAINTS_PRESET', () => { let generator: JavaGenerator; beforeEach(() => { 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', diff --git a/test/generators/java/presets/JacksonPreset.spec.ts b/test/generators/java/presets/JavaJacksonPreset.spec.ts similarity index 100% rename from test/generators/java/presets/JacksonPreset.spec.ts rename to test/generators/java/presets/JavaJacksonPreset.spec.ts diff --git a/test/generators/java/presets/__snapshots__/ConstraintsPreset.spec.ts.snap b/test/generators/java/presets/__snapshots__/JavaConstraintsPreset.spec.ts.snap similarity index 93% rename from test/generators/java/presets/__snapshots__/ConstraintsPreset.spec.ts.snap rename to test/generators/java/presets/__snapshots__/JavaConstraintsPreset.spec.ts.snap index 69d2c13fcf..eddd84c8dc 100644 --- a/test/generators/java/presets/__snapshots__/ConstraintsPreset.spec.ts.snap +++ b/test/generators/java/presets/__snapshots__/JavaConstraintsPreset.spec.ts.snap @@ -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 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; } diff --git a/test/generators/java/presets/__snapshots__/JacksonPreset.spec.ts.snap b/test/generators/java/presets/__snapshots__/JavaJacksonPreset.spec.ts.snap similarity index 100% rename from test/generators/java/presets/__snapshots__/JacksonPreset.spec.ts.snap rename to test/generators/java/presets/__snapshots__/JavaJacksonPreset.spec.ts.snap From 5200e4f8b66922afceba89ae959742b0dfea4077 Mon Sep 17 00:00:00 2001 From: Artur Ciocanu Date: Tue, 20 Dec 2022 11:08:09 +0200 Subject: [PATCH 2/4] Remove fdescribe --- test/generators/java/presets/JavaConstraintsPreset.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/generators/java/presets/JavaConstraintsPreset.spec.ts b/test/generators/java/presets/JavaConstraintsPreset.spec.ts index 53d090f250..23e7c35593 100644 --- a/test/generators/java/presets/JavaConstraintsPreset.spec.ts +++ b/test/generators/java/presets/JavaConstraintsPreset.spec.ts @@ -1,6 +1,6 @@ import { JavaGenerator, JAVA_CONSTRAINTS_PRESET } from '../../../../src/generators'; -fdescribe('JAVA_CONSTRAINTS_PRESET', () => { +describe('JAVA_CONSTRAINTS_PRESET', () => { let generator: JavaGenerator; beforeEach(() => { generator = new JavaGenerator({ presets: [JAVA_CONSTRAINTS_PRESET] }); From 26b52b3c531144cd43ae63a4aac45ccdb5f7a73a Mon Sep 17 00:00:00 2001 From: Artur Ciocanu Date: Tue, 20 Dec 2022 15:38:17 +0200 Subject: [PATCH 3/4] Fix example tests --- .../__snapshots__/index.spec.ts.snap | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/java-generate-javax-constraint-annotation/__snapshots__/index.spec.ts.snap b/examples/java-generate-javax-constraint-annotation/__snapshots__/index.spec.ts.snap index d295950133..262569e5bf 100644 --- a/examples/java-generate-javax-constraint-annotation/__snapshots__/index.spec.ts.snap +++ b/examples/java-generate-javax-constraint-annotation/__snapshots__/index.spec.ts.snap @@ -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 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; } From 7bb2a81e7ce22caaa178a0bf530828f98f7a238c Mon Sep 17 00:00:00 2001 From: Artur Ciocanu Date: Wed, 21 Dec 2022 16:52:48 +0200 Subject: [PATCH 4/4] Revert preset renaming --- .../{JavaConstraintsPreset.ts => ConstraintsPreset.ts} | 0 .../java/presets/{JavaJacksonPreset.ts => JacksonPreset.ts} | 0 src/generators/java/presets/index.ts | 4 ++-- ...avaConstraintsPreset.spec.ts => ConstraintsPreset.spec.ts} | 0 .../{JavaJacksonPreset.spec.ts => JacksonPreset.spec.ts} | 0 ...intsPreset.spec.ts.snap => ConstraintsPreset.spec.ts.snap} | 0 ...aJacksonPreset.spec.ts.snap => JacksonPreset.spec.ts.snap} | 0 7 files changed, 2 insertions(+), 2 deletions(-) rename src/generators/java/presets/{JavaConstraintsPreset.ts => ConstraintsPreset.ts} (100%) rename src/generators/java/presets/{JavaJacksonPreset.ts => JacksonPreset.ts} (100%) rename test/generators/java/presets/{JavaConstraintsPreset.spec.ts => ConstraintsPreset.spec.ts} (100%) rename test/generators/java/presets/{JavaJacksonPreset.spec.ts => JacksonPreset.spec.ts} (100%) rename test/generators/java/presets/__snapshots__/{JavaConstraintsPreset.spec.ts.snap => ConstraintsPreset.spec.ts.snap} (100%) rename test/generators/java/presets/__snapshots__/{JavaJacksonPreset.spec.ts.snap => JacksonPreset.spec.ts.snap} (100%) diff --git a/src/generators/java/presets/JavaConstraintsPreset.ts b/src/generators/java/presets/ConstraintsPreset.ts similarity index 100% rename from src/generators/java/presets/JavaConstraintsPreset.ts rename to src/generators/java/presets/ConstraintsPreset.ts diff --git a/src/generators/java/presets/JavaJacksonPreset.ts b/src/generators/java/presets/JacksonPreset.ts similarity index 100% rename from src/generators/java/presets/JavaJacksonPreset.ts rename to src/generators/java/presets/JacksonPreset.ts diff --git a/src/generators/java/presets/index.ts b/src/generators/java/presets/index.ts index 479d5dde65..77b298ecab 100644 --- a/src/generators/java/presets/index.ts +++ b/src/generators/java/presets/index.ts @@ -1,4 +1,4 @@ export * from './CommonPreset'; export * from './DescriptionPreset'; -export * from './JavaJacksonPreset'; -export * from './JavaConstraintsPreset'; +export * from './JacksonPreset'; +export * from './ConstraintsPreset'; diff --git a/test/generators/java/presets/JavaConstraintsPreset.spec.ts b/test/generators/java/presets/ConstraintsPreset.spec.ts similarity index 100% rename from test/generators/java/presets/JavaConstraintsPreset.spec.ts rename to test/generators/java/presets/ConstraintsPreset.spec.ts diff --git a/test/generators/java/presets/JavaJacksonPreset.spec.ts b/test/generators/java/presets/JacksonPreset.spec.ts similarity index 100% rename from test/generators/java/presets/JavaJacksonPreset.spec.ts rename to test/generators/java/presets/JacksonPreset.spec.ts diff --git a/test/generators/java/presets/__snapshots__/JavaConstraintsPreset.spec.ts.snap b/test/generators/java/presets/__snapshots__/ConstraintsPreset.spec.ts.snap similarity index 100% rename from test/generators/java/presets/__snapshots__/JavaConstraintsPreset.spec.ts.snap rename to test/generators/java/presets/__snapshots__/ConstraintsPreset.spec.ts.snap diff --git a/test/generators/java/presets/__snapshots__/JavaJacksonPreset.spec.ts.snap b/test/generators/java/presets/__snapshots__/JacksonPreset.spec.ts.snap similarity index 100% rename from test/generators/java/presets/__snapshots__/JavaJacksonPreset.spec.ts.snap rename to test/generators/java/presets/__snapshots__/JacksonPreset.spec.ts.snap