Fix for #4440, fixing validation of API endpoints.

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

View File

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

View File

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

View File

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