Skip to content

Commit

Permalink
Merge branch 'master' into fix-model-markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
shockey authored Jun 16, 2017
2 parents ce16666 + 1cab498 commit 99600df
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 36 deletions.
38 changes: 19 additions & 19 deletions dist/swagger-ui-bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/swagger-ui-bundle.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions dist/swagger-ui.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/swagger-ui.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/core/components/curl.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
)
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/model.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class Model extends Component {
switch(type) {
case "object":
return <ObjectModel className="object" { ...this.props } schema={ modelSchema }
name={ modelName || name }
name={ name || modelName }
isRef={ isRef!== undefined ? isRef : !!$$ref }/>
case "array":
return <ArrayModel className="array" { ...this.props } schema={ modelSchema } required={ required } />
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/response.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const getExampleComponent = ( sampleResponse, examples, HighlightCode ) => {
let exampleValue
try {
exampleValue = example && example.toJS ? example.toJS() : example
exampleValue = JSON.stringify(exampleValue)
exampleValue = JSON.stringify(exampleValue, null, 2)
}
catch(e) {
exampleValue = String(example)
Expand Down
12 changes: 8 additions & 4 deletions src/core/curlify.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import win from "./window"

export default function curl( request ){
let curlified = []
let type = ""
Expand All @@ -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" )
Expand Down
4 changes: 4 additions & 0 deletions src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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() :
Expand Down
3 changes: 2 additions & 1 deletion src/core/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ function makeWindow() {
location: {},
history: {},
open: () => {},
close: () => {}
close: () => {},
File: function() {}
}

if(typeof window === "undefined") {
Expand Down
28 changes: 26 additions & 2 deletions test/core/curlify.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import expect from "expect"
import Im from "immutable"
import curl from "core/curlify"
import win from "core/window"

describe("curlify", function() {

Expand Down Expand Up @@ -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 \"[email protected];type=text/plain\"")
})

it("prints a curl post statement from an object", function() {
Expand Down

0 comments on commit 99600df

Please sign in to comment.