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.utils.StrUtil; 019 020import java.io.Serializable; 021import java.util.LinkedList; 022import java.util.List; 023 024public class ApiDocument implements Serializable { 025 026 private String value; 027 private String notes; 028 private String filePath; 029 030 private List<ApiOperation> apiOperations; 031 032 private Class<?> controllerClass; 033 034 public ApiDocument() { 035 } 036 037 public String getValue() { 038 return value; 039 } 040 041 public void setValue(String value) { 042 this.value = value; 043 } 044 045 public String getNotes() { 046 return notes; 047 } 048 049 public void setNotes(String notes) { 050 this.notes = notes; 051 } 052 053 public String getFilePath() { 054 return filePath; 055 } 056 057 public void setFilePath(String filePath) { 058 this.filePath = filePath; 059 } 060 061 public void setFilePathByControllerPath(String controllerPath) { 062 if (controllerPath == null || StrUtil.isBlank(controllerPath)) { 063 throw new IllegalArgumentException("The request mapping path of Controller \"" + getControllerClass().getName() + "\" is empty."); 064 } 065 066 if ("/".equals(controllerPath)) { 067 controllerPath = "index"; 068 } else if (controllerPath.startsWith("/")) { 069 controllerPath = controllerPath.substring(1); 070 } 071 if (controllerPath.contains("/")) { 072 controllerPath = controllerPath.replace("/", "_"); 073 } 074 075 this.filePath = controllerPath; 076 } 077 078 public List<ApiOperation> getApiOperations() { 079 return apiOperations; 080 } 081 082 public void setApiOperations(List<ApiOperation> apiOperations) { 083 this.apiOperations = apiOperations; 084 } 085 086 public void addOperation(ApiOperation apiOperation) { 087 if (apiOperations == null) { 088 apiOperations = new LinkedList<>(); 089 } 090 apiOperations.add(apiOperation); 091 } 092 093 public Class<?> getControllerClass() { 094 return controllerClass; 095 } 096 097 public void setControllerClass(Class<?> controllerClass) { 098 this.controllerClass = controllerClass; 099 } 100 101 @Override 102 public String toString() { 103 return "ApiDocument{" + 104 "value='" + value + '\'' + 105 ", notes='" + notes + '\'' + 106 '}'; 107 } 108}