Merge branch 'master' into master
This commit is contained in:
@@ -24,24 +24,23 @@ export default class ArrayModel extends Component {
|
||||
const Markdown = getComponent("Markdown")
|
||||
const ModelCollapse = getComponent("ModelCollapse")
|
||||
const Model = getComponent("Model")
|
||||
const Property = getComponent("Property")
|
||||
|
||||
const titleEl = title &&
|
||||
<span className="model-title">
|
||||
<span className="model-title__text">{ title }</span>
|
||||
</span>
|
||||
|
||||
/*
|
||||
/*
|
||||
Note: we set `name={null}` in <Model> below because we don't want
|
||||
the name of the current Model passed (and displayed) as the name of the array element Model
|
||||
*/
|
||||
*/
|
||||
|
||||
return <span className="model">
|
||||
<ModelCollapse title={titleEl} collapsed={ depth > expandDepth } collapsedContent="[...]">
|
||||
[
|
||||
{
|
||||
properties.size ? properties.entrySeq().map( ( [ key, v ] ) => <span key={`${key}-${v}`} style={ propStyle }>
|
||||
<br />{ key }: { String(v) }</span>)
|
||||
: null
|
||||
properties.size ? properties.entrySeq().map( ( [ key, v ] ) => <Property key={`${key}-${v}`} propKey={ key } propVal={ v } propStyle={ propStyle } />) : null
|
||||
}
|
||||
{
|
||||
!description ? null :
|
||||
|
||||
@@ -28,6 +28,7 @@ export default class Primitive extends Component {
|
||||
let properties = schema.filter( ( v, key) => ["enum", "type", "format", "description", "$$ref"].indexOf(key) === -1 )
|
||||
const Markdown = getComponent("Markdown")
|
||||
const EnumModel = getComponent("EnumModel")
|
||||
const Property = getComponent("Property")
|
||||
|
||||
return <span className="model">
|
||||
<span className="prop">
|
||||
@@ -35,9 +36,7 @@ export default class Primitive extends Component {
|
||||
<span className="prop-type">{ type }</span>
|
||||
{ format && <span className="prop-format">(${format})</span>}
|
||||
{
|
||||
properties.size ? properties.entrySeq().map( ( [ key, v ] ) => <span key={`${key}-${v}`} style={ propStyle }>
|
||||
<br />{ key }: { String(v) }</span>)
|
||||
: null
|
||||
properties.size ? properties.entrySeq().map( ( [ key, v ] ) => <Property key={`${key}-${v}`} propKey={ key } propVal={ v } propStyle={ propStyle } />) : null
|
||||
}
|
||||
{
|
||||
!description ? null :
|
||||
@@ -56,4 +55,4 @@ export default class Primitive extends Component {
|
||||
</span>
|
||||
</span>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
16
src/core/components/property.jsx
Normal file
16
src/core/components/property.jsx
Normal file
@@ -0,0 +1,16 @@
|
||||
import React from "react"
|
||||
import PropTypes from "prop-types"
|
||||
|
||||
export const Property = ({ propKey, propVal, propStyle }) => {
|
||||
return (
|
||||
<span style={ propStyle }>
|
||||
<br />{ propKey }: { String(propVal) }</span>
|
||||
)
|
||||
}
|
||||
Property.propTypes = {
|
||||
propKey: PropTypes.string,
|
||||
propVal: PropTypes.any,
|
||||
propStyle: PropTypes.object
|
||||
}
|
||||
|
||||
export default Property
|
||||
@@ -1,6 +1,6 @@
|
||||
import React from "react"
|
||||
import PropTypes from "prop-types"
|
||||
import { formatXml } from "core/utils"
|
||||
import formatXml from "xml-but-prettier"
|
||||
import lowerCase from "lodash/lowerCase"
|
||||
|
||||
export default class ResponseBody extends React.Component {
|
||||
@@ -31,7 +31,9 @@ export default class ResponseBody extends React.Component {
|
||||
|
||||
// XML
|
||||
} else if (/xml/i.test(contentType)) {
|
||||
body = formatXml(content)
|
||||
body = formatXml(content, {
|
||||
textNodesOnSameLine: true
|
||||
})
|
||||
bodyEl = <HighlightCode value={ body } />
|
||||
|
||||
// HTML or Plain Text
|
||||
|
||||
@@ -58,13 +58,12 @@ module.exports = function SwaggerUI(opts) {
|
||||
plugins: [
|
||||
],
|
||||
|
||||
// Initial state
|
||||
initialState: { },
|
||||
|
||||
// Inline Plugin
|
||||
fn: { },
|
||||
components: { },
|
||||
state: { },
|
||||
|
||||
// Override some core configs... at your own risk
|
||||
store: { },
|
||||
}
|
||||
|
||||
let queryConfig = parseSearch()
|
||||
@@ -74,12 +73,12 @@ module.exports = function SwaggerUI(opts) {
|
||||
|
||||
const constructorConfig = deepExtend({}, defaults, opts, queryConfig)
|
||||
|
||||
const storeConfigs = deepExtend({}, constructorConfig.store, {
|
||||
const storeConfigs = {
|
||||
system: {
|
||||
configs: constructorConfig.configs
|
||||
},
|
||||
plugins: constructorConfig.presets,
|
||||
state: {
|
||||
state: deepExtend({
|
||||
layout: {
|
||||
layout: constructorConfig.layout,
|
||||
filter: constructorConfig.filter
|
||||
@@ -88,8 +87,8 @@ module.exports = function SwaggerUI(opts) {
|
||||
spec: "",
|
||||
url: constructorConfig.url
|
||||
}
|
||||
}
|
||||
})
|
||||
}, constructorConfig.initialState)
|
||||
}
|
||||
|
||||
let inlinePlugin = ()=> {
|
||||
return {
|
||||
|
||||
@@ -108,9 +108,6 @@ export default class HttpAuth extends React.Component {
|
||||
<Row>
|
||||
<Markdown source={ schema.get("description") } />
|
||||
</Row>
|
||||
<Row>
|
||||
<p>In: <code>{ schema.get("in") }</code></p>
|
||||
</Row>
|
||||
<Row>
|
||||
<label>Value:</label>
|
||||
{
|
||||
|
||||
@@ -48,6 +48,10 @@ export const definitions = onlyOAS3(createSelector(
|
||||
spec => spec.getIn(["components", "schemas"]) || Map()
|
||||
))
|
||||
|
||||
export const hasHost = onlyOAS3((state) => {
|
||||
return spec(state).hasIn(["servers", 0])
|
||||
})
|
||||
|
||||
export const securityDefinitions = onlyOAS3(createSelector(
|
||||
spec,
|
||||
spec => spec.getIn(["components", "securitySchemes"]) || null
|
||||
|
||||
@@ -10,6 +10,7 @@ import auth from "core/plugins/auth"
|
||||
import util from "core/plugins/util"
|
||||
import SplitPaneModePlugin from "core/plugins/split-pane-mode"
|
||||
import downloadUrlPlugin from "core/plugins/download-url"
|
||||
import configsPlugin from "plugins/configs"
|
||||
import deepLinkingPlugin from "core/plugins/deep-linking"
|
||||
|
||||
import App from "core/components/app"
|
||||
@@ -52,6 +53,7 @@ import EnumModel from "core/components/enum-model"
|
||||
import ObjectModel from "core/components/object-model"
|
||||
import ArrayModel from "core/components/array-model"
|
||||
import PrimitiveModel from "core/components/primitive-model"
|
||||
import Property from "core/components/property"
|
||||
import TryItOutButton from "core/components/try-it-out-button"
|
||||
import VersionStamp from "core/components/version-stamp"
|
||||
|
||||
@@ -106,6 +108,7 @@ export default function() {
|
||||
ObjectModel,
|
||||
ArrayModel,
|
||||
PrimitiveModel,
|
||||
Property,
|
||||
TryItOutButton,
|
||||
Markdown,
|
||||
BaseLayout,
|
||||
@@ -122,6 +125,7 @@ export default function() {
|
||||
}
|
||||
|
||||
return [
|
||||
configsPlugin,
|
||||
util,
|
||||
logs,
|
||||
view,
|
||||
|
||||
@@ -155,83 +155,6 @@ export function getList(iterable, keys) {
|
||||
return Im.List.isList(val) ? val : Im.List()
|
||||
}
|
||||
|
||||
// Adapted from http://stackoverflow.com/a/2893259/454004
|
||||
// Note: directly ported from CoffeeScript
|
||||
export function formatXml (xml) {
|
||||
var contexp, fn, formatted, indent, l, lastType, len, lines, ln, reg, transitions, wsexp
|
||||
reg = /(>)(<)(\/*)/g
|
||||
wsexp = /[ ]*(.*)[ ]+\n/g
|
||||
contexp = /(<.+>)(.+\n)/g
|
||||
xml = xml.replace(/\r\n/g, "\n").replace(reg, "$1\n$2$3").replace(wsexp, "$1\n").replace(contexp, "$1\n$2")
|
||||
formatted = ""
|
||||
lines = xml.split("\n")
|
||||
indent = 0
|
||||
lastType = "other"
|
||||
transitions = {
|
||||
"single->single": 0,
|
||||
"single->closing": -1,
|
||||
"single->opening": 0,
|
||||
"single->other": 0,
|
||||
"closing->single": 0,
|
||||
"closing->closing": -1,
|
||||
"closing->opening": 0,
|
||||
"closing->other": 0,
|
||||
"opening->single": 1,
|
||||
"opening->closing": 0,
|
||||
"opening->opening": 1,
|
||||
"opening->other": 1,
|
||||
"other->single": 0,
|
||||
"other->closing": -1,
|
||||
"other->opening": 0,
|
||||
"other->other": 0
|
||||
}
|
||||
fn = function(ln) {
|
||||
var fromTo, key, padding, type, types, value
|
||||
types = {
|
||||
single: Boolean(ln.match(/<.+\/>/)),
|
||||
closing: Boolean(ln.match(/<\/.+>/)),
|
||||
opening: Boolean(ln.match(/<[^!?].*>/))
|
||||
}
|
||||
type = ((function() {
|
||||
var results
|
||||
results = []
|
||||
for (key in types) {
|
||||
value = types[key]
|
||||
if (value) {
|
||||
results.push(key)
|
||||
}
|
||||
}
|
||||
return results
|
||||
})())[0]
|
||||
type = type === void 0 ? "other" : type
|
||||
fromTo = lastType + "->" + type
|
||||
lastType = type
|
||||
padding = ""
|
||||
indent += transitions[fromTo]
|
||||
padding = ((function() {
|
||||
/* eslint-disable no-unused-vars */
|
||||
var m, ref1, results, j
|
||||
results = []
|
||||
for (j = m = 0, ref1 = indent; 0 <= ref1 ? m < ref1 : m > ref1; j = 0 <= ref1 ? ++m : --m) {
|
||||
results.push(" ")
|
||||
}
|
||||
/* eslint-enable no-unused-vars */
|
||||
return results
|
||||
})()).join("")
|
||||
if (fromTo === "opening->closing") {
|
||||
formatted = formatted.substr(0, formatted.length - 1) + ln + "\n"
|
||||
} else {
|
||||
formatted += padding + ln + "\n"
|
||||
}
|
||||
}
|
||||
for (l = 0, len = lines.length; l < len; l++) {
|
||||
ln = lines[l]
|
||||
fn(ln)
|
||||
}
|
||||
return formatted
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adapted from http://github.com/asvd/microlight
|
||||
* @copyright 2016 asvd <heliosframework@gmail.com>
|
||||
|
||||
Reference in New Issue
Block a user