java - 为 swagger-UI 文档的每个枚举值添加描述

标签 java swagger-ui

如何为 swagger-UI 文档的每个枚举值添加一些描述?

我的枚举类:

@ApiModel
public enum EnumCarrierSelectionSubstitutionInformation {
    CARRIER_SELECTION_SUBSTITUTION_INFORMATION_1(1), //
    CARRIER_SELECTION_SUBSTITUTION_INFORMATION_2(2), //
    CARRIER_SELECTION_SUBSTITUTION_INFORMATION_3(3), //
    CARRIER_SELECTION_SUBSTITUTION_INFORMATION_4(4), //
    CARRIER_SELECTION_SUBSTITUTION_INFORMATION_5(5), //
    CARRIER_SELECTION_SUBSTITUTION_INFORMATION_6(6), //
    CARRIER_SELECTION_SUBSTITUTION_INFORMATION_7(7);

    private int numVal;

    EnumCarrierSelectionSubstitutionInformation(int numVal) {
        this.numVal = numVal;
    }

    public int getNumVal() {
        return numVal;
    }
}

模型

private EnumCarrierSelectionSubstitutionInformation carrierSelectionSubstitutionInformation;

// getter setter......

我想向 CARRIER_SELECTION_SUBSTITUTION_INFORMATION_1 添加一些说明。

我试过了

@ApiModelProperty(value = "blabla2")
CARRIER_SELECTION_SUBSTITUTION_INFORMATION_1(1), //

但这不起作用。

Swagger-UI 输出:

carrierSelectionSubstitutionInformation (string, optional) = ['CARRIER_SELECTION_SUBSTITUTION_INFORMATION_1', 'CARRIER_SELECTION_SUBSTITUTION_INFORMATION_2', 'CARRIER_SELECTION_SUBSTITUTION_INFORMATION_3', 'CARRIER_SELECTION_SUBSTITUTION_INFORMATION_4', 'CARRIER_SELECTION_SUBSTITUTION_INFORMATION_5', 'CARRIER_SELECTION_SUBSTITUTION_INFORMATION_6', 'CARRIER_SELECTION_SUBSTITUTION_INFORMATION_7']
string
Enum:   "CARRIER_SELECTION_SUBSTITUTION_INFORMATION_1", "CARRIER_SELECTION_SUBSTITUTION_INFORMATION_2", "CARRIER_SELECTION_SUBSTITUTION_INFORMATION_3", "CARRIER_SELECTION_SUBSTITUTION_INFORMATION_4", "CARRIER_SELECTION_SUBSTITUTION_INFORMATION_5", "CARRIER_SELECTION_SUBSTITUTION_INFORMATION_6", "CARRIER_SELECTION_SUBSTITUTION_INFORMATION_7"

我该怎么做?

最佳答案

public class Enum {

public enum EnumCarrierSelectionSubstitutionInformation {
    CARRIER_SELECTION_SUBSTITUTION_INFORMATION_1(1,"ONE"), //
    CARRIER_SELECTION_SUBSTITUTION_INFORMATION_2(2,"TWO"),

        private final int value;
        private final String description;

        EnumCarrierSelectionSubstitutionInformation(int value, String desc){
            this.value = value;
            this.description = desc;
        }
        public int value(){
            return this.value;
        }
        public String description(){
            return this.description;
        }
    }

    public static void main(String[] args){
        for (EnumCarrierSelectionSubstitutionInformation elem: EnumCarrierSelectionSubstitutionInformation.values()){
            System.out.println(elem + "value is "+ new Integer(elem.value()) + " desc is " + elem.description());
        }
    }
}

关于java - 为 swagger-UI 文档的每个枚举值添加描述,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49531506/

相关文章:

spring-boot - 无法从同一域中的另一台电脑访问 swagger ui

java - 在Java中的类文件中声明接口(interface)

java - Springfox Swagger 'Whitelabel Error Page' :com. google.common.base.Predicate 无法解析

node.js - 在 Node js 中使用多个 api 文档来 Swagger ?

swagger - 如何在 Swagger 规范中定义不同示例的数组?

javascript - JSON/Nodejs/swagger : Newlines not translated to multi-line in strings of express response displayed in swagger

java - ANTLR 通配符运算符不消耗预期输入

java - 如何取消 Perforce P4V 中从本地工作区意外删除的文件的删除标记

java - 如何检查矩形是否与另一个矩形相交?

java - 了解 Java 中的循环不变量