diff --git a/modules/swagger-core/src/main/java/io/swagger/v3/core/util/DeserializationModule31.java b/modules/swagger-core/src/main/java/io/swagger/v3/core/util/DeserializationModule31.java index b9003784e4..1657c5f7b9 100644 --- a/modules/swagger-core/src/main/java/io/swagger/v3/core/util/DeserializationModule31.java +++ b/modules/swagger-core/src/main/java/io/swagger/v3/core/util/DeserializationModule31.java @@ -1,6 +1,11 @@ package io.swagger.v3.core.util; +import com.fasterxml.jackson.databind.BeanDescription; +import com.fasterxml.jackson.databind.DeserializationConfig; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.deser.BeanDeserializerModifier; import com.fasterxml.jackson.databind.module.SimpleModule; +import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.Paths; import io.swagger.v3.oas.models.callbacks.Callback; import io.swagger.v3.oas.models.headers.Header; @@ -26,5 +31,15 @@ public DeserializationModule31() { this.addDeserializer(ApiResponses.class, new ApiResponses31Deserializer()); this.addDeserializer(Paths.class, new Paths31Deserializer()); this.addDeserializer(Callback.class, new Callback31Deserializer()); + + this.setDeserializerModifier(new BeanDeserializerModifier() + { + @Override public JsonDeserializer modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer deserializer) { + if (beanDesc.getBeanClass() == OpenAPI.class) { + return new OpenAPI31Deserializer(deserializer); + } + return deserializer; + } + }); } } diff --git a/modules/swagger-core/src/main/java/io/swagger/v3/core/util/OpenAPI31Deserializer.java b/modules/swagger-core/src/main/java/io/swagger/v3/core/util/OpenAPI31Deserializer.java new file mode 100644 index 0000000000..16e64b2ac5 --- /dev/null +++ b/modules/swagger-core/src/main/java/io/swagger/v3/core/util/OpenAPI31Deserializer.java @@ -0,0 +1,36 @@ +package io.swagger.v3.core.util; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.deser.ResolvableDeserializer; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.SpecVersion; + +import java.io.IOException; + +public class OpenAPI31Deserializer extends StdDeserializer implements ResolvableDeserializer { + + private final JsonDeserializer defaultDeserializer; + + public OpenAPI31Deserializer(JsonDeserializer defaultDeserializer) + { + super(OpenAPI.class); + this.defaultDeserializer = defaultDeserializer; + } + + @Override + public OpenAPI deserialize(JsonParser jp, DeserializationContext ctxt) + throws IOException, JsonProcessingException { + OpenAPI openAPI = (OpenAPI) defaultDeserializer.deserialize(jp, ctxt); + openAPI.setSpecVersion(SpecVersion.V31); + return openAPI; + } + @Override public void resolve(DeserializationContext ctxt) throws JsonMappingException { + ((ResolvableDeserializer) defaultDeserializer).resolve(ctxt); + } +} + diff --git a/modules/swagger-models/src/main/java/io/swagger/v3/oas/models/media/Schema.java b/modules/swagger-models/src/main/java/io/swagger/v3/oas/models/media/Schema.java index 242c7cda3e..89229cbd3a 100644 --- a/modules/swagger-models/src/main/java/io/swagger/v3/oas/models/media/Schema.java +++ b/modules/swagger-models/src/main/java/io/swagger/v3/oas/models/media/Schema.java @@ -1,6 +1,7 @@ package io.swagger.v3.oas.models.media; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.sun.org.apache.xpath.internal.operations.Bool; import io.swagger.v3.oas.models.annotations.OpenAPI30; import io.swagger.v3.oas.models.annotations.OpenAPI31; import io.swagger.v3.oas.models.Components; @@ -26,6 +27,8 @@ public class Schema { + public static final String BIND_TYPE_AND_TYPES = "bind-type"; + protected T _default; private String name; @@ -1110,6 +1113,10 @@ public Schema addRequiredItem(String requiredItem) { **/ public String getType() { + boolean bindTypes = Boolean.valueOf(System.getProperty(BIND_TYPE_AND_TYPES, "false")); + if (bindTypes && type == null && types != null && types.size() == 1) { + return types.iterator().next(); + } return type; }