From 565e6be9cb76fa88b5cf21618cca48f0b2bf42fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?yongyiduan=28=E6=AE=B5=E6=B0=B8=E5=84=84=29?= Date: Wed, 11 Dec 2024 15:08:26 +0800 Subject: [PATCH] =?UTF-8?q?openapi=E6=96=B0=E5=A2=9E=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E7=94=9F=E6=88=90=E8=83=BD=E5=8A=9B=20#7412=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../openapi/service/doc/DocumentService.kt | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/service/doc/DocumentService.kt b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/service/doc/DocumentService.kt index b42ae3d808c9..315f93a161f8 100644 --- a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/service/doc/DocumentService.kt +++ b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/service/doc/DocumentService.kt @@ -361,7 +361,7 @@ class DocumentService { }, it).apply { if (it in polymorphismMap) { this.setRow( - (definitions[it] as Schema).discriminator.toString(), + (definitions[it] as Schema).discriminator.propertyName, "string", getI18n(BK_YES), getI18n(BK_DISCRIMINATOR_ILLUSTRATE, arrayOf("${polymorphismMap[it]?.keys}")), @@ -376,7 +376,7 @@ class DocumentService { // 多态类展示 polymorphismMap[it]?.forEach { (child, value) -> - val discriminator = (definitions[it] as Schema).discriminator.toString() + val discriminator = (definitions[it] as Schema).discriminator.propertyName val childModel = cacheOrLoad({ null }, child) .setRow( discriminator, @@ -701,7 +701,7 @@ class DocumentService { else -> { if (model.discriminator != null) { - loadJson[model.discriminator.toString()] = "string" + loadJson[model.discriminator.propertyName] = "string" } model.properties?.forEach { (key, property) -> loadJson[key] = loadPropertyJson(property, deep) @@ -717,6 +717,7 @@ class DocumentService { val loadJson = mutableMapOf() val key = property.`$ref`.removePrefix("#/components/schemas/") definitions[key]?.let { loadModelJson(it, loadJson, deep) } + deep.remove(property.`$ref`) return loadJson } else { return property.`$ref` @@ -725,7 +726,7 @@ class DocumentService { return when (property) { // swagger无法获取到map的key类型 is MapSchema -> { - mapOf("string" to property.additionalProperties) + mapOf("string" to loadPropertyJson(property.additionalProperties as Schema<*>, deep)) } is ObjectSchema -> { @@ -746,11 +747,8 @@ class DocumentService { is BooleanSchema -> false else -> { - val result = when (property.default) { - is Int -> 0 - is Long -> 0L - is Double -> 0.0 - is Float -> 0f + val result = when (property.type) { + "integer" -> 0 else -> property.type } result @@ -841,9 +839,10 @@ class DocumentService { val infoMap = mutableMapOf() val subTypes = it.getAnnotation(JsonSubTypes::class.java).value // val typeInfo = it.getAnnotation(JsonTypeInfo::class.java).property - val name = it.getAnnotation(SchemaAnnotation::class.java)?.name ?: it.name.split(".").last() + val name = it.getAnnotation(SchemaAnnotation::class.java)?.name?.ifBlank { null } + ?: it.name.split(".").last() subTypes.forEach { child -> - val childName = child.value.java.getAnnotation(SchemaAnnotation::class.java)?.name + val childName = child.value.java.getAnnotation(SchemaAnnotation::class.java)?.name?.ifBlank { null } ?: child.value.java.name.split(".").last() infoMap[childName] = child.name }