Skip to content
This repository was archived by the owner on Dec 4, 2025. It is now read-only.

Commit f3f11ac

Browse files
authored
Merge pull request #864 from linwumingshi/feature/requestPart
Feature/request part
2 parents 1373af0 + fc30b26 commit f3f11ac

12 files changed

Lines changed: 254 additions & 36 deletions
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (C) 2018-2024 smart-doc
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
package com.ly.doc.constants;
22+
23+
/**
24+
* Enum representing Content-Type values for form-data in POST requests.
25+
*
26+
* @see <a href=
27+
* "https://swagger.io/docs/specification/describing-request-body/multipart-requests/">
28+
* Specifying Content-Type</a>
29+
* @author linwumingshi
30+
* @since 3.0.7
31+
*/
32+
public enum FormDataContentTypeEnum {
33+
34+
/**
35+
* application/json: Complex values or arrays of complex values.
36+
*/
37+
APPLICATION_JSON("application/json"),
38+
39+
/**
40+
* text/plain: Primitive values or arrays of primitive values.
41+
*/
42+
TEXT_PLAIN("text/plain"),
43+
44+
/**
45+
* application/octet-stream: Binary or base64 encoded strings.
46+
*/
47+
APPLICATION_OCTET_STREAM("application/octet-stream");
48+
49+
/**
50+
* The Content-Type value.
51+
*/
52+
private final String value;
53+
54+
/**
55+
* Constructor to set the Content-Type value.
56+
* @param value the Content-Type value
57+
*/
58+
FormDataContentTypeEnum(String value) {
59+
this.value = value;
60+
}
61+
62+
/**
63+
* Returns the Content-Type value.
64+
* @return the Content-Type value
65+
*/
66+
public String getValue() {
67+
return value;
68+
}
69+
70+
}

src/main/java/com/ly/doc/constants/SpringMvcRequestAnnotationsEnum.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.util.List;
2525

2626
/**
27+
* spring mvc request annotation enum
28+
*
2729
* @author yu 2019/12/20.
2830
*/
2931
public enum SpringMvcRequestAnnotationsEnum {
@@ -66,7 +68,19 @@ public enum SpringMvcRequestAnnotationsEnum {
6668
/**
6769
* SpringMvc RequestAnnotation RequestHeader fully
6870
*/
69-
REQUEST_HERDER_FULLY("org.springframework.web.bind.annotation.RequestHeader"),;
71+
REQUEST_HERDER_FULLY("org.springframework.web.bind.annotation.RequestHeader"),
72+
73+
/**
74+
* SpringMvc RequestAnnotation RequestPart
75+
*/
76+
REQUEST_PART("RequestPart"),
77+
78+
/**
79+
* SpringMvc RequestAnnotation RequestPart fully
80+
*/
81+
REQUEST_PART_FULLY("org.springframework.web.bind.annotation.RequestPart"),
82+
83+
;
7084

7185
/**
7286
* SpringMvc RequestAnnotation value

src/main/java/com/ly/doc/helper/ParamsBuildHelper.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,26 @@
4545
*/
4646
public class ParamsBuildHelper extends BaseHelper {
4747

48+
/**
49+
* Builds a parameter list based on field information.
50+
* @param className The name of the generic type.
51+
* @param pre A prefix builder for nested fields.
52+
* @param level The next level of nesting.
53+
* @param isRequired Indicates whether the parameter is required.
54+
* @param isResp Indicates whether the parameter is a response parameter.
55+
* @param registryClasses A collection of registered classes.
56+
* @param projectBuilder A project builder instance.
57+
* @param groupClasses A collection of grouped classes.
58+
* @param pid The parent ID of the field.
59+
* @param jsonRequest The JSON request object.
60+
* @param atomicInteger An AtomicInteger for ID generation.
61+
* <p>
62+
* This method handles various types of fields and their values, including handling
63+
* self-referential loops, maps, arrays, objects, and primitive types. It adds
64+
* parameters to the paramList based on the type and structure of the given field,
65+
* recursively calling itself for nested or complex types.
66+
* @return A List of ApiParam instances representing the built parameters.
67+
*/
4868
public static List<ApiParam> buildParams(String className, String pre, int level, String isRequired, boolean isResp,
4969
Map<String, String> registryClasses, ProjectDocConfigBuilder projectBuilder, Set<String> groupClasses,
5070
int pid, boolean jsonRequest, AtomicInteger atomicInteger) {
@@ -384,7 +404,7 @@ else if (DocAnnotationConstants.JSON_FORMAT.equals(simpleAnnotationName)) {
384404
for (int j = 0; j < level; j++) {
385405
preBuilder.append(DocGlobalConstants.FIELD_SPACE);
386406
}
387-
preBuilder.append("└─");
407+
preBuilder.append(DocGlobalConstants.PARAM_PREFIX);
388408
int fieldPid;
389409
ApiParam param = ApiParam.of()
390410
.setField(pre + fieldName)
@@ -664,7 +684,7 @@ private static List<ApiParam> buildMapParam(String[] globGicName, String pre, in
664684
for (int j = 0; j < level; j++) {
665685
preBuilder.append(DocGlobalConstants.FIELD_SPACE);
666686
}
667-
preBuilder.append("└─");
687+
preBuilder.append(DocGlobalConstants.PARAM_PREFIX);
668688
paramList.addAll(buildParams(globGicName[1], preBuilder.toString(), ++nextLevel, isRequired, isResp,
669689
registryClasses, projectBuilder, groupClasses, pid, jsonRequest, atomicInteger));
670690
return paramList;

src/main/java/com/ly/doc/model/FormData.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,46 @@
2020
*/
2121
package com.ly.doc.model;
2222

23+
import com.ly.doc.constants.FormDataContentTypeEnum;
24+
2325
/**
26+
* form data class
27+
*
2428
* @author xingzi 2019/12/21 20:20
2529
*/
2630
public class FormData {
2731

32+
/**
33+
* key
34+
*/
2835
private String key;
2936

37+
/**
38+
* type
39+
*/
3040
private String type;
3141

42+
/**
43+
* description
44+
*/
3245
private String description;
3346

47+
/**
48+
* source
49+
*/
3450
private Object src;
3551

52+
/**
53+
* value
54+
*/
3655
private String value;
3756

57+
/**
58+
* contentType eg: `application/json`,when the param has annotation `@RequestPart`
59+
* @see FormDataContentTypeEnum
60+
*/
61+
private String contentType;
62+
3863
/**
3964
* openapi items
4065
*/
@@ -89,6 +114,18 @@ public void setDescription(String description) {
89114
this.description = description;
90115
}
91116

117+
public String getContentType() {
118+
return contentType;
119+
}
120+
121+
public void setContentType(FormDataContentTypeEnum contentType) {
122+
this.contentType = contentType.getValue();
123+
}
124+
125+
public void setContentType(String contentType) {
126+
this.contentType = contentType;
127+
}
128+
92129
@Override
93130
public String toString() {
94131
return "FormData{" + "key='" + key + '\'' + ", type='" + type + '\'' + ", description='" + description + '\''

src/main/java/com/ly/doc/model/request/CurlRequest.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,46 @@
2020
*/
2121
package com.ly.doc.model.request;
2222

23-
import java.util.List;
24-
2523
import com.ly.doc.model.ApiReqParam;
2624
import com.ly.doc.model.FormData;
2725

26+
import java.util.List;
27+
2828
/**
29+
* curl request
30+
*
2931
* @author yu 2020/12/21.
3032
*/
3133
public class CurlRequest {
3234

35+
/**
36+
* Http method
37+
*/
3338
private String type;
3439

40+
/**
41+
* Request headers
42+
*/
3543
private List<ApiReqParam> reqHeaders;
3644

45+
/**
46+
* Request file form data
47+
*/
3748
private List<FormData> fileFormDataList;
3849

50+
/**
51+
* Request url
52+
*/
3953
private String url;
4054

55+
/**
56+
* Request body
57+
*/
4158
private String body;
4259

60+
/**
61+
* Content-Type
62+
*/
4363
private String contentType;
4464

4565
public static CurlRequest builder() {

0 commit comments

Comments
 (0)