Skip to content
This repository was archived by the owner on Apr 10, 2024. It is now read-only.

Commit a5d4d6e

Browse files
committed
add: 添加支持@get的Query
1 parent 9d82ec7 commit a5d4d6e

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

Plugin/src/com/ciy/plugin/utils/ApiServiceGenerate.kt

+26-11
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,32 @@ object ApiServiceGenerate {
3939
}
4040
}
4141
// 传参模型
42-
val (requestBodyFile, isList) = RequestBodyModelGenerate.createRequestBodyModel(ResponseModelGenerate.captureName("${urlName}ReqModel")
43-
, rootDir, modelPackName, it)
44-
if (requestBodyFile != null) {
45-
var requestBodyType = ClassName(requestBodyFile.packageName, requestBodyFile.name)
46-
val bodyAnnotationType = ClassName("retrofit2.http", "Body")
47-
if (!isList) {
48-
funSpecBuilder.addParameter(ParameterSpec.builder("parameter",requestBodyType.copy(true))
49-
.defaultValue("null").addAnnotation(bodyAnnotationType).build())
50-
} else {
51-
funSpecBuilder.addParameter(ParameterSpec.builder("parameter",LIST.parameterizedBy(requestBodyType).copy(true))
52-
.defaultValue("null").addAnnotation(bodyAnnotationType).build())
42+
if (it.method == "GET") {
43+
it.req_query.forEach { req_it ->
44+
val queryAnnotationType = ClassName("retrofit2.http", "Query")
45+
val queryAnnotation = AnnotationSpec.builder(queryAnnotationType).addMember("%S", req_it.name).build()
46+
// 必传
47+
val required = req_it.required == "1"
48+
funSpecBuilder.addParameter(ParameterSpec.builder(req_it.name, String::class.asTypeName().copy(!required))
49+
.addAnnotation(queryAnnotation).addKdoc(req_it.desc).apply {
50+
if (!required) {
51+
defaultValue("null")
52+
}
53+
}.build())
54+
}
55+
} else {
56+
val (requestBodyFile, isList) = RequestBodyModelGenerate.createRequestBodyModel(ResponseModelGenerate.captureName("${urlName}ReqModel")
57+
, rootDir, modelPackName, it)
58+
if (requestBodyFile != null) {
59+
val requestBodyType = ClassName(requestBodyFile.packageName, requestBodyFile.name)
60+
val bodyAnnotationType = ClassName("retrofit2.http", "Body")
61+
if (!isList) {
62+
funSpecBuilder.addParameter(ParameterSpec.builder("parameter",requestBodyType.copy(true))
63+
.defaultValue("null").addAnnotation(bodyAnnotationType).build())
64+
} else {
65+
funSpecBuilder.addParameter(ParameterSpec.builder("parameter",LIST.parameterizedBy(requestBodyType).copy(true))
66+
.defaultValue("null").addAnnotation(bodyAnnotationType).build())
67+
}
5368
}
5469
}
5570
apiServiceBuilder.addFunction(funSpecBuilder.build())

0 commit comments

Comments
 (0)