From a7b52ec114f9aba97b7ffb6d7bb1b04b630b710a Mon Sep 17 00:00:00 2001 From: Geir Sagberg Date: Sat, 5 Nov 2022 21:09:06 +0100 Subject: [PATCH] feat: create schema reference for enum types (#368) --- CHANGELOG.md | 3 + .../io/bkbn/kompendium/core/util/Helpers.kt | 7 +- .../io/bkbn/kompendium/core/KompendiumTest.kt | 4 + .../bkbn/kompendium/core/util/TestModules.kt | 6 +- .../test/resources/T0008__complex_type.json | 12 ++- .../resources/T0036__nullable_fields.json | 49 +++++------- .../resources/T0037__nullable_enum_field.json | 15 ++-- ...__nested_generic_multiple_type_params.json | 12 ++- .../resources/T0042__simple_recursive.json | 14 ++-- .../resources/T0049__unbacked_property.json | 4 +- .../resources/T0051__top_level_nullable.json | 79 +++++++++++++++++++ .../kompendium/core/fixtures/TestModels.kt | 13 ++- .../kompendium/json/schema/SchemaGenerator.kt | 2 +- .../json/schema/definition/EnumDefinition.kt | 1 + .../json/schema/handler/EnumHandler.kt | 15 ++-- .../schema/handler/SimpleObjectHandler.kt | 20 +++-- .../json/schema/SchemaGeneratorTest.kt | 10 ++- .../resources/T0006__nullable_object.json | 29 +++---- .../test/resources/T0007__simple_enum.json | 3 +- .../test/resources/T0008__nullable_enum.json | 13 +-- .../resources/T0021__object_with_enum.json | 11 +++ 21 files changed, 218 insertions(+), 104 deletions(-) create mode 100644 core/src/test/resources/T0051__top_level_nullable.json create mode 100644 json-schema/src/test/resources/T0021__object_with_enum.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 98b352112..e204856cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ ### Changed +- Schemas for types in nullable properties are no longer nullable themselves +- Enums are now generated as references, which makes it possible to generate types for them + ### Remove --- diff --git a/core/src/main/kotlin/io/bkbn/kompendium/core/util/Helpers.kt b/core/src/main/kotlin/io/bkbn/kompendium/core/util/Helpers.kt index 452594635..c9e15797b 100644 --- a/core/src/main/kotlin/io/bkbn/kompendium/core/util/Helpers.kt +++ b/core/src/main/kotlin/io/bkbn/kompendium/core/util/Helpers.kt @@ -12,6 +12,8 @@ import io.bkbn.kompendium.core.metadata.PutInfo import io.bkbn.kompendium.core.metadata.ResponseInfo import io.bkbn.kompendium.json.schema.SchemaConfigurator import io.bkbn.kompendium.json.schema.SchemaGenerator +import io.bkbn.kompendium.json.schema.definition.NullableDefinition +import io.bkbn.kompendium.json.schema.definition.OneOfDefinition import io.bkbn.kompendium.json.schema.definition.ReferenceDefinition import io.bkbn.kompendium.json.schema.util.Helpers.getReferenceSlug import io.bkbn.kompendium.json.schema.util.Helpers.getSimpleSlug @@ -108,7 +110,10 @@ object Helpers { Unit::class -> null else -> mapOf( "application/json" to MediaType( - schema = ReferenceDefinition(this.getReferenceSlug()), + schema = if (this.isMarkedNullable) OneOfDefinition( + NullableDefinition(), + ReferenceDefinition(this.getReferenceSlug()) + ) else ReferenceDefinition(this.getReferenceSlug()), examples = examples ) ) diff --git a/core/src/test/kotlin/io/bkbn/kompendium/core/KompendiumTest.kt b/core/src/test/kotlin/io/bkbn/kompendium/core/KompendiumTest.kt index b0597c906..e833c0099 100644 --- a/core/src/test/kotlin/io/bkbn/kompendium/core/KompendiumTest.kt +++ b/core/src/test/kotlin/io/bkbn/kompendium/core/KompendiumTest.kt @@ -49,6 +49,7 @@ import io.bkbn.kompendium.core.util.TestModules.simpleGenericResponse import io.bkbn.kompendium.core.util.TestModules.simplePathParsing import io.bkbn.kompendium.core.util.TestModules.simpleRecursive import io.bkbn.kompendium.core.util.TestModules.singleException +import io.bkbn.kompendium.core.util.TestModules.topLevelNullable import io.bkbn.kompendium.core.util.TestModules.trailingSlash import io.bkbn.kompendium.core.util.TestModules.unbackedFieldsResponse import io.bkbn.kompendium.core.util.TestModules.withOperationId @@ -243,6 +244,9 @@ class KompendiumTest : DescribeSpec({ it("Can handle nested type names") { openApiTestAllSerializers("T0044__nested_type_name.json") { nestedTypeName() } } + it("Can handle top level nullable types") { + openApiTestAllSerializers("T0051__top_level_nullable.json") { topLevelNullable() } + } } describe("Error Handling") { it("Throws a clear exception when an unidentified type is encountered") { diff --git a/core/src/test/kotlin/io/bkbn/kompendium/core/util/TestModules.kt b/core/src/test/kotlin/io/bkbn/kompendium/core/util/TestModules.kt index aecb2e798..3a49e5092 100644 --- a/core/src/test/kotlin/io/bkbn/kompendium/core/util/TestModules.kt +++ b/core/src/test/kotlin/io/bkbn/kompendium/core/util/TestModules.kt @@ -24,7 +24,7 @@ import io.bkbn.kompendium.core.fixtures.TestRequest import io.bkbn.kompendium.core.fixtures.TestResponse import io.bkbn.kompendium.core.fixtures.TestSimpleRequest import io.bkbn.kompendium.core.fixtures.TransientObject -import io.bkbn.kompendium.core.fixtures.UnbakcedObject +import io.bkbn.kompendium.core.fixtures.UnbackedObject import io.bkbn.kompendium.core.metadata.DeleteInfo import io.bkbn.kompendium.core.metadata.GetInfo import io.bkbn.kompendium.core.metadata.HeadInfo @@ -568,7 +568,7 @@ object TestModules { fun Routing.ignoredFieldsResponse() = basicGetGenerator() - fun Routing.unbackedFieldsResponse() = basicGetGenerator() + fun Routing.unbackedFieldsResponse() = basicGetGenerator() fun Routing.customFieldNameResponse() = basicGetGenerator() @@ -613,6 +613,8 @@ object TestModules { fun Routing.nestedTypeName() = basicGetGenerator() + fun Routing.topLevelNullable() = basicGetGenerator() + fun Routing.simpleRecursive() = basicGetGenerator() fun Routing.defaultAuthConfig() { diff --git a/core/src/test/resources/T0008__complex_type.json b/core/src/test/resources/T0008__complex_type.json index d3ea01721..4b2b62438 100644 --- a/core/src/test/resources/T0008__complex_type.json +++ b/core/src/test/resources/T0008__complex_type.json @@ -124,15 +124,19 @@ "type": "object", "properties": { "enumeration": { - "enum": [ - "ONE", - "TWO" - ] + "$ref": "#/components/schemas/SimpleEnum" } }, "required": [ "enumeration" ] + }, + "SimpleEnum": { + "type": "string", + "enum": [ + "ONE", + "TWO" + ] } }, "securitySchemes": {} diff --git a/core/src/test/resources/T0036__nullable_fields.json b/core/src/test/resources/T0036__nullable_fields.json index 07d038445..97a2d2571 100644 --- a/core/src/test/resources/T0036__nullable_fields.json +++ b/core/src/test/resources/T0036__nullable_fields.json @@ -91,37 +91,30 @@ "required": [] }, "ProfileMetadataUpdateRequest": { - "oneOf": [ - { - "type": "null" - }, - { - "type": "object", - "properties": { - "isPrivate": { - "oneOf": [ - { - "type": "null" - }, - { - "type": "boolean" - } - ] + "type": "object", + "properties": { + "isPrivate": { + "oneOf": [ + { + "type": "null" }, - "otherThing": { - "oneOf": [ - { - "type": "null" - }, - { - "type": "string" - } - ] + { + "type": "boolean" } - }, - "required": [] + ] + }, + "otherThing": { + "oneOf": [ + { + "type": "null" + }, + { + "type": "string" + } + ] } - ] + }, + "required": [] } }, "securitySchemes": {} diff --git a/core/src/test/resources/T0037__nullable_enum_field.json b/core/src/test/resources/T0037__nullable_enum_field.json index 35484c30d..4fc208e5e 100644 --- a/core/src/test/resources/T0037__nullable_enum_field.json +++ b/core/src/test/resources/T0037__nullable_enum_field.json @@ -62,16 +62,21 @@ "type": "null" }, { - "enum": [ - "YES", - "NO" - ] + "$ref": "#/components/schemas/TestEnum" } ] } }, "required": [] - } + }, + "TestEnum": + { + "type": "string", + "enum": [ + "YES", + "NO" + ] + } }, "securitySchemes": {} }, diff --git a/core/src/test/resources/T0040__nested_generic_multiple_type_params.json b/core/src/test/resources/T0040__nested_generic_multiple_type_params.json index ab4a72f56..946a3da1d 100644 --- a/core/src/test/resources/T0040__nested_generic_multiple_type_params.json +++ b/core/src/test/resources/T0040__nested_generic_multiple_type_params.json @@ -57,10 +57,7 @@ "type": "object", "properties": { "enumeration": { - "enum": [ - "ONE", - "TWO" - ] + "$ref": "#/components/schemas/SimpleEnum" } }, "required": [ @@ -120,6 +117,13 @@ "required": [ "content" ] + }, + "SimpleEnum": { + "type": "string", + "enum": [ + "ONE", + "TWO" + ] } }, "securitySchemes": {} diff --git a/core/src/test/resources/T0042__simple_recursive.json b/core/src/test/resources/T0042__simple_recursive.json index 22d34fda3..df4557942 100644 --- a/core/src/test/resources/T0042__simple_recursive.json +++ b/core/src/test/resources/T0042__simple_recursive.json @@ -53,6 +53,14 @@ "webhooks": {}, "components": { "schemas": { + "ColumnMode": { + "type": "string", + "enum": [ + "NULLABLE", + "REQUIRED", + "REPEATED" + ] + }, "ColumnSchema": { "type": "object", "properties": { @@ -60,11 +68,7 @@ "type": "string" }, "mode": { - "enum": [ - "NULLABLE", - "REQUIRED", - "REPEATED" - ] + "$ref": "#/components/schemas/ColumnMode" }, "name": { "type": "string" diff --git a/core/src/test/resources/T0049__unbacked_property.json b/core/src/test/resources/T0049__unbacked_property.json index 1237e4d69..d3c9cfa18 100644 --- a/core/src/test/resources/T0049__unbacked_property.json +++ b/core/src/test/resources/T0049__unbacked_property.json @@ -39,7 +39,7 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/UnbakcedObject" + "$ref": "#/components/schemas/UnbackedObject" } } } @@ -53,7 +53,7 @@ "webhooks": {}, "components": { "schemas": { - "UnbakcedObject": { + "UnbackedObject": { "type": "object", "properties": { "backed": { diff --git a/core/src/test/resources/T0051__top_level_nullable.json b/core/src/test/resources/T0051__top_level_nullable.json new file mode 100644 index 000000000..b6864d180 --- /dev/null +++ b/core/src/test/resources/T0051__top_level_nullable.json @@ -0,0 +1,79 @@ +{ + "openapi": "3.1.0", + "jsonSchemaDialect": "https://json-schema.org/draft/2020-12/schema", + "info": { + "title": "Test API", + "version": "1.33.7", + "description": "An amazing, fully-ish 😉 generated API spec", + "termsOfService": "https://example.com", + "contact": { + "name": "Homer Simpson", + "url": "https://gph.is/1NPUDiM", + "email": "chunkylover53@aol.com" + }, + "license": { + "name": "MIT", + "url": "https://github.com/bkbnio/kompendium/blob/main/LICENSE" + } + }, + "servers": [ + { + "url": "https://myawesomeapi.com", + "description": "Production instance of my API" + }, + { + "url": "https://staging.myawesomeapi.com", + "description": "Where the fun stuff happens" + } + ], + "paths": { + "/": { + "get": { + "tags": [], + "summary": "Great Summary!", + "description": "testing more", + "parameters": [], + "responses": { + "200": { + "description": "A Successful Endeavor", + "content": { + "application/json": { + "schema": { + "oneOf": [ + { + "type": "null" + }, + { + "$ref": "#/components/schemas/TestResponse" + } + ] + } + } + } + } + }, + "deprecated": false + }, + "parameters": [] + } + }, + "webhooks": {}, + "components": { + "schemas": { + "TestResponse": { + "type": "object", + "properties": { + "c": { + "type": "string" + } + }, + "required": [ + "c" + ] + } + }, + "securitySchemes": {} + }, + "security": [], + "tags": [] +} diff --git a/core/src/testFixtures/kotlin/io/bkbn/kompendium/core/fixtures/TestModels.kt b/core/src/testFixtures/kotlin/io/bkbn/kompendium/core/fixtures/TestModels.kt index c40679f9c..e144cac20 100644 --- a/core/src/testFixtures/kotlin/io/bkbn/kompendium/core/fixtures/TestModels.kt +++ b/core/src/testFixtures/kotlin/io/bkbn/kompendium/core/fixtures/TestModels.kt @@ -163,7 +163,7 @@ data class TransientObject( ) @Serializable -data class UnbakcedObject( +data class UnbackedObject( val backed: String ) { val unbacked: String get() = "unbacked" @@ -176,3 +176,14 @@ data class SerialNameObject( @SerialName("snake_case_name") val camelCaseName: String ) + +enum class Color { + RED, + GREEN, + BLUE +} + +@Serializable +data class ObjectWithEnum( + val color: Color +) diff --git a/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/SchemaGenerator.kt b/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/SchemaGenerator.kt index 561d2f0d1..9f3ff76ce 100644 --- a/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/SchemaGenerator.kt +++ b/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/SchemaGenerator.kt @@ -48,7 +48,7 @@ object SchemaGenerator { Boolean::class -> checkForNull(type, TypeDefinition.BOOLEAN) UUID::class -> checkForNull(type, TypeDefinition.UUID) else -> when { - clazz.isSubclassOf(Enum::class) -> EnumHandler.handle(type, clazz) + clazz.isSubclassOf(Enum::class) -> EnumHandler.handle(type, clazz, cache) clazz.isSubclassOf(Collection::class) -> CollectionHandler.handle(type, cache, schemaConfigurator) clazz.isSubclassOf(Map::class) -> MapHandler.handle(type, cache, schemaConfigurator) else -> { diff --git a/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/definition/EnumDefinition.kt b/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/definition/EnumDefinition.kt index 5da5c56cb..ceece821c 100644 --- a/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/definition/EnumDefinition.kt +++ b/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/definition/EnumDefinition.kt @@ -4,5 +4,6 @@ import kotlinx.serialization.Serializable @Serializable data class EnumDefinition( + val type: String, val enum: Set ) : JsonSchema diff --git a/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/EnumHandler.kt b/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/EnumHandler.kt index 965fd11bb..901fc8da6 100644 --- a/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/EnumHandler.kt +++ b/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/EnumHandler.kt @@ -2,18 +2,17 @@ package io.bkbn.kompendium.json.schema.handler import io.bkbn.kompendium.json.schema.definition.EnumDefinition import io.bkbn.kompendium.json.schema.definition.JsonSchema -import io.bkbn.kompendium.json.schema.definition.NullableDefinition -import io.bkbn.kompendium.json.schema.definition.OneOfDefinition +import io.bkbn.kompendium.json.schema.definition.ReferenceDefinition +import io.bkbn.kompendium.json.schema.util.Helpers.getReferenceSlug +import io.bkbn.kompendium.json.schema.util.Helpers.getSimpleSlug import kotlin.reflect.KClass import kotlin.reflect.KType object EnumHandler { - fun handle(type: KType, clazz: KClass<*>): JsonSchema { + fun handle(type: KType, clazz: KClass<*>, cache: MutableMap): JsonSchema { + cache[type.getSimpleSlug()] = ReferenceDefinition(type.getReferenceSlug()) + val options = clazz.java.enumConstants.map { it.toString() }.toSet() - val definition = EnumDefinition(enum = options) - return when (type.isMarkedNullable) { - true -> OneOfDefinition(NullableDefinition(), definition) - false -> definition - } + return EnumDefinition(type = "string", enum = options) } } diff --git a/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/SimpleObjectHandler.kt b/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/SimpleObjectHandler.kt index 2f5db94d1..25ed0d838 100644 --- a/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/SimpleObjectHandler.kt +++ b/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/SimpleObjectHandler.kt @@ -2,6 +2,7 @@ package io.bkbn.kompendium.json.schema.handler import io.bkbn.kompendium.json.schema.SchemaConfigurator import io.bkbn.kompendium.json.schema.SchemaGenerator +import io.bkbn.kompendium.json.schema.definition.EnumDefinition import io.bkbn.kompendium.json.schema.definition.JsonSchema import io.bkbn.kompendium.json.schema.definition.NullableDefinition import io.bkbn.kompendium.json.schema.definition.OneOfDefinition @@ -71,16 +72,11 @@ object SimpleObjectHandler { .map { schemaConfigurator.serializableName(it) } .toSet() - val definition = TypeDefinition( + return TypeDefinition( type = "object", properties = props, required = required ) - - return when (type.isMarkedNullable) { - true -> OneOfDefinition(NullableDefinition(), definition) - false -> definition - } } private fun KProperty<*>.needsToInjectGenerics( @@ -103,7 +99,7 @@ object SimpleObjectHandler { } val constructedType = propClass.createType(types) return SchemaGenerator.fromTypeToSchema(constructedType, cache, schemaConfigurator).let { - if (it.isOrContainsObjectDef()) { + if (it.isOrContainsObjectOrEnumDef()) { cache[constructedType.getSimpleSlug()] = it ReferenceDefinition(prop.returnType.getReferenceSlug()) } else { @@ -121,7 +117,7 @@ object SimpleObjectHandler { val type = typeMap[prop.returnType.classifier]?.type ?: error("This indicates a bug in Kompendium, please open a GitHub issue") return SchemaGenerator.fromTypeToSchema(type, cache, schemaConfigurator).let { - if (it.isOrContainsObjectDef()) { + if (it.isOrContainsObjectOrEnumDef()) { cache[type.getSimpleSlug()] = it ReferenceDefinition(type.getReferenceSlug()) } else { @@ -136,7 +132,7 @@ object SimpleObjectHandler { schemaConfigurator: SchemaConfigurator ): JsonSchema = SchemaGenerator.fromTypeToSchema(prop.returnType, cache, schemaConfigurator).let { - if (it.isOrContainsObjectDef()) { + if (it.isOrContainsObjectOrEnumDef()) { cache[prop.returnType.getSimpleSlug()] = it ReferenceDefinition(prop.returnType.getReferenceSlug()) } else { @@ -144,10 +140,12 @@ object SimpleObjectHandler { } } - private fun JsonSchema.isOrContainsObjectDef(): Boolean { + private fun JsonSchema.isOrContainsObjectOrEnumDef(): Boolean { val isTypeDef = this is TypeDefinition && type == "object" val isTypeDefOneOf = this is OneOfDefinition && this.oneOf.any { js -> js is TypeDefinition && js.type == "object" } - return isTypeDef || isTypeDefOneOf + val isEnumDef = this is EnumDefinition + val isEnumDefOneOf = this is OneOfDefinition && this.oneOf.any { js -> js is EnumDefinition } + return isTypeDef || isTypeDefOneOf || isEnumDef || isEnumDefOneOf } private fun JsonSchema.isNullable(): Boolean = this is OneOfDefinition && this.oneOf.any { it is NullableDefinition } diff --git a/json-schema/src/test/kotlin/io/bkbn/kompendium/json/schema/SchemaGeneratorTest.kt b/json-schema/src/test/kotlin/io/bkbn/kompendium/json/schema/SchemaGeneratorTest.kt index 5afbb13f9..b7db45220 100644 --- a/json-schema/src/test/kotlin/io/bkbn/kompendium/json/schema/SchemaGeneratorTest.kt +++ b/json-schema/src/test/kotlin/io/bkbn/kompendium/json/schema/SchemaGeneratorTest.kt @@ -2,6 +2,7 @@ package io.bkbn.kompendium.json.schema import io.bkbn.kompendium.core.fixtures.ComplexRequest import io.bkbn.kompendium.core.fixtures.FlibbityGibbit +import io.bkbn.kompendium.core.fixtures.ObjectWithEnum import io.bkbn.kompendium.core.fixtures.SerialNameObject import io.bkbn.kompendium.core.fixtures.SimpleEnum import io.bkbn.kompendium.core.fixtures.SlammaJamma @@ -9,7 +10,7 @@ import io.bkbn.kompendium.core.fixtures.TestHelpers.getFileSnapshot import io.bkbn.kompendium.core.fixtures.TestResponse import io.bkbn.kompendium.core.fixtures.TestSimpleRequest import io.bkbn.kompendium.core.fixtures.TransientObject -import io.bkbn.kompendium.core.fixtures.UnbakcedObject +import io.bkbn.kompendium.core.fixtures.UnbackedObject import io.bkbn.kompendium.json.schema.definition.JsonSchema import io.kotest.assertions.json.shouldEqualJson import io.kotest.assertions.throwables.shouldThrow @@ -40,6 +41,7 @@ class SchemaGeneratorTest : DescribeSpec({ jsonSchemaTest("T0005__complex_object.json") } it("Can generate the schema for a nullable object") { + // Same schema as a non-nullable type, since the nullability will be handled on the property jsonSchemaTest("T0006__nullable_object.json") } it("Can generate the schema for a polymorphic object") { @@ -52,7 +54,7 @@ class SchemaGeneratorTest : DescribeSpec({ jsonSchemaTest("T0018__transient_object.json") } it("Can generate the schema for object with unbacked property") { - jsonSchemaTest("T0019__unbacked_object.json") + jsonSchemaTest("T0019__unbacked_object.json") } it("Can generate the schema for object with SerialName annotation") { jsonSchemaTest("T0020__serial_name_object.json") @@ -63,8 +65,12 @@ class SchemaGeneratorTest : DescribeSpec({ jsonSchemaTest("T0007__simple_enum.json") } it("Can generate the schema for a nullable enum") { + // Same schema as a non-nullable enum, since the nullability will be handled on the property jsonSchemaTest("T0008__nullable_enum.json") } + it("Can generate the schema for an object with an enum property") { + jsonSchemaTest("T0021__object_with_enum.json") + } } describe("Arrays") { it("Can generate the schema for an array of scalars") { diff --git a/json-schema/src/test/resources/T0006__nullable_object.json b/json-schema/src/test/resources/T0006__nullable_object.json index 981b5ea17..873c85a2e 100644 --- a/json-schema/src/test/resources/T0006__nullable_object.json +++ b/json-schema/src/test/resources/T0006__nullable_object.json @@ -1,23 +1,16 @@ { - "oneOf": [ - { - "type": "null" + "type": "object", + "properties": { + "a": { + "type": "string" }, - { - "type": "object", - "properties": { - "a": { - "type": "string" - }, - "b": { - "type": "number", - "format": "int32" - } - }, - "required": [ - "a", - "b" - ] + "b": { + "type": "number", + "format": "int32" } + }, + "required": [ + "a", + "b" ] } diff --git a/json-schema/src/test/resources/T0007__simple_enum.json b/json-schema/src/test/resources/T0007__simple_enum.json index 19f2d782e..35a4f6dfc 100644 --- a/json-schema/src/test/resources/T0007__simple_enum.json +++ b/json-schema/src/test/resources/T0007__simple_enum.json @@ -1,3 +1,4 @@ { - "enum": [ "ONE", "TWO" ] + "enum": [ "ONE", "TWO" ], + "type": "string" } diff --git a/json-schema/src/test/resources/T0008__nullable_enum.json b/json-schema/src/test/resources/T0008__nullable_enum.json index 5c75d54dc..35a4f6dfc 100644 --- a/json-schema/src/test/resources/T0008__nullable_enum.json +++ b/json-schema/src/test/resources/T0008__nullable_enum.json @@ -1,13 +1,4 @@ { - "oneOf": [ - { - "type": "null" - }, - { - "enum": [ - "ONE", - "TWO" - ] - } - ] + "enum": [ "ONE", "TWO" ], + "type": "string" } diff --git a/json-schema/src/test/resources/T0021__object_with_enum.json b/json-schema/src/test/resources/T0021__object_with_enum.json new file mode 100644 index 000000000..0a9a23bca --- /dev/null +++ b/json-schema/src/test/resources/T0021__object_with_enum.json @@ -0,0 +1,11 @@ +{ + "type": "object", + "properties": { + "color": { + "$ref": "#/components/schemas/Color" + } + }, + "required": [ + "color" + ] +}