autocomplete-openapi
Advanced tools
Comparing version
{ | ||
"name": "autocomplete-openapi", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "Autocompletes different parts of an OpenAPI spec", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -7,2 +7,3 @@ "use strict"; | ||
import { tokenizeHeader } from "./parse-request-header.js"; | ||
import { generateRequestHeader, generateResponseBody } from './snippets.js'; | ||
@@ -81,20 +82,44 @@ export class OpenapiAutocomplete { | ||
let result = this.extractor.allProperties( | ||
dataRef, | ||
jsonParsedResult.path, | ||
editingChunk.key || "" | ||
); | ||
if (editingChunk.editing === "key") { | ||
let result = this.extractor.allProperties( | ||
dataRef, | ||
jsonParsedResult.path, | ||
editingChunk.key || "" | ||
); | ||
if (editingChunk.key === null) { | ||
// If there is no key, then we should autocomplete with open quote | ||
if (editingChunk.key === null) { | ||
// If there is no key, then we should autocomplete with open quote | ||
result = result.map((s) => '"' + s + '": '); | ||
} else { | ||
// If there is a key, then we should autocomplete with closing quote only | ||
result = result.map((s) => '"' + s + '": '); | ||
} else { | ||
// If there is a key, then we should autocomplete with closing quote only | ||
result = result.map((s) => s + '": '); | ||
result = result.map((s) => s + '": '); | ||
} | ||
return result; | ||
} | ||
return []; | ||
} | ||
return result; | ||
getSnippets() { | ||
let completions = []; | ||
for (let method of this.methods) { | ||
let [insertText, completionCount] = generateRequestHeader(method); | ||
const dataRef = method.body; | ||
if (dataRef) { | ||
let current = this.extractor.objectByRef(dataRef); | ||
const generatedBody = generateResponseBody(current, completionCount); | ||
insertText += "\n" + generatedBody; | ||
} | ||
completions.push({ | ||
label: method.operationId, | ||
documentation: method.summary, | ||
insertText: insertText, | ||
}); | ||
} | ||
return completions; | ||
} | ||
} |
export class OpenAPIMethod { | ||
constructor(method, path, body, operationId, tags) { | ||
constructor(method, path, body, operationId, tags, parameters,summary) { | ||
this.method = method; | ||
@@ -8,2 +8,4 @@ this.path = path; | ||
this.tags = tags; | ||
this.parameters = parameters; | ||
this.summary = summary; | ||
} | ||
@@ -30,3 +32,5 @@ } | ||
this.openapi.paths[path][method].operationId, | ||
this.openapi.paths[path][method].tags | ||
this.openapi.paths[path][method].tags, | ||
this.openapi.paths[path][method]?.parameters, | ||
this.openapi.paths[path][method].summary | ||
) | ||
@@ -33,0 +37,0 @@ ); |
@@ -24,3 +24,3 @@ "use strict"; | ||
if (method.path == '/telemetry'){ | ||
assert.equal(method.tags[0], 'service') | ||
assert.equal(method.tags[0], "Service"); | ||
} | ||
@@ -27,0 +27,0 @@ } |
Sorry, the diff of this file is too big to display
476229
19.6%21
10.53%15136
15.37%