Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
apidoc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanledexianxianxian
apidoc
Commits
d3cbfeaf
Commit
d3cbfeaf
authored
Jun 22, 2020
by
duanledexianxianxian
😁
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码重构
parent
ec4188d8
Changes
23
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
362 additions
and
221 deletions
+362
-221
apidoc-core/build.gradle
apidoc-core/build.gradle
+1
-0
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/Context.java
...n/java/com/github/fengyuchenglun/apidoc/core/Context.java
+4
-2
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/QueryStringBuilder.java
...fengyuchenglun/apidoc/core/common/QueryStringBuilder.java
+3
-1
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/ArrayTypeDescription.java
.../apidoc/core/common/description/ArrayTypeDescription.java
+3
-0
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/ObjectTypeDescription.java
...apidoc/core/common/description/ObjectTypeDescription.java
+4
-2
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/PrimitiveTypeDescription.java
...doc/core/common/description/PrimitiveTypeDescription.java
+2
-0
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/StringTypeDescription.java
...apidoc/core/common/description/StringTypeDescription.java
+2
-0
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/TypeDescription.java
...nglun/apidoc/core/common/description/TypeDescription.java
+5
-3
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/UnAvailableTypeDescription.java
...c/core/common/description/UnAvailableTypeDescription.java
+2
-0
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/parser/VisitorParser.java
...thub/fengyuchenglun/apidoc/core/parser/VisitorParser.java
+17
-13
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/render/AsciiDocRender.java
...hub/fengyuchenglun/apidoc/core/render/AsciiDocRender.java
+1
-1
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/render/MarkdownRender.java
...hub/fengyuchenglun/apidoc/core/render/MarkdownRender.java
+0
-1
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/render/PostmanRender.java
...thub/fengyuchenglun/apidoc/core/render/PostmanRender.java
+11
-11
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Appendix.java
...om/github/fengyuchenglun/apidoc/core/schema/Appendix.java
+3
-0
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/ParameterType.java
...thub/fengyuchenglun/apidoc/core/schema/ParameterType.java
+2
-2
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Row.java
...ava/com/github/fengyuchenglun/apidoc/core/schema/Row.java
+1
-1
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Section.java
...com/github/fengyuchenglun/apidoc/core/schema/Section.java
+78
-13
apidoc-core/src/main/resources/templates/markdown.ftl
apidoc-core/src/main/resources/templates/markdown.ftl
+21
-3
apidoc-springmvc/src/main/java/com/github/fengyuchenglun/apidoc/springmvc/SpringParser.java
.../github/fengyuchenglun/apidoc/springmvc/SpringParser.java
+11
-9
apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/common/Query.java
.../java/com/github/fengyuchenglun/example/common/Query.java
+20
-2
apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/common/ResultData.java
.../com/github/fengyuchenglun/example/common/ResultData.java
+4
-4
apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/common/User.java
...t/java/com/github/fengyuchenglun/example/common/User.java
+32
-21
apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/spring/advanced/UserController.java
...engyuchenglun/example/spring/advanced/UserController.java
+135
-132
No files found.
apidoc-core/build.gradle
View file @
d3cbfeaf
...
...
@@ -3,4 +3,5 @@ dependencies {
compile
'com.fasterxml.jackson.core:jackson-databind:2.5.2'
compile
'org.asciidoctor:asciidoctorj:2.1.0'
compile
group:
'org.freemarker'
,
name:
'freemarker'
,
version:
'2.3.30'
compile
group:
'com.google.guava'
,
name:
'guava'
,
version:
'23.0'
}
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/Context.java
View file @
d3cbfeaf
package
com.github.fengyuchenglun.apidoc.core
;
import
com.github.fengyuchenglun.apidoc.core.common.Constants
;
import
com.github.fengyuchenglun.apidoc.core.render.AsciiDocRender
;
import
com.github.fengyuchenglun.apidoc.core.render.PostmanRender
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
com.github.fengyuchenglun.apidoc.core.common.helper.FileHelper
;
...
...
@@ -51,8 +53,8 @@ public class Context {
*/
@Setter
private
List
<
ProjectRender
>
renders
=
Lists
.
newArrayList
(
//
new AsciiDocRender(),
//
new PostmanRender(),
new
AsciiDocRender
(),
new
PostmanRender
(),
new
MarkdownRender
());
/**
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/QueryStringBuilder.java
View file @
d3cbfeaf
...
...
@@ -2,6 +2,8 @@ package com.github.fengyuchenglun.apidoc.core.common;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
org.apache.commons.lang3.ClassUtils
;
import
org.apache.commons.lang3.ObjectUtils
;
import
java.util.Iterator
;
...
...
@@ -15,7 +17,7 @@ public class QueryStringBuilder {
}
builder
.
append
(
key
);
builder
.
append
(
"="
);
builder
.
append
(
value
);
builder
.
append
(
ObjectUtils
.
isEmpty
(
value
)
?
"xxx"
:
value
);
return
this
;
}
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/ArrayTypeDescription.java
View file @
d3cbfeaf
...
...
@@ -4,6 +4,7 @@ import com.github.fengyuchenglun.apidoc.core.common.ObjectMappers;
import
com.github.fengyuchenglun.apidoc.core.schema.Row
;
import
com.fasterxml.jackson.databind.node.ArrayNode
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
java.util.ArrayList
;
import
java.util.Collection
;
...
...
@@ -11,6 +12,7 @@ import java.util.Collection;
/**
* 数组类型描述
*/
@EqualsAndHashCode
(
callSuper
=
true
)
@Data
public
class
ArrayTypeDescription
extends
TypeDescription
{
...
...
@@ -81,6 +83,7 @@ public class ArrayTypeDescription extends TypeDescription {
}
}
@Override
public
ArrayNode
getValue
()
{
return
value
;
}
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/ObjectTypeDescription.java
View file @
d3cbfeaf
...
...
@@ -5,6 +5,7 @@ import com.github.fengyuchenglun.apidoc.core.schema.Row;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
com.google.common.collect.Lists
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
lombok.Getter
;
import
lombok.Setter
;
...
...
@@ -17,6 +18,7 @@ import java.util.List;
* @author fengyuchenglun
* @version 1.0.0
*/
@EqualsAndHashCode
(
callSuper
=
true
)
@Data
public
class
ObjectTypeDescription
extends
TypeDescription
{
...
...
@@ -136,11 +138,11 @@ public class ObjectTypeDescription extends TypeDescription {
}
@Override
public
Collection
<
Row
>
rows
(
String
requestP
arameterType
)
{
public
Collection
<
Row
>
rows
(
String
p
arameterType
)
{
Collection
<
Row
>
rows
=
super
.
rows
(
null
);
for
(
TypeDescription
member
:
members
)
{
if
(
member
.
isAvailable
())
{
rows
.
addAll
(
member
.
rows
(
requestP
arameterType
));
rows
.
addAll
(
member
.
rows
(
p
arameterType
));
}
}
return
rows
;
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/PrimitiveTypeDescription.java
View file @
d3cbfeaf
...
...
@@ -3,10 +3,12 @@ package com.github.fengyuchenglun.apidoc.core.common.description;
import
com.github.javaparser.resolution.types.ResolvedPrimitiveType
;
import
com.github.javaparser.resolution.types.ResolvedReferenceType
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
/**
* 原始类型描述
*/
@EqualsAndHashCode
(
callSuper
=
true
)
@Data
public
class
PrimitiveTypeDescription
extends
TypeDescription
{
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/StringTypeDescription.java
View file @
d3cbfeaf
package
com.github.fengyuchenglun.apidoc.core.common.description
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
/**
* 字符串类型
*/
@EqualsAndHashCode
(
callSuper
=
true
)
@Data
public
class
StringTypeDescription
extends
TypeDescription
{
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/TypeDescription.java
View file @
d3cbfeaf
...
...
@@ -9,11 +9,13 @@ import com.google.common.collect.Lists;
import
lombok.Data
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.apache.commons.lang3.ObjectUtils
;
import
java.util.Collection
;
/**
* The type Type description.
*
* @author duanledexianxianxian
*/
@Data
...
...
@@ -51,7 +53,7 @@ public abstract class TypeDescription {
/**
* 是否必填.
*/
protected
Boolean
required
=
false
;
protected
Boolean
required
=
false
;
/**
* Is available boolean.
...
...
@@ -173,7 +175,7 @@ public abstract class TypeDescription {
*
* @return the collection
*/
public
Collection
<
Row
>
rows
(
String
requestP
arameterType
)
{
public
Collection
<
Row
>
rows
(
String
p
arameterType
)
{
String
fullKey
=
fullKey
();
if
(
StringHelper
.
isBlank
(
fullKey
))
{
return
Lists
.
newArrayList
();
...
...
@@ -191,7 +193,7 @@ public abstract class TypeDescription {
// condition.append("required=").append(required);
// }
return
Lists
.
newArrayList
(
new
Row
(
key
,
type
,
required
,
condition
.
toString
(),
def
,
remark
,
requestP
arameterType
));
return
Lists
.
newArrayList
(
new
Row
(
fullKey
,
type
,
required
,
condition
.
toString
(),
def
,
remark
,
p
arameterType
));
}
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/UnAvailableTypeDescription.java
View file @
d3cbfeaf
...
...
@@ -2,6 +2,7 @@ package com.github.fengyuchenglun.apidoc.core.common.description;
import
com.github.fengyuchenglun.apidoc.core.schema.Row
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
java.util.Collection
;
...
...
@@ -9,6 +10,7 @@ import java.util.Collection;
* 未知类型,应该忽略
* @author duanledexianxianxian
*/
@EqualsAndHashCode
(
callSuper
=
true
)
@Data
public
class
UnAvailableTypeDescription
extends
TypeDescription
{
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/parser/VisitorParser.java
View file @
d3cbfeaf
...
...
@@ -33,16 +33,22 @@ public class VisitorParser extends VoidVisitorAdapter<Node> {
public
void
visit
(
final
EnumDeclaration
enumDeclaration
,
final
Node
arg
)
{
// 访问枚举
if
(
arg
instanceof
Project
)
{
Project
project
=
(
Project
)
arg
;
// 章节
Chapter
chapter
=
new
Chapter
();
enumDeclaration
.
getFullyQualifiedName
().
ifPresent
(
chapter:
:
setId
);
chapter
.
setName
(
enumDeclaration
.
getNameAsString
());
enumDeclaration
.
getComment
().
ifPresent
(
chapter:
:
accept
);
OptionalHelper
.
any
(
chapter
.
getTag
(
"book"
),
chapter
.
getTag
(
"group"
))
.
ifPresent
(
tag
->
chapter
.
setBookName
(
tag
.
getContent
()));
project
.
addChapter
(
chapter
);
super
.
visit
(
enumDeclaration
,
chapter
);
// Project project = (Project) arg;
// // 章节
// Chapter chapter = new Chapter();
// enumDeclaration.getFullyQualifiedName().ifPresent(chapter::setId);
// chapter.setName(enumDeclaration.getNameAsString());
// enumDeclaration.getComment().ifPresent(chapter::accept);
// OptionalHelper.any(chapter.getTag("book"), chapter.getTag("group"))
// .ifPresent(tag -> chapter.setBookName(tag.getContent()));
// project.addChapter(chapter);
//放入附录
if
(
enumDeclaration
.
getJavadocComment
().
isPresent
())
{
Appendix
appendix
=
Appendix
.
parse
(
enumDeclaration
.
getJavadocComment
().
get
());
ApiDoc
.
getInstance
().
getProject
().
getAppendices
().
add
(
appendix
);
}
// super.visit(enumDeclaration, chapter);
}
}
...
...
@@ -87,9 +93,7 @@ public class VisitorParser extends VoidVisitorAdapter<Node> {
if
(
commentedNode
instanceof
ClassOrInterfaceDeclaration
||
commentedNode
instanceof
EnumDeclaration
)
{
Appendix
appendix
=
Appendix
.
parse
(
javadocComment
);
if
(
appendix
!=
null
)
{
ApiDoc
.
getInstance
().
getProject
().
getAppendices
().
add
(
appendix
);
}
ApiDoc
.
getInstance
().
getProject
().
getAppendices
().
add
(
appendix
);
}
}
});
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/render/AsciiDocRender.java
View file @
d3cbfeaf
...
...
@@ -74,7 +74,7 @@ public class AsciiDocRender implements ProjectRender {
section
.
getInHeaders
().
values
().
forEach
(
header
->
builder
.
textLine
(
header
.
toString
()));
if
(
section
.
hasRequestBody
())
{
b
.
br
();
b
.
text
(
section
.
getParameterString
());
b
.
text
(
section
.
get
RequestBody
ParameterString
());
}
},
"source,HTTP"
);
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/render/MarkdownRender.java
View file @
d3cbfeaf
...
...
@@ -43,7 +43,6 @@ public class MarkdownRender implements ProjectRender {
}
private
void
build
(
Project
project
)
throws
Exception
{
System
.
out
.
println
(
project
);
String
templatePath
=
ApiDoc
.
getInstance
().
getContext
().
getMarkdownTemplate
();
String
id
=
ApiDoc
.
getInstance
().
getContext
().
getId
();
Path
buildPath
=
ApiDoc
.
getInstance
().
getContext
().
getBuildPath
();
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/render/PostmanRender.java
View file @
d3cbfeaf
...
...
@@ -74,18 +74,18 @@ public class PostmanRender implements ProjectRender {
request
.
setMethod
(
section
.
getMethod
());
request
.
getHeaders
().
addAll
(
section
.
getInHeaders
().
values
());
ObjectNode
objectNode
=
(
ObjectNode
)
section
.
getQueryParameters
();
for
(
String
key
:
section
.
getRequestRows
().
keySet
())
{
if
(
objectNode
.
has
(
key
))
{
Row
row
=
section
.
getRequestRows
().
get
(
key
);
request
.
getUrl
().
getQuery
().
add
(
Parameter
.
of
(
row
));
}
}
if
(
section
.
isQueryParameter
())
{
if
(
Method
.
GET
.
equals
(
request
.
getMethod
()))
{
ObjectNode
objectNode
=
(
ObjectNode
)
section
.
getParameter
();
for
(
String
key
:
section
.
getRequestRows
().
keySet
())
{
if
(
objectNode
.
has
(
key
))
{
Row
row
=
section
.
getRequestRows
().
get
(
key
);
request
.
getUrl
().
getQuery
().
add
(
Parameter
.
of
(
row
));
}
}
}
else
{
// get请求
if
(!
Method
.
GET
.
equals
(
request
.
getMethod
()))
{
request
.
getBody
().
setMode
(
BodyMode
.
urlencoded
);
ObjectNode
objectNode
=
(
ObjectNode
)
section
.
getParameter
();
objectNode
=
(
ObjectNode
)
section
.
getRequestBodyParameters
();
for
(
String
key
:
section
.
getRequestRows
().
keySet
())
{
if
(
objectNode
.
has
(
key
))
{
Row
row
=
section
.
getRequestRows
().
get
(
key
);
...
...
@@ -95,7 +95,7 @@ public class PostmanRender implements ProjectRender {
}
}
else
{
request
.
getBody
().
setMode
(
BodyMode
.
raw
);
request
.
getBody
().
setRaw
(
section
.
getParameterString
());
request
.
getBody
().
setRaw
(
section
.
get
RequestBody
ParameterString
());
}
item
.
setRequest
(
request
);
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Appendix.java
View file @
d3cbfeaf
package
com.github.fengyuchenglun.apidoc.core.schema
;
import
com.github.javaparser.ast.body.BodyDeclaration
;
import
com.github.javaparser.ast.body.EnumDeclaration
;
import
com.github.javaparser.ast.comments.JavadocComment
;
import
com.github.javaparser.ast.nodeTypes.NodeWithSimpleName
;
import
com.github.fengyuchenglun.apidoc.core.common.helper.EnumHelper
;
...
...
@@ -35,6 +36,8 @@ public class Appendix extends Node {
return
cells
.
isEmpty
();
}
/**
* Parse appendix.
*
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/
Request
ParameterType.java
→
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/ParameterType.java
View file @
d3cbfeaf
...
...
@@ -7,7 +7,7 @@ package com.github.fengyuchenglun.apidoc.core.schema;
* @date 2020 /3/29 0:37
* @since 1.0.0
*/
public
enum
Request
ParameterType
{
public
enum
ParameterType
{
/**
* 查询参数.
*/
...
...
@@ -29,7 +29,7 @@ public enum RequestParameterType {
*/
private
String
msg
;
Request
ParameterType
(
String
code
,
String
msg
)
{
ParameterType
(
String
code
,
String
msg
)
{
this
.
code
=
code
;
this
.
msg
=
msg
;
}
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Row.java
View file @
d3cbfeaf
...
...
@@ -42,7 +42,7 @@ public class Row {
/**
* 请求参数类型
*/
String
requestP
arameterType
;
String
p
arameterType
;
/**
...
...
apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Section.java
View file @
d3cbfeaf
...
...
@@ -20,7 +20,7 @@ import java.util.*;
* @version 1.0.0
*/
@Data
@EqualsAndHashCode
(
callSuper
=
true
)
@EqualsAndHashCode
(
callSuper
=
true
)
public
class
Section
extends
Node
{
/**
...
...
@@ -39,14 +39,24 @@ public class Section extends Node {
* 路径变量.
*/
ObjectNode
pathVariable
=
ObjectMappers
.
instance
.
createObjectNode
();
/**
* The Parameter.
*/
JsonNode
parameter
;
/**
* The Query parameter.
*/
boolean
queryParameter
=
true
;
/**
* 查询参数+请求体参数
*/
JsonNode
parameters
=
ObjectMappers
.
instance
.
createObjectNode
();
/**
* 查询参数
*/
JsonNode
queryParameters
=
ObjectMappers
.
instance
.
createObjectNode
();
/**
* 请求体参数
*/
JsonNode
requestBodyParameters
=
ObjectMappers
.
instance
.
createObjectNode
();
/**
* The Request rows.
*/
...
...
@@ -68,6 +78,38 @@ public class Section extends Node {
*/
Object
rawResponse
;
/**
* Sets parameter.
*
* @param parameter the parameter
*/
public
void
setParameters
(
JsonNode
parameter
)
{
((
ObjectNode
)
this
.
parameters
).
setAll
((
ObjectNode
)
parameter
);
}
/**
* Sets query parameters.
*
* @param parameter the parameter
*/
public
void
setQueryParameters
(
JsonNode
parameter
)
{
((
ObjectNode
)
this
.
queryParameters
).
setAll
((
ObjectNode
)
parameter
);
}
/**
* Sets request body parameters.
*
* @param parameter the parameter
*/
public
void
setRequestBodyParameters
(
JsonNode
parameter
)
{
((
ObjectNode
)
this
.
requestBodyParameters
).
setAll
((
ObjectNode
)
parameter
);
}
/**
* Sets uri.
*
* @param uri the uri
*/
public
void
setUri
(
String
uri
)
{
String
value
=
""
;
if
(
StringUtils
.
isNotBlank
(
uri
))
{
...
...
@@ -106,8 +148,8 @@ public class Section extends Node {
public
String
getRequestLine
()
{
StringBuilder
builder
=
new
StringBuilder
(
this
.
method
.
toString
());
builder
.
append
(
" "
).
append
(
this
.
uri
);
if
(
this
.
queryParameter
&&
Objects
.
equals
(
"GET"
,
this
.
method
))
{
String
parameterString
=
getParameterString
();
if
(
Objects
.
equals
(
"GET"
,
this
.
method
))
{
String
parameterString
=
get
Query
ParameterString
();
if
(
StringHelper
.
nonBlank
(
parameterString
))
{
builder
.
append
(
"?"
).
append
(
parameterString
);
}
...
...
@@ -116,16 +158,39 @@ public class Section extends Node {
return
builder
.
toString
();
}
/**
* Get
parameter string
string.
* Get
s query parameter
string.
*
* @return the string
* @return the
query parameter
string
*/
public
String
getParameterString
()
{
if
(
queryParameter
&&
parameter
instanceof
ObjectNode
)
{
return
new
QueryStringBuilder
().
append
((
ObjectNode
)
parameter
).
toString
();
if
(
queryParameter
)
{
// 查询参数
new
QueryStringBuilder
().
append
((
ObjectNode
)
queryParameters
).
toString
();
}
return
ObjectMappers
.
pretty
(
parameter
);
// 请求体参数
return
ObjectMappers
.
pretty
(
parameters
);
}
/**
* Gets query parameter string.
*
* @return the query parameter string
*/
public
String
getQueryParameterString
()
{
return
new
QueryStringBuilder
().
append
((
ObjectNode
)
queryParameters
).
toString
();
}
/**
* Gets request body parameter string.
*
* @return the request body parameter string
*/
public
String
getRequestBodyParameterString
()
{
// 请求体参数
return
ObjectMappers
.
pretty
(
requestBodyParameters
);
}
/**
...
...
@@ -137,7 +202,7 @@ public class Section extends Node {
if
(
Objects
.
equals
(
"GET"
,
this
.
method
))
{
return
false
;
}
return
parameter
!=
null
&&
parameter
.
size
()
>
0
;
return
requestBodyParameters
!=
null
&&
requestBodyParameters
.
size
()
>
0
;
}
/**
...
...
apidoc-core/src/main/resources/templates/markdown.ftl
View file @
d3cbfeaf
...
...
@@ -46,9 +46,13 @@ ${section.method} ${section.uri!''} HTTP/1.1
${inHeaderValue!''}
</#list>
</#if>
<#if section.hasRequestBody(
)>
<#if (section.getQueryParameterString()?length gt 1
)>
${section.getParameterString()}
${section.getQueryParameterString()}
</#if>
<#if section.hasRequestBody()>
${section.getRequestBodyParameterString()}
</#if>
```
<#-- 请求参数table列表-->
...
...
@@ -57,7 +61,7 @@ ${section.getParameterString()}
| 字段 | 类型 | 参数类型 | 是否必填 | 验证 | 默认值 | 描述 |
| :------- | :----- | :----- |:-------- |:-------- | :------ | :---------- |
<#list section.requestRows as rowKey,rowValue>
| ${rowValue.key!''} | ${rowValue.type!''} | **${rowValue.
requestP
arameterType!''}** |${rowValue.required?string('true','false')} | ${rowValue.condition!''} | ${rowValue.def!''} | ${rowValue.remark!''} |
| ${rowValue.key!''} | ${rowValue.type!''} | **${rowValue.
p
arameterType!''}** |${rowValue.required?string('true','false')} | ${rowValue.condition!''} | ${rowValue.def!''} | ${rowValue.remark!''} |
</#list>
</#if>
<#-- 响应-->
...
...
@@ -85,3 +89,17 @@ ${section.getResponseString()}
</#list>
<#------------ END 循环遍历book ---------->
</#if>
# 附录
<#if appendices??>
<#list appendices as appendfix>
## ${appendfix.name}
<#if appendfix.cells?? && (appendfix.cells?size>0)>
| 编码 | 值 | 说明 |
| :------- | :----- |:-----
<#list appendfix.cells as cell>
| <#if (cell.values?size>0)>${cell.values[0]}</#if> | <#if (cell.values?size>1)>${cell.values[1]}</#if> | <#if (cell.values?size>2)>${cell.values[2]}</#if> |
</#list>
</#if>
</#list >
</#if>
apidoc-springmvc/src/main/java/com/github/fengyuchenglun/apidoc/springmvc/SpringParser.java
View file @
d3cbfeaf
...
...
@@ -24,7 +24,7 @@ import com.github.fengyuchenglun.apidoc.springmvc.resovler.SpringComponentTypeRe
import
java.util.List
;
import
java.util.Optional
;
import
static
com
.
github
.
fengyuchenglun
.
apidoc
.
core
.
schema
.
Request
ParameterType
.*;
import
static
com
.
github
.
fengyuchenglun
.
apidoc
.
core
.
schema
.
ParameterType
.*;
/**
...
...
@@ -141,10 +141,12 @@ public class SpringParser implements ParserStrategy {
* @param section the section
*/
private
void
visitParameters
(
MethodDeclaration
n
,
Chapter
chapter
,
Section
section
)
{
if
(
ParameterHelper
.
hasRequestBody
(
n
.
getParameters
()))
{
visitRequestBody
(
n
,
chapter
,
section
);
}
else
{
visitParameter
(
n
,
chapter
,
section
);
for
(
Parameter
parameter
:
n
.
getParameters
())
{
if
(
ParameterHelper
.
isRequestBody
(
parameter
))
{
visitRequestBody
(
n
,
chapter
,
section
);
}
else
{
visitParameter
(
n
,
chapter
,
section
);
}
}
}
...
...
@@ -160,7 +162,7 @@ public class SpringParser implements ParserStrategy {
if
(
ParameterHelper
.
isPathVariable
(
parameter
))
{
section
.
getPathVariable
().
put
(
parameter
.
getNameAsString
(),
""
);
Row
row
=
new
Row
();
row
.
set
Request
ParameterType
(
PATH
.
getMsg
());
row
.
setParameterType
(
PATH
.
getMsg
());
row
.
setKey
(
parameter
.
getNameAsString
());
row
.
setType
(
parameter
.
getType
().
toString
());
// 路径参数必填
...
...
@@ -235,9 +237,9 @@ public class SpringParser implements ParserStrategy {
TypeDescription
description
=
ApiDoc
.
getInstance
().
getTypeResolvers
().
resolve
(
parameter
.
getType
());
if
(
description
.
isAvailable
())
{
if
(
description
.
isArray
())
{
section
.
set
Parameter
(
description
.
asArray
().
getValue
());
section
.
set
RequestBodyParameters
(
description
.
asArray
().
getValue
());
}
else
if
(
description
.
isObject
())
{
section
.
set
Parameter
(
description
.
asObject
().
getValue
());
section
.
set
RequestBodyParameters
(
description
.
asObject
().
getValue
());
}
section
.
addRequestRows
(
description
.
rows
(
BODY
.
getMsg
()));
}
...
...
@@ -299,7 +301,7 @@ public class SpringParser implements ParserStrategy {
}
}
}
section
.
set
Parameter
(
objectTypeDescription
.
getValue
());
section
.
set
QueryParameters
(
objectTypeDescription
.
getValue
());
section
.
addRequestRows
(
objectTypeDescription
.
rows
(
QUERY
.
getMsg
()));
}
...
...
apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/common/Query.java
View file @
d3cbfeaf
...
...
@@ -3,6 +3,8 @@ package com.github.fengyuchenglun.example.common;
import
lombok.Getter
;
import
lombok.Setter
;
import
java.time.LocalDateTime
;
@Setter
@Getter
public
class
Query
{
...
...
@@ -13,8 +15,24 @@ public class Query {
public
static
final
String
CONSTANS
=
""
;
/**
* 查询关键字
* 用户名称
*/
private
String
userName
;
/**
* 用户手机号码
*/
private
String
userPhoneNum
;
/**
* 用户邮箱
*/
private
String
userEmail
;
/**
* 开始时间
*/
private
LocalDateTime
startTime
;
/**
* 结束时间
*/
String
q
=
"123"
;
private
LocalDateTime
endTime
;
}
apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/common/ResultData.java
View file @
d3cbfeaf
...
...
@@ -4,7 +4,7 @@ import lombok.Getter;
import
lombok.Setter
;
/**
*
The type Result data
.
*
统一返回结果对象
.
*
* @param <T> the type parameter
* @author fengyuchenglun
...
...
@@ -25,7 +25,7 @@ public class ResultData<T> {
//返回信息
String
msg
;
/**
*
The Data
.
*
数据对象
.
*/
T
data
;
...
...
@@ -35,7 +35,7 @@ public class ResultData<T> {
* @param <T> the type parameter
* @return the result data
*/
public
static
<
T
>
ResultData
<
T
>
ok
(){
public
static
<
T
>
ResultData
<
T
>
ok
()
{
return
ok
(
null
);
}
...
...
@@ -46,7 +46,7 @@ public class ResultData<T> {
* @param data the data
* @return the result data
*/
public
static
<
T
>
ResultData
<
T
>
ok
(
T
data
){
public
static
<
T
>
ResultData
<
T
>
ok
(
T
data
)
{
ResultData
<
T
>
resultData
=
new
ResultData
<>();
resultData
.
code
=
0
;
resultData
.
msg
=
"ok"
;
...
...
apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/common/User.java
View file @
d3cbfeaf
...
...
@@ -8,6 +8,7 @@ import javax.validation.constraints.Min;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.NotNull
;
import
java.util.Date
;
import
java.util.List
;
/**
* 用户对象
...
...
@@ -19,30 +20,40 @@ import java.util.Date;
@Getter
public
class
User
{
// /**
// * 用户编号.
// */
// int id;
// /**
// * 用户名称.
// */
// @NotBlank
// String name;
// /**
// * 用户年龄.
// */
// @Min(1)
// @NotNull
// Integer age;
// /**
// * 创建时间.
// */
// Date createAt;
// /**
// * 性别.
// */
// @NotBlank
// @JsonProperty("Sex")
// String sex;
/**
* 用户编号.
*/
int
id
;
/**
* 用户名称.
*/
@NotBlank
String
name
;
/**
* 用户年龄.
*/
@Min
(
1
)
@NotNull
Integer
age
;
/**
* 创建时间.
* 用户.
*/
Date
createAt
;
private
UserQuery
query
;
/**
*
性别
.
*
用户
.
*/
@NotBlank
@JsonProperty
(
"Sex"
)
String
sex
;
private
List
<
Menu
>
menus
;
}
apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/spring/advanced/UserController.java
View file @
d3cbfeaf
package
com.github.fengyuchenglun.example.spring.advanced
;
import
com.github.fengyuchenglun.example.annotation.KimController
;
import
com.github.fengyuchenglun.example.common.Query
;
import
com.github.fengyuchenglun.example.common.User
;
import
com.github.fengyuchenglun.example.common.UserQuery
;
...
...
@@ -8,6 +7,7 @@ import lombok.Data;
import
org.springframework.web.bind.annotation.*
;
import
java.io.Serializable
;
import
java.util.List
;
/**
* 用户接口.
...
...
@@ -18,138 +18,141 @@ import java.io.Serializable;
* @index 20
* @since 1.0.0
*/
@
Kim
Controller
@
Rest
Controller
@RequestMapping
(
"/api/v1/users"
)
public
class
UserController
{
/**
* 查看用户详情
*
* @param userId 用户编号
* @param query 过滤条件
* @return 用户对象 user
*/
@GetMapping
(
value
=
"/{userId}"
)
public
User
detail
(
@PathVariable
String
userId
,
Query
query
)
{
User
user
=
new
User
();
return
user
;
}
/**
* 查看用户详情
*
* @param query 过滤条件
* @return 用户对象 user
*/
@GetMapping
(
value
=
"/detail1"
)
public
User
detail1
(
Query
query
)
{
User
user
=
new
User
();
return
user
;
}
/**
* 查看用户详情
*
* @param query 过滤条件
* @return 用户对象 user
*/
@GetMapping
(
value
=
"/detail3"
)
public
User
detail3
(
@RequestParam
Query
query
)
{
User
user
=
new
User
();
return
user
;
}
/**
* 查看用户详情
*
* @param query 过滤条件
* @return 用户对象 user
*/
@GetMapping
(
value
=
"/detail4"
)
public
User
detail4
(
@RequestParam
(
required
=
false
)
Query
query
)
{
User
user
=
new
User
();
return
user
;
}
/**
* 查看用户详情
*
* @return 用户对象 user
*/
@GetMapping
(
value
=
"/detail5"
)
public
User
detail5
()
{
User
user
=
new
User
();
return
user
;
}
/**
* 查看用户详情
*
* @param userName the user name
* @param age the age
* @param query the query
* @return 用户对象 user
*/
@GetMapping
(
value
=
"/detail6"
)
public
User
detail6
(
String
userName
,
Integer
age
,
UserQuery
query
)
{
User
user
=
new
User
();
return
user
;
}
/**
* 查看用户详情
*
* @return 用户对象 user
*/
@GetMapping
(
value
=
"/detail7"
)
public
void
detail7
()
{
}
/**
* 删除用户
*
* @param userId the user id
* @return boolean 是否成功
*/
@DeleteMapping
(
value
=
"/{userId}"
)
public
Boolean
deleteUser
(
@PathVariable
(
"userId"
)
Long
userId
)
{
return
true
;
}
/**
* 用户表单对象.
*
* @author duanledexianxianxian
*/
@Data
public
static
class
UserForm
implements
Serializable
{
private
static
final
long
serialVersionUID
=
5681371348688016281L
;
/**
* 用户名
*/
private
String
userName
;
/**
* 地址
*/
private
String
address
;
/**
* 年龄
*/
private
Integer
age
;
}
/**
* 添加用户
*
* @param form 用户表单对象
* @return integer 返回记录
*/
@PostMapping
public
Integer
add
(
@RequestBody
UserForm
form
)
{
return
null
;
}
//
// /**
// * 查看用户详情
// *
// * @param userId 用户编号
// * @param age 年龄
// * @param query 过滤条件
// * @return 用户对象 user
// */
// @PostMapping(value = "/{userId}")
// public User detail(@PathVariable String userId, String age, @RequestBody Query query) {
// User user = new User();
// return user;
// }
//
// /**
// * 查看用户详情
// * 测试get的query对象
// *
// * @param query 过滤条件
// * @return 用户对象 user
// */
// @GetMapping(value = "/detail1")
// public User detail1(Query query) {
// User user = new User();
// return user;
// }
//
//
// /**
// * 测试get的query对象,带RequestParam注解
// *
// * @param query 过滤条件
// * @return 用户对象 user
// */
// @GetMapping(value = "/detail3")
// public User detail3(@RequestParam String query) {
// User user = new User();
// return user;
// }
//
// /**
// * 测试get的query对象,带RequestParam注解,required=false
// *
// * @param query 过滤条件
// * @return 用户对象 user
// */
// @GetMapping(value = "/detail4")
// public User detail4(@RequestParam(required = false) String query) {
// User user = new User();
// return user;
// }
//
// /**
// * get-无查询参数
// *
// * @return 用户对象 user
// */
// @GetMapping(value = "/detail5")
// public List<User> detail5() {
// return null;
// }
//
// /**
// * get-原始对象+查询对象
// *
// * @param userName the user name
// * @param age the age
// * @param query the query
// * @return 用户对象 user
// */
// @GetMapping(value = "/detail6")
// public User detail6(String userName, Integer age, UserQuery query) {
// User user = new User();
// return user;
// }
//
// /**
// * post-
// *
// * @return 用户对象 user
// */
// @GetMapping(value = "/post1")
// public UserQuery post1() {
// return null;
// }
//
//
// /**
// * 删除用户
// *
// * @param userId the user id
// * @return boolean 是否成功
// */
// @DeleteMapping(value = "/{userId}")
// public Boolean deleteUser(@PathVariable("userId") Long userId) {
// return true;
// }
//
//
// /**
// * 用户表单对象.
// *
// * @author duanledexianxianxian
// */
// @Data
// public static class UserForm implements Serializable {
//
// private static final long serialVersionUID = 5681371348688016281L;
// /**
// * 用户名
// */
// private String userName;
// /**
// * 地址
// */
// private String address;
// /**
// * 年龄
// */
// private Integer age;
// }
//
// /**
// * 添加用户
// *
// * @param form 用户表单对象
// * @return integer 返回记录
// */
// @PostMapping
// public Integer add(@RequestBody UserForm form) {
// return null;
// }
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment