#133: Fixed YAML parsing bug in OpenAPI parser
This commit is contained in:
@@ -972,6 +972,7 @@ const AngularWorkflow = (props) => {
|
||||
setLastSaved(false)
|
||||
|
||||
/*
|
||||
// Used to not be able to edit trigger-based branches.
|
||||
const triggercheck = workflow.triggers.find(trigger => trigger.id === event.target.data()["source"])
|
||||
if (triggercheck === undefined) {
|
||||
*/
|
||||
|
||||
@@ -26,6 +26,7 @@ import CircularProgress from '@material-ui/core/CircularProgress';
|
||||
import Chip from '@material-ui/core/Chip';
|
||||
import ChipInput from 'material-ui-chip-input'
|
||||
|
||||
import YAML from 'yaml'
|
||||
import ErrorOutline from '@material-ui/icons/ErrorOutline';
|
||||
import { useAlert } from "react-alert";
|
||||
import words from "shellwords"
|
||||
@@ -325,15 +326,37 @@ const AppCreator = (props) => {
|
||||
throw new Error("NOT 200 :O")
|
||||
}
|
||||
|
||||
//console.log("DATA: ", response.text())
|
||||
return response.json()
|
||||
})
|
||||
.then((responseJson) => {
|
||||
console.log("THE BODY IS HERE")
|
||||
setIsAppLoaded(true)
|
||||
if (!responseJson.success) {
|
||||
alert.error("Failed to verify")
|
||||
} else {
|
||||
const data = JSON.parse(responseJson.body)
|
||||
parseIncomingOpenapiData(data)
|
||||
} else{
|
||||
console.log("HMM 2")
|
||||
var jsonvalid = false
|
||||
var tmpvalue = ""
|
||||
try {
|
||||
tmpvalue = JSON.parse(responseJson.body)
|
||||
jsonvalid = true
|
||||
} catch (e) {
|
||||
console.log("Error JSON: ", e)
|
||||
}
|
||||
|
||||
if (!jsonvalid) {
|
||||
try {
|
||||
tmpvalue = YAML.parse(responseJson.body, )
|
||||
jsonvalid = true
|
||||
} catch(e) {
|
||||
console.log("Error YAML: ", e)
|
||||
}
|
||||
}
|
||||
|
||||
if (jsonvalid) {
|
||||
parseIncomingOpenapiData(tmpvalue)
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
@@ -359,13 +382,15 @@ const AppCreator = (props) => {
|
||||
// Sets the data up as it should be at later points
|
||||
// This is the data FROM the database, not what's being saved
|
||||
const parseIncomingOpenapiData = (data) => {
|
||||
//console.log("DATA: ", data.info)
|
||||
setBasedata(data)
|
||||
|
||||
setName(data.info.title)
|
||||
setDescription(data.info.description)
|
||||
document.title = "Apps - "+data.info.title
|
||||
|
||||
if (data.info !== null && data.info !== undefined) {
|
||||
console.log("DATA: ", data)
|
||||
setName(data.info.title)
|
||||
setDescription(data.info.description)
|
||||
document.title = "Apps - "+data.info.title
|
||||
|
||||
if (data.info["x-logo"] !== undefined) {
|
||||
setFileBase64(data.info["x-logo"])
|
||||
}
|
||||
|
||||
@@ -1167,6 +1167,7 @@ const Apps = (props) => {
|
||||
return
|
||||
}
|
||||
|
||||
console.log("Validating response!")
|
||||
validateOpenApi(responseJson)
|
||||
})
|
||||
.catch(error => {
|
||||
@@ -1185,10 +1186,12 @@ const Apps = (props) => {
|
||||
|
||||
|
||||
try {
|
||||
return JSON.stringify(YAML.parse(apidata))
|
||||
const parsed = YAML.parse(YAML.stringify(apidata))
|
||||
//const parsed = YAML.parse(apidata))
|
||||
return YAML.stringify(parsed)
|
||||
} catch(error) {
|
||||
console.log("YAML DECODE ERROR - TRY SOMETHING ELSE?: "+error)
|
||||
setOpenApiError(error.toString())
|
||||
setOpenApiError("Local error: "+ error.toString())
|
||||
}
|
||||
|
||||
return ""
|
||||
@@ -1197,19 +1200,23 @@ const Apps = (props) => {
|
||||
// Sends the data to backend, which should return a version 3 of the same API
|
||||
// If 200 - continue, otherwise, there's some issue somewhere
|
||||
const validateOpenApi = (openApidata) => {
|
||||
const newApidata = escapeApiData(openApidata)
|
||||
var newApidata = escapeApiData(openApidata)
|
||||
if (newApidata === "") {
|
||||
// Used to return here
|
||||
newApidata = openApidata
|
||||
return
|
||||
}
|
||||
|
||||
//console.log(newApidata)
|
||||
|
||||
setValidation(true)
|
||||
fetch(globalUrl+"/api/v1/validate_openapi", {
|
||||
method: 'POST',
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
},
|
||||
body: newApidata,
|
||||
credentials: "include",
|
||||
body: openApidata,
|
||||
credentials: "include",
|
||||
})
|
||||
.then((response) => {
|
||||
setValidation(false)
|
||||
|
||||
Reference in New Issue
Block a user