Skip to content

Commit

Permalink
Merge pull request #242 from muehmar/187-rename-value-to-items-in-arr…
Browse files Browse the repository at this point in the history
…ay-classes

187 rename value to items in array classes
  • Loading branch information
muehmar authored Jan 23, 2024
2 parents 4c401fe + 7048a12 commit 8200514
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static JavaArrayPojo wrap(ArrayPojo arrayPojo, TypeMappings typeMappings)

private static JavaPojoMember createItemTypeMember(
ArrayPojo arrayPojo, JavaPojoName pojoName, JavaArrayType javaArrayType) {
final JavaName name = JavaName.fromString("value");
final JavaName name = JavaName.fromString("items");
return javaPojoMemberBuilder()
.pojoName(pojoName)
.name(name)
Expand All @@ -95,8 +95,7 @@ private static JavaPojoMember createItemTypeMember(
private static JavaArrayType createJavaArrayType(ArrayPojo arrayPojo, TypeMappings typeMappings) {
final ArrayType arrayType =
ArrayType.ofItemType(arrayPojo.getItemType()).withConstraints(arrayPojo.getConstraints());
final JavaArrayType javaArrayType = JavaArrayType.wrap(arrayType, typeMappings);
return javaArrayType;
return JavaArrayType.wrap(arrayType, typeMappings);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import javax.validation.constraints.NotNull;
*/
public class PosologyDto {
@JsonValue
private final List<Double> value;
private final List<Double> items;

@JsonCreator
public PosologyDto(
List<Double> value
List<Double> items
) {
this.value = value;
this.items = items;
}

public static PosologyDto fromItems(List<Double> items) {
Expand All @@ -34,31 +34,31 @@ public class PosologyDto {
* Doses to be taken
*/
@NotNull
public List<Double> getValue() {
return value;
public List<Double> getItems() {
return items;
}

/**
* Doses to be taken
*/
public PosologyDto withValue(List<Double> value) {
return new PosologyDto(value);
public PosologyDto withItems(List<Double> items) {
return new PosologyDto(items);
}

boolean isValid() {
return new Validator().isValid();
}

private class Validator {
private boolean isValueValid() {
if(value != null) {
return value.stream().allMatch(this::isValueValueValid);
private boolean isItemsValid() {
if(items != null) {
return items.stream().allMatch(this::isItemsValueValid);
}

return false;
}

private boolean isValueValueValid(Double valueValue) {
private boolean isItemsValueValid(Double itemsValue) {
return true;
}

Expand All @@ -72,20 +72,20 @@ public class PosologyDto {
if (this == obj) return true;
if (obj == null || this.getClass() != obj.getClass()) return false;
final PosologyDto other = (PosologyDto) obj;
return Objects.deepEquals(this.value, other.value);
return Objects.deepEquals(this.items, other.items);
}

@Override
public int hashCode() {
return Objects.hash(
value
items
);
}

@Override
public String toString() {
return "PosologyDto{" +
"value=" + value +
"items=" + items +
"}";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import javax.validation.constraints.NotNull;
*/
public class PosologyDto {
@JsonValue
private final List<Double> value;
private final List<Double> items;

@JsonCreator
public PosologyDto(
List<Double> value
List<Double> items
) {
this.value = value;
this.items = items;
}

public static PosologyDto fromItems(List<Double> items) {
Expand All @@ -36,37 +36,37 @@ public class PosologyDto {
* Doses to be taken
*/
@NotNull
public List<Double> getValue() {
return value;
public List<Double> getItems() {
return items;
}

/**
* Doses to be taken
*/
public PosologyDto withValue(List<Double> value) {
return new PosologyDto(value);
public PosologyDto withItems(List<Double> items) {
return new PosologyDto(items);
}

@AssertTrue(message = "value does not contain unique items")
private boolean hasValueUniqueItems() {
return new HashSet<>(value).size() == value.size();
@AssertTrue(message = "items does not contain unique items")
private boolean hasItemsUniqueItems() {
return new HashSet<>(items).size() == items.size();
}

boolean isValid() {
return new Validator().isValid();
}

private class Validator {
private boolean isValueValid() {
if(value != null) {
return hasValueUniqueItems()
&& value.stream().allMatch(this::isValueValueValid);
private boolean isItemsValid() {
if(items != null) {
return hasItemsUniqueItems()
&& items.stream().allMatch(this::isItemsValueValid);
}

return false;
}

private boolean isValueValueValid(Double valueValue) {
private boolean isItemsValueValid(Double itemsValue) {
return true;
}

Expand All @@ -80,20 +80,20 @@ public class PosologyDto {
if (this == obj) return true;
if (obj == null || this.getClass() != obj.getClass()) return false;
final PosologyDto other = (PosologyDto) obj;
return Objects.deepEquals(this.value, other.value);
return Objects.deepEquals(this.items, other.items);
}

@Override
public int hashCode() {
return Objects.hash(
value
items
);
}

@Override
public String toString() {
return "PosologyDto{" +
"value=" + value +
"items=" + items +
"}";
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
arrayPojo=[
private class Validator {
private boolean isValueValid() {
if(value != null) {
return value.stream().allMatch(this::isValueValueValid);
private boolean isItemsValid() {
if(items != null) {
return items.stream().allMatch(this::isItemsValueValid);
}

return false;
}

private boolean isValueValueValid(Double valueValue) {
private boolean isItemsValueValid(Double itemsValue) {
return true;
}

Expand All @@ -21,16 +21,16 @@ private class Validator {

arrayPojoWithUniqueItems=[
private class Validator {
private boolean isValueValid() {
if(value != null) {
return hasValueUniqueItems()
&& value.stream().allMatch(this::isValueValueValid);
private boolean isItemsValid() {
if(items != null) {
return hasItemsUniqueItems()
&& items.stream().allMatch(this::isItemsValueValid);
}

return false;
}

private boolean isValueValueValid(Double valueValue) {
private boolean isItemsValueValid(Double itemsValue) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
import static com.github.muehmar.gradle.openapi.generator.java.generator.pojo.MemberGenerator.memberGenerator;
import static com.github.muehmar.gradle.openapi.generator.settings.TestPojoSettings.defaultTestSettings;
import static io.github.muehmar.codegenerator.writer.Writer.javaWriter;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import au.com.origin.snapshots.Expect;
import au.com.origin.snapshots.annotations.SnapshotName;
import com.github.muehmar.gradle.openapi.generator.java.generator.pojo.MemberGenerator.MemberContent;
import com.github.muehmar.gradle.openapi.generator.java.model.pojo.JavaPojos;
import com.github.muehmar.gradle.openapi.generator.java.ref.JacksonRefs;
import com.github.muehmar.gradle.openapi.generator.java.ref.JavaRefs;
import com.github.muehmar.gradle.openapi.generator.settings.PojoSettings;
import com.github.muehmar.gradle.openapi.snapshot.SnapshotTest;
import com.github.muehmar.gradle.openapi.snapshot.SnapshotUtil;
import io.github.muehmar.codegenerator.Generator;
import io.github.muehmar.codegenerator.writer.Writer;
import org.junit.jupiter.api.Test;
Expand All @@ -33,10 +30,7 @@ void generate_when_samplePojo_then_correctOutputAndRef() {
defaultTestSettings(),
javaWriter());

assertTrue(writer.getRefs().exists(JavaRefs.JAVA_UTIL_MAP::equals));

final String output = writer.asString();
expect.toMatchSnapshot(output);
expect.toMatchSnapshot(SnapshotUtil.writerSnapshot(writer));
}

@Test
Expand All @@ -50,22 +44,17 @@ void generate_when_illegalIdentifierPojo_then_matchSnapshot() {
defaultTestSettings(),
javaWriter());

assertTrue(writer.getRefs().exists(JavaRefs.JAVA_UTIL_MAP::equals));

final String output = writer.asString();
expect.toMatchSnapshot(output);
expect.toMatchSnapshot(SnapshotUtil.writerSnapshot(writer));
}

@Test
@SnapshotName("arrayPojo")
void generate_when_arrayPojo_then_correctOutputAndRef() {
final Generator<MemberContent, PojoSettings> gen = memberGenerator();

final Writer writer =
gen.generate(JavaPojos.arrayPojo().getMemberContent(), defaultTestSettings(), javaWriter());

assertTrue(writer.getRefs().exists(JacksonRefs.JSON_VALUE::equals));

final String output = writer.asString();
assertEquals("@JsonValue\n" + "private final List<Double> value;", output);
expect.toMatchSnapshot(SnapshotUtil.writerSnapshot(writer));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
allNecessityAndNullabilityVariants=[
java.util.Map

private final String requiredStringVal;
private final String requiredNullableStringVal;
private final boolean isRequiredNullableStringValPresent;
Expand All @@ -10,7 +12,18 @@ private final Map<String, Object> additionalProperties;
]


arrayPojo=[
com.fasterxml.jackson.annotation.JsonValue
java.util.List

@JsonValue
private final List<Double> items;
]


illegalIdentifierPojo=[
java.util.Map

private final String switch_;
private final boolean isSwitchNull;
private final String point_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || this.getClass() != obj.getClass()) return false;
final PosologyDto other = (PosologyDto) obj;
return Objects.deepEquals(this.value, other.value);
return Objects.deepEquals(this.items, other.items);
}
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ java.util.Objects
@Override
public int hashCode() {
return Objects.hash(
value
items
);
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
arrayPojo=[
@JsonCreator
public PosologyDto(
List<Double> value
List<Double> items
) {
this.value = value;
this.items = items;
}
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ arrayPojo=[
@Override
public String toString() {
return "PosologyDto{" +
"value=" + value +
"items=" + items +
"}";
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void wrap_when_arrayPojo_then_correctJavaPojoMemberCreated() {

final JavaPojoMember arrayPojoMember = javaArrayPojo.getArrayPojoMember();

assertEquals(JavaName.fromString("value"), arrayPojoMember.getName());
assertEquals(JavaName.fromString("items"), arrayPojoMember.getName());
assertEquals(arrayPojo.getDescription(), arrayPojoMember.getDescription());
assertEquals(arrayPojo.getConstraints(), arrayPojoMember.getJavaType().getConstraints());
assertEquals(
Expand Down

0 comments on commit 8200514

Please sign in to comment.