Skip to content

Commit

Permalink
Add serdable to enums, fixes #407
Browse files Browse the repository at this point in the history
  • Loading branch information
sschnabe committed Sep 18, 2024
1 parent a8f4e77 commit 82106aa
Show file tree
Hide file tree
Showing 63 changed files with 452 additions and 1 deletion.
1 change: 1 addition & 0 deletions gen/main/java/issue/_331/StringWithEnum.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package issue._331;

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@io.micronaut.serde.annotation.Serdeable
public enum StringWithEnum {

A("A"),
Expand Down
1 change: 1 addition & 0 deletions gen/main/java/issue/_363/_false/EnumWithPrefix.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package issue._363._false;

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@io.micronaut.serde.annotation.Serdeable
public enum EnumWithPrefix {

AAA_FOO("aaa_foo"),
Expand Down
1 change: 1 addition & 0 deletions gen/main/java/issue/_363/_false/EnumWithoutPrefix.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package issue._363._false;

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@io.micronaut.serde.annotation.Serdeable
public enum EnumWithoutPrefix {

FOO("foo"),
Expand Down
1 change: 1 addition & 0 deletions gen/main/java/issue/_363/_true/EnumWithPrefix.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package issue._363._true;

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@io.micronaut.serde.annotation.Serdeable
public enum EnumWithPrefix {

FOO("aaa_foo"),
Expand Down
1 change: 1 addition & 0 deletions gen/main/java/issue/_363/_true/EnumWithoutPrefix.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package issue._363._true;

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@io.micronaut.serde.annotation.Serdeable
public enum EnumWithoutPrefix {

FOO("foo"),
Expand Down
79 changes: 79 additions & 0 deletions gen/main/java/issue/_407/Cat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package issue._407;

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@io.micronaut.serde.annotation.Serdeable
public final class Cat implements Pet {

@com.fasterxml.jackson.annotation.JsonProperty("hunts")
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
private java.lang.Boolean hunts;

@com.fasterxml.jackson.annotation.JsonProperty("age")
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
private java.lang.Integer age;

@Override
public PetType getPetType() {
return PetType.CAT;
}

// methods

@Override
public boolean equals(Object object) {
if (object == this) {
return true;
}
if (object == null || getClass() != object.getClass()) {
return false;
}
Cat other = (Cat) object;
return java.util.Objects.equals(hunts, other.hunts)
&& java.util.Objects.equals(age, other.age);
}

@Override
public int hashCode() {
return java.util.Objects.hash(hunts, age);
}

@Override
public java.lang.String toString() {
return new java.lang.StringBuilder()
.append("Cat[")
.append("hunts=").append(hunts).append(",")
.append("age=").append(age)
.append("]")
.toString();
}

// fluent

public Cat hunts(java.lang.Boolean newHunts) {
this.hunts = newHunts;
return this;
}

public Cat age(java.lang.Integer newAge) {
this.age = newAge;
return this;
}

// getter/setter

public java.lang.Boolean getHunts() {
return hunts;
}

public void setHunts(java.lang.Boolean newHunts) {
this.hunts = newHunts;
}

public java.lang.Integer getAge() {
return age;
}

public void setAge(java.lang.Integer newAge) {
this.age = newAge;
}
}
116 changes: 116 additions & 0 deletions gen/main/java/issue/_407/Dog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package issue._407;

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@io.micronaut.serde.annotation.Serdeable
public final class Dog implements Pet {

@com.fasterxml.jackson.annotation.JsonProperty("bark")
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
private java.lang.Boolean bark;

@com.fasterxml.jackson.annotation.JsonProperty("breed")
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
private Breed breed;

@Override
public PetType getPetType() {
return PetType.DOG;
}

// methods

@Override
public boolean equals(Object object) {
if (object == this) {
return true;
}
if (object == null || getClass() != object.getClass()) {
return false;
}
Dog other = (Dog) object;
return java.util.Objects.equals(bark, other.bark)
&& java.util.Objects.equals(breed, other.breed);
}

@Override
public int hashCode() {
return java.util.Objects.hash(bark, breed);
}

@Override
public java.lang.String toString() {
return new java.lang.StringBuilder()
.append("Dog[")
.append("bark=").append(bark).append(",")
.append("breed=").append(breed)
.append("]")
.toString();
}

// fluent

public Dog bark(java.lang.Boolean newBark) {
this.bark = newBark;
return this;
}

public Dog breed(Breed newBreed) {
this.breed = newBreed;
return this;
}

// getter/setter

public java.lang.Boolean getBark() {
return bark;
}

public void setBark(java.lang.Boolean newBark) {
this.bark = newBark;
}

public Breed getBreed() {
return breed;
}

public void setBreed(Breed newBreed) {
this.breed = newBreed;
}

@io.micronaut.serde.annotation.Serdeable
public enum Breed {

DINGO("Dingo"),
HUSKY("Husky"),
RETRIEVER("Retriever"),
SHEPHERD("Shepherd");

public static final java.lang.String DINGO_VALUE = "Dingo";
public static final java.lang.String HUSKY_VALUE = "Husky";
public static final java.lang.String RETRIEVER_VALUE = "Retriever";
public static final java.lang.String SHEPHERD_VALUE = "Shepherd";

private final java.lang.String value;

private Breed(java.lang.String value) {
this.value = value;
}

@com.fasterxml.jackson.annotation.JsonCreator
public static Breed toEnum(java.lang.String value) {
return toOptional(value).orElseThrow(() -> new IllegalArgumentException("Unknown value '" + value + "'."));
}

public static java.util.Optional<Breed> toOptional(java.lang.String value) {
return java.util.Arrays
.stream(values())
.filter(e -> e.value.equals(value))
.findAny();
}

@com.fasterxml.jackson.annotation.JsonValue
public java.lang.String getValue() {
return value;
}
}
}
13 changes: 13 additions & 0 deletions gen/main/java/issue/_407/Pet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package issue._407;

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@com.fasterxml.jackson.annotation.JsonTypeInfo(use = com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME, include = com.fasterxml.jackson.annotation.JsonTypeInfo.As.EXISTING_PROPERTY, property = "petType")
@com.fasterxml.jackson.annotation.JsonSubTypes({
@com.fasterxml.jackson.annotation.JsonSubTypes.Type(value = Cat.class, name = "Cat"),
@com.fasterxml.jackson.annotation.JsonSubTypes.Type(value = Dog.class, name = "Dog")
})
public sealed interface Pet permits Cat, Dog {

@com.fasterxml.jackson.annotation.JsonProperty("petType")
PetType getPetType();
}
35 changes: 35 additions & 0 deletions gen/main/java/issue/_407/PetType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package issue._407;

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@io.micronaut.serde.annotation.Serdeable
public enum PetType {

DOG("Dog"),
CAT("Cat");

public static final java.lang.String DOG_VALUE = "Dog";
public static final java.lang.String CAT_VALUE = "Cat";

private final java.lang.String value;

private PetType(java.lang.String value) {
this.value = value;
}

@com.fasterxml.jackson.annotation.JsonCreator
public static PetType toEnum(java.lang.String value) {
return toOptional(value).orElseThrow(() -> new IllegalArgumentException("Unknown value '" + value + "'."));
}

public static java.util.Optional<PetType> toOptional(java.lang.String value) {
return java.util.Arrays
.stream(values())
.filter(e -> e.value.equals(value))
.findAny();
}

@com.fasterxml.jackson.annotation.JsonValue
public java.lang.String getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package issue._414;

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@io.micronaut.serde.annotation.Serdeable
public class ModelPrefixModelObjectModelSuffix {

@com.fasterxml.jackson.annotation.JsonProperty("a")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package testmodel.micronaut_pojo;

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@io.micronaut.serde.annotation.Serdeable
public enum EnumerationInteger {

NUMBER_MINUS_2147483648(-2147483648),
Expand Down
2 changes: 2 additions & 0 deletions gen/main/java/testmodel/micronaut_pojo/EnumerationModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public void setEmbeddedDefault(EmbeddedDefault newEmbeddedDefault) {
this.embeddedDefault = newEmbeddedDefault;
}

@io.micronaut.serde.annotation.Serdeable
public enum Embedded {

FIRST("first"),
Expand Down Expand Up @@ -142,6 +143,7 @@ public java.lang.String getValue() {
}
}

@io.micronaut.serde.annotation.Serdeable
public enum EmbeddedDefault {

THREE("three"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package testmodel.micronaut_pojo;

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@io.micronaut.serde.annotation.Serdeable
public enum EnumerationNumber {

NUMBER_MINUS_1(-1D),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package testmodel.micronaut_pojo;

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@io.micronaut.serde.annotation.Serdeable
public enum EnumerationString {

ONE("one"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package testmodel.micronaut_pojo;

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@io.micronaut.serde.annotation.Serdeable
public enum EnumerationStringDefault {

THREE("three"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package testmodel.micronaut_pojo;

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@io.micronaut.serde.annotation.Serdeable
public enum InheritanceWithEnumTypeEnum {

INHERITANCE1("Inheritance1"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public void setType(Type newType) {
this.type = newType;
}

@io.micronaut.serde.annotation.Serdeable
public enum Type {

ONE("one");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public void setType(Type newType) {
this.type = newType;
}

@io.micronaut.serde.annotation.Serdeable
public enum Type {

TWO("two");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package testmodel.micronaut_pojo_constants;

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@io.micronaut.serde.annotation.Serdeable
public enum EnumerationInteger {

NUMBER_MINUS_2147483648(-2147483648),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public void setEmbeddedDefault(EmbeddedDefault newEmbeddedDefault) {
this.embeddedDefault = newEmbeddedDefault;
}

@io.micronaut.serde.annotation.Serdeable
public enum Embedded {

FIRST("first"),
Expand Down Expand Up @@ -147,6 +148,7 @@ public java.lang.String getValue() {
}
}

@io.micronaut.serde.annotation.Serdeable
public enum EmbeddedDefault {

THREE("three"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package testmodel.micronaut_pojo_constants;

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@io.micronaut.serde.annotation.Serdeable
public enum EnumerationNumber {

NUMBER_MINUS_1(-1D),
Expand Down
Loading

0 comments on commit 82106aa

Please sign in to comment.