Squash commit: Links reimplementation; OAS interface improvements

This commit is contained in:
Kyle Shockey
2017-06-16 00:28:09 -07:00
parent e415ec7f8a
commit 9dc9a857b7
8 changed files with 67 additions and 12 deletions

View File

@@ -60,10 +60,12 @@ export default class Response extends React.Component {
let schema = inferSchema(response.toJS())
let headers = response.get("headers")
let examples = response.get("examples")
let links = response.get("links")
const Headers = getComponent("headers")
const HighlightCode = getComponent("highlightCode")
const ModelExample = getComponent("modelExample")
const Markdown = getComponent( "Markdown" )
const OperationLink = getComponent("operationLink")
let sampleResponse = schema ? getSampleSchema(schema, contentType, { includeReadOnly: true }) : null
let example = getExampleComponent( sampleResponse, examples, HighlightCode )
@@ -91,8 +93,15 @@ export default class Response extends React.Component {
<Headers headers={ headers }/>
) : null}
</td>
</td>
{specSelectors.isOAS3() ? <td>
{ links ?
links.toSeq().map((link, key) => {
return <OperationLink key={key} name={key} link={ link }/>
})
: <i>No links</i>}
</td> : null}
</tr>
)
}

View File

@@ -64,6 +64,7 @@ export default class Responses extends React.Component {
<tr className="responses-header">
<td className="col col_header response-col_status">Code</td>
<td className="col col_header response-col_description">Description</td>
{ specSelectors.isOAS3() ? <td className="col col_header response-col_description">Links</td> : null }
</tr>
</thead>
<tbody>

View File

@@ -1,7 +1,9 @@
import Callbacks from "./callbacks"
import RequestBody from "./request-body"
import OperationLink from "./operation-link.jsx"
export default {
Callbacks,
RequestBody
RequestBody,
operationLink: OperationLink
}

View File

@@ -0,0 +1,29 @@
import React, { Component } from "react"
export default class OperationLink extends Component {
render() {
const { link, name } = this.props
let targetOp = link.get("operationId") || link.get("operationRef")
let parameters = link.get("parameters") && link.get("parameters").toJS()
let headers = link.get("headers") && link.get("headers").toJS()
let description = link.get("description")
return <span>
<div style={{ padding: "7px" }}>{name}{description ? `: ${description}` : ""}</div>
<pre>
Parameters {padString(0, JSON.stringify(parameters, null, 2)) || "{}"}<br /><br />
Headers {padString(0, JSON.stringify(headers, null, 2)) || "{}"}<br />
</pre>
</span>
}
}
function padString(n, string) {
if(typeof string !== "string") { return "" }
return string
.split("\n")
.map((line, i) => i > 0 ? Array(n + 1).join(" ") + line : line)
.join("\n")
}

View File

@@ -1,15 +1,18 @@
import React from "react"
export const SUPPORTED_OPENAPI_VERSIONS = ["3.0.0-rc0", "3.0.0-RC1"]
export function isOAS3(jsSpec) {
return !!jsSpec.openapi && SUPPORTED_OPENAPI_VERSIONS.indexOf(jsSpec.openapi) > -1
const oasVersion = jsSpec.get("openapi")
if(!oasVersion) {
return false
}
return oasVersion.startsWith("3.0.0")
}
export function OAS3ComponentWrapFactory(Component) {
return (Ori, system) => (props) => {
if(system && system.specSelectors && system.specSelectors.specJson) {
const spec = system.specSelectors.specJson().toJS()
const spec = system.specSelectors.specJson()
if(isOAS3(spec)) {
return <Component {...props} {...system} Ori={Ori}></Component>

View File

@@ -10,9 +10,6 @@ export default function() {
wrapComponents,
statePlugins: {
spec: {
// wrapActions,
// reducers,
// actions,
wrapSelectors
}
}

View File

@@ -1,14 +1,14 @@
import { createSelector } from "reselect"
import { Map } from "immutable"
import { SUPPORTED_OPENAPI_VERSIONS } from "./helpers"
import { isOAS3 as isOAS3Helper } from "./helpers"
// Helpers
function onlyOAS3(selector) {
return (ori, system) => (...args) => {
const spec = system.getSystem().specSelectors.specJson()
const version = spec.get("openapi")
if(typeof version === "string" && SUPPORTED_OPENAPI_VERSIONS.indexOf(version) > -1) {
if(isOAS3Helper(spec)) {
return selector(...args)
} else {
return ori(...args)
@@ -43,3 +43,10 @@ export const definitions = onlyOAS3(createSelector(
spec,
spec => spec.getIn(["components", "schemas"]) || Map()
))
// New selectors
export const isOAS3 = (ori, system) => () => {
const spec = system.getSystem().specSelectors.specJson()
return isOAS3Helper(spec)
}

View File

@@ -46,6 +46,13 @@ export const spec = state => {
return res
}
export const isOAS3 = createSelector(
// isOAS3 is stubbed out here to work around an issue with injecting more selectors
// in the OAS3 plugin, and to ensure that the function is always available.
spec,
spec => false
)
export const info = createSelector(
spec,
spec => returnSelfOrNewMap(spec && spec.get("info"))