diff --git a/core/src/main/java/io/smallrye/openapi/runtime/scanner/OpenApiDataObjectScanner.java b/core/src/main/java/io/smallrye/openapi/runtime/scanner/OpenApiDataObjectScanner.java index befe05083..0deca9b4d 100644 --- a/core/src/main/java/io/smallrye/openapi/runtime/scanner/OpenApiDataObjectScanner.java +++ b/core/src/main/java/io/smallrye/openapi/runtime/scanner/OpenApiDataObjectScanner.java @@ -67,27 +67,31 @@ */ public class OpenApiDataObjectScanner { - // Object - public static final Type OBJECT_TYPE = Type.create(DotName.createSimple(java.lang.Object.class.getName()), Type.Kind.CLASS); // Collection (list-type things) public static final DotName COLLECTION_INTERFACE_NAME = DotName.createSimple(Collection.class.getName()); public static final Type COLLECTION_TYPE = Type.create(COLLECTION_INTERFACE_NAME, Type.Kind.CLASS); + // Iterable (also list-type things) public static final DotName ITERABLE_INTERFACE_NAME = DotName.createSimple(Iterable.class.getName()); public static final Type ITERABLE_TYPE = Type.create(ITERABLE_INTERFACE_NAME, Type.Kind.CLASS); + // Map public static final DotName MAP_INTERFACE_NAME = DotName.createSimple(Map.class.getName()); public static final Type MAP_TYPE = Type.create(MAP_INTERFACE_NAME, Type.Kind.CLASS); + // Set public static final DotName SET_INTERFACE_NAME = DotName.createSimple(java.util.Set.class.getName()); public static final Type SET_TYPE = Type.create(SET_INTERFACE_NAME, Type.Kind.CLASS); + // Enum public static final DotName ENUM_INTERFACE_NAME = DotName.createSimple(Enum.class.getName()); public static final Type ENUM_TYPE = Type.create(ENUM_INTERFACE_NAME, Type.Kind.CLASS); + // String type public static final Type STRING_TYPE = Type.create(DotName.createSimple(String.class.getName()), Type.Kind.CLASS); + // Array type - public static final Type ARRAY_TYPE_OBJECT = Type.create(DotName.createSimple("[Ljava.lang.Object;"), Type.Kind.ARRAY); + public static final Type ARRAY_TYPE_OBJECT = Type.create(DotName.createSimple(Map[].class.getName()), Type.Kind.ARRAY); private static ClassInfo collectionStandin; private static ClassInfo iterableStandin; diff --git a/core/src/main/java/io/smallrye/openapi/runtime/scanner/dataobject/TypeProcessor.java b/core/src/main/java/io/smallrye/openapi/runtime/scanner/dataobject/TypeProcessor.java index 14ccb9fb2..e90c3fdf1 100644 --- a/core/src/main/java/io/smallrye/openapi/runtime/scanner/dataobject/TypeProcessor.java +++ b/core/src/main/java/io/smallrye/openapi/runtime/scanner/dataobject/TypeProcessor.java @@ -5,7 +5,6 @@ import static io.smallrye.openapi.runtime.scanner.OpenApiDataObjectScanner.ENUM_TYPE; import static io.smallrye.openapi.runtime.scanner.OpenApiDataObjectScanner.ITERABLE_TYPE; import static io.smallrye.openapi.runtime.scanner.OpenApiDataObjectScanner.MAP_TYPE; -import static io.smallrye.openapi.runtime.scanner.OpenApiDataObjectScanner.OBJECT_TYPE; import static io.smallrye.openapi.runtime.scanner.OpenApiDataObjectScanner.SET_TYPE; import static io.smallrye.openapi.runtime.scanner.OpenApiDataObjectScanner.STRING_TYPE; import static io.smallrye.openapi.runtime.util.TypeUtil.isTerminalType; @@ -128,7 +127,7 @@ public Type processType() { // Raw Map if (isA(type, MAP_TYPE)) { - return OBJECT_TYPE; + return MAP_TYPE; } // Simple case: bare class or primitive type. @@ -225,7 +224,7 @@ private Type readParameterizedType(ParameterizedType pType, Schema schema) { schema.additionalPropertiesSchema(readGenericValueType(valueType, schema)); } - typeRead = OBJECT_TYPE; + typeRead = MAP_TYPE; if (TypeUtil.allowRegistration(context, pType)) { // This type will be inspected later, if necessary. diff --git a/core/src/main/java/io/smallrye/openapi/runtime/util/TypeUtil.java b/core/src/main/java/io/smallrye/openapi/runtime/util/TypeUtil.java index d57aed7fc..a576bf111 100644 --- a/core/src/main/java/io/smallrye/openapi/runtime/util/TypeUtil.java +++ b/core/src/main/java/io/smallrye/openapi/runtime/util/TypeUtil.java @@ -60,6 +60,7 @@ public class TypeUtil { private static final DotName DOTNAME_VOID = DotName.createSimple(Void.class.getName()); private static final String UUID_PATTERN = "[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}"; + private static final TypeWithFormat ANY = TypeWithFormat.anyType().build(); private static final TypeWithFormat STRING_FORMAT = TypeWithFormat.of(SchemaType.STRING).build(); private static final TypeWithFormat BINARY_FORMAT = TypeWithFormat.of(SchemaType.STRING).format(DataFormat.BINARY).build(); private static final TypeWithFormat BYTE_FORMAT = TypeWithFormat.of(SchemaType.STRING).format(DataFormat.BYTE).build(); @@ -118,6 +119,8 @@ public class TypeUtil { // https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#dataTypeFormat static { + TYPE_MAP.put(DOTNAME_OBJECT, ANY); + // String TYPE_MAP.put(DotName.createSimple(String.class.getName()), STRING_FORMAT); TYPE_MAP.put(DotName.createSimple(StringBuffer.class.getName()), STRING_FORMAT); @@ -963,7 +966,6 @@ static class Builder { private boolean opaque; Builder(SchemaType schemaType) { - Objects.requireNonNull(schemaType); properties.put(SchemaConstant.PROP_TYPE, schemaType); } @@ -1005,9 +1007,14 @@ TypeWithFormat build() { } static Builder of(SchemaType schemaType) { + Objects.requireNonNull(schemaType); return new Builder(schemaType); } + static Builder anyType() { + return new Builder(null); + } + private final Map properties; private final boolean opaque; @@ -1017,8 +1024,8 @@ private TypeWithFormat(Map properties, boolean opaque) { } boolean isSchemaType(SchemaType... schemaTypes) { - return Arrays.stream(schemaTypes) - .anyMatch(properties.get(SchemaConstant.PROP_TYPE)::equals); + SchemaType type = (SchemaType) properties.get(SchemaConstant.PROP_TYPE); + return type != null && Arrays.stream(schemaTypes).anyMatch(type::equals); } Map getProperties() { diff --git a/core/src/test/resources/io/smallrye/openapi/runtime/scanner/components.schemas.field-overrides-type.json b/core/src/test/resources/io/smallrye/openapi/runtime/scanner/components.schemas.field-overrides-type.json index fb9367f0d..22177fe12 100644 --- a/core/src/test/resources/io/smallrye/openapi/runtime/scanner/components.schemas.field-overrides-type.json +++ b/core/src/test/resources/io/smallrye/openapi/runtime/scanner/components.schemas.field-overrides-type.json @@ -42,7 +42,6 @@ "type": "string" }, "prop2": { - "type": "object" } } } diff --git a/core/src/test/resources/io/smallrye/openapi/runtime/scanner/components.schemas.nonparameterized-ancestry-chain-link.json b/core/src/test/resources/io/smallrye/openapi/runtime/scanner/components.schemas.nonparameterized-ancestry-chain-link.json index fb564eafc..a3b8b02c3 100644 --- a/core/src/test/resources/io/smallrye/openapi/runtime/scanner/components.schemas.nonparameterized-ancestry-chain-link.json +++ b/core/src/test/resources/io/smallrye/openapi/runtime/scanner/components.schemas.nonparameterized-ancestry-chain-link.json @@ -5,7 +5,6 @@ "1PairStringString": { "type": "array", "items": { - "type": "object" } }, "TestBean": { diff --git a/core/src/test/resources/io/smallrye/openapi/runtime/scanner/components.schemas.registered-schema-type-preserved.json b/core/src/test/resources/io/smallrye/openapi/runtime/scanner/components.schemas.registered-schema-type-preserved.json index 383b80024..360e1036d 100644 --- a/core/src/test/resources/io/smallrye/openapi/runtime/scanner/components.schemas.registered-schema-type-preserved.json +++ b/core/src/test/resources/io/smallrye/openapi/runtime/scanner/components.schemas.registered-schema-type-preserved.json @@ -115,8 +115,7 @@ "example": "F176f717c7a71" }, "data": { - "description": "The business data object", - "type": "object" + "description": "The business data object" }, "kind": { "description": "The class-name of the business data object", diff --git a/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/generic.complexNesting.expected.json b/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/generic.complexNesting.expected.json index 37c402410..001579b9a 100644 --- a/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/generic.complexNesting.expected.json +++ b/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/generic.complexNesting.expected.json @@ -22,7 +22,6 @@ "type" : "object", "properties" : { "bar" : { - "type" : "object" }, "foo" : { "maxLength" : 123456, @@ -62,7 +61,6 @@ "type" : "object", "properties" : { "bar" : { - "type" : "object" }, "foo" : { "maxLength" : 123456, @@ -102,7 +100,6 @@ "type" : "object", "properties" : { "bar" : { - "type" : "object" }, "foo" : { "maxLength" : 123456, diff --git a/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/generic.withBounds.expected.json b/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/generic.withBounds.expected.json index 97b8cf10c..133eac1c1 100644 --- a/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/generic.withBounds.expected.json +++ b/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/generic.withBounds.expected.json @@ -6,7 +6,6 @@ "required" : [ "bar", "foo" ], "properties" : { "bar" : { - "type" : "object" }, "foo" : { "format" : "int32", diff --git a/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/params.method-target-nojaxrs.json b/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/params.method-target-nojaxrs.json index 58ddeb7ae..4ead02b34 100644 --- a/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/params.method-target-nojaxrs.json +++ b/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/params.method-target-nojaxrs.json @@ -177,7 +177,6 @@ "data": { "type": "array", "items": { - "type": "object" } } } diff --git a/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/refsEnabled.generic.complexNesting.expected.json b/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/refsEnabled.generic.complexNesting.expected.json index 01741bde9..464717dfd 100644 --- a/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/refsEnabled.generic.complexNesting.expected.json +++ b/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/refsEnabled.generic.complexNesting.expected.json @@ -9,7 +9,6 @@ "type": "object", "properties": { "bar": { - "type": "object" }, "foo": { "type": "object", diff --git a/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/refsEnabled.generic.withBounds.expected.json b/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/refsEnabled.generic.withBounds.expected.json index 424937708..6e54cc351 100644 --- a/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/refsEnabled.generic.withBounds.expected.json +++ b/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/refsEnabled.generic.withBounds.expected.json @@ -6,7 +6,6 @@ "required" : [ "bar", "foo" ], "properties" : { "bar" : { - "type" : "object" }, "foo" : { "format" : "int32", diff --git a/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/refsEnabled.kitchenSink.expected.json b/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/refsEnabled.kitchenSink.expected.json index 5a2a32ce0..64aea62b5 100644 --- a/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/refsEnabled.kitchenSink.expected.json +++ b/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/refsEnabled.kitchenSink.expected.json @@ -21,13 +21,11 @@ "type": "object", "properties": { "theQ": { - "type": "object" }, "theT": { "$ref": "#/components/schemas/Baz" }, "ultimateTShouldBeQ": { - "type": "object" } } }, @@ -186,14 +184,11 @@ "type": "object", "properties": { "qAgain": { - "type": "object" }, "qAgain3": { - "type": "object" }, "qValue": { - "description": "Ah, Q, my favourite variable!", - "type": "object" + "description": "Ah, Q, my favourite variable!" }, "tAgain2": { "type": "string" @@ -306,7 +301,6 @@ "type": "object", "properties": { "bar": { - "type": "object" }, "foo": { "maxLength": 123456, @@ -418,7 +412,6 @@ "barSuper": { "type": "array", "items": { - "type": "object" } }, "bareCollection": { @@ -433,7 +426,6 @@ "blahMap": { "type": "object", "additionalProperties": { - "type": "object" } }, "booking": { diff --git a/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/refsEnabled.unresolvable.expected.json b/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/refsEnabled.unresolvable.expected.json index e426e9400..23acff404 100644 --- a/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/refsEnabled.unresolvable.expected.json +++ b/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/refsEnabled.unresolvable.expected.json @@ -14,13 +14,11 @@ "type": "object", "properties": { "theQ": { - "type": "object" }, "theT": { "$ref": "#/components/schemas/Baz" }, "ultimateTShouldBeQ": { - "type": "object" } } } diff --git a/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/resource.testCsvConsumesProduces.json b/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/resource.testCsvConsumesProduces.json index bc4cba960..71e43988e 100644 --- a/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/resource.testCsvConsumesProduces.json +++ b/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/resource.testCsvConsumesProduces.json @@ -1,68 +1,59 @@ { - "openapi" : "3.0.3", - "paths" : { - "/multi-produce-consume" : { - "get" : { - "responses" : { - "200" : { - "description" : "OK", - "content" : { - "text/plain" : { - "schema" : { - "type" : "object" + "openapi": "3.0.3", + "paths": { + "/multi-produce-consume": { + "get": { + "responses": { + "200": { + "description": "OK", + "content": { + "text/plain": { + "schema": { } } } } } }, - "post" : { - "requestBody" : { - "content" : { - "text/plain" : { - "schema" : { - "type" : "object" + "post": { + "requestBody": { + "content": { + "text/plain": { + "schema": { } }, - "text/html" : { - "schema" : { - "type" : "object" + "text/html": { + "schema": { } }, - "application/json" : { - "schema" : { - "type" : "object" + "application/json": { + "schema": { } }, - "application/xml" : { - "schema" : { - "type" : "object" + "application/xml": { + "schema": { } } } }, - "responses" : { - "200" : { - "description" : "OK", - "content" : { - "application/json" : { - "schema" : { - "type" : "object" + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { } }, - "application/xml" : { - "schema" : { - "type" : "object" + "application/xml": { + "schema": { } }, - "text/plain" : { - "schema" : { - "type" : "object" + "text/plain": { + "schema": { } }, - "text/html" : { - "schema" : { - "type" : "object" + "text/html": { + "schema": { } } } @@ -71,4 +62,4 @@ } } } -} +} \ No newline at end of file diff --git a/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/special.wildcard.expected.json b/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/special.wildcard.expected.json index e58f7722e..2e5cda041 100644 --- a/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/special.wildcard.expected.json +++ b/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/special.wildcard.expected.json @@ -1,10 +1,9 @@ { - "components" : { - "schemas" : { - "test.io.smallrye.openapi.runtime.scanner.entities.SpecialCaseTestContainer" : { - "type" : "array", - "items" : { - "type" : "object" + "components": { + "schemas": { + "test.io.smallrye.openapi.runtime.scanner.entities.SpecialCaseTestContainer": { + "type": "array", + "items": { } } } diff --git a/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/special.wildcardWithSuperBound.expected.json b/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/special.wildcardWithSuperBound.expected.json index e58f7722e..2e5cda041 100644 --- a/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/special.wildcardWithSuperBound.expected.json +++ b/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/special.wildcardWithSuperBound.expected.json @@ -1,10 +1,9 @@ { - "components" : { - "schemas" : { - "test.io.smallrye.openapi.runtime.scanner.entities.SpecialCaseTestContainer" : { - "type" : "array", - "items" : { - "type" : "object" + "components": { + "schemas": { + "test.io.smallrye.openapi.runtime.scanner.entities.SpecialCaseTestContainer": { + "type": "array", + "items": { } } } diff --git a/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/unresolvable.expected.json b/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/unresolvable.expected.json index 79a04564c..88bda96de 100644 --- a/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/unresolvable.expected.json +++ b/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/unresolvable.expected.json @@ -1,23 +1,21 @@ { - "components" : { - "schemas" : { - "test.io.smallrye.openapi.runtime.scanner.entities.Bar" : { + "components": { + "schemas": { + "test.io.smallrye.openapi.runtime.scanner.entities.Bar": { "type": "object", - "properties" : { - "theQ" : { - "type" : "object" + "properties": { + "theQ": { }, - "theT" : { - "type" : "object", - "properties" : { - "an_integer_value" : { - "format" : "int32", - "type" : "integer" + "theT": { + "type": "object", + "properties": { + "an_integer_value": { + "format": "int32", + "type": "integer" } } }, - "ultimateTShouldBeQ" : { - "type" : "object" + "ultimateTShouldBeQ": { } } } diff --git a/testsuite/data/src/main/java/io/smallrye/openapi/testdata/java/Marker.java b/testsuite/data/src/main/java/io/smallrye/openapi/testdata/java/Marker.java new file mode 100644 index 000000000..8d26e6e6f --- /dev/null +++ b/testsuite/data/src/main/java/io/smallrye/openapi/testdata/java/Marker.java @@ -0,0 +1,5 @@ +package io.smallrye.openapi.testdata.java; + +public interface Marker { + +}