From a66166da5f4d615abe781c320b801c878134bbca Mon Sep 17 00:00:00 2001 From: younker Date: Sun, 23 Apr 2023 17:14:36 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0DocJavaMethod=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E6=8B=93=E5=B1=95=20#488?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../doc/handler/ICustomJavaMethodHandler.java | 37 +++++++++++++++++++ .../java/com/power/doc/model/ApiConfig.java | 13 +++++++ .../power/doc/template/IRestDocTemplate.java | 4 ++ 3 files changed, 54 insertions(+) create mode 100644 src/main/java/com/power/doc/handler/ICustomJavaMethodHandler.java diff --git a/src/main/java/com/power/doc/handler/ICustomJavaMethodHandler.java b/src/main/java/com/power/doc/handler/ICustomJavaMethodHandler.java new file mode 100644 index 00000000..ff0d5943 --- /dev/null +++ b/src/main/java/com/power/doc/handler/ICustomJavaMethodHandler.java @@ -0,0 +1,37 @@ +/* + * smart-doc https://github.com/smart-doc-group/smart-doc + * + * Copyright (C) 2018-2023 smart-doc + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.power.doc.handler; + +import com.power.doc.model.DocJavaMethod; +import com.thoughtworks.qdox.model.JavaClass; + +import java.util.List; + +/** + * @author yangyang + * @date 2023/4/23 + */ +@FunctionalInterface +public interface ICustomJavaMethodHandler { + List apply(JavaClass cls, List methodList); +} diff --git a/src/main/java/com/power/doc/model/ApiConfig.java b/src/main/java/com/power/doc/model/ApiConfig.java index 1c57e113..37fdfb52 100644 --- a/src/main/java/com/power/doc/model/ApiConfig.java +++ b/src/main/java/com/power/doc/model/ApiConfig.java @@ -29,6 +29,7 @@ import com.power.common.util.CollectionUtil; import com.power.doc.constants.DocLanguage; +import com.power.doc.handler.ICustomJavaMethodHandler; import com.power.doc.model.rpc.RpcApiDependency; /** @@ -348,6 +349,10 @@ public class ApiConfig { * @since 2.2.5 */ private boolean responseParamsTable = Boolean.TRUE; + /** + * @since 2.6.8 + */ + private ICustomJavaMethodHandler customJavaMethodHandler; public String getCodePath() { return codePath; @@ -928,4 +933,12 @@ public String getServerEnv() { public void setServerEnv(String serverEnv) { this.serverEnv = serverEnv; } + + public ICustomJavaMethodHandler getCustomJavaMethodHandler() { + return customJavaMethodHandler; + } + + public void setCustomJavaMethodHandler(ICustomJavaMethodHandler customJavaMethodHandler) { + this.customJavaMethodHandler = customJavaMethodHandler; + } } diff --git a/src/main/java/com/power/doc/template/IRestDocTemplate.java b/src/main/java/com/power/doc/template/IRestDocTemplate.java index d06bf512..d480266a 100644 --- a/src/main/java/com/power/doc/template/IRestDocTemplate.java +++ b/src/main/java/com/power/doc/template/IRestDocTemplate.java @@ -329,6 +329,10 @@ default List buildEntryPointMethod( } } } + // call ICustomJavaMethodHandler + if (apiConfig.getCustomJavaMethodHandler() != null) { + docJavaMethods = apiConfig.getCustomJavaMethodHandler().apply(cls, docJavaMethods); + } List methodDocList = new ArrayList<>(methods.size()); int methodOrder = 0; for (DocJavaMethod docJavaMethod : docJavaMethods) { From c4e93db5fca6fe5bc5f20ad73556c79c579ecfb5 Mon Sep 17 00:00:00 2001 From: younker Date: Mon, 24 Apr 2023 20:29:30 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=A7=BB=E9=99=A4@date=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/power/doc/handler/ICustomJavaMethodHandler.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/power/doc/handler/ICustomJavaMethodHandler.java b/src/main/java/com/power/doc/handler/ICustomJavaMethodHandler.java index ff0d5943..cd88a337 100644 --- a/src/main/java/com/power/doc/handler/ICustomJavaMethodHandler.java +++ b/src/main/java/com/power/doc/handler/ICustomJavaMethodHandler.java @@ -28,8 +28,9 @@ import java.util.List; /** + * handle customized operation for {@link DocJavaMethod}. + * * @author yangyang - * @date 2023/4/23 */ @FunctionalInterface public interface ICustomJavaMethodHandler {