001/** 002 * Copyright (c) 2015-2022, Michael Yang 杨福海 (fuhai999@gmail.com). 003 * <p> 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package io.jboot.apidoc; 017 018import io.jboot.apidoc.annotation.ApiPara; 019import io.jboot.utils.ClassType; 020import io.jboot.utils.ClassUtil; 021import io.jboot.utils.StrUtil; 022 023import java.io.Serializable; 024 025public class ApiParameter implements Serializable { 026 027 private String name; 028 private String value; 029 private String notes; 030 031 private ClassType dataType; 032 033 private HttpMethod[] httpMethods; 034 private Boolean require; 035 private Boolean notBlank; 036 private Boolean notEmpty; 037 private Boolean email; 038 private Long min; 039 private Long max; 040 private String pattern; 041 private String defaultValue; 042 043 public ApiParameter() { 044 } 045 046 public ApiParameter(ApiPara apiPara, HttpMethod[] defaultMethods) { 047 this.name = apiPara.name(); 048 this.value = apiPara.value(); 049 this.notes = apiPara.notes(); 050 this.dataType = ClassUtil.getClassType(apiPara.dataType(), null); 051 this.httpMethods = apiPara.method().length == 0 ? defaultMethods : apiPara.method(); 052 this.require = apiPara.require(); 053 } 054 055 public String getName() { 056 return name; 057 } 058 059 public void setName(String name) { 060 this.name = name; 061 } 062 063 public String getValue() { 064 return value; 065 } 066 067 public void setValue(String value) { 068 this.value = value; 069 } 070 071 public String getNotes() { 072 return notes; 073 } 074 075 public void setNotes(String notes) { 076 this.notes = notes; 077 } 078 079 public ClassType getDataType() { 080 return dataType; 081 } 082 083 public void setDataType(ClassType dataType) { 084 this.dataType = dataType; 085 } 086 087 public HttpMethod[] getHttpMethods() { 088 return httpMethods; 089 } 090 091 public void setHttpMethods(HttpMethod[] httpMethods) { 092 this.httpMethods = httpMethods; 093 } 094 095 public Boolean getRequire() { 096 return require; 097 } 098 099 public void setRequire(Boolean require) { 100 this.require = require; 101 } 102 103 public Boolean getNotBlank() { 104 return notBlank; 105 } 106 107 public void setNotBlank(Boolean notBlank) { 108 this.notBlank = notBlank; 109 } 110 111 public Boolean getNotEmpty() { 112 return notEmpty; 113 } 114 115 public void setNotEmpty(Boolean notEmpty) { 116 this.notEmpty = notEmpty; 117 } 118 119 public Boolean getEmail() { 120 return email; 121 } 122 123 public void setEmail(Boolean email) { 124 this.email = email; 125 } 126 127 public Long getMin() { 128 return min; 129 } 130 131 public void setMin(Long min) { 132 this.min = min; 133 } 134 135 public Long getMax() { 136 return max; 137 } 138 139 public void setMax(Long max) { 140 this.max = max; 141 } 142 143 public String getPattern() { 144 return pattern; 145 } 146 147 public void setPattern(String pattern) { 148 this.pattern = pattern; 149 } 150 151 public String getDefaultValue() { 152 return defaultValue; 153 } 154 155 public void setDefaultValue(String defaultValue) { 156 this.defaultValue = defaultValue; 157 } 158 159 public String getHttpMethodsString() { 160 StringBuilder sb = new StringBuilder(); 161 if (httpMethods != null) { 162 for (int i = 0; i < httpMethods.length; i++) { 163 sb.append(httpMethods[i].getValue()); 164 if (i != httpMethods.length - 1) { 165 sb.append(", "); 166 } 167 } 168 } 169 return sb.toString(); 170 } 171 172 public String getNotesString() { 173 StringBuilder sb = new StringBuilder(); 174 if (StrUtil.isNotBlank(defaultValue)) { 175 sb.append("默认值:" + defaultValue); 176 } 177 178 if (StrUtil.isNotBlank(notes)) { 179 if (sb.length() > 0) { 180 sb.append(" ;"); 181 } 182 sb.append(notes); 183 } 184 return sb.toString(); 185 } 186 187 188 @Override 189 public String toString() { 190 return "ApiParameter{" + 191 "name='" + name + '\'' + 192 ", value='" + value + '\'' + 193 ", notes='" + notes + '\'' + 194 '}'; 195 } 196}