diff --git a/src/core/components/response.jsx b/src/core/components/response.jsx index e354c61e..086f86ed 100644 --- a/src/core/components/response.jsx +++ b/src/core/components/response.jsx @@ -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 { ) : null} - + + {specSelectors.isOAS3() ? + { links ? + links.toSeq().map((link, key) => { + return + }) + : No links} + : null} ) } diff --git a/src/core/components/responses.jsx b/src/core/components/responses.jsx index 8bbe4f0f..c7fae6d2 100644 --- a/src/core/components/responses.jsx +++ b/src/core/components/responses.jsx @@ -64,6 +64,7 @@ export default class Responses extends React.Component { Code Description + { specSelectors.isOAS3() ? Links : null } diff --git a/src/core/plugins/oas3/components/index.js b/src/core/plugins/oas3/components/index.js index f6c2174d..8186ce8e 100644 --- a/src/core/plugins/oas3/components/index.js +++ b/src/core/plugins/oas3/components/index.js @@ -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 } diff --git a/src/core/plugins/oas3/components/operation-link.jsx b/src/core/plugins/oas3/components/operation-link.jsx new file mode 100644 index 00000000..f747e262 --- /dev/null +++ b/src/core/plugins/oas3/components/operation-link.jsx @@ -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 +
{name}{description ? `: ${description}` : ""}
+
+        Parameters {padString(0, JSON.stringify(parameters, null, 2)) || "{}"}

+ Headers {padString(0, JSON.stringify(headers, null, 2)) || "{}"}
+
+
+ } + +} + +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") +} diff --git a/src/core/plugins/oas3/helpers.js b/src/core/plugins/oas3/helpers.js index b8bb3aa9..6aa10823 100644 --- a/src/core/plugins/oas3/helpers.js +++ b/src/core/plugins/oas3/helpers.js @@ -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 diff --git a/src/core/plugins/oas3/index.js b/src/core/plugins/oas3/index.js index f8827455..3413b65e 100644 --- a/src/core/plugins/oas3/index.js +++ b/src/core/plugins/oas3/index.js @@ -10,9 +10,6 @@ export default function() { wrapComponents, statePlugins: { spec: { - // wrapActions, - // reducers, - // actions, wrapSelectors } } diff --git a/src/core/plugins/oas3/wrap-selectors.js b/src/core/plugins/oas3/wrap-selectors.js index edbe0bca..27b3bb7b 100644 --- a/src/core/plugins/oas3/wrap-selectors.js +++ b/src/core/plugins/oas3/wrap-selectors.js @@ -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) +} diff --git a/src/core/plugins/spec/selectors.js b/src/core/plugins/spec/selectors.js index d8487e89..fa11003a 100644 --- a/src/core/plugins/spec/selectors.js +++ b/src/core/plugins/spec/selectors.js @@ -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"))