diff --git a/modules/openapi-generator/src/test/resources/3_0/jaxrs-spec/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/openapi-generator/src/test/resources/3_0/jaxrs-spec/petstore-with-fake-endpoints-models-for-testing.yaml index 28b35f47071..ab021b4b528 100644 --- a/modules/openapi-generator/src/test/resources/3_0/jaxrs-spec/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/jaxrs-spec/petstore-with-fake-endpoints-models-for-testing.yaml @@ -1303,6 +1303,38 @@ paths: responses: 200: description: The instance started successfully + /fake/tests/defaults: + get: + tags: + - fake + summary: test enum default in request body + operationId: fake-tests-defaults + responses: + default: + description: response + content: + application/json: + schema: + type: object + properties: + stringEnum: + $ref: '#/components/schemas/StringEnum' + integerEnum: + $ref: '#/components/schemas/IntegerEnum' + stringEnumInline: + type: string + enum: + - foo + - bar + - baz + default: foo + integerEnumInline: + type: integer + enum: + - 1 + - 2 + - 3 + default: 1 servers: - url: 'http://{server}.swagger.io:{port}/v2' description: petstore server @@ -2061,3 +2093,17 @@ components: enum: - admin - user + StringEnum: + type: string + enum: + - foo + - bar + - baz + default: foo + IntegerEnum: + type: integer + enum: + - 1 + - 2 + - 3 + default: 1 diff --git a/samples/server/petstore/jaxrs-spec/.openapi-generator/FILES b/samples/server/petstore/jaxrs-spec/.openapi-generator/FILES index 6576c008a87..7155b1df8e8 100644 --- a/samples/server/petstore/jaxrs-spec/.openapi-generator/FILES +++ b/samples/server/petstore/jaxrs-spec/.openapi-generator/FILES @@ -27,12 +27,14 @@ src/gen/java/org/openapitools/model/EnumArrays.java src/gen/java/org/openapitools/model/EnumClass.java src/gen/java/org/openapitools/model/EnumTest.java src/gen/java/org/openapitools/model/FakeBigDecimalMap200Response.java +src/gen/java/org/openapitools/model/FakeTestsDefaultsDefaultResponse.java src/gen/java/org/openapitools/model/FileSchemaTestClass.java src/gen/java/org/openapitools/model/Foo.java src/gen/java/org/openapitools/model/FooGetDefaultResponse.java src/gen/java/org/openapitools/model/FormatTest.java src/gen/java/org/openapitools/model/HasOnlyReadOnly.java src/gen/java/org/openapitools/model/HealthCheckResult.java +src/gen/java/org/openapitools/model/IntegerEnum.java src/gen/java/org/openapitools/model/MapTest.java src/gen/java/org/openapitools/model/MixedPropertiesAndAdditionalPropertiesClass.java src/gen/java/org/openapitools/model/Model200Response.java @@ -56,6 +58,7 @@ src/gen/java/org/openapitools/model/Pet.java src/gen/java/org/openapitools/model/ReadOnlyFirst.java src/gen/java/org/openapitools/model/SingleRefType.java src/gen/java/org/openapitools/model/SpecialModelName.java +src/gen/java/org/openapitools/model/StringEnum.java src/gen/java/org/openapitools/model/Tag.java src/gen/java/org/openapitools/model/TestInlineFreeformAdditionalPropertiesRequest.java src/gen/java/org/openapitools/model/User.java diff --git a/samples/server/petstore/jaxrs-spec/src/gen/java/org/openapitools/api/FakeApi.java b/samples/server/petstore/jaxrs-spec/src/gen/java/org/openapitools/api/FakeApi.java index 1bc3632286b..ea851e03906 100644 --- a/samples/server/petstore/jaxrs-spec/src/gen/java/org/openapitools/api/FakeApi.java +++ b/samples/server/petstore/jaxrs-spec/src/gen/java/org/openapitools/api/FakeApi.java @@ -6,6 +6,7 @@ import org.openapitools.model.Client; import java.util.Date; import org.openapitools.model.EnumClass; import org.openapitools.model.FakeBigDecimalMap200Response; +import org.openapitools.model.FakeTestsDefaultsDefaultResponse; import java.io.File; import org.openapitools.model.FileSchemaTestClass; import org.openapitools.model.HealthCheckResult; @@ -133,6 +134,17 @@ public class FakeApi { return Response.ok().entity("magic!").build(); } + @GET + @Path("/tests/defaults") + @Produces({ "application/json" }) + @ApiOperation(value = "test enum default in request body", notes = "", response = FakeTestsDefaultsDefaultResponse.class, tags={ "fake" }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "response", response = FakeTestsDefaultsDefaultResponse.class) + }) + public Response fakeTestsDefaults() { + return Response.ok().entity("magic!").build(); + } + @POST @Path("/additionalProperties-reference") @Consumes({ "application/json" }) diff --git a/samples/server/petstore/jaxrs-spec/src/gen/java/org/openapitools/model/FakeTestsDefaultsDefaultResponse.java b/samples/server/petstore/jaxrs-spec/src/gen/java/org/openapitools/model/FakeTestsDefaultsDefaultResponse.java new file mode 100644 index 00000000000..890a0f0a213 --- /dev/null +++ b/samples/server/petstore/jaxrs-spec/src/gen/java/org/openapitools/model/FakeTestsDefaultsDefaultResponse.java @@ -0,0 +1,299 @@ +package org.openapitools.model; + +import com.fasterxml.jackson.annotation.JsonTypeName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.openapitools.model.IntegerEnum; +import org.openapitools.model.StringEnum; +import java.io.Serializable; +import javax.validation.constraints.*; +import javax.validation.Valid; + +import io.swagger.annotations.*; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.annotation.JsonTypeName; + + + +@JsonTypeName("fake_tests_defaults_default_response") +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen", comments = "Generator version: 7.6.0-SNAPSHOT") +public class FakeTestsDefaultsDefaultResponse implements Serializable { + private StringEnum stringEnum = StringEnum.FOO; + private IntegerEnum integerEnum = IntegerEnum.NUMBER_1; + public enum StringEnumInlineEnum { + + FOO(String.valueOf("foo")), BAR(String.valueOf("bar")), BAZ(String.valueOf("baz")); + + + private String value; + + StringEnumInlineEnum (String v) { + value = v; + } + + public String value() { + return value; + } + + @Override + @JsonValue + public String toString() { + return String.valueOf(value); + } + + /** + * Convert a String into String, as specified in the + * See JAX RS 2.0 Specification, section 3.2, p. 12 + */ + public static StringEnumInlineEnum fromString(String s) { + for (StringEnumInlineEnum b : StringEnumInlineEnum.values()) { + // using Objects.toString() to be safe if value type non-object type + // because types like 'int' etc. will be auto-boxed + if (java.util.Objects.toString(b.value).equals(s)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected string value '" + s + "'"); + } + + @JsonCreator + public static StringEnumInlineEnum fromValue(String value) { + for (StringEnumInlineEnum b : StringEnumInlineEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } +} + + private StringEnumInlineEnum stringEnumInline = StringEnumInlineEnum.FOO; + public enum IntegerEnumInlineEnum { + + NUMBER_1(Integer.valueOf(1)), NUMBER_2(Integer.valueOf(2)), NUMBER_3(Integer.valueOf(3)); + + + private Integer value; + + IntegerEnumInlineEnum (Integer v) { + value = v; + } + + public Integer value() { + return value; + } + + @Override + @JsonValue + public String toString() { + return String.valueOf(value); + } + + /** + * Convert a String into Integer, as specified in the + * See JAX RS 2.0 Specification, section 3.2, p. 12 + */ + public static IntegerEnumInlineEnum fromString(String s) { + for (IntegerEnumInlineEnum b : IntegerEnumInlineEnum.values()) { + // using Objects.toString() to be safe if value type non-object type + // because types like 'int' etc. will be auto-boxed + if (java.util.Objects.toString(b.value).equals(s)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected string value '" + s + "'"); + } + + @JsonCreator + public static IntegerEnumInlineEnum fromValue(Integer value) { + for (IntegerEnumInlineEnum b : IntegerEnumInlineEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } +} + + private IntegerEnumInlineEnum integerEnumInline = IntegerEnumInlineEnum.NUMBER_1; + + protected FakeTestsDefaultsDefaultResponse(FakeTestsDefaultsDefaultResponseBuilder b) { + this.stringEnum = b.stringEnum; + this.integerEnum = b.integerEnum; + this.stringEnumInline = b.stringEnumInline; + this.integerEnumInline = b.integerEnumInline; + } + + public FakeTestsDefaultsDefaultResponse() { + } + + /** + **/ + public FakeTestsDefaultsDefaultResponse stringEnum(StringEnum stringEnum) { + this.stringEnum = stringEnum; + return this; + } + + + @ApiModelProperty(value = "") + @JsonProperty("stringEnum") + @Valid public StringEnum getStringEnum() { + return stringEnum; + } + + @JsonProperty("stringEnum") + public void setStringEnum(StringEnum stringEnum) { + this.stringEnum = stringEnum; + } + + /** + **/ + public FakeTestsDefaultsDefaultResponse integerEnum(IntegerEnum integerEnum) { + this.integerEnum = integerEnum; + return this; + } + + + @ApiModelProperty(value = "") + @JsonProperty("integerEnum") + @Valid public IntegerEnum getIntegerEnum() { + return integerEnum; + } + + @JsonProperty("integerEnum") + public void setIntegerEnum(IntegerEnum integerEnum) { + this.integerEnum = integerEnum; + } + + /** + **/ + public FakeTestsDefaultsDefaultResponse stringEnumInline(StringEnumInlineEnum stringEnumInline) { + this.stringEnumInline = stringEnumInline; + return this; + } + + + @ApiModelProperty(value = "") + @JsonProperty("stringEnumInline") + public StringEnumInlineEnum getStringEnumInline() { + return stringEnumInline; + } + + @JsonProperty("stringEnumInline") + public void setStringEnumInline(StringEnumInlineEnum stringEnumInline) { + this.stringEnumInline = stringEnumInline; + } + + /** + **/ + public FakeTestsDefaultsDefaultResponse integerEnumInline(IntegerEnumInlineEnum integerEnumInline) { + this.integerEnumInline = integerEnumInline; + return this; + } + + + @ApiModelProperty(value = "") + @JsonProperty("integerEnumInline") + public IntegerEnumInlineEnum getIntegerEnumInline() { + return integerEnumInline; + } + + @JsonProperty("integerEnumInline") + public void setIntegerEnumInline(IntegerEnumInlineEnum integerEnumInline) { + this.integerEnumInline = integerEnumInline; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + FakeTestsDefaultsDefaultResponse fakeTestsDefaultsDefaultResponse = (FakeTestsDefaultsDefaultResponse) o; + return Objects.equals(this.stringEnum, fakeTestsDefaultsDefaultResponse.stringEnum) && + Objects.equals(this.integerEnum, fakeTestsDefaultsDefaultResponse.integerEnum) && + Objects.equals(this.stringEnumInline, fakeTestsDefaultsDefaultResponse.stringEnumInline) && + Objects.equals(this.integerEnumInline, fakeTestsDefaultsDefaultResponse.integerEnumInline); + } + + @Override + public int hashCode() { + return Objects.hash(stringEnum, integerEnum, stringEnumInline, integerEnumInline); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class FakeTestsDefaultsDefaultResponse {\n"); + + sb.append(" stringEnum: ").append(toIndentedString(stringEnum)).append("\n"); + sb.append(" integerEnum: ").append(toIndentedString(integerEnum)).append("\n"); + sb.append(" stringEnumInline: ").append(toIndentedString(stringEnumInline)).append("\n"); + sb.append(" integerEnumInline: ").append(toIndentedString(integerEnumInline)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + + public static FakeTestsDefaultsDefaultResponseBuilder builder() { + return new FakeTestsDefaultsDefaultResponseBuilderImpl(); + } + + private static final class FakeTestsDefaultsDefaultResponseBuilderImpl extends FakeTestsDefaultsDefaultResponseBuilder { + + @Override + protected FakeTestsDefaultsDefaultResponseBuilderImpl self() { + return this; + } + + @Override + public FakeTestsDefaultsDefaultResponse build() { + return new FakeTestsDefaultsDefaultResponse(this); + } + } + + public static abstract class FakeTestsDefaultsDefaultResponseBuilder> { + private StringEnum stringEnum = StringEnum.FOO; + private IntegerEnum integerEnum = IntegerEnum.NUMBER_1; + private StringEnumInlineEnum stringEnumInline = StringEnumInlineEnum.FOO; + private IntegerEnumInlineEnum integerEnumInline = IntegerEnumInlineEnum.NUMBER_1; + protected abstract B self(); + + public abstract C build(); + + public B stringEnum(StringEnum stringEnum) { + this.stringEnum = stringEnum; + return self(); + } + public B integerEnum(IntegerEnum integerEnum) { + this.integerEnum = integerEnum; + return self(); + } + public B stringEnumInline(StringEnumInlineEnum stringEnumInline) { + this.stringEnumInline = stringEnumInline; + return self(); + } + public B integerEnumInline(IntegerEnumInlineEnum integerEnumInline) { + this.integerEnumInline = integerEnumInline; + return self(); + } + } +} + diff --git a/samples/server/petstore/jaxrs-spec/src/gen/java/org/openapitools/model/IntegerEnum.java b/samples/server/petstore/jaxrs-spec/src/gen/java/org/openapitools/model/IntegerEnum.java new file mode 100644 index 00000000000..01c18bf99ad --- /dev/null +++ b/samples/server/petstore/jaxrs-spec/src/gen/java/org/openapitools/model/IntegerEnum.java @@ -0,0 +1,59 @@ +package org.openapitools.model; + +import java.io.Serializable; +import javax.validation.constraints.*; +import javax.validation.Valid; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * Gets or Sets IntegerEnum + */ +public enum IntegerEnum { + + NUMBER_1(1), + + NUMBER_2(2), + + NUMBER_3(3); + + private Integer value; + + IntegerEnum(Integer value) { + this.value = value; + } + + /** + * Convert a String into Integer, as specified in the + * See JAX RS 2.0 Specification, section 3.2, p. 12 + */ + public static IntegerEnum fromString(String s) { + for (IntegerEnum b : IntegerEnum.values()) { + // using Objects.toString() to be safe if value type non-object type + // because types like 'int' etc. will be auto-boxed + if (java.util.Objects.toString(b.value).equals(s)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected string value '" + s + "'"); + } + + @Override + @JsonValue + public String toString() { + return String.valueOf(value); + } + + @JsonCreator + public static IntegerEnum fromValue(Integer value) { + for (IntegerEnum b : IntegerEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } +} + + diff --git a/samples/server/petstore/jaxrs-spec/src/gen/java/org/openapitools/model/StringEnum.java b/samples/server/petstore/jaxrs-spec/src/gen/java/org/openapitools/model/StringEnum.java new file mode 100644 index 00000000000..4e37a7e483b --- /dev/null +++ b/samples/server/petstore/jaxrs-spec/src/gen/java/org/openapitools/model/StringEnum.java @@ -0,0 +1,59 @@ +package org.openapitools.model; + +import java.io.Serializable; +import javax.validation.constraints.*; +import javax.validation.Valid; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * Gets or Sets StringEnum + */ +public enum StringEnum { + + FOO("foo"), + + BAR("bar"), + + BAZ("baz"); + + private String value; + + StringEnum(String value) { + this.value = value; + } + + /** + * Convert a String into String, as specified in the + * See JAX RS 2.0 Specification, section 3.2, p. 12 + */ + public static StringEnum fromString(String s) { + for (StringEnum b : StringEnum.values()) { + // using Objects.toString() to be safe if value type non-object type + // because types like 'int' etc. will be auto-boxed + if (java.util.Objects.toString(b.value).equals(s)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected string value '" + s + "'"); + } + + @Override + @JsonValue + public String toString() { + return String.valueOf(value); + } + + @JsonCreator + public static StringEnum fromValue(String value) { + for (StringEnum b : StringEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } +} + + diff --git a/samples/server/petstore/jaxrs-spec/src/main/openapi/openapi.yaml b/samples/server/petstore/jaxrs-spec/src/main/openapi/openapi.yaml index d456aa0a571..ec445c1aac9 100644 --- a/samples/server/petstore/jaxrs-spec/src/main/openapi/openapi.yaml +++ b/samples/server/petstore/jaxrs-spec/src/main/openapi/openapi.yaml @@ -1484,6 +1484,23 @@ paths: - application/json x-tags: - tag: fake + /fake/tests/defaults: + get: + operationId: fake-tests-defaults + responses: + default: + content: + application/json: + schema: + $ref: '#/components/schemas/fake_tests_defaults_default_response' + description: response + summary: test enum default in request body + tags: + - fake + x-accepts: + - application/json + x-tags: + - tag: fake components: requestBodies: UserArray: @@ -2260,6 +2277,20 @@ components: - user title: SingleRefType type: string + StringEnum: + default: foo + enum: + - foo + - bar + - baz + type: string + IntegerEnum: + default: 1 + enum: + - 1 + - 2 + - 3 + type: integer _foo_get_default_response: example: string: @@ -2422,6 +2453,32 @@ components: required: - requiredFile type: object + fake_tests_defaults_default_response: + example: + stringEnum: foo + integerEnum: 0 + stringEnumInline: foo + integerEnumInline: 6 + properties: + stringEnum: + $ref: '#/components/schemas/StringEnum' + integerEnum: + $ref: '#/components/schemas/IntegerEnum' + stringEnumInline: + default: foo + enum: + - foo + - bar + - baz + type: string + integerEnumInline: + default: 1 + enum: + - 1 + - 2 + - 3 + type: integer + type: object securitySchemes: petstore_auth: flows: