forked from loafle/openapi-generator-original
Add tests for @Valid (enum) (#18664)
* add tests for #18430 * add new filies
This commit is contained in:
parent
d5559d5e65
commit
926a07fe4d
@ -1303,6 +1303,38 @@ paths:
|
|||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: The instance started successfully
|
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:
|
servers:
|
||||||
- url: 'http://{server}.swagger.io:{port}/v2'
|
- url: 'http://{server}.swagger.io:{port}/v2'
|
||||||
description: petstore server
|
description: petstore server
|
||||||
@ -2061,3 +2093,17 @@ components:
|
|||||||
enum:
|
enum:
|
||||||
- admin
|
- admin
|
||||||
- user
|
- user
|
||||||
|
StringEnum:
|
||||||
|
type: string
|
||||||
|
enum:
|
||||||
|
- foo
|
||||||
|
- bar
|
||||||
|
- baz
|
||||||
|
default: foo
|
||||||
|
IntegerEnum:
|
||||||
|
type: integer
|
||||||
|
enum:
|
||||||
|
- 1
|
||||||
|
- 2
|
||||||
|
- 3
|
||||||
|
default: 1
|
||||||
|
@ -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/EnumClass.java
|
||||||
src/gen/java/org/openapitools/model/EnumTest.java
|
src/gen/java/org/openapitools/model/EnumTest.java
|
||||||
src/gen/java/org/openapitools/model/FakeBigDecimalMap200Response.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/FileSchemaTestClass.java
|
||||||
src/gen/java/org/openapitools/model/Foo.java
|
src/gen/java/org/openapitools/model/Foo.java
|
||||||
src/gen/java/org/openapitools/model/FooGetDefaultResponse.java
|
src/gen/java/org/openapitools/model/FooGetDefaultResponse.java
|
||||||
src/gen/java/org/openapitools/model/FormatTest.java
|
src/gen/java/org/openapitools/model/FormatTest.java
|
||||||
src/gen/java/org/openapitools/model/HasOnlyReadOnly.java
|
src/gen/java/org/openapitools/model/HasOnlyReadOnly.java
|
||||||
src/gen/java/org/openapitools/model/HealthCheckResult.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/MapTest.java
|
||||||
src/gen/java/org/openapitools/model/MixedPropertiesAndAdditionalPropertiesClass.java
|
src/gen/java/org/openapitools/model/MixedPropertiesAndAdditionalPropertiesClass.java
|
||||||
src/gen/java/org/openapitools/model/Model200Response.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/ReadOnlyFirst.java
|
||||||
src/gen/java/org/openapitools/model/SingleRefType.java
|
src/gen/java/org/openapitools/model/SingleRefType.java
|
||||||
src/gen/java/org/openapitools/model/SpecialModelName.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/Tag.java
|
||||||
src/gen/java/org/openapitools/model/TestInlineFreeformAdditionalPropertiesRequest.java
|
src/gen/java/org/openapitools/model/TestInlineFreeformAdditionalPropertiesRequest.java
|
||||||
src/gen/java/org/openapitools/model/User.java
|
src/gen/java/org/openapitools/model/User.java
|
||||||
|
@ -6,6 +6,7 @@ import org.openapitools.model.Client;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import org.openapitools.model.EnumClass;
|
import org.openapitools.model.EnumClass;
|
||||||
import org.openapitools.model.FakeBigDecimalMap200Response;
|
import org.openapitools.model.FakeBigDecimalMap200Response;
|
||||||
|
import org.openapitools.model.FakeTestsDefaultsDefaultResponse;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import org.openapitools.model.FileSchemaTestClass;
|
import org.openapitools.model.FileSchemaTestClass;
|
||||||
import org.openapitools.model.HealthCheckResult;
|
import org.openapitools.model.HealthCheckResult;
|
||||||
@ -133,6 +134,17 @@ public class FakeApi {
|
|||||||
return Response.ok().entity("magic!").build();
|
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
|
@POST
|
||||||
@Path("/additionalProperties-reference")
|
@Path("/additionalProperties-reference")
|
||||||
@Consumes({ "application/json" })
|
@Consumes({ "application/json" })
|
||||||
|
@ -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
|
||||||
|
* <a href="https://download.oracle.com/otndocs/jcp/jaxrs-2_0-fr-eval-spec/index.html">See JAX RS 2.0 Specification, section 3.2, p. 12</a>
|
||||||
|
*/
|
||||||
|
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
|
||||||
|
* <a href="https://download.oracle.com/otndocs/jcp/jaxrs-2_0-fr-eval-spec/index.html">See JAX RS 2.0 Specification, section 3.2, p. 12</a>
|
||||||
|
*/
|
||||||
|
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<FakeTestsDefaultsDefaultResponse, FakeTestsDefaultsDefaultResponseBuilderImpl> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected FakeTestsDefaultsDefaultResponseBuilderImpl self() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FakeTestsDefaultsDefaultResponse build() {
|
||||||
|
return new FakeTestsDefaultsDefaultResponse(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static abstract class FakeTestsDefaultsDefaultResponseBuilder<C extends FakeTestsDefaultsDefaultResponse, B extends FakeTestsDefaultsDefaultResponseBuilder<C, B>> {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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
|
||||||
|
* <a href="https://download.oracle.com/otndocs/jcp/jaxrs-2_0-fr-eval-spec/index.html">See JAX RS 2.0 Specification, section 3.2, p. 12</a>
|
||||||
|
*/
|
||||||
|
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 + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -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
|
||||||
|
* <a href="https://download.oracle.com/otndocs/jcp/jaxrs-2_0-fr-eval-spec/index.html">See JAX RS 2.0 Specification, section 3.2, p. 12</a>
|
||||||
|
*/
|
||||||
|
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 + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -1484,6 +1484,23 @@ paths:
|
|||||||
- application/json
|
- application/json
|
||||||
x-tags:
|
x-tags:
|
||||||
- tag: fake
|
- 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:
|
components:
|
||||||
requestBodies:
|
requestBodies:
|
||||||
UserArray:
|
UserArray:
|
||||||
@ -2260,6 +2277,20 @@ components:
|
|||||||
- user
|
- user
|
||||||
title: SingleRefType
|
title: SingleRefType
|
||||||
type: string
|
type: string
|
||||||
|
StringEnum:
|
||||||
|
default: foo
|
||||||
|
enum:
|
||||||
|
- foo
|
||||||
|
- bar
|
||||||
|
- baz
|
||||||
|
type: string
|
||||||
|
IntegerEnum:
|
||||||
|
default: 1
|
||||||
|
enum:
|
||||||
|
- 1
|
||||||
|
- 2
|
||||||
|
- 3
|
||||||
|
type: integer
|
||||||
_foo_get_default_response:
|
_foo_get_default_response:
|
||||||
example:
|
example:
|
||||||
string:
|
string:
|
||||||
@ -2422,6 +2453,32 @@ components:
|
|||||||
required:
|
required:
|
||||||
- requiredFile
|
- requiredFile
|
||||||
type: object
|
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:
|
securitySchemes:
|
||||||
petstore_auth:
|
petstore_auth:
|
||||||
flows:
|
flows:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user