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,12 @@
import getRefsForPath from "./get-refs-for-path"
export default function getCompletions(editor, session, pos, prefix, cb, ctx, system) {
const { fn: { getPathForPosition } } = system
const { AST } = ctx
var editorValue = editor.getValue()
const path = getPathForPosition({ pos, prefix, editorValue, AST})
const suggestions = getRefsForPath({ system, path})
cb(null, suggestions)
}
@@ -0,0 +1,24 @@
import isArray from "lodash/isArray"
import last from "lodash/last"
export default function getRefsForPath({ system, path }) {
// Note fellow ace hackers:
// we have to be weary of _what_ ace will filter on, see the order ( probably should be fixed, but... ): https://github.com/ajaxorg/ace/blob/b219b5584456534fbccb5fb20470c61011fa0b0a/lib/ace/autocomplete.js#L469
// Because of that, I'm matching on `caption` and using `snippet` instead of `value` for injecting
if(isArray(path) && last(path) === "$ref") {
const localRefs = system.specSelectors.localRefs()
const refType = system.specSelectors.getRefType(path)
return localRefs
.filter(r => r.get("type") == refType)
.toJS()
.map(r => ({
score: 100,
meta: "local",
snippet: `'${r.$ref}'`, // wrap in quotes
caption: r.name,
}))
}
return []
}
@@ -0,0 +1,11 @@
import * as wrapActions from "./wrap-actions"
export default function EditorAutosuggestRefsPlugin() {
return {
statePlugins: {
editor: {
wrapActions,
}
}
}
}
@@ -0,0 +1,11 @@
import getCompletions from "./get-completions"
// Add an autosuggest completer
export const addAutosuggestionCompleters = (ori, system) => (context) => {
return ori(context).concat([{
getCompletions(...args) {
// Add `context`, then `system` as the last args
return getCompletions(...args, context, system)
}
}])
}