Skip to content

Commit

Permalink
Add support for open api.
Browse files Browse the repository at this point in the history
  • Loading branch information
shalousun committed Aug 19, 2020
1 parent ebd2939 commit d30fa0f
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 54 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repositories {

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.13'
compile 'com.github.shalousun:smart-doc:1.9.1'
compile 'com.github.shalousun:smart-doc:1.9.2'
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
Expand Down
108 changes: 55 additions & 53 deletions src/main/java/com/smartdoc/gradle/constant/GlobalConstants.java
Original file line number Diff line number Diff line change
@@ -1,53 +1,55 @@
/*
* smart-doc https://github.com/shalousun/smart-doc
*
* Copyright (C) 2018-2020 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.smartdoc.gradle.constant;

/**
* @author yu 2019/12/13.
*/
public interface GlobalConstants {

String ERROR_MSG = "Failed to build ApiConfig, check if the configuration file is correct.";

String DEFAULT_CONFIG = "./src/main/resources/default.json";

String TASK_GROUP = "Documentation";

String REST_HTML_TASK = "smartDocRestHtml";

String REST_ADOC_TASK = "smartDocRestAdoc";

String REST_MARKDOWN_TASK = "smartDocRestMarkdown";

String POSTMAN_TASK = "smartDocPostman";

String RPC_HTML_TASK = "smartDocRpcHtml";

String RPC_ADOC_TASK = "smartDocRpcAdoc";

String RPC_MARKDOWN_TASK = "smartDocRpcMarkdown";

String EXTENSION_NAME = "smartdoc";

String SRC_MAIN_JAVA_PATH = "/src/main/java";
}
/*
* smart-doc https://github.com/shalousun/smart-doc
*
* Copyright (C) 2018-2020 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.smartdoc.gradle.constant;

/**
* @author yu 2019/12/13.
*/
public interface GlobalConstants {

String ERROR_MSG = "Failed to build ApiConfig, check if the configuration file is correct.";

String DEFAULT_CONFIG = "./src/main/resources/default.json";

String TASK_GROUP = "Documentation";

String REST_HTML_TASK = "smartDocRestHtml";

String REST_ADOC_TASK = "smartDocRestAdoc";

String REST_MARKDOWN_TASK = "smartDocRestMarkdown";

String POSTMAN_TASK = "smartDocPostman";

String OPEN_API_TASK = "smartDocOpenApi";

String RPC_HTML_TASK = "smartDocRpcHtml";

String RPC_ADOC_TASK = "smartDocRpcAdoc";

String RPC_MARKDOWN_TASK = "smartDocRpcMarkdown";

String EXTENSION_NAME = "smartdoc";

String SRC_MAIN_JAVA_PATH = "/src/main/java";
}
5 changes: 5 additions & 0 deletions src/main/java/com/smartdoc/gradle/plugin/SmartDocPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public void apply(Project project) {
postmanTask.setGroup(GlobalConstants.TASK_GROUP);
postmanTask.dependsOn(javaCompileTask);

// create open api
OpenApiTask openApiTask = project.getTasks().create(GlobalConstants.OPEN_API_TASK, OpenApiTask.class);
openApiTask.setGroup(GlobalConstants.TASK_GROUP);
openApiTask.dependsOn(javaCompileTask);

//create rpc html
RpcHtmlTask rpcHtmlTask = project.getTasks().create(GlobalConstants.RPC_HTML_TASK, RpcHtmlTask.class);
rpcHtmlTask.setGroup(GlobalConstants.TASK_GROUP);
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/smartdoc/gradle/task/OpenApiTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.smartdoc.gradle.task;

import com.power.doc.builder.OpenApiBuilder;
import com.power.doc.model.ApiConfig;
import com.thoughtworks.qdox.JavaProjectBuilder;
import org.gradle.api.logging.Logger;

/**
* Support OpenApi 3.0+
* @author yu 2020/8/20.
*/
public class OpenApiTask extends DocBaseTask {

@Override
public void executeAction(ApiConfig apiConfig, JavaProjectBuilder javaProjectBuilder, Logger logger) {
try {
OpenApiBuilder.buildOpenApi(apiConfig, javaProjectBuilder);
} catch (Exception e) {
e.printStackTrace();
}
}
}

0 comments on commit d30fa0f

Please sign in to comment.