From 57eea204d74d1ee6399b0164165dfa7e03fde8d5 Mon Sep 17 00:00:00 2001 From: Chrimle Date: Wed, 18 Sep 2024 22:20:01 +0200 Subject: [PATCH] Generate record with `Set`-fields --- src/main/resources/api.yaml | 22 ++++++++ .../java/com/chrimle/example/TestSuite.java | 6 +++ .../AdditionalEnumTypeAnnotationTests.java | 1 + .../AdditionalModelTypeAnnotationTests.java | 1 + .../SerializableModelTests.java | 1 + .../example/standard/StandardTests.java | 1 + .../UseEnumCaseInsensitiveTests.java | 1 + .../utils/GeneratedRecordTestUtils.java | 15 ++++++ .../ExampleRecordWithSetFields.java | 51 ++++++++++++++++++ .../ExampleRecordWithSetFields.java | 54 +++++++++++++++++++ .../ExampleRecordWithSetFields.java | 54 +++++++++++++++++++ .../standard/ExampleRecordWithSetFields.java | 51 ++++++++++++++++++ .../ExampleRecordWithSetFields.java | 51 ++++++++++++++++++ 13 files changed, 309 insertions(+) create mode 100644 target/generated-sources/openapi/src/additionalEnumTypeAnnotations/src/gen/java/main/com/chrimle/example/additionalEnumTypeAnnotations/ExampleRecordWithSetFields.java create mode 100644 target/generated-sources/openapi/src/additionalModelTypeAnnotations/src/gen/java/main/com/chrimle/example/additionalModelTypeAnnotations/ExampleRecordWithSetFields.java create mode 100644 target/generated-sources/openapi/src/serializableModel/src/gen/java/main/com/chrimle/example/serializableModel/ExampleRecordWithSetFields.java create mode 100644 target/generated-sources/openapi/src/standard/src/gen/java/main/com/chrimle/example/standard/ExampleRecordWithSetFields.java create mode 100644 target/generated-sources/openapi/src/useEnumCaseInsensitive/src/gen/java/main/com/chrimle/example/useEnumCaseInsensitive/ExampleRecordWithSetFields.java diff --git a/src/main/resources/api.yaml b/src/main/resources/api.yaml index 068a83aa..09de1a78 100644 --- a/src/main/resources/api.yaml +++ b/src/main/resources/api.yaml @@ -105,6 +105,28 @@ components: field3: type: number description: yet another Number field + ExampleRecordWithSetFields: + type: object + description: Example of a Record with Set fields + properties: + field1: + type: array + description: a Set field + uniqueItems: true + items: + type: boolean + field2: + type: array + description: another Set field + uniqueItems: true + items: + type: boolean + field3: + type: array + description: yet another Set field + uniqueItems: true + items: + type: boolean ExampleRecordWithExampleRecordFields: type: object description: Example of a Record with Record fields diff --git a/src/test/java/com/chrimle/example/TestSuite.java b/src/test/java/com/chrimle/example/TestSuite.java index 52ea8a30..ecc6c12b 100644 --- a/src/test/java/com/chrimle/example/TestSuite.java +++ b/src/test/java/com/chrimle/example/TestSuite.java @@ -16,6 +16,7 @@ public record TestSuite exampleRecordWithIntegerFields, Class exampleRecordWithNumberFields, Class exampleRecordWithStringFields, + Class exampleRecordWithSetFields, boolean hasAdditionalModelTypeAnnotations, boolean hasAdditionalEnumTypeAnnotations, boolean useEnumCaseInsensitive, @@ -80,6 +81,11 @@ public void assertModels() { hasAdditionalModelTypeAnnotations, serializableModel ); + GeneratedRecordTestUtils.assertExampleRecordWithSetFields( + exampleRecordWithSetFields, + hasAdditionalModelTypeAnnotations, + serializableModel + ); GeneratedRecordTestUtils.assertExampleRecordWithDefaultFields( exampleRecordWithDefaultFields, hasAdditionalModelTypeAnnotations, diff --git a/src/test/java/com/chrimle/example/additionalEnumTypeAnnotations/AdditionalEnumTypeAnnotationTests.java b/src/test/java/com/chrimle/example/additionalEnumTypeAnnotations/AdditionalEnumTypeAnnotationTests.java index 290c4142..dd95cbee 100644 --- a/src/test/java/com/chrimle/example/additionalEnumTypeAnnotations/AdditionalEnumTypeAnnotationTests.java +++ b/src/test/java/com/chrimle/example/additionalEnumTypeAnnotations/AdditionalEnumTypeAnnotationTests.java @@ -29,6 +29,7 @@ public void testAllGeneratedClasses() { ExampleRecordWithIntegerFields.class, ExampleRecordWithNumberFields.class, ExampleRecordWithStringFields.class, + ExampleRecordWithSetFields.class, HAS_ADDITIONAL_MODEL_TYPE_ANNOTATIONS, HAS_ADDITIONAL_ENUM_TYPE_ANNOTATIONS, USE_ENUM_CASE_INSENSITIVE, diff --git a/src/test/java/com/chrimle/example/additionalModelTypeAnnotations/AdditionalModelTypeAnnotationTests.java b/src/test/java/com/chrimle/example/additionalModelTypeAnnotations/AdditionalModelTypeAnnotationTests.java index 1d8485fd..3f8ba78b 100644 --- a/src/test/java/com/chrimle/example/additionalModelTypeAnnotations/AdditionalModelTypeAnnotationTests.java +++ b/src/test/java/com/chrimle/example/additionalModelTypeAnnotations/AdditionalModelTypeAnnotationTests.java @@ -29,6 +29,7 @@ public void testAllGeneratedClasses() { ExampleRecordWithIntegerFields.class, ExampleRecordWithNumberFields.class, ExampleRecordWithStringFields.class, + ExampleRecordWithSetFields.class, HAS_ADDITIONAL_MODEL_TYPE_ANNOTATIONS, HAS_ADDITIONAL_ENUM_TYPE_ANNOTATIONS, USE_ENUM_CASE_INSENSITIVE, diff --git a/src/test/java/com/chrimle/example/serializableModel/SerializableModelTests.java b/src/test/java/com/chrimle/example/serializableModel/SerializableModelTests.java index 6f509467..01cbb71d 100644 --- a/src/test/java/com/chrimle/example/serializableModel/SerializableModelTests.java +++ b/src/test/java/com/chrimle/example/serializableModel/SerializableModelTests.java @@ -29,6 +29,7 @@ public void testAllGeneratedClasses() { ExampleRecordWithIntegerFields.class, ExampleRecordWithNumberFields.class, ExampleRecordWithStringFields.class, + ExampleRecordWithSetFields.class, HAS_ADDITIONAL_MODEL_TYPE_ANNOTATIONS, HAS_ADDITIONAL_ENUM_TYPE_ANNOTATIONS, USE_ENUM_CASE_INSENSITIVE, diff --git a/src/test/java/com/chrimle/example/standard/StandardTests.java b/src/test/java/com/chrimle/example/standard/StandardTests.java index 8a289ec2..940e1f39 100644 --- a/src/test/java/com/chrimle/example/standard/StandardTests.java +++ b/src/test/java/com/chrimle/example/standard/StandardTests.java @@ -29,6 +29,7 @@ public void testAllGeneratedClasses() { ExampleRecordWithIntegerFields.class, ExampleRecordWithNumberFields.class, ExampleRecordWithStringFields.class, + ExampleRecordWithSetFields.class, HAS_ADDITIONAL_MODEL_TYPE_ANNOTATIONS, HAS_ADDITIONAL_ENUM_TYPE_ANNOTATIONS, USE_ENUM_CASE_INSENSITIVE, diff --git a/src/test/java/com/chrimle/example/useEnumCaseInsensitive/UseEnumCaseInsensitiveTests.java b/src/test/java/com/chrimle/example/useEnumCaseInsensitive/UseEnumCaseInsensitiveTests.java index 2169ff7e..05aa5eea 100644 --- a/src/test/java/com/chrimle/example/useEnumCaseInsensitive/UseEnumCaseInsensitiveTests.java +++ b/src/test/java/com/chrimle/example/useEnumCaseInsensitive/UseEnumCaseInsensitiveTests.java @@ -29,6 +29,7 @@ public void testAllGeneratedClasses() { ExampleRecordWithIntegerFields.class, ExampleRecordWithNumberFields.class, ExampleRecordWithStringFields.class, + ExampleRecordWithSetFields.class, HAS_ADDITIONAL_MODEL_TYPE_ANNOTATIONS, HAS_ADDITIONAL_ENUM_TYPE_ANNOTATIONS, USE_ENUM_CASE_INSENSITIVE, diff --git a/src/test/java/com/chrimle/example/utils/GeneratedRecordTestUtils.java b/src/test/java/com/chrimle/example/utils/GeneratedRecordTestUtils.java index 107e322f..24c44892 100644 --- a/src/test/java/com/chrimle/example/utils/GeneratedRecordTestUtils.java +++ b/src/test/java/com/chrimle/example/utils/GeneratedRecordTestUtils.java @@ -3,6 +3,7 @@ import java.lang.reflect.Constructor; import java.math.BigDecimal; import java.util.List; +import java.util.Set; /** * Generalized Test-class for testing Generated Record-classes @@ -219,4 +220,18 @@ public static void assertExampleRecordWithDefaultFields( ); } + public static void assertExampleRecordWithSetFields( + final Class classUnderTest, + final boolean hasAdditionalTypeAnnotations, + final boolean isSerializableModel) { + assertRecord( + classUnderTest, + false, + hasAdditionalTypeAnnotations, + isSerializableModel, + Set.class, + Set.class, + Set.class + ); + } } diff --git a/target/generated-sources/openapi/src/additionalEnumTypeAnnotations/src/gen/java/main/com/chrimle/example/additionalEnumTypeAnnotations/ExampleRecordWithSetFields.java b/target/generated-sources/openapi/src/additionalEnumTypeAnnotations/src/gen/java/main/com/chrimle/example/additionalEnumTypeAnnotations/ExampleRecordWithSetFields.java new file mode 100644 index 00000000..12a1a53f --- /dev/null +++ b/target/generated-sources/openapi/src/additionalEnumTypeAnnotations/src/gen/java/main/com/chrimle/example/additionalEnumTypeAnnotations/ExampleRecordWithSetFields.java @@ -0,0 +1,51 @@ +/* + * Example OpenAPI Spec. + * An example OpenAPI-spec to generate example Java records. + * + * The version of the OpenAPI document: 0.0.1 + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + * + * This class was generated using custom mustache templates from + * openapi-to-java-records-mustache-templates. For further information, + * questions, requesting features or reporting issues, please visit: + * https://github.com/Chrimle/openapi-to-java-records-mustache-templates. + * Generated with Version: 1.6.0 + * + */ + +package com.chrimle.example.additionalEnumTypeAnnotations; + +import java.util.Objects; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; +import java.util.Arrays; +import java.util.LinkedHashSet; +import java.util.Set; + +/** + * Example of a Record with Set fields + * @param field1 a Set field + * @param field2 another Set field + * @param field3 yet another Set field + */ +public record ExampleRecordWithSetFields( + @javax.annotation.Nonnull Set field1, + @javax.annotation.Nonnull Set field2, + @javax.annotation.Nonnull Set field3) { + + public ExampleRecordWithSetFields( + @javax.annotation.Nullable final Set field1, + @javax.annotation.Nullable final Set field2, + @javax.annotation.Nullable final Set field3) { + this.field1 = Objects.requireNonNullElse(field1, new LinkedHashSet<>()); + this.field2 = Objects.requireNonNullElse(field2, new LinkedHashSet<>()); + this.field3 = Objects.requireNonNullElse(field3, new LinkedHashSet<>()); + } +} diff --git a/target/generated-sources/openapi/src/additionalModelTypeAnnotations/src/gen/java/main/com/chrimle/example/additionalModelTypeAnnotations/ExampleRecordWithSetFields.java b/target/generated-sources/openapi/src/additionalModelTypeAnnotations/src/gen/java/main/com/chrimle/example/additionalModelTypeAnnotations/ExampleRecordWithSetFields.java new file mode 100644 index 00000000..2ff9260f --- /dev/null +++ b/target/generated-sources/openapi/src/additionalModelTypeAnnotations/src/gen/java/main/com/chrimle/example/additionalModelTypeAnnotations/ExampleRecordWithSetFields.java @@ -0,0 +1,54 @@ +/* + * Example OpenAPI Spec. + * An example OpenAPI-spec to generate example Java records. + * + * The version of the OpenAPI document: 0.0.1 + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + * + * This class was generated using custom mustache templates from + * openapi-to-java-records-mustache-templates. For further information, + * questions, requesting features or reporting issues, please visit: + * https://github.com/Chrimle/openapi-to-java-records-mustache-templates. + * Generated with Version: 1.6.0 + * + */ + +package com.chrimle.example.additionalModelTypeAnnotations; + +import java.util.Objects; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; +import java.util.Arrays; +import java.util.LinkedHashSet; +import java.util.Set; + +/** + * Example of a Record with Set fields + * @param field1 a Set field + * @param field2 another Set field + * @param field3 yet another Set field + */ +@com.chrimle.example.annotations.TestAnnotationOne +@com.chrimle.example.annotations.TestAnnotationTwo +@com.chrimle.example.annotations.TestAnnotationThree +public record ExampleRecordWithSetFields( + @javax.annotation.Nonnull Set field1, + @javax.annotation.Nonnull Set field2, + @javax.annotation.Nonnull Set field3) { + + public ExampleRecordWithSetFields( + @javax.annotation.Nullable final Set field1, + @javax.annotation.Nullable final Set field2, + @javax.annotation.Nullable final Set field3) { + this.field1 = Objects.requireNonNullElse(field1, new LinkedHashSet<>()); + this.field2 = Objects.requireNonNullElse(field2, new LinkedHashSet<>()); + this.field3 = Objects.requireNonNullElse(field3, new LinkedHashSet<>()); + } +} diff --git a/target/generated-sources/openapi/src/serializableModel/src/gen/java/main/com/chrimle/example/serializableModel/ExampleRecordWithSetFields.java b/target/generated-sources/openapi/src/serializableModel/src/gen/java/main/com/chrimle/example/serializableModel/ExampleRecordWithSetFields.java new file mode 100644 index 00000000..4a5a258c --- /dev/null +++ b/target/generated-sources/openapi/src/serializableModel/src/gen/java/main/com/chrimle/example/serializableModel/ExampleRecordWithSetFields.java @@ -0,0 +1,54 @@ +/* + * Example OpenAPI Spec. + * An example OpenAPI-spec to generate example Java records. + * + * The version of the OpenAPI document: 0.0.1 + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + * + * This class was generated using custom mustache templates from + * openapi-to-java-records-mustache-templates. For further information, + * questions, requesting features or reporting issues, please visit: + * https://github.com/Chrimle/openapi-to-java-records-mustache-templates. + * Generated with Version: 1.6.0 + * + */ + +package com.chrimle.example.serializableModel; + +import java.util.Objects; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; +import java.util.Arrays; +import java.util.LinkedHashSet; +import java.util.Set; +import java.io.Serializable; + +/** + * Example of a Record with Set fields + * @param field1 a Set field + * @param field2 another Set field + * @param field3 yet another Set field + */ +public record ExampleRecordWithSetFields( + @javax.annotation.Nonnull Set field1, + @javax.annotation.Nonnull Set field2, + @javax.annotation.Nonnull Set field3) { + + private static final long serialVersionUID = 1L; + + public ExampleRecordWithSetFields( + @javax.annotation.Nullable final Set field1, + @javax.annotation.Nullable final Set field2, + @javax.annotation.Nullable final Set field3) { + this.field1 = Objects.requireNonNullElse(field1, new LinkedHashSet<>()); + this.field2 = Objects.requireNonNullElse(field2, new LinkedHashSet<>()); + this.field3 = Objects.requireNonNullElse(field3, new LinkedHashSet<>()); + } +} diff --git a/target/generated-sources/openapi/src/standard/src/gen/java/main/com/chrimle/example/standard/ExampleRecordWithSetFields.java b/target/generated-sources/openapi/src/standard/src/gen/java/main/com/chrimle/example/standard/ExampleRecordWithSetFields.java new file mode 100644 index 00000000..518c4e91 --- /dev/null +++ b/target/generated-sources/openapi/src/standard/src/gen/java/main/com/chrimle/example/standard/ExampleRecordWithSetFields.java @@ -0,0 +1,51 @@ +/* + * Example OpenAPI Spec. + * An example OpenAPI-spec to generate example Java records. + * + * The version of the OpenAPI document: 0.0.1 + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + * + * This class was generated using custom mustache templates from + * openapi-to-java-records-mustache-templates. For further information, + * questions, requesting features or reporting issues, please visit: + * https://github.com/Chrimle/openapi-to-java-records-mustache-templates. + * Generated with Version: 1.6.0 + * + */ + +package com.chrimle.example.standard; + +import java.util.Objects; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; +import java.util.Arrays; +import java.util.LinkedHashSet; +import java.util.Set; + +/** + * Example of a Record with Set fields + * @param field1 a Set field + * @param field2 another Set field + * @param field3 yet another Set field + */ +public record ExampleRecordWithSetFields( + @javax.annotation.Nonnull Set field1, + @javax.annotation.Nonnull Set field2, + @javax.annotation.Nonnull Set field3) { + + public ExampleRecordWithSetFields( + @javax.annotation.Nullable final Set field1, + @javax.annotation.Nullable final Set field2, + @javax.annotation.Nullable final Set field3) { + this.field1 = Objects.requireNonNullElse(field1, new LinkedHashSet<>()); + this.field2 = Objects.requireNonNullElse(field2, new LinkedHashSet<>()); + this.field3 = Objects.requireNonNullElse(field3, new LinkedHashSet<>()); + } +} diff --git a/target/generated-sources/openapi/src/useEnumCaseInsensitive/src/gen/java/main/com/chrimle/example/useEnumCaseInsensitive/ExampleRecordWithSetFields.java b/target/generated-sources/openapi/src/useEnumCaseInsensitive/src/gen/java/main/com/chrimle/example/useEnumCaseInsensitive/ExampleRecordWithSetFields.java new file mode 100644 index 00000000..cd0813eb --- /dev/null +++ b/target/generated-sources/openapi/src/useEnumCaseInsensitive/src/gen/java/main/com/chrimle/example/useEnumCaseInsensitive/ExampleRecordWithSetFields.java @@ -0,0 +1,51 @@ +/* + * Example OpenAPI Spec. + * An example OpenAPI-spec to generate example Java records. + * + * The version of the OpenAPI document: 0.0.1 + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + * + * This class was generated using custom mustache templates from + * openapi-to-java-records-mustache-templates. For further information, + * questions, requesting features or reporting issues, please visit: + * https://github.com/Chrimle/openapi-to-java-records-mustache-templates. + * Generated with Version: 1.6.0 + * + */ + +package com.chrimle.example.useEnumCaseInsensitive; + +import java.util.Objects; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; +import java.util.Arrays; +import java.util.LinkedHashSet; +import java.util.Set; + +/** + * Example of a Record with Set fields + * @param field1 a Set field + * @param field2 another Set field + * @param field3 yet another Set field + */ +public record ExampleRecordWithSetFields( + @javax.annotation.Nonnull Set field1, + @javax.annotation.Nonnull Set field2, + @javax.annotation.Nonnull Set field3) { + + public ExampleRecordWithSetFields( + @javax.annotation.Nullable final Set field1, + @javax.annotation.Nullable final Set field2, + @javax.annotation.Nullable final Set field3) { + this.field1 = Objects.requireNonNullElse(field1, new LinkedHashSet<>()); + this.field2 = Objects.requireNonNullElse(field2, new LinkedHashSet<>()); + this.field3 = Objects.requireNonNullElse(field3, new LinkedHashSet<>()); + } +}