Skip to content

Commit

Permalink
Generate record with Set-fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Chrimle committed Sep 18, 2024
1 parent 370c50b commit 57eea20
Show file tree
Hide file tree
Showing 13 changed files with 309 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/main/resources/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/com/chrimle/example/TestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public record TestSuite<DeprecatedExampleEnum extends Enum<DeprecatedExampleEnum
Class<?> exampleRecordWithIntegerFields,
Class<?> exampleRecordWithNumberFields,
Class<?> exampleRecordWithStringFields,
Class<?> exampleRecordWithSetFields,
boolean hasAdditionalModelTypeAnnotations,
boolean hasAdditionalEnumTypeAnnotations,
boolean useEnumCaseInsensitive,
Expand Down Expand Up @@ -80,6 +81,11 @@ public void assertModels() {
hasAdditionalModelTypeAnnotations,
serializableModel
);
GeneratedRecordTestUtils.assertExampleRecordWithSetFields(
exampleRecordWithSetFields,
hasAdditionalModelTypeAnnotations,
serializableModel
);
GeneratedRecordTestUtils.assertExampleRecordWithDefaultFields(
exampleRecordWithDefaultFields,
hasAdditionalModelTypeAnnotations,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
);
}
}
Original file line number Diff line number Diff line change
@@ -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<Boolean> field1,
@javax.annotation.Nonnull Set<Boolean> field2,
@javax.annotation.Nonnull Set<Boolean> field3) {

public ExampleRecordWithSetFields(
@javax.annotation.Nullable final Set<Boolean> field1,
@javax.annotation.Nullable final Set<Boolean> field2,
@javax.annotation.Nullable final Set<Boolean> field3) {
this.field1 = Objects.requireNonNullElse(field1, new LinkedHashSet<>());
this.field2 = Objects.requireNonNullElse(field2, new LinkedHashSet<>());
this.field3 = Objects.requireNonNullElse(field3, new LinkedHashSet<>());
}
}
Original file line number Diff line number Diff line change
@@ -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<Boolean> field1,
@javax.annotation.Nonnull Set<Boolean> field2,
@javax.annotation.Nonnull Set<Boolean> field3) {

public ExampleRecordWithSetFields(
@javax.annotation.Nullable final Set<Boolean> field1,
@javax.annotation.Nullable final Set<Boolean> field2,
@javax.annotation.Nullable final Set<Boolean> field3) {
this.field1 = Objects.requireNonNullElse(field1, new LinkedHashSet<>());
this.field2 = Objects.requireNonNullElse(field2, new LinkedHashSet<>());
this.field3 = Objects.requireNonNullElse(field3, new LinkedHashSet<>());
}
}
Original file line number Diff line number Diff line change
@@ -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<Boolean> field1,
@javax.annotation.Nonnull Set<Boolean> field2,
@javax.annotation.Nonnull Set<Boolean> field3) {

private static final long serialVersionUID = 1L;

public ExampleRecordWithSetFields(
@javax.annotation.Nullable final Set<Boolean> field1,
@javax.annotation.Nullable final Set<Boolean> field2,
@javax.annotation.Nullable final Set<Boolean> field3) {
this.field1 = Objects.requireNonNullElse(field1, new LinkedHashSet<>());
this.field2 = Objects.requireNonNullElse(field2, new LinkedHashSet<>());
this.field3 = Objects.requireNonNullElse(field3, new LinkedHashSet<>());
}
}
Original file line number Diff line number Diff line change
@@ -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<Boolean> field1,
@javax.annotation.Nonnull Set<Boolean> field2,
@javax.annotation.Nonnull Set<Boolean> field3) {

public ExampleRecordWithSetFields(
@javax.annotation.Nullable final Set<Boolean> field1,
@javax.annotation.Nullable final Set<Boolean> field2,
@javax.annotation.Nullable final Set<Boolean> field3) {
this.field1 = Objects.requireNonNullElse(field1, new LinkedHashSet<>());
this.field2 = Objects.requireNonNullElse(field2, new LinkedHashSet<>());
this.field3 = Objects.requireNonNullElse(field3, new LinkedHashSet<>());
}
}
Original file line number Diff line number Diff line change
@@ -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<Boolean> field1,
@javax.annotation.Nonnull Set<Boolean> field2,
@javax.annotation.Nonnull Set<Boolean> field3) {

public ExampleRecordWithSetFields(
@javax.annotation.Nullable final Set<Boolean> field1,
@javax.annotation.Nullable final Set<Boolean> field2,
@javax.annotation.Nullable final Set<Boolean> field3) {
this.field1 = Objects.requireNonNullElse(field1, new LinkedHashSet<>());
this.field2 = Objects.requireNonNullElse(field2, new LinkedHashSet<>());
this.field3 = Objects.requireNonNullElse(field3, new LinkedHashSet<>());
}
}

0 comments on commit 57eea20

Please sign in to comment.