-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added support for OpenAPI's components. - Refactored some variable names. - Updated `README.md` file.
- Loading branch information
Showing
10 changed files
with
146 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
local utils = require("outln.utils") | ||
|
||
local M = {} | ||
|
||
-- Cleans OpenAPI query captures of endpoints. | ||
local function clean_endpoints(qc) | ||
local qc_clean = {} | ||
|
||
for _, capture in pairs(qc) do | ||
local name = capture[1] | ||
local line = capture[2] | ||
|
||
if name:sub(1, 1) == "/" then | ||
qc_clean[line] = {} | ||
|
||
table.insert( | ||
qc_clean[line], | ||
name | ||
) | ||
end | ||
end | ||
|
||
return qc_clean | ||
end | ||
|
||
-- Cleans OpenAPI's query captures of components. | ||
local function clean_components(qc) | ||
local qc_clean = {} | ||
|
||
for _, capture in pairs(qc) do | ||
local name = capture[1] | ||
local line = capture[2] | ||
|
||
local char = name:sub(1, 1) | ||
|
||
if utils.is_alphabetical(char) and utils.is_uppercase(char) then | ||
qc_clean[line] = {} | ||
|
||
table.insert( | ||
qc_clean[line], | ||
name | ||
) | ||
end | ||
end | ||
|
||
return qc_clean | ||
end | ||
|
||
-- Cleans query captures based on provided language type and option. | ||
function M.clean_query_captures(qc, lang_type, option) | ||
if lang_type == "openapi" then | ||
if option == "endpoints" then | ||
return clean_endpoints(qc) | ||
end | ||
|
||
if option == "components" then | ||
return clean_components(qc) | ||
end | ||
end | ||
|
||
return qc | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,36 @@ | ||
local querier = require("outln.querier") | ||
local queries = require("outln.queries") | ||
local utils = require("outln.utils") | ||
local querier = require("outln.querier") | ||
local cleaner = require("outln.cleaner") | ||
local sorter = require("outln.sorter") | ||
|
||
local M = {} | ||
|
||
-- Handles getting language-specific query captures. | ||
function M.handle(lang, lang_type, options) | ||
local qc = {} | ||
local t = {} | ||
|
||
for k, v in pairs(options) do | ||
if v == true then | ||
local query = queries[lang_type][k] | ||
for definition, enabled in pairs(options) do | ||
if enabled then | ||
local query = queries[lang_type][definition] | ||
|
||
if query ~= nil then | ||
qc[k] = querier.get_query_captures( | ||
local qc = querier.get_query_captures( | ||
lang, | ||
query | ||
) | ||
|
||
qc[k] = utils.sort_query_captures(qc[k]) | ||
qc = cleaner.clean_query_captures( | ||
qc, | ||
lang_type, | ||
definition | ||
) | ||
|
||
t[definition] = sorter.sort_query_captures(qc) | ||
end | ||
end | ||
end | ||
|
||
if lang_type == "openapi" then | ||
qc = utils.clean_openapi_query_captures(qc) | ||
end | ||
|
||
return qc | ||
return t | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
local M = {} | ||
|
||
-- Sorts query captures based on line numbers. | ||
function M.sort_query_captures(qc) | ||
table.sort(qc, function(x, y) | ||
return x[2] < y[2] | ||
end) | ||
|
||
return qc | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,21 @@ | ||
local M = {} | ||
|
||
-- Cleans OpenAPI query captures. | ||
function M.clean_openapi_query_captures(qc) | ||
local qc_clean = {} | ||
|
||
for k, v in pairs(qc) do | ||
qc_clean[k] = {} | ||
|
||
for _, j in pairs(v) do | ||
if j[1]:sub(1, 1) == "/" then | ||
table.insert(qc_clean[k], j) | ||
end | ||
end | ||
-- Checks if the character is alphabetical. | ||
function M.is_alphabetical(c) | ||
if string.match(c, "%a") then | ||
return true | ||
end | ||
|
||
return qc_clean | ||
return false | ||
end | ||
|
||
-- Sorts query captures based on line numbers. | ||
function M.sort_query_captures(qc) | ||
table.sort(qc, function(a, b) | ||
return a[2] < b[2] | ||
end) | ||
-- Checks if the character is uppercase. | ||
function M.is_uppercase(c) | ||
if c == string.upper(c) then | ||
return true | ||
end | ||
|
||
return qc | ||
return false | ||
end | ||
|
||
return M |