From 6dec1239bda75698eb7eba01b0cbc195264f355c Mon Sep 17 00:00:00 2001 From: ThibaudAv Date: Tue, 27 Jun 2023 08:58:40 +0200 Subject: [PATCH] feat: use gioConfig.banner.text as description by default So that the plugin's json schema is compatible with the 2 json-schema components. I add some capabilities to this one. --- .../gv-schema-form-control.js | 4 +- .../gv-schema-form-group.stories.js | 5 +++ testing/resources/schemas/policy-cache.json | 45 ++++++++++++++++--- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/organisms/gv-schema-form-control/gv-schema-form-control.js b/src/organisms/gv-schema-form-control/gv-schema-form-control.js index daf45a13..89987780 100644 --- a/src/organisms/gv-schema-form-control/gv-schema-form-control.js +++ b/src/organisms/gv-schema-form-control/gv-schema-form-control.js @@ -213,8 +213,8 @@ export class GvSchemaFormControl extends UpdateAfterBrowser(LitElement) { element.type = 'password'; } - if (this.control.description) { - element.description = this.control.description; + if (this.control.description || this.control.gioConfig?.banner) { + element.description = this.control.gioConfig?.banner?.text ?? this.control.description; } if (placeholder != null) { diff --git a/src/organisms/gv-schema-form-group/gv-schema-form-group.stories.js b/src/organisms/gv-schema-form-group/gv-schema-form-group.stories.js index 74f3b291..42a0e844 100644 --- a/src/organisms/gv-schema-form-group/gv-schema-form-group.stories.js +++ b/src/organisms/gv-schema-form-group/gv-schema-form-group.stories.js @@ -18,6 +18,7 @@ import { makeStory } from '../../../testing/lib/make-story'; import mixed from '../../../testing/resources/schemas/mixed.json'; import htmlToJson from '../../../testing/resources/schemas/html-to-json.json'; import httpConnector from '../../../testing/resources/schemas/http-connector.json'; +import policyCache from '../../../testing/resources/schemas/policy-cache.json'; import { fetch } from 'whatwg-fetch'; import grammar from '../../../testing/resources/el-grammar.json'; import resourceCacheRedis from '../../../testing/resources/schemas/resource-cache-redis.json'; @@ -133,6 +134,10 @@ export const HttpConnector = makeStory(conf, { items: [{ schema: httpConnector }], }); +export const PolicyCache = makeStory(conf, { + items: [{ schema: policyCache }], +}); + export const ResourceCacheRedis = makeStory(conf, { items: [{ schema: resourceCacheRedis, 'has-footer': true }], }); diff --git a/testing/resources/schemas/policy-cache.json b/testing/resources/schemas/policy-cache.json index 68aa261c..3b0b810b 100644 --- a/testing/resources/schemas/policy-cache.json +++ b/testing/resources/schemas/policy-cache.json @@ -1,6 +1,7 @@ { + "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", - "id": "urn:jsonschema:io:gravitee:policy:cache:configuration:CachePolicyConfiguration", + "additionalProperties": false, "properties": { "cacheName": { "title": "Cache name", @@ -9,14 +10,17 @@ "x-schema-form": { "event": { "name": "fetch-resources", - "types": ["cache"] + "regexTypes": "^cache" } } }, "key": { "title": "Key", - "description": "The key used to store the element (support EL).", - "type": "string" + "description": "The key used to store the element (Support EL).", + "type": "string", + "x-schema-form": { + "expression-language": true + } }, "timeToLiveSeconds": { "title": "Time to live (in seconds)", @@ -24,6 +28,30 @@ "description": "Time to live of the element put in cache (Default to 10 minutes).", "type": "integer" }, + "methods": { + "title": "Methods to cache", + "description": "Select which method you want to cache.", + "type": "array", + "default": ["GET", "OPTIONS", "HEAD"], + "items": { + "type": "string", + "enum": ["CONNECT", "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT", "TRACE"] + } + }, + "responseCondition": { + "title": "Response Condition", + "description": "(Support EL)", + "type": "string", + "x-schema-form": { + "expression-language": true + }, + "gioConfig": { + "banner": { + "title": "Response Condition", + "text": "Add an extra condition (with Expression Language) based on the response to activate cache.
For example use {#upstreamResponse.status == 200} to only cache 200 responses status. By default, 2xx only are cached.
\uD83D\uDEA8 upstreamResponse.content is not supported." + } + } + }, "useResponseCacheHeaders": { "title": "Use response headers", "description": "Time to live based on 'Cache-Control' and / or 'Expires' headers from response.", @@ -31,10 +59,15 @@ }, "scope": { "title": "Scope", - "description": "Cached response can be set for a single consumer (application) or for all consumers.
WARNING: Please be aware that by using an \"API\" scope, data will be shared between all consumers!", "type": "string", "default": "APPLICATION", - "enum": ["API", "APPLICATION"] + "enum": ["API", "APPLICATION"], + "gioConfig": { + "banner": { + "title": "Scope", + "text": "Cached response can be set for a single consumer (application) or for all consumers.
WARNING: Please be aware that by using an \"API\" scope, data will be shared between all consumers!" + } + } } }, "required": ["cacheName", "timeToLiveSeconds"]