Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Sunny_yiyi
Swagger Ui
提交
4fb5b86d
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,体验更适合开发者的 AI 搜索 >>
提交
4fb5b86d
编写于
8月 29, 2013
作者:
T
Tony Tam
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
updated swagger-js to address sample schema issues
上级
f22efb66
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
225 addition
and
99 deletion
+225
-99
dist/lib/swagger.js
dist/lib/swagger.js
+112
-49
lib/swagger.js
lib/swagger.js
+112
-49
package.json
package.json
+1
-1
未找到文件。
dist/lib/swagger.js
浏览文件 @
4fb5b86d
...
...
@@ -33,13 +33,11 @@
if
(
options
.
url
!=
null
)
{
this
.
url
=
options
.
url
;
}
this
.
supportedSubmitMethods
=
options
.
supportedSubmitMethods
!=
null
?
options
.
supportedSubmitMethods
:
[
'
get
'
];
if
(
options
.
success
!=
null
)
{
this
.
success
=
options
.
success
;
}
this
.
failure
=
options
.
failure
!=
null
?
options
.
failure
:
function
()
{};
this
.
progress
=
options
.
progress
!=
null
?
options
.
progress
:
function
()
{};
this
.
defaultHeaders
=
options
.
headers
!=
null
?
options
.
headers
:
{};
if
(
options
.
success
!=
null
)
{
this
.
build
();
}
...
...
@@ -66,55 +64,14 @@
}
},
response
:
function
(
rawResponse
)
{
var
api
,
isApi
,
newName
,
operation
,
res
,
resource
,
response
,
_i
,
_j
,
_k
,
_len
,
_len1
,
_len2
,
_ref
,
_ref1
,
_ref2
;
var
response
;
response
=
JSON
.
parse
(
rawResponse
.
content
.
data
);
if
(
response
.
apiVersion
!=
null
)
{
_this
.
apiVersion
=
response
.
apiVersion
;
}
_this
.
apis
=
{};
_this
.
apisArray
=
[];
_this
.
produces
=
response
.
produces
;
if
(
response
.
info
!=
null
)
{
_this
.
info
=
response
.
info
;
}
isApi
=
false
;
_ref
=
response
.
apis
;
for
(
_i
=
0
,
_len
=
_ref
.
length
;
_i
<
_len
;
_i
++
)
{
api
=
_ref
[
_i
];
if
(
api
.
operations
)
{
_ref1
=
api
.
operations
;
for
(
_j
=
0
,
_len1
=
_ref1
.
length
;
_j
<
_len1
;
_j
++
)
{
operation
=
_ref1
[
_j
];
isApi
=
true
;
}
}
}
if
(
isApi
)
{
newName
=
response
.
resourcePath
.
replace
(
/
\/
/g
,
''
);
_this
.
resourcePath
=
response
.
resourcePath
;
res
=
new
SwaggerResource
(
response
,
_this
);
_this
.
apis
[
newName
]
=
res
;
_this
.
apisArray
.
push
(
res
);
_this
.
swaggerVersion
=
response
.
swaggerVersion
;
if
(
_this
.
swaggerVersion
===
"
1.2
"
)
{
return
_this
.
buildFromSpec
(
response
);
}
else
{
if
(
response
.
basePath
)
{
_this
.
basePath
=
response
.
basePath
;
}
else
if
(
_this
.
url
.
indexOf
(
'
?
'
)
>
0
)
{
_this
.
basePath
=
_this
.
url
.
substring
(
0
,
_this
.
url
.
lastIndexOf
(
'
?
'
));
}
else
{
_this
.
basePath
=
_this
.
url
;
}
_ref2
=
response
.
apis
;
for
(
_k
=
0
,
_len2
=
_ref2
.
length
;
_k
<
_len2
;
_k
++
)
{
resource
=
_ref2
[
_k
];
res
=
new
SwaggerResource
(
resource
,
_this
);
_this
.
apis
[
res
.
name
]
=
res
;
_this
.
apisArray
.
push
(
res
);
}
return
_this
.
buildFrom1_1Spec
(
response
);
}
if
(
_this
.
success
)
{
_this
.
success
();
}
return
_this
;
}
}
};
...
...
@@ -129,6 +86,109 @@
return
this
;
};
SwaggerApi
.
prototype
.
buildFromSpec
=
function
(
response
)
{
var
api
,
isApi
,
newName
,
operation
,
res
,
resource
,
_i
,
_j
,
_k
,
_len
,
_len1
,
_len2
,
_ref
,
_ref1
,
_ref2
;
if
(
response
.
apiVersion
!=
null
)
{
this
.
apiVersion
=
response
.
apiVersion
;
}
this
.
apis
=
{};
this
.
apisArray
=
[];
this
.
produces
=
response
.
produces
;
if
(
response
.
info
!=
null
)
{
this
.
info
=
response
.
info
;
}
isApi
=
false
;
_ref
=
response
.
apis
;
for
(
_i
=
0
,
_len
=
_ref
.
length
;
_i
<
_len
;
_i
++
)
{
api
=
_ref
[
_i
];
if
(
api
.
operations
)
{
_ref1
=
api
.
operations
;
for
(
_j
=
0
,
_len1
=
_ref1
.
length
;
_j
<
_len1
;
_j
++
)
{
operation
=
_ref1
[
_j
];
isApi
=
true
;
}
}
}
if
(
isApi
)
{
newName
=
response
.
resourcePath
.
replace
(
/
\/
/g
,
''
);
this
.
resourcePath
=
response
.
resourcePath
;
res
=
new
SwaggerResource
(
response
,
this
);
this
.
apis
[
newName
]
=
res
;
this
.
apisArray
.
push
(
res
);
}
else
{
if
(
response
.
basePath
)
{
this
.
basePath
=
response
.
basePath
;
}
else
if
(
this
.
url
.
indexOf
(
'
?
'
)
>
0
)
{
this
.
basePath
=
this
.
url
.
substring
(
0
,
this
.
url
.
lastIndexOf
(
'
?
'
));
}
else
{
this
.
basePath
=
this
.
url
;
}
_ref2
=
response
.
apis
;
for
(
_k
=
0
,
_len2
=
_ref2
.
length
;
_k
<
_len2
;
_k
++
)
{
resource
=
_ref2
[
_k
];
res
=
new
SwaggerResource
(
resource
,
this
);
this
.
apis
[
res
.
name
]
=
res
;
this
.
apisArray
.
push
(
res
);
}
}
if
(
this
.
success
)
{
this
.
success
();
}
return
this
;
};
SwaggerApi
.
prototype
.
buildFrom1_1Spec
=
function
(
response
)
{
var
api
,
isApi
,
newName
,
operation
,
res
,
resource
,
_i
,
_j
,
_k
,
_len
,
_len1
,
_len2
,
_ref
,
_ref1
,
_ref2
;
console
.
log
(
"
This API is using a deprecated version of Swagger! Please see http://github.com/wordnik/swagger-core/wiki for more info
"
);
if
(
response
.
apiVersion
!=
null
)
{
this
.
apiVersion
=
response
.
apiVersion
;
}
this
.
apis
=
{};
this
.
apisArray
=
[];
this
.
produces
=
response
.
produces
;
if
(
response
.
info
!=
null
)
{
this
.
info
=
response
.
info
;
}
isApi
=
false
;
_ref
=
response
.
apis
;
for
(
_i
=
0
,
_len
=
_ref
.
length
;
_i
<
_len
;
_i
++
)
{
api
=
_ref
[
_i
];
if
(
api
.
operations
)
{
_ref1
=
api
.
operations
;
for
(
_j
=
0
,
_len1
=
_ref1
.
length
;
_j
<
_len1
;
_j
++
)
{
operation
=
_ref1
[
_j
];
isApi
=
true
;
}
}
}
if
(
isApi
)
{
newName
=
response
.
resourcePath
.
replace
(
/
\/
/g
,
''
);
this
.
resourcePath
=
response
.
resourcePath
;
res
=
new
SwaggerResource
(
response
,
this
);
this
.
apis
[
newName
]
=
res
;
this
.
apisArray
.
push
(
res
);
}
else
{
if
(
response
.
basePath
)
{
this
.
basePath
=
response
.
basePath
;
}
else
if
(
this
.
url
.
indexOf
(
'
?
'
)
>
0
)
{
this
.
basePath
=
this
.
url
.
substring
(
0
,
this
.
url
.
lastIndexOf
(
'
?
'
));
}
else
{
this
.
basePath
=
this
.
url
;
}
_ref2
=
response
.
apis
;
for
(
_k
=
0
,
_len2
=
_ref2
.
length
;
_k
<
_len2
;
_k
++
)
{
resource
=
_ref2
[
_k
];
res
=
new
SwaggerResource
(
resource
,
this
);
this
.
apis
[
res
.
name
]
=
res
;
this
.
apisArray
.
push
(
res
);
}
}
if
(
this
.
success
)
{
this
.
success
();
}
return
this
;
};
SwaggerApi
.
prototype
.
selfReflect
=
function
()
{
var
resource
,
resource_name
,
_ref
;
if
(
this
.
apis
==
null
)
{
...
...
@@ -448,6 +508,7 @@
SwaggerModel
.
prototype
.
createJSONSample
=
function
(
modelsToIgnore
)
{
var
prop
,
result
,
_i
,
_len
,
_ref
;
console
.
log
(
"
creating json sample for
"
+
this
);
result
=
{};
modelsToIgnore
=
modelsToIgnore
||
[];
modelsToIgnore
.
push
(
this
.
name
);
...
...
@@ -456,6 +517,7 @@
prop
=
_ref
[
_i
];
result
[
prop
.
name
]
=
prop
.
getSampleValue
(
modelsToIgnore
);
}
modelsToIgnore
.
pop
(
this
.
name
);
return
result
;
};
...
...
@@ -467,7 +529,8 @@
function
SwaggerModelProperty
(
name
,
obj
)
{
this
.
name
=
name
;
this
.
dataType
=
obj
.
type
;
this
.
dataType
=
obj
.
type
||
obj
.
dataType
||
obj
[
"
$ref
"
];
console
.
log
(
this
.
name
+
"
has data type
"
+
this
.
dataType
);
this
.
isCollection
=
this
.
dataType
&&
(
this
.
dataType
.
toLowerCase
()
===
'
array
'
||
this
.
dataType
.
toLowerCase
()
===
'
list
'
||
this
.
dataType
.
toLowerCase
()
===
'
set
'
);
this
.
descr
=
obj
.
description
;
this
.
required
=
obj
.
required
;
...
...
lib/swagger.js
浏览文件 @
4fb5b86d
...
...
@@ -33,13 +33,11 @@
if
(
options
.
url
!=
null
)
{
this
.
url
=
options
.
url
;
}
this
.
supportedSubmitMethods
=
options
.
supportedSubmitMethods
!=
null
?
options
.
supportedSubmitMethods
:
[
'
get
'
];
if
(
options
.
success
!=
null
)
{
this
.
success
=
options
.
success
;
}
this
.
failure
=
options
.
failure
!=
null
?
options
.
failure
:
function
()
{};
this
.
progress
=
options
.
progress
!=
null
?
options
.
progress
:
function
()
{};
this
.
defaultHeaders
=
options
.
headers
!=
null
?
options
.
headers
:
{};
if
(
options
.
success
!=
null
)
{
this
.
build
();
}
...
...
@@ -66,55 +64,14 @@
}
},
response
:
function
(
rawResponse
)
{
var
api
,
isApi
,
newName
,
operation
,
res
,
resource
,
response
,
_i
,
_j
,
_k
,
_len
,
_len1
,
_len2
,
_ref
,
_ref1
,
_ref2
;
var
response
;
response
=
JSON
.
parse
(
rawResponse
.
content
.
data
);
if
(
response
.
apiVersion
!=
null
)
{
_this
.
apiVersion
=
response
.
apiVersion
;
}
_this
.
apis
=
{};
_this
.
apisArray
=
[];
_this
.
produces
=
response
.
produces
;
if
(
response
.
info
!=
null
)
{
_this
.
info
=
response
.
info
;
}
isApi
=
false
;
_ref
=
response
.
apis
;
for
(
_i
=
0
,
_len
=
_ref
.
length
;
_i
<
_len
;
_i
++
)
{
api
=
_ref
[
_i
];
if
(
api
.
operations
)
{
_ref1
=
api
.
operations
;
for
(
_j
=
0
,
_len1
=
_ref1
.
length
;
_j
<
_len1
;
_j
++
)
{
operation
=
_ref1
[
_j
];
isApi
=
true
;
}
}
}
if
(
isApi
)
{
newName
=
response
.
resourcePath
.
replace
(
/
\/
/g
,
''
);
_this
.
resourcePath
=
response
.
resourcePath
;
res
=
new
SwaggerResource
(
response
,
_this
);
_this
.
apis
[
newName
]
=
res
;
_this
.
apisArray
.
push
(
res
);
_this
.
swaggerVersion
=
response
.
swaggerVersion
;
if
(
_this
.
swaggerVersion
===
"
1.2
"
)
{
return
_this
.
buildFromSpec
(
response
);
}
else
{
if
(
response
.
basePath
)
{
_this
.
basePath
=
response
.
basePath
;
}
else
if
(
_this
.
url
.
indexOf
(
'
?
'
)
>
0
)
{
_this
.
basePath
=
_this
.
url
.
substring
(
0
,
_this
.
url
.
lastIndexOf
(
'
?
'
));
}
else
{
_this
.
basePath
=
_this
.
url
;
}
_ref2
=
response
.
apis
;
for
(
_k
=
0
,
_len2
=
_ref2
.
length
;
_k
<
_len2
;
_k
++
)
{
resource
=
_ref2
[
_k
];
res
=
new
SwaggerResource
(
resource
,
_this
);
_this
.
apis
[
res
.
name
]
=
res
;
_this
.
apisArray
.
push
(
res
);
}
return
_this
.
buildFrom1_1Spec
(
response
);
}
if
(
_this
.
success
)
{
_this
.
success
();
}
return
_this
;
}
}
};
...
...
@@ -129,6 +86,109 @@
return
this
;
};
SwaggerApi
.
prototype
.
buildFromSpec
=
function
(
response
)
{
var
api
,
isApi
,
newName
,
operation
,
res
,
resource
,
_i
,
_j
,
_k
,
_len
,
_len1
,
_len2
,
_ref
,
_ref1
,
_ref2
;
if
(
response
.
apiVersion
!=
null
)
{
this
.
apiVersion
=
response
.
apiVersion
;
}
this
.
apis
=
{};
this
.
apisArray
=
[];
this
.
produces
=
response
.
produces
;
if
(
response
.
info
!=
null
)
{
this
.
info
=
response
.
info
;
}
isApi
=
false
;
_ref
=
response
.
apis
;
for
(
_i
=
0
,
_len
=
_ref
.
length
;
_i
<
_len
;
_i
++
)
{
api
=
_ref
[
_i
];
if
(
api
.
operations
)
{
_ref1
=
api
.
operations
;
for
(
_j
=
0
,
_len1
=
_ref1
.
length
;
_j
<
_len1
;
_j
++
)
{
operation
=
_ref1
[
_j
];
isApi
=
true
;
}
}
}
if
(
isApi
)
{
newName
=
response
.
resourcePath
.
replace
(
/
\/
/g
,
''
);
this
.
resourcePath
=
response
.
resourcePath
;
res
=
new
SwaggerResource
(
response
,
this
);
this
.
apis
[
newName
]
=
res
;
this
.
apisArray
.
push
(
res
);
}
else
{
if
(
response
.
basePath
)
{
this
.
basePath
=
response
.
basePath
;
}
else
if
(
this
.
url
.
indexOf
(
'
?
'
)
>
0
)
{
this
.
basePath
=
this
.
url
.
substring
(
0
,
this
.
url
.
lastIndexOf
(
'
?
'
));
}
else
{
this
.
basePath
=
this
.
url
;
}
_ref2
=
response
.
apis
;
for
(
_k
=
0
,
_len2
=
_ref2
.
length
;
_k
<
_len2
;
_k
++
)
{
resource
=
_ref2
[
_k
];
res
=
new
SwaggerResource
(
resource
,
this
);
this
.
apis
[
res
.
name
]
=
res
;
this
.
apisArray
.
push
(
res
);
}
}
if
(
this
.
success
)
{
this
.
success
();
}
return
this
;
};
SwaggerApi
.
prototype
.
buildFrom1_1Spec
=
function
(
response
)
{
var
api
,
isApi
,
newName
,
operation
,
res
,
resource
,
_i
,
_j
,
_k
,
_len
,
_len1
,
_len2
,
_ref
,
_ref1
,
_ref2
;
console
.
log
(
"
This API is using a deprecated version of Swagger! Please see http://github.com/wordnik/swagger-core/wiki for more info
"
);
if
(
response
.
apiVersion
!=
null
)
{
this
.
apiVersion
=
response
.
apiVersion
;
}
this
.
apis
=
{};
this
.
apisArray
=
[];
this
.
produces
=
response
.
produces
;
if
(
response
.
info
!=
null
)
{
this
.
info
=
response
.
info
;
}
isApi
=
false
;
_ref
=
response
.
apis
;
for
(
_i
=
0
,
_len
=
_ref
.
length
;
_i
<
_len
;
_i
++
)
{
api
=
_ref
[
_i
];
if
(
api
.
operations
)
{
_ref1
=
api
.
operations
;
for
(
_j
=
0
,
_len1
=
_ref1
.
length
;
_j
<
_len1
;
_j
++
)
{
operation
=
_ref1
[
_j
];
isApi
=
true
;
}
}
}
if
(
isApi
)
{
newName
=
response
.
resourcePath
.
replace
(
/
\/
/g
,
''
);
this
.
resourcePath
=
response
.
resourcePath
;
res
=
new
SwaggerResource
(
response
,
this
);
this
.
apis
[
newName
]
=
res
;
this
.
apisArray
.
push
(
res
);
}
else
{
if
(
response
.
basePath
)
{
this
.
basePath
=
response
.
basePath
;
}
else
if
(
this
.
url
.
indexOf
(
'
?
'
)
>
0
)
{
this
.
basePath
=
this
.
url
.
substring
(
0
,
this
.
url
.
lastIndexOf
(
'
?
'
));
}
else
{
this
.
basePath
=
this
.
url
;
}
_ref2
=
response
.
apis
;
for
(
_k
=
0
,
_len2
=
_ref2
.
length
;
_k
<
_len2
;
_k
++
)
{
resource
=
_ref2
[
_k
];
res
=
new
SwaggerResource
(
resource
,
this
);
this
.
apis
[
res
.
name
]
=
res
;
this
.
apisArray
.
push
(
res
);
}
}
if
(
this
.
success
)
{
this
.
success
();
}
return
this
;
};
SwaggerApi
.
prototype
.
selfReflect
=
function
()
{
var
resource
,
resource_name
,
_ref
;
if
(
this
.
apis
==
null
)
{
...
...
@@ -448,6 +508,7 @@
SwaggerModel
.
prototype
.
createJSONSample
=
function
(
modelsToIgnore
)
{
var
prop
,
result
,
_i
,
_len
,
_ref
;
console
.
log
(
"
creating json sample for
"
+
this
);
result
=
{};
modelsToIgnore
=
modelsToIgnore
||
[];
modelsToIgnore
.
push
(
this
.
name
);
...
...
@@ -456,6 +517,7 @@
prop
=
_ref
[
_i
];
result
[
prop
.
name
]
=
prop
.
getSampleValue
(
modelsToIgnore
);
}
modelsToIgnore
.
pop
(
this
.
name
);
return
result
;
};
...
...
@@ -467,7 +529,8 @@
function
SwaggerModelProperty
(
name
,
obj
)
{
this
.
name
=
name
;
this
.
dataType
=
obj
.
type
;
this
.
dataType
=
obj
.
type
||
obj
.
dataType
||
obj
[
"
$ref
"
];
console
.
log
(
this
.
name
+
"
has data type
"
+
this
.
dataType
);
this
.
isCollection
=
this
.
dataType
&&
(
this
.
dataType
.
toLowerCase
()
===
'
array
'
||
this
.
dataType
.
toLowerCase
()
===
'
list
'
||
this
.
dataType
.
toLowerCase
()
===
'
set
'
);
this
.
descr
=
obj
.
description
;
this
.
required
=
obj
.
required
;
...
...
package.json
浏览文件 @
4fb5b86d
{
"name"
:
"swagger-ui"
,
"version"
:
"2.0.
0
"
,
"version"
:
"2.0.
1
"
,
"description"
:
"Swagger UI is a dependency-free collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API"
,
"scripts"
:
{
"build"
:
"PATH=$PATH:./node_modules/.bin cake dist"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录