Fix for #4440, fixing validation of API endpoints.

This commit is contained in:
mike12345567 2022-02-12 10:35:10 +00:00
parent 8ca38cf135
commit 126499f383
3 changed files with 22 additions and 9 deletions

View File

@ -1,6 +1,16 @@
<script>
import "@spectrum-css/buttongroup/dist/index-vars.css"
export let vertical = false
export let gap = ""
$: gapStyle =
gap === "L"
? "var(--spacing-l)"
: gap === "M"
? "var(--spacing-m)"
: gap === "S"
? "var(--spacing-s)"
: null
function group(element) {
const buttons = Array.from(element.getElementsByTagName("button"))
@ -14,6 +24,7 @@
use:group
class="spectrum-ButtonGroup"
class:spectrum-ButtonGroup--vertical={vertical}
style={gapStyle ? `gap: ${gapStyle};` : null}
>
<slot />
</div>

View File

@ -39,7 +39,7 @@
$: datasource = $datasources.list.find(ds => ds._id === query.datasourceId)
$: query.schema = fieldsToSchema(fields)
$: datasourceType = datasource?.source
$: integrationInfo = $integrations[datasourceType]
$: integrationInfo = datasourceType ? $integrations[datasourceType] : null
$: queryConfig = integrationInfo?.query
$: shouldShowQueryConfig = queryConfig && query.queryVerb
$: readQuery = query.queryVerb === "read" || query.readable
@ -160,7 +160,7 @@
</div>
<div class="viewer-controls">
<Heading size="S">Results</Heading>
<ButtonGroup>
<ButtonGroup gap="M">
<Button cta disabled={queryInvalid} on:click={saveQuery}>
Save Query
</Button>

View File

@ -1,6 +1,8 @@
const joiValidator = require("../../../middleware/joi-validator")
const Joi = require("joi")
const OPTIONAL_STRING = Joi.string().optional().allow(null).allow("")
exports.queryValidation = () => {
return Joi.object({
_id: Joi.string(),
@ -18,7 +20,7 @@ exports.queryValidation = () => {
queryVerb: Joi.string().allow().required(),
extra: Joi.object().optional(),
schema: Joi.object({}).required().unknown(true),
transformer: Joi.string().optional(),
transformer: OPTIONAL_STRING,
flags: Joi.object().optional(),
})
}
@ -31,18 +33,18 @@ exports.generateQueryValidation = () => {
exports.generateQueryPreviewValidation = () => {
// prettier-ignore
return joiValidator.body(Joi.object({
_id: Joi.string().optional(),
_rev: Joi.string().optional(),
_id: OPTIONAL_STRING,
_rev: OPTIONAL_STRING,
readable: Joi.boolean().optional(),
fields: Joi.object().required(),
queryVerb: Joi.string().allow().required(),
name: Joi.string().required(),
queryVerb: Joi.string().required(),
name: OPTIONAL_STRING,
flags: Joi.object().optional(),
schema: Joi.object().optional(),
extra: Joi.object().optional(),
datasourceId: Joi.string().required(),
transformer: Joi.string().optional(),
transformer: OPTIONAL_STRING,
parameters: Joi.object({}).required().unknown(true),
queryId: Joi.string().optional(),
queryId: OPTIONAL_STRING,
}))
}