diff --git a/wow-openapi/src/main/kotlin/me/ahoo/wow/openapi/converter/BoundedContextConverter.kt b/wow-openapi/src/main/kotlin/me/ahoo/wow/openapi/converter/BoundedContextConverter.kt new file mode 100644 index 00000000000..c65d7a10c8a --- /dev/null +++ b/wow-openapi/src/main/kotlin/me/ahoo/wow/openapi/converter/BoundedContextConverter.kt @@ -0,0 +1,32 @@ +/* + * Copyright [2021-present] [ahoo wang (https://github.com/Ahoo-Wang)]. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package me.ahoo.wow.openapi.converter + +import io.swagger.v3.oas.models.media.Schema +import me.ahoo.wow.configuration.BoundedContext + +/** + * BoundedContext Converter + */ +class BoundedContextConverter : TargetTypeModifyConverter() { + + override val targetType: Class<*> = BoundedContext::class.java + + override fun modify(resolvedSchema: Schema<*>): Schema<*> { + val result = checkNotNull(resolvedSchema.properties[BoundedContext::aggregates.name]) + result.additionalProperties = true + result.default = emptyMap() + return resolvedSchema + } +} diff --git a/wow-openapi/src/main/kotlin/me/ahoo/wow/openapi/converter/BoundedContextSchemaNameConverter.kt b/wow-openapi/src/main/kotlin/me/ahoo/wow/openapi/converter/BoundedContextSchemaNameConverter.kt index 7bbe97c3e0f..11f5260ce08 100644 --- a/wow-openapi/src/main/kotlin/me/ahoo/wow/openapi/converter/BoundedContextSchemaNameConverter.kt +++ b/wow-openapi/src/main/kotlin/me/ahoo/wow/openapi/converter/BoundedContextSchemaNameConverter.kt @@ -23,6 +23,7 @@ import me.ahoo.wow.serialization.JsonSerializer class BoundedContextSchemaNameConverter : ModelConverter { companion object { + const val STD_LIB_PREFIX = "java." fun AnnotatedType.getRawClass(): Class<*>? { val schemaType = this.type if (schemaType is Class<*>) { @@ -52,14 +53,21 @@ class BoundedContextSchemaNameConverter : ModelConverter { context: ModelConverterContext, chain: Iterator ): Schema<*>? { - if (type.name.isNullOrBlank()) { - type.getRawClass()?.let { - type.name = it.toSchemaName() - } - } + resolveName(type) if (chain.hasNext()) { return chain.next().resolve(type, context, chain) } return null } + + private fun resolveName(type: AnnotatedType) { + if (type.name.isNullOrBlank().not()) { + return + } + val rawClass = type.getRawClass() ?: return + if (rawClass.name.startsWith(STD_LIB_PREFIX)) { + return + } + type.name = rawClass.toSchemaName() + } } diff --git a/wow-openapi/src/main/kotlin/me/ahoo/wow/openapi/converter/CommandResultConverter.kt b/wow-openapi/src/main/kotlin/me/ahoo/wow/openapi/converter/CommandResultConverter.kt index 6f5a5f6b0ee..a4d7caf8be8 100644 --- a/wow-openapi/src/main/kotlin/me/ahoo/wow/openapi/converter/CommandResultConverter.kt +++ b/wow-openapi/src/main/kotlin/me/ahoo/wow/openapi/converter/CommandResultConverter.kt @@ -15,6 +15,7 @@ package me.ahoo.wow.openapi.converter import io.swagger.v3.oas.models.media.Schema import me.ahoo.wow.command.CommandResult +import me.ahoo.wow.command.CommandResultCapable /** * CommandResult Converter @@ -24,8 +25,8 @@ class CommandResultConverter : TargetTypeModifyConverter() { override val targetType: Class<*> = CommandResult::class.java override fun modify(resolvedSchema: Schema<*>): Schema<*> { - val result = checkNotNull(resolvedSchema.properties[CommandResult::result.name]) - result.additionalProperties = null + val result = checkNotNull(resolvedSchema.properties[CommandResultCapable::result.name]) + result.additionalProperties = true result.default = emptyMap() return resolvedSchema } diff --git a/wow-openapi/src/main/kotlin/me/ahoo/wow/openapi/converter/ConditionConverter.kt b/wow-openapi/src/main/kotlin/me/ahoo/wow/openapi/converter/ConditionConverter.kt index c89e6621f50..901641bd4fd 100644 --- a/wow-openapi/src/main/kotlin/me/ahoo/wow/openapi/converter/ConditionConverter.kt +++ b/wow-openapi/src/main/kotlin/me/ahoo/wow/openapi/converter/ConditionConverter.kt @@ -25,7 +25,10 @@ class ConditionConverter : TargetTypeModifyConverter() { resolvedSchema.properties[Condition::operator.name]?.default = Operator.ALL.name resolvedSchema.properties[Condition::value.name]?.default = EMPTY_VALUE resolvedSchema.properties[Condition::children.name]?.default = emptyList() - resolvedSchema.properties[Condition::options.name]?.default = emptyMap() + resolvedSchema.properties[Condition::options.name]?.let { + it.default = emptyMap() + it.additionalProperties(true) + } return resolvedSchema } } diff --git a/wow-openapi/src/main/kotlin/me/ahoo/wow/openapi/converter/MessageHeaderConverter.kt b/wow-openapi/src/main/kotlin/me/ahoo/wow/openapi/converter/MessageHeaderConverter.kt new file mode 100644 index 00000000000..ecea1448be4 --- /dev/null +++ b/wow-openapi/src/main/kotlin/me/ahoo/wow/openapi/converter/MessageHeaderConverter.kt @@ -0,0 +1,30 @@ +/* + * Copyright [2021-present] [ahoo wang (https://github.com/Ahoo-Wang)]. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package me.ahoo.wow.openapi.converter + +import io.swagger.v3.oas.models.media.Schema +import me.ahoo.wow.api.messaging.Header + +/** + * Header Converter + */ +class MessageHeaderConverter : TargetTypeModifyConverter() { + + override val targetType: Class<*> = Header::class.java + + override fun modify(resolvedSchema: Schema<*>): Schema<*> { + resolvedSchema.additionalProperties = true + return resolvedSchema + } +} diff --git a/wow-openapi/src/main/kotlin/me/ahoo/wow/openapi/converter/WaitSignalConverter.kt b/wow-openapi/src/main/kotlin/me/ahoo/wow/openapi/converter/WaitSignalConverter.kt new file mode 100644 index 00000000000..e42af776e63 --- /dev/null +++ b/wow-openapi/src/main/kotlin/me/ahoo/wow/openapi/converter/WaitSignalConverter.kt @@ -0,0 +1,33 @@ +/* + * Copyright [2021-present] [ahoo wang (https://github.com/Ahoo-Wang)]. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package me.ahoo.wow.openapi.converter + +import io.swagger.v3.oas.models.media.Schema +import me.ahoo.wow.command.CommandResultCapable +import me.ahoo.wow.command.wait.WaitSignal + +/** + * WaitSignal Converter + */ +class WaitSignalConverter : TargetTypeModifyConverter() { + + override val targetType: Class<*> = WaitSignal::class.java + + override fun modify(resolvedSchema: Schema<*>): Schema<*> { + val result = checkNotNull(resolvedSchema.properties[CommandResultCapable::result.name]) + result.additionalProperties = true + result.default = emptyMap() + return resolvedSchema + } +} diff --git a/wow-openapi/src/main/kotlin/me/ahoo/wow/openapi/converter/WowMetadataConverter.kt b/wow-openapi/src/main/kotlin/me/ahoo/wow/openapi/converter/WowMetadataConverter.kt new file mode 100644 index 00000000000..21ac3dbcaf3 --- /dev/null +++ b/wow-openapi/src/main/kotlin/me/ahoo/wow/openapi/converter/WowMetadataConverter.kt @@ -0,0 +1,32 @@ +/* + * Copyright [2021-present] [ahoo wang (https://github.com/Ahoo-Wang)]. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package me.ahoo.wow.openapi.converter + +import io.swagger.v3.oas.models.media.Schema +import me.ahoo.wow.configuration.WowMetadata + +/** + * WowMetadata Converter + */ +class WowMetadataConverter : TargetTypeModifyConverter() { + + override val targetType: Class<*> = WowMetadata::class.java + + override fun modify(resolvedSchema: Schema<*>): Schema<*> { + val result = checkNotNull(resolvedSchema.properties[WowMetadata::contexts.name]) + result.additionalProperties = true + result.default = emptyMap() + return resolvedSchema + } +} diff --git a/wow-openapi/src/main/resources/META-INF/services/io.swagger.v3.core.converter.ModelConverter b/wow-openapi/src/main/resources/META-INF/services/io.swagger.v3.core.converter.ModelConverter index 2bdb2cbeef5..8fe63170800 100644 --- a/wow-openapi/src/main/resources/META-INF/services/io.swagger.v3.core.converter.ModelConverter +++ b/wow-openapi/src/main/resources/META-INF/services/io.swagger.v3.core.converter.ModelConverter @@ -20,6 +20,10 @@ me.ahoo.wow.openapi.converter.EventStreamConverter me.ahoo.wow.openapi.converter.DomainEventConverter me.ahoo.wow.openapi.converter.StateEventConverter me.ahoo.wow.openapi.converter.CommandResultConverter +me.ahoo.wow.openapi.converter.WaitSignalConverter +me.ahoo.wow.openapi.converter.BoundedContextConverter +me.ahoo.wow.openapi.converter.WowMetadataConverter +me.ahoo.wow.openapi.converter.MessageHeaderConverter me.ahoo.wow.openapi.converter.ConditionConverter me.ahoo.wow.openapi.converter.ProjectionConverter me.ahoo.wow.openapi.converter.ListQueryConverter