首页 > 解决方案 > 如何为对象生成附加属性为假的 swagger json?

问题描述

我有以下带有招摇描述的对象:

/**
 * Response about request failure
 */
@Schema(description = "Response about request failure")
data class ErrorDtoRs(
        @field:Schema(description = "Error type", maxLength = 64)
        val type: String? = null,
        @field:Schema(description = "Error message", maxLength = 255)
        val message: String?)

此对象的 Swagger json:

 "components": {
    "schemas": {
      "ErrorDtoRs": {
        "type": "object",
        "properties": {
          "type": {
            "maxLength": 64,
            "type": "string",
            "description": "Error type"
          },
          "message": {
            "maxLength": 255,
            "type": "string",
            "description": "Error message"
          }
        },
        "description": "Response about request failure"
      },

如何为对象生成附加属性为 false 的 swagger json,如下所示:

 "components": {
    "schemas": {
      "ErrorDtoRs": {
        "type": "object",
        "additionalProperties": "false",
        "properties": {
          "type": {
            "maxLength": 64,
            "type": "string",
            "description": "Error type"
          },
          "message": {
            "maxLength": 255,
            "type": "string",
            "description": "Error message"
          }
        },
        "description": "Response about request failure"
      },

招摇:2.1.4 OpenApi:3.0.1

标签: kotlinswaggeropenapi

解决方案


推荐阅读