Started automated OpenAPI naming
This commit is contained in:
@@ -297,7 +297,7 @@ const AppCreator = (props) => {
|
|||||||
const checkQuery = () => {
|
const checkQuery = () => {
|
||||||
var urlParams = new URLSearchParams(window.location.search)
|
var urlParams = new URLSearchParams(window.location.search)
|
||||||
if (!urlParams.has("id")) {
|
if (!urlParams.has("id")) {
|
||||||
setIsAppLoaded(true)
|
setIsAppLoaded(true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -362,7 +362,10 @@ const AppCreator = (props) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data.servers !== undefined && data.servers.length > 0) {
|
if (data.servers !== undefined && data.servers.length > 0) {
|
||||||
setBaseUrl(data.servers[0].url)
|
var firstUrl = data.servers[0].url
|
||||||
|
if (firstUrl.endsWith("/")) {
|
||||||
|
setBaseUrl(firstUrl.slice(0, firstUrl.length-1))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is annoying (:
|
// This is annoying (:
|
||||||
@@ -380,6 +383,7 @@ const AppCreator = (props) => {
|
|||||||
|
|
||||||
// FIXME - headers?
|
// FIXME - headers?
|
||||||
var newActions = []
|
var newActions = []
|
||||||
|
var wordlist = {}
|
||||||
for (let [path, pathvalue] of Object.entries(data.paths)) {
|
for (let [path, pathvalue] of Object.entries(data.paths)) {
|
||||||
for (let [method, methodvalue] of Object.entries(pathvalue)) {
|
for (let [method, methodvalue] of Object.entries(pathvalue)) {
|
||||||
var newaction = {
|
var newaction = {
|
||||||
@@ -426,6 +430,61 @@ const AppCreator = (props) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (newaction.name === "" || newaction.name === undefined) {
|
||||||
|
// Find a unique part of the string
|
||||||
|
// FIXME: Looks for length between /, find the one where they differ
|
||||||
|
// Should find others with the same START to their path
|
||||||
|
// Make a list of reserved names? Aka things that show up only once
|
||||||
|
if (Object.getOwnPropertyNames(wordlist).length === 0) {
|
||||||
|
for (let [newpath, pathvalue] of Object.entries(data.paths)) {
|
||||||
|
const newpathsplit = newpath.split("/")
|
||||||
|
for(var key in newpathsplit) {
|
||||||
|
const pathitem = newpathsplit[key].toLowerCase()
|
||||||
|
if (wordlist[pathitem] === undefined) {
|
||||||
|
wordlist[pathitem] = 1
|
||||||
|
} else {
|
||||||
|
wordlist[pathitem] += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//console.log("WORDLIST: ", wordlist)
|
||||||
|
|
||||||
|
// Remove underscores and make it normal with upper case etc
|
||||||
|
const urlsplit = path.split("/")
|
||||||
|
if (urlsplit.length > 0) {
|
||||||
|
var curname = ""
|
||||||
|
for(var key in urlsplit) {
|
||||||
|
var subpath = urlsplit[key]
|
||||||
|
if (wordlist[subpath] > 2 || subpath.length < 1) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
curname = subpath
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Check if the name already exists
|
||||||
|
// FIXME: Check if first part of parsedname is verb, otherwise use method
|
||||||
|
const parsedname = curname.split("_").join(" ").split("-").join(" ").split("{").join(" ").split("}").join(" ").trim()
|
||||||
|
if (parsedname.length === 0) {
|
||||||
|
newaction.errors.push("Missing name")
|
||||||
|
} else {
|
||||||
|
const newname = method.charAt(0).toUpperCase() + method.slice(1) + " " + parsedname
|
||||||
|
const searchactions = newActions.find(data => data.name === newname)
|
||||||
|
console.log("SEARCH: ", searchactions)
|
||||||
|
if (searchactions !== undefined) {
|
||||||
|
newaction.errors.push("Missing name")
|
||||||
|
} else {
|
||||||
|
newaction.name = newname
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
newaction.errors.push("Missing name")
|
||||||
|
}
|
||||||
|
}
|
||||||
newActions.push(newaction)
|
newActions.push(newaction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1013,7 +1072,7 @@ const AppCreator = (props) => {
|
|||||||
|
|
||||||
const getActionErrors = () => {
|
const getActionErrors = () => {
|
||||||
var errormessage = []
|
var errormessage = []
|
||||||
if (currentAction.name.length === 0) {
|
if (currentAction.name === undefined || currentAction.name.length === 0) {
|
||||||
errormessage.push("Name can't be empty")
|
errormessage.push("Name can't be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -500,6 +500,10 @@ const Apps = (props) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleSearchChange = (search) => {
|
const handleSearchChange = (search) => {
|
||||||
|
if (apps === undefined || apps === null || apps.length === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const searchfield = search.toLowerCase()
|
const searchfield = search.toLowerCase()
|
||||||
const newapps = apps.filter(data => data.name.toLowerCase().includes(searchfield) || data.description.toLowerCase().includes(searchfield))
|
const newapps = apps.filter(data => data.name.toLowerCase().includes(searchfield) || data.description.toLowerCase().includes(searchfield))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user