Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Ihor Kaharlichenko
swagger-ui-oms
Commits
542d4fe4
Commit
542d4fe4
authored
Dec 27, 2013
by
invincible
Browse files
safe-JSON-parsing-check-for-type-undefined
parent
97e96ba3
Changes
3
Hide whitespace changes
Inline
Side-by-side
dist/lib/swagger.js
View file @
542d4fe4
...
...
@@ -63,10 +63,18 @@
}
},
response
:
function
(
rawResponse
)
{
var
response
;
response
=
JSON
.
parse
(
rawResponse
.
content
.
data
);
if
(
/^
[\]
,:{}
\s]
*$/
.
test
(
rawResponse
.
content
.
data
.
replace
(
/
\\[
"
\\\/
bfnrtu
]
/g
,
'
@
'
).
replace
(
/"
[^
"
\\\n\r]
*"|true|false|null|-
?\d
+
(?:\.\d
*
)?(?:[
eE
][
+
\-]?\d
+
)?
/g
,
'
]
'
).
replace
(
/
(?:
^|:|,
)(?:\s
*
\[)
+/g
,
''
)))
{
try
{
var
response
=
JSON
.
parse
(
rawResponse
.
content
.
data
);
}
catch
(
e
)
{
var
response
=
rawResponse
.
content
.
data
;
}
}
else
{
var
response
=
rawResponse
.
content
.
data
;
}
_this
.
swaggerVersion
=
response
.
swaggerVersion
;
if
(
_this
.
swaggerVersion
===
"
1.2
"
)
{
if
(
_this
.
swaggerVersion
===
"
1.2
"
)
{
return
_this
.
buildFromSpec
(
response
);
}
else
{
return
_this
.
buildFrom1_1Spec
(
response
);
...
...
@@ -290,7 +298,7 @@
this
.
api
.
fail
(
"
SwaggerResources must have a path.
"
);
}
if
(
this
.
path
.
substring
(
0
,
4
)
===
'
http
'
)
{
this
.
url
=
this
.
path
.
replace
(
'
{format}
'
,
'
json
'
);
this
.
url
=
this
.
path
.
replace
(
'
{format}
'
,
'
json
'
);
}
else
{
this
.
url
=
this
.
api
.
basePath
+
this
.
path
.
replace
(
'
{format}
'
,
'
json
'
);
}
...
...
@@ -305,7 +313,16 @@
},
response
:
function
(
rawResponse
)
{
var
response
;
response
=
JSON
.
parse
(
rawResponse
.
content
.
data
);
if
(
/^
[\]
,:{}
\s]
*$/
.
test
(
rawResponse
.
content
.
data
.
replace
(
/
\\[
"
\\\/
bfnrtu
]
/g
,
'
@
'
).
replace
(
/"
[^
"
\\\n\r]
*"|true|false|null|-
?\d
+
(?:\.\d
*
)?(?:[
eE
][
+
\-]?\d
+
)?
/g
,
'
]
'
).
replace
(
/
(?:
^|:|,
)(?:\s
*
\[)
+/g
,
''
)))
{
try
{
var
response
=
JSON
.
parse
(
rawResponse
.
content
.
data
);
}
catch
(
e
)
{
var
response
=
rawResponse
.
content
.
data
;
}
}
else
{
var
response
=
rawResponse
.
content
.
data
;
}
return
_this
.
addApiDeclaration
(
response
);
}
}
...
...
@@ -641,10 +658,10 @@
parameter
=
_ref1
[
_i
];
parameter
.
name
=
parameter
.
name
||
parameter
.
type
||
parameter
.
dataType
;
type
=
parameter
.
type
||
parameter
.
dataType
;
if
(
type
.
toLowerCase
()
===
'
boolean
'
)
{
parameter
.
allowableValues
=
{};
parameter
.
allowableValues
.
values
=
[
"
true
"
,
"
false
"
];
}
if
(
typeof
(
type
)
!=
'
undefined
'
&&
type
.
toLowerCase
()
===
'
boolean
'
)
{
parameter
.
allowableValues
=
{};
parameter
.
allowableValues
.
values
=
[
"
true
"
,
"
false
"
];
}
parameter
.
signature
=
this
.
getSignature
(
type
,
this
.
resource
.
models
);
parameter
.
sampleJSON
=
this
.
getSampleJSON
(
type
,
this
.
resource
.
models
);
if
(
parameter
[
"
enum
"
]
!=
null
)
{
...
...
@@ -702,11 +719,11 @@
}
SwaggerOperation
.
prototype
.
isListType
=
function
(
type
)
{
if
(
type
.
indexOf
(
'
[
'
)
>=
0
)
{
return
type
.
substring
(
type
.
indexOf
(
'
[
'
)
+
1
,
type
.
indexOf
(
'
]
'
));
}
else
{
return
void
0
;
}
if
(
typeof
(
type
)
!=
'
undefined
'
&&
type
.
indexOf
(
'
[
'
)
>=
0
)
{
return
type
.
substring
(
type
.
indexOf
(
'
[
'
)
+
1
,
type
.
indexOf
(
'
]
'
));
}
else
{
return
void
0
;
}
};
SwaggerOperation
.
prototype
.
getSignature
=
function
(
type
,
models
)
{
...
...
dist/swagger-ui.js
View file @
542d4fe4
...
...
@@ -1509,14 +1509,16 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
contentTypeModel
.
produces
=
this
.
model
.
produces
;
_ref5
=
this
.
model
.
parameters
;
for
(
_i
=
0
,
_len
=
_ref5
.
length
;
_i
<
_len
;
_i
++
)
{
param
=
_ref5
[
_i
];
type
=
param
.
type
||
param
.
dataType
;
if
(
type
.
toLowerCase
()
===
'
file
'
)
{
if
(
!
contentTypeModel
.
consumes
)
{
console
.
log
(
"
set content type
"
);
contentTypeModel
.
consumes
=
'
multipart/form-data
'
;
}
}
param
=
_ref5
[
_i
];
type
=
param
.
type
||
param
.
dataType
;
if
(
typeof
(
type
)
!=
'
undefined
'
&&
type
.
toLowerCase
()
===
'
file
'
)
{
if
(
!
contentTypeModel
.
consumes
)
{
console
.
log
(
"
set content type
"
);
contentTypeModel
.
consumes
=
'
multipart/form-data
'
;
}
}
}
responseContentTypeView
=
new
ResponseContentTypeView
({
model
:
contentTypeModel
...
...
@@ -1904,8 +1906,8 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
if
(
this
.
model
.
paramType
===
'
body
'
)
{
this
.
model
.
isBody
=
true
;
}
if
(
type
.
toLowerCase
()
===
'
file
'
)
{
this
.
model
.
isFile
=
true
;
if
(
typeof
(
type
)
!=
'
undefined
'
&&
type
.
toLowerCase
()
===
'
file
'
)
{
this
.
model
.
isFile
=
true
;
}
template
=
this
.
template
();
$
(
this
.
el
).
html
(
template
(
this
.
model
));
...
...
lib/swagger.js
View file @
542d4fe4
...
...
@@ -63,10 +63,18 @@
}
},
response
:
function
(
rawResponse
)
{
var
response
;
response
=
JSON
.
parse
(
rawResponse
.
content
.
data
);
if
(
/^
[\]
,:{}
\s]
*$/
.
test
(
rawResponse
.
content
.
data
.
replace
(
/
\\[
"
\\\/
bfnrtu
]
/g
,
'
@
'
).
replace
(
/"
[^
"
\\\n\r]
*"|true|false|null|-
?\d
+
(?:\.\d
*
)?(?:[
eE
][
+
\-]?\d
+
)?
/g
,
'
]
'
).
replace
(
/
(?:
^|:|,
)(?:\s
*
\[)
+/g
,
''
)))
{
try
{
var
response
=
JSON
.
parse
(
rawResponse
.
content
.
data
);
}
catch
(
e
)
{
var
response
=
rawResponse
.
content
.
data
;
}
}
else
{
var
response
=
rawResponse
.
content
.
data
;
}
_this
.
swaggerVersion
=
response
.
swaggerVersion
;
if
(
_this
.
swaggerVersion
===
"
1.2
"
)
{
if
(
_this
.
swaggerVersion
===
"
1.2
"
)
{
return
_this
.
buildFromSpec
(
response
);
}
else
{
return
_this
.
buildFrom1_1Spec
(
response
);
...
...
@@ -290,7 +298,7 @@
this
.
api
.
fail
(
"
SwaggerResources must have a path.
"
);
}
if
(
this
.
path
.
substring
(
0
,
4
)
===
'
http
'
)
{
this
.
url
=
this
.
path
.
replace
(
'
{format}
'
,
'
json
'
);
this
.
url
=
this
.
path
.
replace
(
'
{format}
'
,
'
json
'
);
}
else
{
this
.
url
=
this
.
api
.
basePath
+
this
.
path
.
replace
(
'
{format}
'
,
'
json
'
);
}
...
...
@@ -305,7 +313,16 @@
},
response
:
function
(
rawResponse
)
{
var
response
;
response
=
JSON
.
parse
(
rawResponse
.
content
.
data
);
if
(
/^
[\]
,:{}
\s]
*$/
.
test
(
rawResponse
.
content
.
data
.
replace
(
/
\\[
"
\\\/
bfnrtu
]
/g
,
'
@
'
).
replace
(
/"
[^
"
\\\n\r]
*"|true|false|null|-
?\d
+
(?:\.\d
*
)?(?:[
eE
][
+
\-]?\d
+
)?
/g
,
'
]
'
).
replace
(
/
(?:
^|:|,
)(?:\s
*
\[)
+/g
,
''
)))
{
try
{
var
response
=
JSON
.
parse
(
rawResponse
.
content
.
data
);
}
catch
(
e
)
{
var
response
=
rawResponse
.
content
.
data
;
}
}
else
{
var
response
=
rawResponse
.
content
.
data
;
}
return
_this
.
addApiDeclaration
(
response
);
}
}
...
...
@@ -641,10 +658,10 @@
parameter
=
_ref1
[
_i
];
parameter
.
name
=
parameter
.
name
||
parameter
.
type
||
parameter
.
dataType
;
type
=
parameter
.
type
||
parameter
.
dataType
;
if
(
type
.
toLowerCase
()
===
'
boolean
'
)
{
parameter
.
allowableValues
=
{};
parameter
.
allowableValues
.
values
=
[
"
true
"
,
"
false
"
];
}
if
(
typeof
(
type
)
!=
'
undefined
'
&&
type
.
toLowerCase
()
===
'
boolean
'
)
{
parameter
.
allowableValues
=
{};
parameter
.
allowableValues
.
values
=
[
"
true
"
,
"
false
"
];
}
parameter
.
signature
=
this
.
getSignature
(
type
,
this
.
resource
.
models
);
parameter
.
sampleJSON
=
this
.
getSampleJSON
(
type
,
this
.
resource
.
models
);
if
(
parameter
[
"
enum
"
]
!=
null
)
{
...
...
@@ -702,11 +719,11 @@
}
SwaggerOperation
.
prototype
.
isListType
=
function
(
type
)
{
if
(
type
.
indexOf
(
'
[
'
)
>=
0
)
{
return
type
.
substring
(
type
.
indexOf
(
'
[
'
)
+
1
,
type
.
indexOf
(
'
]
'
));
}
else
{
return
void
0
;
}
if
(
typeof
(
type
)
!=
'
undefined
'
&&
type
.
indexOf
(
'
[
'
)
>=
0
)
{
return
type
.
substring
(
type
.
indexOf
(
'
[
'
)
+
1
,
type
.
indexOf
(
'
]
'
));
}
else
{
return
void
0
;
}
};
SwaggerOperation
.
prototype
.
getSignature
=
function
(
type
,
models
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment