Commit 46cafbb5 authored by duanledexianxianxian's avatar duanledexianxianxian 😁

Refactoring code.

parent 19054687
package com.apidoc.core.schema;
import lombok.extern.slf4j.Slf4j;
/**
* 支持的http method
*/
@Slf4j
public enum Method {
GET,POST,PUT,DELETE,
OPTIONS,PATCH,COPY,HEAD,LINK,UNLINK,PURGE,LOCK,UNLOCK,PROPFIND,VIEW;
public static Method of(String name) {
return valueOf(name);
}
}
package com.apidoc.core;
import com.apidoc.core.common.helper.StringHelper;
import com.apidoc.core.parser.ParserStrategy;
import com.apidoc.core.parser.VisitorParser;
import com.apidoc.core.render.ProjectRender;
import com.apidoc.core.resolver.TypeResolvers;
import com.apidoc.core.schema.Project;
package kim.apidoc.core;
import kim.apidoc.core.common.helper.StringHelper;
import kim.apidoc.core.parser.ParserStrategy;
import kim.apidoc.core.parser.VisitorParser;
import kim.apidoc.core.render.ProjectRender;
import kim.apidoc.core.resolver.TypeResolvers;
import kim.apidoc.core.schema.Project;
import com.github.javaparser.ParseResult;
import com.github.javaparser.ParserConfiguration;
import com.github.javaparser.ast.CompilationUnit;
......@@ -38,17 +38,6 @@ public class ApiDoc {
* ApiDoc实例
*/
private static ApiDoc INSTANCE;
/**
* Get instance api doc.
*
* @return the api doc
*/
public static ApiDoc getInstance(){
return INSTANCE;
}
/**
* 上下文
*/
......@@ -59,7 +48,6 @@ public class ApiDoc {
*/
@Getter
private Project project = new Project();
/**
* The Visitor parser.
*/
......@@ -68,7 +56,6 @@ public class ApiDoc {
* The Parser configuration.
*/
private ParserConfiguration parserConfiguration;
/**
* The Type resolvers.
*/
......@@ -78,7 +65,7 @@ public class ApiDoc {
/**
* Instantiates a new ApiDoc.
*/
private ApiDoc(){
private ApiDoc() {
init(new Context());
}
......@@ -87,16 +74,25 @@ public class ApiDoc {
*
* @param context the context
*/
public ApiDoc(Context context){
public ApiDoc(Context context) {
init(context);
}
/**
* Get instance api doc.
*
* @return the api doc
*/
public static ApiDoc getInstance() {
return INSTANCE;
}
/**
* 初始化环境配置
*
* @param context the context
*/
private void init(Context context){
private void init(Context context) {
INSTANCE = this;
this.context = context;
project.setId(context.getId());
......@@ -133,21 +129,21 @@ public class ApiDoc {
*
* @return the parser strategy
*/
private ParserStrategy loadParserStrategy(){
private ParserStrategy loadParserStrategy() {
ServiceLoader<ParserStrategy> serviceLoader = ServiceLoader.load(ParserStrategy.class);
List<ParserStrategy> strategies = Lists.newArrayList(serviceLoader);
if(strategies.isEmpty()){
if (strategies.isEmpty()) {
throw new IllegalArgumentException("no ParserStrategy implements found");
}
if(StringHelper.isBlank(context.framework)){
if (StringHelper.isBlank(context.framework)) {
return strategies.get(0);
}
for (ParserStrategy strategy : strategies) {
if(Objects.equals(context.framework,strategy.name())){
if (Objects.equals(context.framework, strategy.name())) {
return strategy;
}
}
throw new IllegalArgumentException("no ParserStrategy implements found for "+context.framework);
throw new IllegalArgumentException("no ParserStrategy implements found for " + context.framework);
}
/**
......@@ -155,12 +151,12 @@ public class ApiDoc {
*
* @return project project
*/
public Project parse(){
public Project parse() {
for (Path source : this.context.getSources()) {
SourceRoot root = new SourceRoot(source, parserConfiguration);
try {
for (ParseResult<CompilationUnit> result : root.tryToParse()) {
if(result.isSuccessful() && result.getResult().isPresent()){
if (result.isSuccessful() && result.getResult().isPresent()) {
result.getResult().get().accept(visitorParser, project);
}
}
......@@ -174,7 +170,7 @@ public class ApiDoc {
/**
* 渲染解析结果
*/
public void render(){
public void render() {
for (ProjectRender render : this.context.getRenders()) {
render.render(project);
}
......
package com.apidoc.core;
package kim.apidoc.core;
import com.apidoc.core.common.helper.FileHelper;
import com.apidoc.core.render.AsciiDocRender;
import com.apidoc.core.render.PostmanRender;
import com.apidoc.core.render.ProjectRender;
import kim.apidoc.core.common.helper.FileHelper;
import kim.apidoc.core.render.AsciiDocRender;
import kim.apidoc.core.render.PostmanRender;
import kim.apidoc.core.render.ProjectRender;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.Getter;
......
package com.apidoc.core.common;
package kim.apidoc.core.common;
import com.google.common.base.Strings;
......
package com.apidoc.core.common;
package kim.apidoc.core.common;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
......
package com.apidoc.core.common;
package kim.apidoc.core.common;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
......
package com.apidoc.core.common;
package kim.apidoc.core.common;
import com.apidoc.core.common.helper.StringHelper;
import kim.apidoc.core.common.helper.StringHelper;
import com.google.common.collect.Lists;
import lombok.EqualsAndHashCode;
import lombok.Getter;
......
package com.apidoc.core.common.description;
package kim.apidoc.core.common.description;
import com.apidoc.core.common.ObjectMappers;
import com.apidoc.core.schema.Row;
import kim.apidoc.core.common.ObjectMappers;
import kim.apidoc.core.schema.Row;
import com.fasterxml.jackson.databind.node.ArrayNode;
import java.util.ArrayList;
......@@ -15,47 +15,47 @@ public class ArrayTypeDescription extends TypeDescription {
public ArrayTypeDescription(TypeDescription component) {
this.component = component;
this.value = ObjectMappers.instance.createArrayNode();
if(component.isAvailable()){
if (component.isAvailable()) {
this.type = component.getType() + "[]";
if(component.isPrimitive()){
if (component.isPrimitive()) {
primitive(component.asPrimitive());
}else if(component.isString()){
} else if (component.isString()) {
value.add(component.asString().getValue());
}else if(component.isArray()){
} else if (component.isArray()) {
value.add(component.asArray().getValue());
}else if(component.isObject()){
} else if (component.isObject()) {
value.add(component.asObject().getValue());
}
}else{
} else {
this.type = "[]";
}
}
public void primitive(PrimitiveTypeDescription typeDescription){
switch (typeDescription.getType()){
public void primitive(PrimitiveTypeDescription typeDescription) {
switch (typeDescription.getType()) {
case "byte":
value.add((byte)typeDescription.getValue());
value.add((byte) typeDescription.getValue());
break;
case "short":
value.add((short)typeDescription.getValue());
value.add((short) typeDescription.getValue());
break;
case "char":
value.add((char)typeDescription.getValue());
value.add((char) typeDescription.getValue());
break;
case "int":
value.add((int)typeDescription.getValue());
value.add((int) typeDescription.getValue());
break;
case "long":
value.add((long)typeDescription.getValue());
value.add((long) typeDescription.getValue());
break;
case "boolean":
value.add((boolean)typeDescription.getValue());
value.add((boolean) typeDescription.getValue());
break;
case "float":
value.add((float)typeDescription.getValue());
value.add((float) typeDescription.getValue());
break;
case "double":
value.add((double)typeDescription.getValue());
value.add((double) typeDescription.getValue());
break;
}
}
......@@ -76,17 +76,17 @@ public class ArrayTypeDescription extends TypeDescription {
}
}
public ArrayNode getValue(){
public ArrayNode getValue() {
return value;
}
@Override
public Collection<Row> rows() {
ArrayList<Row> rows = new ArrayList<>();
if(key != null){
if (key != null) {
rows.addAll(super.rows());
}
if(component.isAvailable()){
if (component.isAvailable()) {
rows.addAll(component.rows());
}
return rows;
......
package com.apidoc.core.common.description;
package kim.apidoc.core.common.description;
import com.apidoc.core.common.ObjectMappers;
import com.apidoc.core.schema.Row;
import kim.apidoc.core.common.ObjectMappers;
import kim.apidoc.core.schema.Row;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.Lists;
import lombok.Getter;
......@@ -14,9 +14,8 @@ import java.util.List;
@Getter
public class ObjectTypeDescription extends TypeDescription {
private ObjectNode value = ObjectMappers.instance.createObjectNode();
protected List<TypeDescription> members = Lists.newArrayList();
private ObjectNode value = ObjectMappers.instance.createObjectNode();
public void merge(ObjectTypeDescription other) {
value.setAll(other.getValue());
......@@ -87,6 +86,7 @@ public class ObjectTypeDescription extends TypeDescription {
}
}
@Override
public ObjectNode getValue() {
return value;
}
......
package com.apidoc.core.common.description;
package kim.apidoc.core.common.description;
import com.github.javaparser.resolution.types.ResolvedPrimitiveType;
import com.github.javaparser.resolution.types.ResolvedReferenceType;
......@@ -6,8 +6,8 @@ import com.github.javaparser.resolution.types.ResolvedReferenceType;
public class PrimitiveTypeDescription extends TypeDescription {
public PrimitiveTypeDescription(ResolvedReferenceType referenceType){
switch (referenceType.getId()){
public PrimitiveTypeDescription(ResolvedReferenceType referenceType) {
switch (referenceType.getId()) {
case "java.lang.Byte":
value = (byte) 0;
type = "byte";
......@@ -33,7 +33,7 @@ public class PrimitiveTypeDescription extends TypeDescription {
type = "double";
break;
case "java.lang.Character":
value = (char)0;
value = (char) 0;
type = "char";
break;
case "java.lang.Boolean":
......@@ -43,9 +43,10 @@ public class PrimitiveTypeDescription extends TypeDescription {
}
}
public PrimitiveTypeDescription(ResolvedPrimitiveType resolvedPrimitiveType){
public PrimitiveTypeDescription(ResolvedPrimitiveType resolvedPrimitiveType) {
type = resolvedPrimitiveType.describe();
switch (resolvedPrimitiveType){
switch (resolvedPrimitiveType) {
case BYTE:
value = (byte) 0;
break;
......@@ -65,7 +66,7 @@ public class PrimitiveTypeDescription extends TypeDescription {
value = 0d;
break;
case CHAR:
value = (char)0;
value = (char) 0;
break;
case BOOLEAN:
value = false;
......
package com.apidoc.core.common.description;
package kim.apidoc.core.common.description;
public class StringTypeDescription extends TypeDescription {
......@@ -7,7 +7,8 @@ public class StringTypeDescription extends TypeDescription {
value = charSequence.toString();
}
public String getValue(){
return (String)value;
@Override
public String getValue() {
return (String) value;
}
}
package com.apidoc.core.common.description;
package kim.apidoc.core.common.description;
import com.apidoc.core.common.helper.StringHelper;
import com.apidoc.core.schema.Row;
import kim.apidoc.core.common.helper.StringHelper;
import kim.apidoc.core.schema.Row;
import com.google.common.collect.Lists;
import lombok.Getter;
import lombok.Setter;
......@@ -61,36 +61,36 @@ public abstract class TypeDescription {
return (ObjectTypeDescription) this;
}
public void addRemark(String value){
if(value==null){
public void addRemark(String value) {
if (value == null) {
return;
}
if(remark==null){
if (remark == null) {
remark = value;
}else{
} else {
remark += " " + value;
}
}
public String fullKey(){
return StringHelper.join(".",prefix,key);
public String fullKey() {
return StringHelper.join(".", prefix, key);
}
public Collection<Row> rows() {
String key = fullKey();
if(StringHelper.isBlank(key)){
if (StringHelper.isBlank(key)) {
return Lists.newArrayList();
}
String def;
if(defaultValue!=null){
if (defaultValue != null) {
def = String.valueOf(defaultValue);
}else if(value!=null){
} else if (value != null) {
def = String.valueOf(value);
}else{
} else {
def = "";
}
if(required!=null){
if (required != null) {
condition.append("required=").append(required);
}
......
package com.apidoc.core.common.description;
package kim.apidoc.core.common.description;
import com.apidoc.core.schema.Row;
import kim.apidoc.core.schema.Row;
import java.util.Collection;
......
package com.apidoc.core.common.diff;
package kim.apidoc.core.common.diff;
import com.google.common.base.Charsets;
import lombok.Getter;
......@@ -42,7 +42,7 @@ public class FileMatcher {
return changs;
}
public void rederHtml(Path templateHtml, Path resultHtml) {
public void renderHtml(Path templateHtml, Path resultHtml) {
String results = matchPatcher.diff_prettyHtml(diffs);
String[] lines = br(results).replaceAll("<span>|</span>", "").split("\n");
String html = readFile(templateHtml);
......
package com.apidoc.core.common.diff;
package kim.apidoc.core.common.diff;
import java.awt.*;
import java.io.File;
......@@ -9,7 +9,7 @@ import java.nio.file.Path;
public class FileSystem {
public static boolean open(Path path) {
if(!Files.exists(path)){
if (!Files.exists(path)) {
return false;
}
if (cmd(path.toString())) {
......@@ -25,8 +25,8 @@ public class FileSystem {
private static boolean cmd(String command, String args) {
try {
Process p = Runtime.getRuntime().exec(new String[]{command,args});
return p!=null;
Process p = Runtime.getRuntime().exec(new String[]{command, args});
return p != null;
} catch (IOException e) {
e.printStackTrace();
}
......@@ -45,6 +45,14 @@ public class FileSystem {
return false;
}
private static OS currentOS() {
String s = System.getProperty("os.name").toLowerCase();
if (s.contains("win")) {
return OS.win;
}
return OS.mac;
}
public enum OS {
mac("open"),
win("explorer");
......@@ -55,17 +63,9 @@ public class FileSystem {
this.command = command;
}
public String getCommand(){
public String getCommand() {
return command;
}
}
private static OS currentOS() {
String s = System.getProperty("os.name").toLowerCase();
if (s.contains("win")) {
return OS.win;
}
return OS.mac;
}
}
......@@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.apidoc.core.common.diff;
package kim.apidoc.core.common.diff;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
......
package com.apidoc.core.common.helper;
package kim.apidoc.core.common.helper;
import com.github.javaparser.ast.expr.*;
import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations;
......
package com.apidoc.core.common.helper;
package kim.apidoc.core.common.helper;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.body.FieldDeclaration;
......
package com.apidoc.core.common.helper;
package kim.apidoc.core.common.helper;
import com.github.javaparser.ast.body.FieldDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;
......
package com.apidoc.core.common.helper;
package kim.apidoc.core.common.helper;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.Node;
......
package com.apidoc.core.common.helper;
package kim.apidoc.core.common.helper;
import com.github.javaparser.ast.NodeList;
import com.github.javaparser.ast.expr.*;
......
package com.apidoc.core.common.helper;
package kim.apidoc.core.common.helper;
import com.github.javaparser.ast.expr.Expression;
import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration;
......
package com.apidoc.core.common.helper;
package kim.apidoc.core.common.helper;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
......
package com.apidoc.core.common.helper;
package kim.apidoc.core.common.helper;
import com.github.javaparser.ast.body.FieldDeclaration;
import com.github.javaparser.ast.expr.AnnotationExpr;
......
package com.apidoc.core.common.helper;
package kim.apidoc.core.common.helper;
import com.google.common.collect.Sets;
......
package com.apidoc.core.common.helper;
package kim.apidoc.core.common.helper;
import com.google.common.base.Strings;
......
package com.apidoc.core.common.helper;
package kim.apidoc.core.common.helper;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.ImportDeclaration;
......
package com.apidoc.core.common.helper;
package kim.apidoc.core.common.helper;
import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration;
import com.github.javaparser.resolution.types.ResolvedReferenceType;
......
package com.apidoc.core.common.helper;
package kim.apidoc.core.common.helper;
import com.github.javaparser.ast.body.FieldDeclaration;
import com.github.javaparser.ast.expr.AnnotationExpr;
......
package com.apidoc.core.common.markup;
package kim.apidoc.core.common.markup;
import com.apidoc.core.common.markup.asciidoc.AsciiDocBuilder;
import kim.apidoc.core.common.markup.asciidoc.AsciiDocBuilder;
import java.util.List;
import java.util.function.Consumer;
......
package com.apidoc.core.common.markup.asciidoc;
package kim.apidoc.core.common.markup.asciidoc;
public enum AsciiDoc implements CharSequence {
EXTENSION(".adoc"),
......
package com.apidoc.core.common.markup.asciidoc;
package kim.apidoc.core.common.markup.asciidoc;
import com.apidoc.core.common.Assert;
import com.apidoc.core.common.markup.MarkupBuilder;
import kim.apidoc.core.common.Assert;
import kim.apidoc.core.common.markup.MarkupBuilder;
import com.google.common.base.Strings;
import java.util.List;
......
package com.apidoc.core.common.markup.asciidoc;
package kim.apidoc.core.common.markup.asciidoc;
/**
* https://en.wikipedia.org/wiki/Web_colors#HTML_color_names
......
package com.apidoc.core.common.markup.markdown;
package kim.apidoc.core.common.markup.markdown;
public enum Markdown implements CharSequence {
EXTENSION(".md"),
......
package com.apidoc.core.common.markup.markdown;
package kim.apidoc.core.common.markup.markdown;
import com.apidoc.core.common.Assert;
import com.apidoc.core.common.markup.MarkupBuilder;
import kim.apidoc.core.common.Assert;
import kim.apidoc.core.common.markup.MarkupBuilder;
import com.google.common.base.Strings;
import java.util.List;
import java.util.function.Consumer;
import java.util.regex.Matcher;
import static com.apidoc.core.common.markup.markdown.Markdown.*;
public class MarkdownBuilder implements MarkupBuilder {
public static final int MAX_TITLE = 6;
......@@ -19,7 +17,7 @@ public class MarkdownBuilder implements MarkupBuilder {
@Override
public MarkupBuilder header(String text, CharSequence... attrs) {
Assert.notBlank(text, "header must not be blank");
content.append(HEADER);
content.append(Markdown.HEADER);
content.append(nobr(text.trim()));
br();
return this;
......@@ -30,7 +28,7 @@ public class MarkdownBuilder implements MarkupBuilder {
Assert.notBlank(text, "header must not be blank");
Assert.between(level, 1, MAX_TITLE, "title level can not be " + level);
br();
content.append(Strings.repeat(TITLE.toString(), level + 1)).append(WHITESPACE)
content.append(Strings.repeat(Markdown.TITLE.toString(), level + 1)).append(Markdown.WHITESPACE)
.append(nobr(text.trim()));
br();
return this;
......@@ -67,35 +65,35 @@ public class MarkdownBuilder implements MarkupBuilder {
@Override
public MarkupBuilder note(String text) {
content.append(QUOTE);
content.append(Markdown.QUOTE);
paragraph(text);
return this;
}
@Override
public MarkupBuilder tip(String text) {
content.append(QUOTE);
content.append(Markdown.QUOTE);
paragraph(text);
return this;
}
@Override
public MarkupBuilder important(String text) {
content.append(QUOTE);
content.append(Markdown.QUOTE);
paragraph(text);
return this;
}
@Override
public MarkupBuilder warning(String text) {
content.append(QUOTE);
content.append(Markdown.QUOTE);
paragraph(text);
return this;
}
@Override
public MarkupBuilder caution(String text) {
content.append(QUOTE);
content.append(Markdown.QUOTE);
paragraph(text);
return this;
}
......@@ -114,42 +112,42 @@ public class MarkdownBuilder implements MarkupBuilder {
@Override
public MarkupBuilder listing(Consumer<MarkupBuilder> consumer, CharSequence... attrs) {
return block(consumer, LISTING, attrs);
return block(consumer, Markdown.LISTING, attrs);
}
@Override
public MarkupBuilder literal(Consumer<MarkupBuilder> consumer, CharSequence... attrs) {
return block(consumer, LISTING, attrs);
return block(consumer, Markdown.LISTING, attrs);
}
@Override
public MarkupBuilder sidebar(Consumer<MarkupBuilder> consumer, CharSequence... attrs) {
return block(consumer, LISTING, attrs);
return block(consumer, Markdown.LISTING, attrs);
}
@Override
public MarkupBuilder comment(Consumer<MarkupBuilder> consumer, CharSequence... attrs) {
return block(consumer, LISTING, attrs);
return block(consumer, Markdown.LISTING, attrs);
}
@Override
public MarkupBuilder passthrough(Consumer<MarkupBuilder> consumer, CharSequence... attrs) {
return block(consumer, LISTING, attrs);
return block(consumer, Markdown.LISTING, attrs);
}
@Override
public MarkupBuilder quote(Consumer<MarkupBuilder> consumer, CharSequence... attrs) {
return block(consumer, LISTING, attrs);
return block(consumer, Markdown.LISTING, attrs);
}
@Override
public MarkupBuilder example(Consumer<MarkupBuilder> consumer, CharSequence... attrs) {
return block(consumer, LISTING, attrs);
return block(consumer, Markdown.LISTING, attrs);
}
@Override
public MarkupBuilder list(String text) {
return list(text, LIST_FLAG);
return list(text, Markdown.LIST_FLAG);
}
@Override
......@@ -187,28 +185,28 @@ public class MarkdownBuilder implements MarkupBuilder {
public MarkupBuilder table(List<List<String>> data, boolean header, boolean footer) {
for (int i = 0; i < data.size(); i++) {
content.append(TABLE_CELL);
content.append(Markdown.TABLE_CELL);
for (int j = 0; j < data.get(i).size(); j++) {
String value = data.get(i).get(j);
if(value!=null){
content.append(data.get(i).get(j).replace(TABLE_CELL, "\\" + TABLE_CELL));
content.append(data.get(i).get(j).replace(Markdown.TABLE_CELL, "\\" + Markdown.TABLE_CELL));
}else{
content.append(" ");
}
content.append(TABLE_CELL);
content.append(Markdown.TABLE_CELL);
}
br();
if(i==0 && header){
content.append(TABLE_CELL);
content.append(Markdown.TABLE_CELL);
for (int j = 0; j < data.get(i).size(); j++) {
content.append(TABLE_Header);
content.append(Markdown.TABLE_Header);
}
br();
}
if(i==data.size()-2 && footer){
content.append(TABLE_CELL);
content.append(Markdown.TABLE_CELL);
for (int j = 0; j < data.get(i).size(); j++) {
content.append(TABLE_Header);
content.append(Markdown.TABLE_Header);
}
br();
}
......@@ -231,55 +229,55 @@ public class MarkdownBuilder implements MarkupBuilder {
@Override
public MarkupBuilder emphasized(String text, CharSequence... textStyle) {
return style(EMPHASIZED, text, textStyle);
return style(Markdown.EMPHASIZED, text, textStyle);
}
@Override
public MarkupBuilder strong(String text, CharSequence... textStyle) {
return style(STRONG, text, textStyle);
return style(Markdown.STRONG, text, textStyle);
}
@Override
public MarkupBuilder monospaced(String text, CharSequence... textStyle) {
return style(MONOSPACED, text, textStyle);
return style(Markdown.MONOSPACED, text, textStyle);
}
@Override
public MarkupBuilder quoted(String text, CharSequence... textStyle) {
return style(QUOTE, text, textStyle);
return style(Markdown.QUOTE, text, textStyle);
}
@Override
public MarkupBuilder doubleQuoted(String text, CharSequence... textStyle) {
return style(DOUBLE_QUOTED, text, textStyle);
return style(Markdown.DOUBLE_QUOTED, text, textStyle);
}
@Override
public MarkupBuilder unquoted(String text, CharSequence... textStyle) {
return style(UNQUOTED, text, textStyle);
return style(Markdown.UNQUOTED, text, textStyle);
}
@Override
public MarkupBuilder br() {
content.append(BR);
content.append(Markdown.BR);
return this;
}
@Override
public MarkupBuilder hbr() {
content.append(HBR);
content.append(Markdown.HBR);
return this;
}
@Override
public MarkupBuilder newLine() {
content.append(NEW_LINE);
content.append(Markdown.NEW_LINE);
return this;
}
@Override
public MarkupBuilder pageBreak() {
content.append(PAGEBREAKS);
content.append(Markdown.PAGEBREAKS);
br();
return this;
}
......@@ -298,8 +296,8 @@ public class MarkdownBuilder implements MarkupBuilder {
if (Assert.isBlank(content)) {
return content;
}
return content.replaceAll(BR.toString(),
Matcher.quoteReplacement(WHITESPACE.toString()));
return content.replaceAll(Markdown.BR.toString(),
Matcher.quoteReplacement(Markdown.WHITESPACE.toString()));
}
}
package com.apidoc.core.common.postman;
package kim.apidoc.core.common.postman;
import lombok.Getter;
import lombok.Setter;
......
package com.apidoc.core.common.postman;
package kim.apidoc.core.common.postman;
/**
* 对应postman定义的mode
......
package com.apidoc.core.common.postman;
package kim.apidoc.core.common.postman;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
......
package com.apidoc.core.common.postman;
package kim.apidoc.core.common.postman;
import lombok.Getter;
import lombok.Setter;
......
package com.apidoc.core.common.postman;
package kim.apidoc.core.common.postman;
import lombok.Getter;
import lombok.Setter;
......
package com.apidoc.core.common.postman;
package kim.apidoc.core.common.postman;
import com.apidoc.core.schema.Row;
import kim.apidoc.core.schema.Row;
import lombok.Getter;
import lombok.Setter;
......
package com.apidoc.core.common.postman;
package kim.apidoc.core.common.postman;
import lombok.Getter;
import lombok.Setter;
......
package com.apidoc.core.common.postman;
package kim.apidoc.core.common.postman;
import com.apidoc.core.schema.Header;
import com.apidoc.core.schema.Method;
import kim.apidoc.core.schema.Header;
import kim.apidoc.core.schema.Method;
import lombok.Getter;
import lombok.Setter;
......
package com.apidoc.core.common.postman;
package kim.apidoc.core.common.postman;
import com.apidoc.core.schema.Header;
import kim.apidoc.core.schema.Header;
import lombok.Getter;
import lombok.Setter;
......
package com.apidoc.core.common.postman;
package kim.apidoc.core.common.postman;
import lombok.Getter;
import lombok.Setter;
......
package com.apidoc.core.parser;
package kim.apidoc.core.parser;
import com.apidoc.core.schema.Chapter;
import com.apidoc.core.schema.Section;
import kim.apidoc.core.schema.Chapter;
import kim.apidoc.core.schema.Section;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;
......
package com.apidoc.core.parser;
package kim.apidoc.core.parser;
import com.apidoc.core.common.helper.OptionalHelper;
import com.apidoc.core.schema.Chapter;
import com.apidoc.core.schema.Node;
import com.apidoc.core.schema.Project;
import com.apidoc.core.schema.Section;
import kim.apidoc.core.common.helper.OptionalHelper;
import kim.apidoc.core.schema.Chapter;
import kim.apidoc.core.schema.Node;
import kim.apidoc.core.schema.Project;
import kim.apidoc.core.schema.Section;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
......
package com.apidoc.core.render;
import com.apidoc.core.ApiDoc;
import com.apidoc.core.common.helper.FileHelper;
import com.apidoc.core.common.helper.StringHelper;
import com.apidoc.core.common.markup.MarkupBuilder;
import com.apidoc.core.common.markup.asciidoc.AsciiDoc;
import com.apidoc.core.schema.*;
package kim.apidoc.core.render;
import kim.apidoc.core.ApiDoc;
import kim.apidoc.core.common.helper.FileHelper;
import kim.apidoc.core.common.helper.StringHelper;
import kim.apidoc.core.common.markup.MarkupBuilder;
import kim.apidoc.core.common.markup.asciidoc.AsciiDoc;
import com.google.common.collect.Lists;
import kim.apidoc.core.schema.*;
import lombok.extern.slf4j.Slf4j;
import org.asciidoctor.Asciidoctor;
import org.asciidoctor.AttributesBuilder;
......
package kim.apidoc.core.render;
import kim.apidoc.core.schema.Project;
/**
* 生成markdown api文档
*
* @author duanledexianxianxian
* @version 1.0.0
* @date 2020 /3/26 19:03
* @since 1.0.0
*/
public class MarkdownRender implements ProjectRender {
@Override
public void render(Project project) {
}
}
package com.apidoc.core.render;
package kim.apidoc.core.render;
import com.apidoc.core.ApiDoc;
import com.apidoc.core.common.ObjectMappers;
import com.apidoc.core.common.helper.FileHelper;
import com.apidoc.core.common.postman.*;
import com.apidoc.core.schema.*;
import com.fasterxml.jackson.databind.node.ObjectNode;
import kim.apidoc.core.ApiDoc;
import kim.apidoc.core.common.ObjectMappers;
import kim.apidoc.core.common.helper.FileHelper;
import kim.apidoc.core.common.postman.*;
import kim.apidoc.core.schema.*;
import lombok.extern.slf4j.Slf4j;
import java.nio.file.Path;
......
package com.apidoc.core.render;
package kim.apidoc.core.render;
import com.apidoc.core.schema.Project;
import kim.apidoc.core.schema.Project;
/**
* The interface Project render.
......
package com.apidoc.core.resolver;
package kim.apidoc.core.resolver;
import com.apidoc.core.ApiDoc;
import com.apidoc.core.common.description.TypeDescription;
import com.apidoc.core.common.description.ArrayTypeDescription;
import kim.apidoc.core.ApiDoc;
import kim.apidoc.core.common.description.TypeDescription;
import kim.apidoc.core.common.description.ArrayTypeDescription;
import com.github.javaparser.resolution.types.ResolvedType;
public class ArrayTypeResolver implements TypeResolver {
......
package com.apidoc.core.resolver;
package kim.apidoc.core.resolver;
import com.apidoc.core.ApiDoc;
import com.apidoc.core.common.helper.TypeParameterHelper;
import com.apidoc.core.common.description.ArrayTypeDescription;
import com.apidoc.core.common.description.TypeDescription;
import com.apidoc.core.common.description.UnAvailableTypeDescription;
import kim.apidoc.core.ApiDoc;
import kim.apidoc.core.common.helper.TypeParameterHelper;
import kim.apidoc.core.common.description.ArrayTypeDescription;
import kim.apidoc.core.common.description.TypeDescription;
import kim.apidoc.core.common.description.UnAvailableTypeDescription;
import com.github.javaparser.resolution.types.ResolvedType;
import com.google.common.collect.ImmutableList;
......
package com.apidoc.core.resolver;
package kim.apidoc.core.resolver;
import com.apidoc.core.common.description.TypeDescription;
import com.apidoc.core.common.description.StringTypeDescription;
import kim.apidoc.core.common.description.TypeDescription;
import kim.apidoc.core.common.description.StringTypeDescription;
import com.github.javaparser.resolution.types.ResolvedType;
import com.google.common.collect.ImmutableList;
......
package com.apidoc.core.resolver;
package kim.apidoc.core.resolver;
import com.apidoc.core.common.description.StringTypeDescription;
import com.apidoc.core.common.description.TypeDescription;
import kim.apidoc.core.common.description.StringTypeDescription;
import kim.apidoc.core.common.description.TypeDescription;
import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration;
import com.github.javaparser.resolution.declarations.ResolvedEnumDeclaration;
import com.github.javaparser.resolution.types.ResolvedType;
......
package com.apidoc.core.resolver;
package kim.apidoc.core.resolver;
import com.apidoc.core.common.description.TypeDescription;
import com.apidoc.core.common.description.UnAvailableTypeDescription;
import kim.apidoc.core.common.description.TypeDescription;
import kim.apidoc.core.common.description.UnAvailableTypeDescription;
import com.github.javaparser.resolution.types.ResolvedType;
import com.google.common.collect.ImmutableList;
......@@ -9,24 +9,14 @@ import com.google.common.collect.ImmutableList;
* 不支持直接使用Map,建议使用DTO
*/
public class MapTypeResolver implements TypeResolver {
@Override
public boolean accept(ResolvedType type) {
return isMap(type);
}
@Override
public TypeDescription resolve(ResolvedType type) {
return new UnAvailableTypeDescription();
}
private static boolean isMap(ResolvedType type){
if(!type.isReferenceType()){
private static boolean isMap(ResolvedType type) {
if (!type.isReferenceType()) {
return false;
}
return isMap(type.asReferenceType().getId());
}
private static boolean isMap(String id){
private static boolean isMap(String id) {
return ImmutableList.of("java.util.Map",
"java.util.HashMap",
"java.util.Hashtable",
......@@ -35,4 +25,14 @@ public class MapTypeResolver implements TypeResolver {
"java.lang.TreeMap"
).contains(id);
}
@Override
public boolean accept(ResolvedType type) {
return isMap(type);
}
@Override
public TypeDescription resolve(ResolvedType type) {
return new UnAvailableTypeDescription();
}
}
package com.apidoc.core.resolver;
package kim.apidoc.core.resolver;
import com.apidoc.core.ApiDoc;
import com.apidoc.core.common.description.ObjectTypeDescription;
import com.apidoc.core.common.description.TypeDescription;
import com.apidoc.core.common.helper.*;
import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration;
import com.github.javaparser.resolution.types.ResolvedReferenceType;
import com.github.javaparser.resolution.types.ResolvedType;
import kim.apidoc.core.ApiDoc;
import kim.apidoc.core.common.description.ObjectTypeDescription;
import kim.apidoc.core.common.description.TypeDescription;
import kim.apidoc.core.common.helper.*;
import java.util.Optional;
......
package com.apidoc.core.resolver;
package kim.apidoc.core.resolver;
import com.apidoc.core.common.description.PrimitiveTypeDescription;
import com.apidoc.core.common.description.TypeDescription;
import kim.apidoc.core.common.description.PrimitiveTypeDescription;
import kim.apidoc.core.common.description.TypeDescription;
import com.github.javaparser.resolution.types.ResolvedType;
import com.google.common.collect.ImmutableList;
......
package com.apidoc.core.resolver;
package kim.apidoc.core.resolver;
import com.apidoc.core.common.description.TypeDescription;
import com.apidoc.core.common.description.StringTypeDescription;
import kim.apidoc.core.common.description.TypeDescription;
import kim.apidoc.core.common.description.StringTypeDescription;
import com.github.javaparser.resolution.types.ResolvedType;
import com.google.common.collect.ImmutableList;
......
package com.apidoc.core.resolver;
package kim.apidoc.core.resolver;
import com.apidoc.core.common.description.TypeDescription;
import com.apidoc.core.common.description.UnAvailableTypeDescription;
import kim.apidoc.core.common.description.TypeDescription;
import kim.apidoc.core.common.description.UnAvailableTypeDescription;
import com.github.javaparser.resolution.types.ResolvedType;
public class SystemObjectTypeResolver implements TypeResolver {
......
package com.apidoc.core.resolver;
package kim.apidoc.core.resolver;
import com.apidoc.core.common.description.TypeDescription;
import kim.apidoc.core.common.description.TypeDescription;
import com.github.javaparser.ast.type.Type;
public interface TypeNameResolver {
......
package com.apidoc.core.resolver;
package kim.apidoc.core.resolver;
import com.apidoc.core.common.description.TypeDescription;
import kim.apidoc.core.common.description.TypeDescription;
import com.github.javaparser.resolution.types.ResolvedType;
public interface TypeResolver {
......
package com.apidoc.core.resolver;
package kim.apidoc.core.resolver;
import com.apidoc.core.common.description.TypeDescription;
import com.apidoc.core.common.helper.TypeNameHelper;
import com.apidoc.core.common.description.UnAvailableTypeDescription;
import kim.apidoc.core.common.description.TypeDescription;
import kim.apidoc.core.common.helper.TypeNameHelper;
import kim.apidoc.core.common.description.UnAvailableTypeDescription;
import com.github.javaparser.ast.type.Type;
import com.github.javaparser.resolution.UnsolvedSymbolException;
import com.github.javaparser.resolution.types.ResolvedType;
......
package com.apidoc.core.schema;
package kim.apidoc.core.schema;
import lombok.Getter;
import lombok.Setter;
......@@ -6,14 +6,31 @@ import lombok.Setter;
import java.util.Set;
import java.util.TreeSet;
/**
* The type Book.
*
* @author fengyuchenglun
* @version 1.0.0
*/
@Setter
@Getter
public class Book extends Node {
/**
* The constant DEFAULT.
*/
public static final String DEFAULT = "index";
/**
* 章
*/
Set<Chapter> chapters = new TreeSet<>();
/**
* Instantiates a new Book.
*
* @param id the id
*/
public Book(String id) {
this.id = id;
}
......
package com.apidoc.core.schema;
package kim.apidoc.core.schema;
import lombok.Getter;
import lombok.Setter;
......@@ -8,13 +8,22 @@ import java.util.TreeSet;
/**
* 章,一个类解析为一章
*
* @author fengyuchenglun
* @version 1.0.0
*/
@Setter
@Getter
public class Chapter extends Node {
/**
* The Book name.
*/
String bookName;
/**
* The Sections.
*/
Set<Section> sections = new TreeSet<>();
}
package com.apidoc.core.schema;
package kim.apidoc.core.schema;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
/**
* The type Header.
*
* @author fengyuchenglun
* @version 1.0.0
*/
@Setter
@Getter
@NoArgsConstructor
public class Header{
public class Header {
public static final Header APPLICATION_JSON = new Header("Content-Type","application/json");
public static final Header X_FORM_WWW_URLENCODED = new Header("Content-Type","x-www-form-urlencoded");
/**
* The constant APPLICATION_JSON.
*/
public static final Header APPLICATION_JSON = new Header("Content-Type", "application/json");
/**
* The constant X_FORM_WWW_URLENCODED.
*/
public static final Header X_FORM_WWW_URLENCODED = new Header("Content-Type", "x-www-form-urlencoded");
/**
* The Key.
*/
String key;
/**
* The Value.
*/
String value;
/**
* The Description.
*/
String description;
/**
* Instantiates a new Header.
*
* @param key the key
* @param value the value
*/
public Header(String key, String value) {
this.key = key;
this.value = value;
}
public static Header valueOf(String text){
/**
* Value of header.
*
* @param text the text
* @return the header
*/
public static Header valueOf(String text) {
String[] arr = text.split(":");
Header header = new Header();
header.setKey(arr[0]);
if(arr.length>1){
if (arr.length > 1) {
header.setValue(arr[1]);
}
return header;
}
@Override
public String toString(){
public String toString() {
return key + ": " + value;
}
......
package kim.apidoc.core.schema;
import lombok.extern.slf4j.Slf4j;
/**
* 支持的http method
* @author fengyuchenglun
*/
@Slf4j
public enum Method {
/**
* Get method.
*/
GET,
/**
* Post method.
*/
POST,
/**
* Put method.
*/
PUT,
/**
* Delete method.
*/
DELETE,
/**
* Options method.
*/
OPTIONS,
/**
* Patch method.
*/
PATCH,
/**
* Copy method.
*/
COPY,
/**
* Head method.
*/
HEAD,
/**
* Link method.
*/
LINK,
/**
* Unlink method.
*/
UNLINK,
/**
* Purge method.
*/
PURGE,
/**
* Lock method.
*/
LOCK,
/**
* Unlock method.
*/
UNLOCK,
/**
* Propfind method.
*/
PROPFIND,
/**
* View method.
*/
VIEW;
/**
* Of method.
*
* @param name the name
* @return the method
*/
public static Method of(String name) {
return valueOf(name);
}
}
package com.apidoc.core.schema;
package kim.apidoc.core.schema;
import com.apidoc.core.Context;
import com.apidoc.core.common.helper.CommentHelper;
import com.apidoc.core.common.helper.StringHelper;
import kim.apidoc.core.Context;
import kim.apidoc.core.common.helper.CommentHelper;
import kim.apidoc.core.common.helper.StringHelper;
import com.github.javaparser.ast.comments.Comment;
import com.github.javaparser.javadoc.Javadoc;
import lombok.Getter;
......
package com.apidoc.core.schema;
package kim.apidoc.core.schema;
import lombok.Getter;
import lombok.Setter;
......@@ -31,7 +31,7 @@ public class Project extends Node {
* @param chapter the chapter
*/
public void addChapter(Chapter chapter) {
if(Objects.isNull(chapter.getBookName())){
if (Objects.isNull(chapter.getBookName())) {
chapter.setBookName(Book.DEFAULT);
}
if (!books.containsKey(chapter.getBookName())) {
......
package com.apidoc.core.schema;
package kim.apidoc.core.schema;
import lombok.*;
/**
* The type Row.
*
* @author fengyuchenglun
* @version 1.0.0
*/
@EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
......@@ -9,12 +15,32 @@ import lombok.*;
@Getter
public class Row {
/**
* The Key.
*/
String key;
/**
* The Type.
*/
String type;
/**
* The Condition.
*/
String condition;
/**
* The Def.
*/
String def;
/**
* The Remark.
*/
String remark;
/**
* Instantiates a new Row.
*
* @param type the type
*/
public Row(String type) {
this.type = type;
}
......
package com.apidoc.core.schema;
package kim.apidoc.core.schema;
import com.apidoc.core.common.ObjectMappers;
import com.apidoc.core.common.QueryStringBuilder;
import com.apidoc.core.common.helper.StringHelper;
import kim.apidoc.core.common.ObjectMappers;
import kim.apidoc.core.common.QueryStringBuilder;
import kim.apidoc.core.common.helper.StringHelper;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.Getter;
......@@ -12,42 +12,93 @@ import java.util.*;
/**
* 小节,一个请求,封装为一个小节
*
* @author fengyuchenglun
* @version 1.0.0
*/
@Setter
@Getter
public class Section extends Node {
/**
* The Method.
*/
Method method;
/**
* The Uri.
*/
String uri;
Map<String,Header> inHeaders = new LinkedHashMap<>();
/**
* The In headers.
*/
Map<String, Header> inHeaders = new LinkedHashMap<>();
/**
* The Path variable.
*/
ObjectNode pathVariable = ObjectMappers.instance.createObjectNode();
/**
* The Parameter.
*/
JsonNode parameter;
/**
* The Query parameter.
*/
boolean queryParameter = true;
Map<String,Row> requestRows = new LinkedHashMap<>();
Map<String,Header> outHeaders = new LinkedHashMap<>();
/**
* The Request rows.
*/
Map<String, Row> requestRows = new LinkedHashMap<>();
/**
* The Out headers.
*/
Map<String, Header> outHeaders = new LinkedHashMap<>();
/**
* The Response.
*/
JsonNode response;
Map<String,Row> responseRows = new LinkedHashMap<>();
/**
* The Response rows.
*/
Map<String, Row> responseRows = new LinkedHashMap<>();
/**
* The Raw response.
*/
Object rawResponse;
public void addRequestRow(Row row){
/**
* Add request row.
*
* @param row the row
*/
public void addRequestRow(Row row) {
requestRows.put(row.getKey(), row);
}
public void addRequestRows(Collection<Row> rows){
/**
* Add request rows.
*
* @param rows the rows
*/
public void addRequestRows(Collection<Row> rows) {
for (Row row : rows) {
if(row.getKey()!=null && !requestRows.containsKey(row.getKey())){
requestRows.put(row.getKey(),row);
if (row.getKey() != null && !requestRows.containsKey(row.getKey())) {
requestRows.put(row.getKey(), row);
}
}
}
public String getRequestLine(){
/**
* Get request line string.
*
* @return the string
*/
public String getRequestLine() {
StringBuilder builder = new StringBuilder(this.method.toString());
builder.append(" ").append(this.uri);
if(this.queryParameter && Objects.equals("GET", this.method)){
if (this.queryParameter && Objects.equals("GET", this.method)) {
String parameterString = getParameterString();
if(StringHelper.nonBlank(parameterString)){
if (StringHelper.nonBlank(parameterString)) {
builder.append("?").append(parameterString);
}
}
......@@ -55,52 +106,92 @@ public class Section extends Node {
return builder.toString();
}
public String getParameterString(){
if(queryParameter && parameter instanceof ObjectNode){
return new QueryStringBuilder().append((ObjectNode)parameter).toString();
/**
* Get parameter string string.
*
* @return the string
*/
public String getParameterString() {
if (queryParameter && parameter instanceof ObjectNode) {
return new QueryStringBuilder().append((ObjectNode) parameter).toString();
}
return ObjectMappers.pretty(parameter);
}
public boolean hasRequestBody(){
if(Objects.equals("GET",this.method)){
/**
* Has request body boolean.
*
* @return the boolean
*/
public boolean hasRequestBody() {
if (Objects.equals("GET", this.method)) {
return false;
}
return parameter!=null && parameter.size()>0;
return parameter != null && parameter.size() > 0;
}
public void addResponseRow(Row row){
/**
* Add response row.
*
* @param row the row
*/
public void addResponseRow(Row row) {
responseRows.put(row.getKey(), row);
}
public void addResponseRows(Collection<Row> rows){
/**
* Add response rows.
*
* @param rows the rows
*/
public void addResponseRows(Collection<Row> rows) {
for (Row row : rows) {
if(row.getKey()!=null && !responseRows.containsKey(row.getKey())) {
if (row.getKey() != null && !responseRows.containsKey(row.getKey())) {
responseRows.put(row.getKey(), row);
}
}
}
public boolean hasResponseBody(){
return response!=null || rawResponse!=null;
/**
* Has response body boolean.
*
* @return the boolean
*/
public boolean hasResponseBody() {
return response != null || rawResponse != null;
}
public String getResponseString(){
if(response!=null){
/**
* Get response string string.
*
* @return the string
*/
public String getResponseString() {
if (response != null) {
return ObjectMappers.pretty(response);
}
return String.valueOf(rawResponse);
}
public void addInHeader(Header header){
/**
* Add in header.
*
* @param header the header
*/
public void addInHeader(Header header) {
if (!inHeaders.containsKey(header.getKey())) {
inHeaders.put(header.getKey(),header);
inHeaders.put(header.getKey(), header);
}
}
public void addOutHeader(Header header){
/**
* Add out header.
*
* @param header the header
*/
public void addOutHeader(Header header) {
if (!outHeaders.containsKey(header.getKey())) {
outHeaders.put(header.getKey(),header);
outHeaders.put(header.getKey(), header);
}
}
......
package com.apidoc.core.schema;
package kim.apidoc.core.schema;
import lombok.Getter;
import lombok.Setter;
......@@ -8,23 +8,41 @@ import java.util.Objects;
/**
* //@param username 用户名
* id key content
* id key content
*
* @author fengyuchenglun
* @version 1.0.0
*/
@Slf4j
@Setter
@Getter
public class Tag {
/**
* The Id.
*/
String id;
/**
* The Key.
*/
String key;
/**
* The Content.
*/
String content;
public int getIntContent(int def){
/**
* Get int content int.
*
* @param def the def
* @return the int
*/
public int getIntContent(int def) {
if (Objects.nonNull(content)) {
try{
try {
return Integer.parseInt(content);
}catch (Exception e){
log.warn(content+" parse error");
} catch (Exception e) {
log.warn(content + " parse error");
}
}
return def;
......
package com.apigcc.springmvc;
package com.kim.apidoc.springmvc;
import com.github.javaparser.ast.NodeList;
import com.github.javaparser.ast.body.Parameter;
......
package com.apigcc.springmvc;
package com.kim.apidoc.springmvc;
import com.apidoc.core.common.URI;
import com.apidoc.core.common.helper.AnnotationHelper;
import com.apidoc.core.common.helper.ClassDeclarationHelper;
import com.apidoc.core.common.helper.ExpressionHelper;
import com.apidoc.core.schema.Method;
import kim.apidoc.core.common.URI;
import kim.apidoc.core.common.helper.AnnotationHelper;
import kim.apidoc.core.common.helper.ClassDeclarationHelper;
import kim.apidoc.core.common.helper.ExpressionHelper;
import kim.apidoc.core.schema.Method;
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.NodeList;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
......
package com.apigcc.springmvc;
package com.kim.apidoc.springmvc;
import com.apidoc.core.ApiDoc;
import kim.apidoc.core.ApiDoc;
import com.google.common.collect.Lists;
import lombok.Data;
......
package com.apigcc.springmvc;
import com.apidoc.core.ApiDoc;
import com.apidoc.core.common.URI;
import com.apidoc.core.common.description.ObjectTypeDescription;
import com.apidoc.core.common.description.TypeDescription;
import com.apidoc.core.common.helper.AnnotationHelper;
import com.apidoc.core.common.helper.ExpressionHelper;
import com.apidoc.core.common.helper.StringHelper;
import com.apidoc.core.parser.ParserStrategy;
import com.apidoc.core.schema.Chapter;
import com.apidoc.core.schema.Header;
import com.apidoc.core.schema.Row;
import com.apidoc.core.schema.Section;
import com.apigcc.springmvc.resovler.SpringComponentTypeResolver;
package com.kim.apidoc.springmvc;
import com.kim.apidoc.springmvc.resovler.SpringComponentTypeResolver;
import kim.apidoc.core.ApiDoc;
import kim.apidoc.core.common.URI;
import kim.apidoc.core.common.description.ObjectTypeDescription;
import kim.apidoc.core.common.description.TypeDescription;
import kim.apidoc.core.common.helper.AnnotationHelper;
import kim.apidoc.core.common.helper.ExpressionHelper;
import kim.apidoc.core.common.helper.StringHelper;
import kim.apidoc.core.parser.ParserStrategy;
import kim.apidoc.core.schema.Chapter;
import kim.apidoc.core.schema.Header;
import kim.apidoc.core.schema.Row;
import kim.apidoc.core.schema.Section;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.body.Parameter;
......@@ -22,9 +22,6 @@ import com.github.javaparser.ast.expr.Expression;
import java.util.List;
import java.util.Optional;
import static com.apigcc.springmvc.ParameterHelper.ANNOTATION_REQUEST_HEADER;
import static com.apigcc.springmvc.ParameterHelper.ANNOTATION_REQUEST_PARAM;
/**
* spring 解析
......@@ -196,7 +193,7 @@ public class SpringParser implements ParserStrategy {
if (ParameterHelper.isRequestHeader(parameter)) {
String key = parameter.getNameAsString();
String defaultValue = "{value}";
AnnotationExpr annotationExpr = parameter.getAnnotationByName(ANNOTATION_REQUEST_HEADER).get();
AnnotationExpr annotationExpr = parameter.getAnnotationByName(ParameterHelper.ANNOTATION_REQUEST_HEADER).get();
Optional<Expression> valueOptional = AnnotationHelper.getAnyAttribute(annotationExpr, "value", "name");
if (valueOptional.isPresent()) {
key = String.valueOf(ExpressionHelper.getValue(valueOptional.get()));
......@@ -260,7 +257,7 @@ public class SpringParser implements ParserStrategy {
Object defaultValue = null;
Boolean required = null;
Optional<AnnotationExpr> optional = parameter.getAnnotationByName(ANNOTATION_REQUEST_PARAM);
Optional<AnnotationExpr> optional = parameter.getAnnotationByName(ParameterHelper.ANNOTATION_REQUEST_PARAM);
if (optional.isPresent()) {
Optional<Expression> valueOptional = AnnotationHelper.getAnyAttribute(optional.get(), "value", "name");
if (valueOptional.isPresent()) {
......
package com.apigcc.springmvc.resovler;
import com.apidoc.core.ApiDoc;
import com.apidoc.core.common.description.TypeDescription;
import com.apidoc.core.common.description.UnAvailableTypeDescription;
import com.apidoc.core.common.helper.TypeParameterHelper;
import com.apidoc.core.resolver.TypeNameResolver;
import com.apidoc.core.resolver.TypeResolver;
package com.kim.apidoc.springmvc.resovler;
import kim.apidoc.core.ApiDoc;
import kim.apidoc.core.common.description.TypeDescription;
import kim.apidoc.core.common.description.UnAvailableTypeDescription;
import kim.apidoc.core.common.helper.TypeParameterHelper;
import kim.apidoc.core.resolver.TypeNameResolver;
import kim.apidoc.core.resolver.TypeResolver;
import com.github.javaparser.ast.NodeList;
import com.github.javaparser.ast.type.Type;
import com.github.javaparser.resolution.types.ResolvedType;
......
com.kim.apidoc.springmvc.SpringParser
\ No newline at end of file
package com.apigcc.example;
package com.kim.apidoc.example;
import com.apidoc.core.ApiDoc;
import com.apidoc.core.Context;
import kim.apidoc.core.ApiDoc;
import kim.apidoc.core.Context;
import org.junit.Test;
import java.nio.file.Paths;
......
package com.apigcc.example.annotation;
package com.kim.apidoc.example.annotation;
import org.springframework.stereotype.Controller;
import java.lang.annotation.ElementType;
......
package com.apigcc.example.annotation;
package com.kim.apidoc.example.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
......
package com.apigcc.example.common;
package com.kim.apidoc.example.common;
import lombok.Getter;
import lombok.Setter;
......
package com.apigcc.example.common;
package com.kim.apidoc.example.common;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonProperty;
......
package com.apigcc.example.common;
package com.kim.apidoc.example.common;
import lombok.Getter;
import lombok.Setter;
......
package com.apigcc.example.common;
package com.kim.apidoc.example.common;
import lombok.Getter;
import lombok.Setter;
......
package com.apigcc.example.common;
package com.kim.apidoc.example.common;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
......
package com.apigcc.example.common;
package com.kim.apidoc.example.common;
import lombok.Getter;
import lombok.Setter;
......
package com.apigcc.example.common;
package com.kim.apidoc.example.common;
/**
* 某些用户信息框架,如spring security的用户登录信息
......
package com.apigcc.example.common;
package com.kim.apidoc.example.common;
import lombok.Getter;
import lombok.Setter;
......
package com.apigcc.example.common;
package com.kim.apidoc.example.common;
import lombok.Getter;
import lombok.Setter;
......
package com.apigcc.example.spring;
package com.kim.apidoc.example.spring;
import org.springframework.web.bind.annotation.RequestMapping;
......
package com.apigcc.example.spring.advanced;
package com.kim.apidoc.example.spring.advanced;
import com.apigcc.example.common.ResultData;
import com.apigcc.example.spring.BaseController;
import com.kim.apidoc.example.common.ResultData;
import com.kim.apidoc.example.spring.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
......
package com.apigcc.example.spring.advanced;
package com.kim.apidoc.example.spring.advanced;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......
package com.apigcc.example.spring.advanced;
package com.kim.apidoc.example.spring.advanced;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......
package com.apigcc.example.spring.advanced;
package com.kim.apidoc.example.spring.advanced;
import com.apigcc.example.annotation.KimController;
import com.apigcc.example.common.ResultData;
import com.apigcc.example.common.User;
import com.kim.apidoc.example.annotation.KimController;
import com.kim.apidoc.example.common.ResultData;
import com.kim.apidoc.example.common.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment