Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HTTP style to the Request-example #588

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

returncode
Copy link

添加HTTP样式Request-example

@shalousun
Copy link
Collaborator

麻烦说明下这个pr的目的是什么,什么场景需要。也提供下这个修改前后的一个文档效果对比图

@returncode
Copy link
Author

提供一种 HTTP形式 Request-example ,和浏览器控制台调试网络请求格式一致,还有可以通过VSCode插件Rest-client调试接口
post json

curl -X POST -H 'Content-Type: application/json' -i {{host}}/demo/add --data '{
  "userName": "张三",
  "password": "12356"
}'
POST {{host}}/demo/add HTTP/1.1
Content-Type:application/json

{
  "userName": "张三",
  "password": "12356"
}

post form-data

curl -X POST -i {{host}}/demo/save
POST {{host}}/demo/save HTTP/1.1
Content-Type:application/x-www-form-urlencoded;charset=UTF-8

username=wanglei
&password=123456

upload file

curl -X POST -H 'Content-Type: multipart/form-data' -F 'file=' -i {{host}}/file/upload --data 'userName=张三&password=12356'
POST {{host}}/file/upload HTTP/1.1
Content-Type:multipart/form-data; boundary=be921224e6064b9788320b550d0a8fab

--be921224e6064b9788320b550d0a8fab
Content-Disposition: form-data; name="file"; filename="xxxxx.pdf"
Content-Type: application/pdf

< xxxxx.pdf
--be921224e6064b9788320b550d0a8fab
Content-Disposition: form-data; name="userName"

张三
--be921224e6064b9788320b550d0a8fab
Content-Disposition: form-data; name="password"

12356
--be921224e6064b9788320b550d0a8fab--

get form-data

curl -X GET -i {{host}}/list/userPage2?page=0&size=0
GET {{host}}/list/userPage2 
?page=0
&size=0
Content-Type:application/x-www-form-urlencoded;charset=UTF-8

@shalousun
Copy link
Collaborator

curl下的http 样例可以在restclient中直接使用吗?

@returncode
Copy link
Author

get form-data 可以用,其他的用不了

List<ApiParam> queryParams = apiMethodDoc.getQueryParams();
List<ApiParam> requestParams = apiMethodDoc.getRequestParams();
StringBuilder title = new StringBuilder().append("### ").append(apiMethodDoc.getDesc()).append("\n");
StringBuilder request = new StringBuilder().append(methodType).append(" ").append(apiMethodDoc.getUrl()).append(isGet ? " " : " HTTP/1.1").append("\n");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http/1.1这个硬编码是不是不太好,也存其它版本

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是参考Rest-client标准,有无对代码无影响。

/**
* http flag
*/
private boolean http;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个定义是不是语义不够精细。http代表配置http协议呢还是http样例呢,可以换个更详细的单词

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

能否给建议个合适的单词?

@@ -742,16 +743,62 @@ else if (javaClass.isEnum()) {
return ApiParamTreeUtil.buildMethodReqParam(paramList, queryReqParamMap, pathReqParamMap, requestBodyCounter);
}

default ApiRequestExample buildReqJson(DocJavaMethod javaMethod, ApiMethodDoc apiMethodDoc, String methodType,
ProjectDocConfigBuilder configBuilder, FrameworkAnnotations frameworkAnnotations) {
default String buildHttpJson(DocJavaMethod docJavaMethod, ApiMethodDoc apiMethodDoc, String methodType, ProjectDocConfigBuilder projectBuilder, FrameworkAnnotations frameworkAnnotations) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

下面这新增的内容是不是在html的文档格式下不起作用

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

html的文档格式下指什么功能及作用

@jcleng
Copy link

jcleng commented Sep 16, 2023

有用

@shalousun shalousun changed the title 添加HTTP样式Request-example Add HTTP style to the Request-example Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants