diff --git a/backend/go-app/codegen.go b/backend/go-app/codegen.go
index aa5200b1..256dd34b 100644
--- a/backend/go-app/codegen.go
+++ b/backend/go-app/codegen.go
@@ -242,6 +242,7 @@ func buildStructure(swagger *openapi3.Swagger, curHash string) (string, error) {
return appPath, nil
}
+// This function generates the python code that's being used.
func makePythoncode(swagger *openapi3.Swagger, name, url, method string, parameters, optionalQueries []string) (string, string) {
method = strings.ToLower(method)
queryString := ""
@@ -259,9 +260,6 @@ func makePythoncode(swagger *openapi3.Swagger, name, url, method string, paramet
}
}
- // How to add authentication?
- // I think it should be like:
- // async def(self, auth, baseurl, data):
// api.Authentication.Parameters[0].Value = "BearerAuth"
authenticationParameter := ""
authenticationSetup := ""
@@ -270,14 +268,15 @@ func makePythoncode(swagger *openapi3.Swagger, name, url, method string, paramet
if swagger.Components.SecuritySchemes != nil {
if swagger.Components.SecuritySchemes["BearerAuth"] != nil {
authenticationParameter = ", apikey"
- authenticationSetup = "headers[\"Authorization\"] = f\"Bearer {apikey}\""
+ authenticationSetup = "if apikey != \" \": headers[\"Authorization\"] = f\"Bearer {apikey}\""
} else if swagger.Components.SecuritySchemes["BasicAuth"] != nil {
authenticationParameter = ", username, password"
authenticationAddin = ", auth=(username, password)"
} else if swagger.Components.SecuritySchemes["ApiKeyAuth"] != nil {
authenticationParameter = ", apikey"
if swagger.Components.SecuritySchemes["ApiKeyAuth"].Value.In == "header" {
- authenticationSetup = fmt.Sprintf("headers[\"%s\"] = apikey", swagger.Components.SecuritySchemes["ApiKeyAuth"].Value.Name)
+ // This is a way to bypass apikeys by passing " "
+ authenticationSetup = fmt.Sprintf(`if apikey != " ": headers["%s"] = apikey`, swagger.Components.SecuritySchemes["ApiKeyAuth"].Value.Name)
} else if swagger.Components.SecuritySchemes["ApiKeyAuth"].Value.In == "query" {
// This might suck lol
key := "?"
@@ -285,7 +284,7 @@ func makePythoncode(swagger *openapi3.Swagger, name, url, method string, paramet
key = "&"
}
- authenticationSetup = fmt.Sprintf("url+=f\"%s%s={apikey}\"", key, swagger.Components.SecuritySchemes["ApiKeyAuth"].Value.Name)
+ authenticationSetup = fmt.Sprintf("if apikey != \" \": url+=f\"%s%s={apikey}\"", key, swagger.Components.SecuritySchemes["ApiKeyAuth"].Value.Name)
}
}
}
@@ -444,6 +443,7 @@ func generateYaml(swagger *openapi3.Swagger, newmd5 string) (*openapi3.Swagger,
Description: "The apikey to use",
Multiline: false,
Required: true,
+ Example: "The API key to use. Space = skip",
Schema: SchemaDefinition{
Type: "string",
},
@@ -460,6 +460,7 @@ func generateYaml(swagger *openapi3.Swagger, newmd5 string) (*openapi3.Swagger,
Description: "The apikey to use",
Multiline: false,
Required: true,
+ Example: "The API key to use. Space = skip",
Schema: SchemaDefinition{
Type: "string",
},
@@ -475,6 +476,7 @@ func generateYaml(swagger *openapi3.Swagger, newmd5 string) (*openapi3.Swagger,
Description: "The username to use",
Multiline: false,
Required: true,
+ Example: "The username to use",
Schema: SchemaDefinition{
Type: "string",
},
@@ -484,6 +486,7 @@ func generateYaml(swagger *openapi3.Swagger, newmd5 string) (*openapi3.Swagger,
Description: "The password to use",
Multiline: false,
Required: true,
+ Example: "The password to use",
Schema: SchemaDefinition{
Type: "string",
},
diff --git a/frontend/src/AppCreator.js b/frontend/src/AppCreator.js
index 98aa7146..697b585e 100644
--- a/frontend/src/AppCreator.js
+++ b/frontend/src/AppCreator.js
@@ -4,11 +4,13 @@ import {BrowserView, MobileView} from "react-device-detect";
import {Link} from 'react-router-dom';
import Paper from '@material-ui/core/Paper';
+import FormControlLabel from '@material-ui/core/FormControlLabel';
import Button from '@material-ui/core/Button';
import Divider from '@material-ui/core/Divider';
import Select from '@material-ui/core/Select';
import MenuItem from '@material-ui/core/MenuItem';
import FormControl from '@material-ui/core/FormControl';
+import Switch from '@material-ui/core/Switch';
import Dialog from '@material-ui/core/Dialog';
import DialogTitle from '@material-ui/core/DialogTitle';
import DialogContent from '@material-ui/core/DialogContent';
@@ -196,6 +198,7 @@ const AppCreator = (props) => {
const [updater, setUpdater] = useState("tmp")
const [baseUrl, setBaseUrl] = useState("");
const [actionsModalOpen, setActionsModalOpen] = useState(false);
+ const [authenticationRequired, setAuthenticationRequired] = useState(false);
const [authenticationOption, setAuthenticationOption] = useState(authenticationOptions[0]);
const [parameterName, setParameterName] = useState("");
const [parameterLocation, setParameterLocation] = useState(apikeySelection.length > 0 ? apikeySelection[0] : "");
@@ -433,6 +436,7 @@ const AppCreator = (props) => {
for (const [key, value] of Object.entries(securitySchemes)) {
if (value.scheme === "bearer") {
setAuthenticationOption("Bearer auth")
+ setAuthenticationRequired(true)
break
} else if (value.type === "apiKey") {
setAuthenticationOption("API key")
@@ -446,9 +450,11 @@ const AppCreator = (props) => {
console.log("PARAM NAME: ", value.name)
setParameterName(value.name)
+ setAuthenticationRequired(true)
break
} else if (value.scheme === "basic") {
setAuthenticationOption("Basic auth")
+ setAuthenticationRequired(true)
break
}
}
@@ -704,7 +710,6 @@ const AppCreator = (props) => {
Users will be required to submit their API as the header "Authorization: Bearer APIKEY"
-
: null
@@ -717,7 +722,6 @@ const AppCreator = (props) => {
Users will be required to submit a valid username and password before using the API
-
: null
@@ -850,7 +854,6 @@ const AppCreator = (props) => {
)}
)}
-
: null
@@ -1559,11 +1562,17 @@ const AppCreator = (props) => {
}}
/>
- Authentication
+ Authentication
+