Skip to content

Commit

Permalink
Implement records, fix #217
Browse files Browse the repository at this point in the history
  • Loading branch information
sschnabe committed Aug 18, 2023
1 parent dd01edc commit 7e4a0d2
Show file tree
Hide file tree
Showing 45 changed files with 2,141 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Include in your `pom.xml`:
* generateExamples: generate example objects for the model, based on example and default values (default `false`)
* generateAuthentication: generate Àuthentication into controller interfaces if response code 401 is present (default `false`)
* sealed: generate sealed interfaces (default `true`)
* record: generate records instead of pojos (default `false`)

For examples see [integration tests](src/it).

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package testmodel.micronaut_record;

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@io.micronaut.serde.annotation.Serdeable
public record AdditionalPropertiesModel(

@com.fasterxml.jackson.annotation.JsonProperty(JSON_PROPERTY_ID)
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
java.lang.String id) {

public static final java.lang.String JSON_PROPERTY_ID = "id";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package testmodel.micronaut_record;

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@com.fasterxml.jackson.annotation.JsonTypeInfo(use = com.fasterxml.jackson.annotation.JsonTypeInfo.Id.DEDUCTION, visible = true)
@com.fasterxml.jackson.annotation.JsonSubTypes({
@com.fasterxml.jackson.annotation.JsonSubTypes.Type(value = PropertyTypeOne.class),
@com.fasterxml.jackson.annotation.JsonSubTypes.Type(value = PropertyTypeTwo.class)
})
public sealed interface AdditionalPropertiesModelValue permits PropertyTypeOne, PropertyTypeTwo {}
40 changes: 40 additions & 0 deletions gen/main/java/testmodel/micronaut_record/EnumerationInteger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package testmodel.micronaut_record;

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

NUMBER_MINUS_2147483648(-2147483648),
NUMBER_MINUS_1(-1),
NUMBER_0(0),
NUMBER_1(1),
NUMBER_2147483647(2147483647);

public static final java.lang.Integer NUMBER_MINUS_2147483648_VALUE = -2147483648;
public static final java.lang.Integer NUMBER_MINUS_1_VALUE = -1;
public static final java.lang.Integer NUMBER_0_VALUE = 0;
public static final java.lang.Integer NUMBER_1_VALUE = 1;
public static final java.lang.Integer NUMBER_2147483647_VALUE = 2147483647;

private final java.lang.Integer value;

private EnumerationInteger(java.lang.Integer value) {
this.value = value;
}

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

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

@com.fasterxml.jackson.annotation.JsonValue
public java.lang.Integer getValue() {
return value;
}
}
91 changes: 91 additions & 0 deletions gen/main/java/testmodel/micronaut_record/EnumerationModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package testmodel.micronaut_record;

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@io.micronaut.serde.annotation.Serdeable
public record EnumerationModel(

@com.fasterxml.jackson.annotation.JsonProperty(JSON_PROPERTY_STRING)
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
EnumerationString string,

@com.fasterxml.jackson.annotation.JsonProperty(JSON_PROPERTY_STRING_DEFAULT)
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
EnumerationStringDefault stringDefault,

@com.fasterxml.jackson.annotation.JsonProperty(JSON_PROPERTY_EMBEDDED)
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
Embedded embedded,

@com.fasterxml.jackson.annotation.JsonProperty(JSON_PROPERTY_EMBEDDED_DEFAULT)
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
EmbeddedDefault embeddedDefault) {

public static final java.lang.String JSON_PROPERTY_STRING = "string";
public static final java.lang.String JSON_PROPERTY_STRING_DEFAULT = "string-default";
public static final java.lang.String JSON_PROPERTY_EMBEDDED = "embedded";
public static final java.lang.String JSON_PROPERTY_EMBEDDED_DEFAULT = "embedded-default";

public enum Embedded {

FIRST("first"),
SECOND("second");

public static final java.lang.String FIRST_VALUE = "first";
public static final java.lang.String SECOND_VALUE = "second";

private final java.lang.String value;

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

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

public static java.util.Optional<Embedded> 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;
}
}

public enum EmbeddedDefault {

THREE("three"),
FOUR("four");

public static final java.lang.String THREE_VALUE = "three";
public static final java.lang.String FOUR_VALUE = "four";

private final java.lang.String value;

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

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

public static java.util.Optional<EmbeddedDefault> 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;
}
}
}
36 changes: 36 additions & 0 deletions gen/main/java/testmodel/micronaut_record/EnumerationNumber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package testmodel.micronaut_record;

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

NUMBER_MINUS_1(-1D),
NUMBER_0(0D),
NUMBER_1(1D);

public static final java.lang.Double NUMBER_MINUS_1_VALUE = -1D;
public static final java.lang.Double NUMBER_0_VALUE = 0D;
public static final java.lang.Double NUMBER_1_VALUE = 1D;

private final java.lang.Double value;

private EnumerationNumber(java.lang.Double value) {
this.value = value;
}

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

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

@com.fasterxml.jackson.annotation.JsonValue
public java.lang.Double getValue() {
return value;
}
}
34 changes: 34 additions & 0 deletions gen/main/java/testmodel/micronaut_record/EnumerationString.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package testmodel.micronaut_record;

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

ONE("one"),
TWO("two");

public static final java.lang.String ONE_VALUE = "one";
public static final java.lang.String TWO_VALUE = "two";

private final java.lang.String value;

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

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

public static java.util.Optional<EnumerationString> 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
@@ -0,0 +1,34 @@
package testmodel.micronaut_record;

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

THREE("three"),
FOUR("four");

public static final java.lang.String THREE_VALUE = "three";
public static final java.lang.String FOUR_VALUE = "four";

private final java.lang.String value;

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

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

public static java.util.Optional<EnumerationStringDefault> 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;
}
}
23 changes: 23 additions & 0 deletions gen/main/java/testmodel/micronaut_record/FirstModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package testmodel.micronaut_record;

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@io.micronaut.serde.annotation.Serdeable
public record FirstModel(

@com.fasterxml.jackson.annotation.JsonProperty(JSON_PROPERTY_TYPE)
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
java.lang.String type,

@com.fasterxml.jackson.annotation.JsonProperty(JSON_PROPERTY_FIRST)
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
java.lang.String first,

@jakarta.validation.Valid
@com.fasterxml.jackson.annotation.JsonProperty(JSON_PROPERTY_SECOND_LEVEL)
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
SecondLevelModel secondLevel) implements OneOfModel {

public static final java.lang.String JSON_PROPERTY_TYPE = "type";
public static final java.lang.String JSON_PROPERTY_FIRST = "first";
public static final java.lang.String JSON_PROPERTY_SECOND_LEVEL = "secondLevel";
}
18 changes: 18 additions & 0 deletions gen/main/java/testmodel/micronaut_record/InheritanceExtended.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package testmodel.micronaut_record;

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@io.micronaut.serde.annotation.Serdeable
public record InheritanceExtended(

@jakarta.validation.constraints.NotNull
@com.fasterxml.jackson.annotation.JsonProperty(JSON_PROPERTY_FOO)
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.ALWAYS)
java.lang.String foo,

@jakarta.validation.constraints.NotNull
@com.fasterxml.jackson.annotation.JsonProperty(JSON_PROPERTY_BAR)
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.ALWAYS)
java.lang.String bar) implements InheritanceSimple {

public static final java.lang.String JSON_PROPERTY_BAR = "bar";
}
13 changes: 13 additions & 0 deletions gen/main/java/testmodel/micronaut_record/InheritanceSimple.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package testmodel.micronaut_record;

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@com.fasterxml.jackson.databind.annotation.JsonDeserialize(as = InheritanceSimpleDefault.class)
public sealed interface InheritanceSimple permits InheritanceExtended, InheritanceSimpleDefault {

java.lang.String JSON_PROPERTY_FOO = "foo";


@com.fasterxml.jackson.annotation.JsonProperty(JSON_PROPERTY_FOO)
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.ALWAYS)
java.lang.String foo();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package testmodel.micronaut_record;

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@io.micronaut.serde.annotation.Serdeable
public record InheritanceSimpleDefault(

@jakarta.validation.constraints.NotNull
@com.fasterxml.jackson.annotation.JsonProperty(JSON_PROPERTY_FOO)
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.ALWAYS)
java.lang.String foo) implements InheritanceSimple {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package testmodel.micronaut_record;

@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 = InheritanceWithEnumType.JSON_DISCRIMINATOR)
@com.fasterxml.jackson.annotation.JsonSubTypes({
@com.fasterxml.jackson.annotation.JsonSubTypes.Type(value = InheritanceWithEnumType1.class, name = "Inheritance1"),
@com.fasterxml.jackson.annotation.JsonSubTypes.Type(value = InheritanceWithEnumType2.class, name = "Inheritance2"),
@com.fasterxml.jackson.annotation.JsonSubTypes.Type(value = InheritanceWithEnumType3.class, name = "Inheritance3")
})
public sealed interface InheritanceWithEnumType permits InheritanceWithEnumType1, InheritanceWithEnumType2, InheritanceWithEnumType3 {

java.lang.String JSON_DISCRIMINATOR = "type";

@com.fasterxml.jackson.annotation.JsonProperty(JSON_DISCRIMINATOR)
InheritanceWithEnumTypeEnum type();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package testmodel.micronaut_record;

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@io.micronaut.serde.annotation.Serdeable
public record InheritanceWithEnumType1(

@com.fasterxml.jackson.annotation.JsonProperty(JSON_PROPERTY_D)
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
java.lang.String d) implements InheritanceWithEnumType {

public static final java.lang.String JSON_PROPERTY_D = "d";

@Override
public InheritanceWithEnumTypeEnum type() {
return InheritanceWithEnumTypeEnum.INHERITANCE1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package testmodel.micronaut_record;

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@io.micronaut.serde.annotation.Serdeable
public record InheritanceWithEnumType2(

@com.fasterxml.jackson.annotation.JsonProperty(JSON_PROPERTY_E)
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
java.lang.String e) implements InheritanceWithEnumType {

public static final java.lang.String JSON_PROPERTY_E = "e";

@Override
public InheritanceWithEnumTypeEnum type() {
return InheritanceWithEnumTypeEnum.INHERITANCE2;
}
}
Loading

0 comments on commit 7e4a0d2

Please sign in to comment.