Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Sunny_yiyi
Swagger Ui
提交
00745bca
S
Swagger Ui
项目概览
Sunny_yiyi
/
Swagger Ui
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Swagger Ui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
00745bca
编写于
6月 13, 2017
作者:
S
shockey
提交者:
GitHub
6月 13, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3211 from dwickern/multipart-file-upload
Fix #2922: file uploads fail to render curl command
上级
667976ca
1bd11907
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
41 addition
and
8 deletion
+41
-8
src/core/components/curl.jsx
src/core/components/curl.jsx
+1
-1
src/core/curlify.js
src/core/curlify.js
+8
-4
src/core/utils.js
src/core/utils.js
+4
-0
src/core/window.js
src/core/window.js
+2
-1
test/core/curlify.js
test/core/curlify.js
+26
-2
未找到文件。
src/core/components/curl.jsx
浏览文件 @
00745bca
...
...
@@ -19,7 +19,7 @@ export default class Curl extends React.Component {
<
div
>
<
h4
>
Curl
</
h4
>
<
div
className
=
"copy-paste"
>
<
textarea
onFocus
=
{
this
.
handleFocus
}
className
=
"curl"
style
=
{
{
whiteSpace
:
"
normal
"
}
}
value
=
{
curl
}
></
textarea
>
<
textarea
onFocus
=
{
this
.
handleFocus
}
readOnly
=
"true"
className
=
"curl"
style
=
{
{
whiteSpace
:
"
normal
"
}
}
value
=
{
curl
}
></
textarea
>
</
div
>
</
div
>
)
...
...
src/core/curlify.js
浏览文件 @
00745bca
import
win
from
"
./window
"
export
default
function
curl
(
request
){
let
curlified
=
[]
let
type
=
""
...
...
@@ -18,11 +20,13 @@ export default function curl( request ){
if
(
request
.
get
(
"
body
"
)
){
if
(
type
===
"
multipart/form-data
"
&&
request
.
get
(
"
method
"
)
===
"
POST
"
)
{
let
formDataBody
=
request
.
get
(
"
body
"
).
split
(
"
&
"
)
for
(
var
data
in
formDataBody
)
{
for
(
let
[
k
,
v
]
of
request
.
get
(
"
body
"
).
values
())
{
curlified
.
push
(
"
-F
"
)
curlified
.
push
(
formDataBody
[
data
])
if
(
v
instanceof
win
.
File
)
{
curlified
.
push
(
`"
${
k
}
=@
${
v
.
name
}
;type=
${
v
.
type
}
"`
)
}
else
{
curlified
.
push
(
`"
${
k
}
=
${
v
}
"`
)
}
}
}
else
{
curlified
.
push
(
"
-d
"
)
...
...
src/core/utils.js
浏览文件 @
00745bca
...
...
@@ -7,6 +7,7 @@ import _memoize from "lodash/memoize"
import
some
from
"
lodash/some
"
import
eq
from
"
lodash/eq
"
import
{
memoizedSampleFromSchema
,
memoizedCreateXMLExample
}
from
"
core/plugins/samples/fn
"
import
win
from
"
./window
"
const
DEFAULT_REPONSE_KEY
=
"
default
"
...
...
@@ -34,6 +35,9 @@ export function fromJSOrdered (js) {
if
(
isImmutable
(
js
))
return
js
// Can't do much here
if
(
js
instanceof
win
.
File
)
return
js
return
!
isObject
(
js
)
?
js
:
Array
.
isArray
(
js
)
?
Im
.
Seq
(
js
).
map
(
fromJSOrdered
).
toList
()
:
...
...
src/core/window.js
浏览文件 @
00745bca
...
...
@@ -3,7 +3,8 @@ function makeWindow() {
location
:
{},
history
:
{},
open
:
()
=>
{},
close
:
()
=>
{}
close
:
()
=>
{},
File
:
function
()
{}
}
if
(
typeof
window
===
"
undefined
"
)
{
...
...
test/core/curlify.js
浏览文件 @
00745bca
import
expect
from
"
expect
"
import
Im
from
"
immutable
"
import
curl
from
"
core/curlify
"
import
win
from
"
core/window
"
describe
(
"
curlify
"
,
function
()
{
...
...
@@ -131,12 +132,35 @@ describe("curlify", function() {
url
:
"
http://example.com
"
,
method
:
"
POST
"
,
headers
:
{
"
content-type
"
:
"
multipart/form-data
"
},
body
:
"
id=123&name=Sahar
"
body
:
[
[
"
id
"
,
"
123
"
],
[
"
name
"
,
"
Sahar
"
]
]
}
let
curlified
=
curl
(
Im
.
fromJS
(
req
))
expect
(
curlified
).
toEqual
(
"
curl -X POST
\"
http://example.com
\"
-H
\"
content-type: multipart/form-data
\"
-F id=123 -F name=Sahar
"
)
expect
(
curlified
).
toEqual
(
"
curl -X POST
\"
http://example.com
\"
-H
\"
content-type: multipart/form-data
\"
-F
\"
id=123
\"
-F
\"
name=Sahar
\"
"
)
})
it
(
"
should print a curl with formData and file
"
,
function
()
{
var
file
=
new
win
.
File
()
file
.
name
=
"
file.txt
"
file
.
type
=
"
text/plain
"
var
req
=
{
url
:
"
http://example.com
"
,
method
:
"
POST
"
,
headers
:
{
"
content-type
"
:
"
multipart/form-data
"
},
body
:
[
[
"
id
"
,
"
123
"
],
[
"
file
"
,
file
]
]
}
let
curlified
=
curl
(
Im
.
fromJS
(
req
))
expect
(
curlified
).
toEqual
(
"
curl -X POST
\"
http://example.com
\"
-H
\"
content-type: multipart/form-data
\"
-F
\"
id=123
\"
-F
\"
file=@file.txt;type=text/plain
\"
"
)
})
it
(
"
prints a curl post statement from an object
"
,
function
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录