Added Swagger

This commit is contained in:
2020-06-10 08:25:21 +02:00
parent 5c6f37eaf7
commit af76cbca87
257 changed files with 48861 additions and 12 deletions
@@ -0,0 +1,64 @@
import React from "react"
import PropTypes from "prop-types"
import JumpIcon from "./jump-icon.svg"
export class JumpToPath extends React.Component {
static propTypes = {
editorActions: PropTypes.object.isRequired,
specSelectors: PropTypes.object.isRequired,
fn: PropTypes.object.isRequired,
path: PropTypes.oneOfType([
PropTypes.array,
PropTypes.string
]),
content: PropTypes.element,
showButton: PropTypes.bool,
specPath: PropTypes.array, // The location within the spec. Used as a fallback if `path` doesn't exist
}
static defaultProps = {
path: "",
}
shouldComponentUpdate(nextProps) {
let { shallowEqualKeys } = nextProps.fn
return shallowEqualKeys(this.props, nextProps, [
"content", "showButton", "path", "specPath"
])
}
jumpToPath = (e) => {
e.stopPropagation()
const {
specPath=[],
path,
specSelectors,
editorActions
} = this.props
const jumpPath = specSelectors.bestJumpPath({path, specPath})
editorActions.jumpToLine(specSelectors.getSpecLineFromPath(jumpPath))
}
defaultJumpContent = <img src={JumpIcon} onClick={this.jumpToPath} className="view-line-link" title={"Jump to definition"} />
render() {
let { content, showButton } = this.props
if (content) {
// if we were given content to render, wrap it
return (
<span onClick={ this.jumpToPath }>
{ showButton ? this.defaultJumpContent : null }
{content}
</span>
)
} else {
// just render a link
return this.defaultJumpContent
}
}
}
+11
View File
@@ -0,0 +1,11 @@
import spec from "./spec"
import * as components from "./components"
export default function JumpToPathPlugin() {
return [
spec,
{
components,
}
]
}
@@ -0,0 +1,3 @@
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 24 24" enable-background="new 0 0 24 24" xml:space="preserve">
<path d="M19 7v4H5.83l3.58-3.59L8 6l-6 6 6 6 1.41-1.41L5.83 13H21V7z"/>
</svg>

After

Width:  |  Height:  |  Size: 281 B

+77
View File
@@ -0,0 +1,77 @@
import { unescapeJsonPointerToken } from "../refs-util"
export default function spec() {
return {
statePlugins: {
spec: {
selectors: {
getSpecLineFromPath: (state, path) => ({fn: { AST }, specSelectors: { specStr }}) => {
return AST.getLineNumberForPath(specStr(), path.toJS ? path.toJS() : path)
},
// This will search return `path if it exists, else it'll look for the best $ref jump point
// There is one caveat, it'll not search _down_ for deeply nested $refs. In those cases, it'll bring you to the shallower $ref.
bestJumpPath: (state, {path, specPath}) => (system) => {
const {
specSelectors: { specJson },
fn: { transformPathToArray }
} = system
// We"ve been given an explicit path? Use that...
if(path) {
return typeof path === "string" ? transformPathToArray(path, specJson().toJS()) : path
}
// Try each path in the resolved spec, starting from the deepest
for(let i = specPath.length; i >= 0; i--) {
const tryPath = specPath.slice(0,i)
// A $ref exists in the source? ( ie: pre-resolver)
const $ref = specJson().getIn([...tryPath, "$ref"])
// We have a $ref in the source?
if($ref) {
if(!/^#\//.test($ref)) {
return [...tryPath, "$ref"]
} else { // Is local $ref
// Get rid of the trailing '#'
const pointer = $ref.charAt(0) === "#" ? $ref.substr(1) : $ref
return jsonPointerToArray(pointer)
}
}
// This path exists in the source spec?
if(specJson().hasIn(tryPath)) {
return tryPath
}
}
// ...else just specPath, which is hopefully close enough
return specPath
}
}
}
}
}
}
// Copied out of swagger-client, not sure if it should be exposed as a lib or as part of the public swagger-client api.
/**
* Converts a JSON pointer to array.
* @api public
*/
function jsonPointerToArray(pointer) {
if (typeof pointer !== "string") {
throw new TypeError(`Expected a string, got a ${typeof pointer}`)
}
if (pointer[0] === "/") {
pointer = pointer.substr(1)
}
if (pointer === "") {
return []
}
return pointer.split("/").map(unescapeJsonPointerToken)
}