The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Type every :any and [:map-of :keyword ...] property in the API (#82196)
Alexander Polyankin38cda45f69fb
diff --git a/.claude/skills/add-malli-schemas/SKILL.md b/.claude/skills/add-malli-schemas/SKILL.mdindex 7fcb638f820..9709a0e93e4 100644--- a/.claude/skills/add-malli-schemas/SKILL.md+++ b/.claude/skills/add-malli-schemas/SKILL.md@@ -149,8 +149,7 @@ ms/NonBlankString ;; Non-empty stringms/BooleanValue ;; String "true"/"false" or booleanms/MaybeBooleanValue ;; BooleanValue or nilms/TemporalString ;; ISO-8601 date/time string (for REQUEST params only!)-ms/Map ;; Any map-ms/JSONString ;; JSON-encoded string+ms/OpaqueJSONObject ;; JSON object whose keys are not ours to declare; string-keyedms/PositiveNum ;; Positive numberms/IntGreaterThanOrEqualToZero ;; 0 or positive```diff --git a/.clj-kondo/config/modules/config.edn b/.clj-kondo/config/modules/config.ednindex 3767259b7dd..25ad333e89b 100644--- a/.clj-kondo/config/modules/config.edn+++ b/.clj-kondo/config/modules/config.edn@@ -109,6 +109,7 @@query-processorsearchsettings+ usersutilwarehouses}:model-exports #{:model/Action}@@ -1446,6 +1447,7 @@transformstransforms-baseutil+ warehouse-schemawarehouses}:model-exports #{:model/AiUsageLog:model/Metabot@@ -1596,6 +1598,7 @@parameterspermissionspremium-features+ queriesquery-processorrequestsession@@ -1887,6 +1890,7 @@graphliblib-be+ lib-metricmetricsmodelsparameters@@ -2709,6 +2713,7 @@drivereventslib+ lib-bemodel-persistencemodelspermissionsdiff --git a/dev/src/dev/api/preview.clj b/dev/src/dev/api/preview.cljindex a926b3c0c6d..d30449bbd77 100644--- a/dev/src/dev/api/preview.clj+++ b/dev/src/dev/api/preview.clj@@ -33,7 +33,7 @@(api.macros/defendpoint :get "/preview-card/:id""Get HTML rendering of a Card with `id`."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](let [card (api/read-check :model/Card id)result (pulse-card-query-results card)]@@ -51,7 +51,7 @@This endpoint relies on a custom middleware defined in `metabase.channel.render.core/style-tag-nonce-middleware` toallow the style tag to render properly, given our Content Security Policy setup."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](api/read-check :model/Dashboard id){:status 200@@ -68,7 +68,7 @@(api.macros/defendpoint :get "/preview-card-info/:id""Get JSON object containing HTML rendering of a Card with `id` and other information."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](let [card (api/read-check :model/Card id)result (pulse-card-query-results card)@@ -90,9 +90,9 @@(api.macros/defendpoint :get "/preview-card-png/:id""Get PNG rendering of a Card with `id`. Optionally specify `width` as a query parameter."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]- {:keys [width]} :- [:map+ {:keys [width]} :- [:map {:closed true}[:width {:optional true} [:maybe ms/PositiveInt]]]](let [card (api/read-check :model/Card id)result (pulse-card-query-results card)diff --git a/dev/src/dev/api/prototype.clj b/dev/src/dev/api/prototype.cljindex 1e39348035e..32a30d284a0 100644--- a/dev/src/dev/api/prototype.clj+++ b/dev/src/dev/api/prototype.clj@@ -40,7 +40,7 @@(api.macros/defendpoint :get "/:type/""Gets all records of the given type.Any parameters passed will be used for equals filters"- [{:keys [type]} :- [:map [:type ms/NonBlankString]]+ [{:keys [type]} :- [:map {:closed true} [:type ms/NonBlankString]]query-args](filter (fn [obj](every? (fn [[query-k query-v]]@@ -54,7 +54,7 @@(api.macros/defendpoint :get "/:type/:id""Returns an existing record"- [{:keys [type id]} :- [:map+ [{:keys [type id]} :- [:map {:closed true}[:type ms/NonBlankString][:id ms/PositiveInt]]](-> (api/check-404 (t2/query-one {:select [:id :content]@@ -65,7 +65,7 @@(api.macros/defendpoint :post "/:type/""Create a new record."- [{:keys [type]} :- [:map+ [{:keys [type]} :- [:map {:closed true}[:type ms/NonBlankString]]_query-paramsbody]@@ -76,7 +76,7 @@(api.macros/defendpoint :put "/:type/:id""Updates an existing record."- [{:keys [type id]} :- [:map+ [{:keys [type id]} :- [:map {:closed true}[:type ms/NonBlankString][:id ms/PositiveInt]]_query-params@@ -88,21 +88,19 @@(api.macros/defendpoint :delete "/:type/:id""Deletes an existing record."- [{:keys [type id]} :- [:map+ [{:keys [type id]} :- [:map {:closed true}[:type ms/NonBlankString][:id ms/PositiveInt]]_query-paramsbody](api/check-404 (t2/delete! (prototype-table) id))-{:id id})(api.macros/defendpoint :delete "/:type/all""Deletes all records of this type. Helpful for resetting to a clean state."- [{:keys [type]} :- [:map+ [{:keys [type]} :- [:map {:closed true}[:type ms/NonBlankString]]_query-paramsbody](t2/delete! (prototype-table) :type type)-{:message "All records deleted" :type type})diff --git a/enterprise/backend/src/metabase_enterprise/action_v2/api.clj b/enterprise/backend/src/metabase_enterprise/action_v2/api.cljindex cc413c85d5e..25a5978beb0 100644--- a/enterprise/backend/src/metabase_enterprise/action_v2/api.clj+++ b/enterprise/backend/src/metabase_enterprise/action_v2/api.clj@@ -9,6 +9,7 @@[metabase.api.routes.common :refer [+auth]][metabase.events.core :as events][metabase.lib.schema.parameter :as lib.schema.parameter]+ [metabase.util :as u][metabase.util.malli :as mu][metabase.util.malli.registry :as mr][metabase.util.malli.schema :as ms]))@@ -29,9 +30,10 @@(mr/def ::api-action-expression"A more relaxed version of ::action-expression that can still have opaque identifiers inside inside.- Open ([[ms/Map]]) rather than a bare `:map`: the shape is deliberately unspecified here, and a closed map with no- declared entries would have every key stripped during request decoding, so the handler would only ever see `{}`."- ms/Map)+ Opaque ([[ms/OpaqueJSONObject]]) rather than a bare `:map`: the shape is deliberately unspecified here, and a closed+ map with no declared entries would have every key stripped during request decoding, so the handler would only ever+ see `{}`."+ ms/OpaqueJSONObject)(mr/def ::api-action-id-or-expression"All the various ways of referring to an action with the v2 APIs."@@ -44,17 +46,16 @@[:ref ::lib.schema.parameter/parameter.value])(def ^:private strict-action-value-map- [:map-of :keyword [:ref ::action-value]])+ [:map-of :string [:ref ::action-value]])(mr/def ::action-value-map- "A map from parameter name / column name to a value. Keys are keywords: the request decoder keywordizes map keys and- the handler reads them via `(keyword ...)`, so the FE never sends anything else.+ "A map from parameter name / column name to a value. The names are the action's and the table's, so the map is+ string-keyed, here and all the way down to the action that runs it.- Same shape as [[metabase.actions.schema/execute-parameter-values]]. Decoding sees a permissive- `[:map-of :keyword :any]` and the values are validated against, rather than decoded through,- [[strict-action-value-map]]."+ Same shape as [[metabase.actions.schema/execute-parameter-values]]. Decoding sees a permissive string-keyed map and the+ values are validated against, rather than decoded through, [[strict-action-value-map]]."[:and- [:map-of :keyword :any]+ ms/OpaqueJSONObject[:fn {:error/message "value must be a scalar, or a sequence of scalars"}#(mr/validate strict-action-value-map %)]])@@ -100,7 +101,8 @@(merge input params)(reduce-kv(fn [acc k v]- (let [override (when-not (:visible v) (get params k))]+ (let [k (u/qualified-name k)+ override (when-not (:visible v) (get params k))](case (:sourceType v);; It seems like misconfiguration to configure a default :value for "ask-user", but some tests do it."ask-user" (assoc acc k (if (contains? params k) override (:value v)))@@ -127,8 +129,8 @@(= ::input x) input(= ::params x) params;; specific key- (tag? ::key x) (get root (keyword (second x)))- (tag? ::param x) (get params (keyword (second x)))+ (tag? ::key x) (get root (second x))+ (tag? ::param x) (get params (second x)):elsex))mapping)))))@@ -172,9 +174,7 @@[{}{}{:keys [action scope params input]}- ;; `params` and `input` are open ([[ms/Map]]): their keys are the action's parameter names and the table's column- ;; names, so nothing here can be declared, and a bare `:map` would be stripped down to `{}` before the handler ran.- :- [:map+ :- [:map {:closed true}[:action ::api-action-id-or-expression][:scope ::types/scope.raw][:params {:optional true} ::action-value-map]@@ -213,7 +213,7 @@{}{:keys [action scope inputs params]};; see the note on `POST /execute` for why `inputs` and `params` are open- :- [:map+ :- [:map {:closed true}[:action ::api-action-id-or-expression][:scope ::types/scope.raw][:inputs [:sequential {:min 1} ::action-value-map]]@@ -239,7 +239,7 @@{};; TODO support for bulk actions{:keys [action scope input]}- :- [:map+ :- [:map {:closed true}[:action ::api-action-id-or-expression][:scope ::types/scope.raw][:input {:optional true} ::action-value-map]]]diff --git a/enterprise/backend/src/metabase_enterprise/action_v2/data_editing.clj b/enterprise/backend/src/metabase_enterprise/action_v2/data_editing.cljindex eed28f57f20..bc0bd53c0d1 100644--- a/enterprise/backend/src/metabase_enterprise/action_v2/data_editing.clj+++ b/enterprise/backend/src/metabase_enterprise/action_v2/data_editing.clj@@ -121,7 +121,7 @@(action-v2.db/fields-by-name table-id field-names))coerce-fn (->> (for [{field-name :name, :keys [coercion_strategy, semantic_type]} fields:when (not (isa? semantic_type :type/PK))]- [(keyword field-name)+ [field-name(or (when (nil? coercion_strategy) identity)(:in (data-editing.coerce/coercion-fns coercion_strategy))(throw (ex-info "Coercion strategy has no defined coercion function"@@ -129,7 +129,7 @@:field field-name:coercion_strategy coercion_strategy})))])(into {}))- coerce (fn [k v] (some-> v ((coerce-fn (keyword k) identity))))]+ coerce (fn [k v] (some-> v ((coerce-fn (name k) identity))))](for [row input-rows](m/map-kv-vals coerce row))))diff --git a/enterprise/backend/src/metabase_enterprise/advanced_config/api/logs.clj b/enterprise/backend/src/metabase_enterprise/advanced_config/api/logs.cljindex 2bd6b4bb8aa..c76e5c65954 100644--- a/enterprise/backend/src/metabase_enterprise/advanced_config/api/logs.clj+++ b/enterprise/backend/src/metabase_enterprise/advanced_config/api/logs.clj@@ -31,7 +31,7 @@(api.macros/defendpoint :get "/query_execution/:yyyy-mm""Fetch rows for the month specified by `:yyyy-mm` from the query_execution logs table.Must be a superuser."- [{:keys [yyyy-mm]} :- [:map+ [{:keys [yyyy-mm]} :- [:map {:closed true}[:yyyy-mm (mu/with-api-error-message [:re #"\d{4}-\d{2}"](deferred-tru "Must be a string like 2020-04 or 2222-11."))]]](let [[year month] (mc/coerce [:tuplediff --git a/enterprise/backend/src/metabase_enterprise/advanced_permissions/api/application.clj b/enterprise/backend/src/metabase_enterprise/advanced_permissions/api/application.cljindex 9701eb4587e..12101b333ed 100644--- a/enterprise/backend/src/metabase_enterprise/advanced_permissions/api/application.clj+++ b/enterprise/backend/src/metabase_enterprise/advanced_permissions/api/application.clj@@ -38,6 +38,23 @@[graph](update graph :groups dejsonify-groups))+(def ^:private RequestGroupId+ "A PermissionsGroup ID as it arrives as a JSON object key in a `PUT /graph` request body: the request middleware+ keywordizes it, so it is turned back into the string it was and has to spell the integer [[dejsonify-groups]] parses+ -- a key that doesn't is rejected here rather than throwing down there."+ [:and+ [:string {:decode/api #(cond-> % (keyword? %) name)}]+ [:re {:error/message "group ID"} #"\d+"]])++(def ^:private RequestGroups+ "The `:groups` half of an application permissions graph as it arrives in a `PUT /graph` request body: group ID ->+ permission type -> permission. [[dejsonify-graph]] turns the values into keywords right after this schema runs."+ [:map-of+ RequestGroupId+ [:map-of+ [:enum :setting :monitoring :subscription]+ (ms/enum-keywords-and-strings :yes :no)]])+;; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to;; use our API + we will need it when we make auto-TypeScript-signature generation happen;;@@ -46,16 +63,19 @@"Do a batch update of Application Permissions by passing a modified graph."[_route-params{skip-graph? :skip-graph- force? :force} :- [:map+ force? :force} :- [:map {:closed true}[:skip-graph {:default false} [:maybe ms/BooleanValue]][:force {:default false} [:maybe ms/BooleanValue]]]- body :- [:map+ body :- [:map {:closed true}[:revision {:optional true} [:maybe ms/Int]][:force {:optional true} [:maybe :boolean]]- ;; keyed by group id, then by application permission type -- `dejsonify-graph` below turns both back- ;; into the int and keyword the graph is stored under- [:groups [:map-of :keyword [:map-of :keyword ms/NonBlankString]]]]]+ [:groups RequestGroups]]+ request](api/check-superuser)+ (let [raw-groups (get-in request [:body :groups])]+ (api/check-no-dropped-entries raw-groups (:groups body))+ (doseq [[group-id perm-type->perm] (:groups body)]+ (api/check-no-dropped-entries (get raw-groups (keyword group-id)) perm-type->perm)))(-> bodydejsonify-graph(a-perms/update-graph! force?))diff --git a/enterprise/backend/src/metabase_enterprise/audit_app/api/user.clj b/enterprise/backend/src/metabase_enterprise/audit_app/api/user.cljindex e2dcaa4022a..4eba0e80b12 100644--- a/enterprise/backend/src/metabase_enterprise/audit_app/api/user.clj+++ b/enterprise/backend/src/metabase_enterprise/audit_app/api/user.clj@@ -37,7 +37,7 @@(api.macros/defendpoint :delete "/:id/subscriptions""Delete all Alert and DashboardSubscription subscriptions for a User (i.e., so they will no longer receive them).Archive all Alerts and DashboardSubscriptions created by the User. Only allowed for admins or for the current user."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](users/check-self-or-superuser id);; delete all `PulseChannelRecipient` rows for this User, which means they will no longer receive anydiff --git a/enterprise/backend/src/metabase_enterprise/cloud_add_ons/api.clj b/enterprise/backend/src/metabase_enterprise/cloud_add_ons/api.cljindex 28d8f68118f..b8c2a0936c6 100644--- a/enterprise/backend/src/metabase_enterprise/cloud_add_ons/api.clj+++ b/enterprise/backend/src/metabase_enterprise/cloud_add_ons/api.clj@@ -162,11 +162,11 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :post "/:product-type""Purchase an add-on."- [{:keys [product-type]} :- [:map+ [{:keys [product-type]} :- [:map {:closed true}[:product-type cloud-add-on-product-types]]_query-params{:keys [quantity]- terms-of-service :terms_of_service} :- [:map+ terms-of-service :terms_of_service} :- [:map {:closed true}[:quantity {:optional true} [:maybe :int]][:terms_of_service {:optional true} [:maybe :boolean]]]](api/check-superuser)@@ -221,7 +221,7 @@[:status :int][:body :any]]"Remove an add-on."- [{:keys [product-type]} :- [:map+ [{:keys [product-type]} :- [:map {:closed true}[:product-type cloud-add-on-product-types]]](api/check-superuser)(conddiff --git a/enterprise/backend/src/metabase_enterprise/cloud_proxy/api.clj b/enterprise/backend/src/metabase_enterprise/cloud_proxy/api.cljindex d089eab8218..f3ddbae5012 100644--- a/enterprise/backend/src/metabase_enterprise/cloud_proxy/api.clj+++ b/enterprise/backend/src/metabase_enterprise/cloud_proxy/api.clj@@ -28,7 +28,7 @@schema cannot dispatch on the `:operation-id` route param, and each is therefore optional -- the operationitself rejects parameters that don't belong to it, or are missing. Adding an operation to the allowlistsabove means adding its parameters here."- [:map {:decode/normalize lib.schema.common/normalize-map}+ [:map {:closed true :decode/normalize lib.schema.common/normalize-map}[:plan-alias {:optional true} ms/NonBlankString][:new-plan-alias {:optional true} ms/NonBlankString][:force-end-trial {:optional true} :boolean]])@@ -44,7 +44,7 @@This endpoint is used only for hosted instances, and calls Harbormaster Store using a OpenAPI client.:operation-id is the operation-id of the Harbormaster Store endpoint.All parameters for the operation are taken in the POST body."- [{:keys [operation-id]} :- [:map+ [{:keys [operation-id]} :- [:map {:closed true}[:operation-id ms/NonBlankString]]_query-paramsbody :- [:maybe OperationParams]]diff --git a/enterprise/backend/src/metabase_enterprise/content_translation/routes.clj b/enterprise/backend/src/metabase_enterprise/content_translation/routes.cljindex ac4958ff6b8..26bc56ffa24 100644--- a/enterprise/backend/src/metabase_enterprise/content_translation/routes.clj+++ b/enterprise/backend/src/metabase_enterprise/content_translation/routes.clj@@ -69,9 +69,9 @@:max-file-count 1}}[_route_params_query-params- {{:keys [tempfile size]} :file} :- [:map+ {{:keys [tempfile size]} :file} :- [:map {:closed true}[:file- [:map+ [:map {:closed true}[:filename :string][:size :int][:tempfile (ms/InstanceOfClass java.io.File)]]]]]@@ -90,9 +90,9 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/dictionary/:token""Fetch the content translation dictionary via a JSON Web Token signed with the `embedding-secret-key`."- [{:keys [token]} :- [:map+ [{:keys [token]} :- [:map {:closed true}[:token ms/NonBlankString]]- {:keys [locale]} :- [:map [:locale {:optional true} [:maybe :string]]]]+ {:keys [locale]} :- [:map {:closed true} [:locale {:optional true} [:maybe :string]]]];; this will error if bad(embedding.jwt/unsign token)(if locale@@ -102,7 +102,7 @@(api.macros/defendpoint :get "/dictionary" :- DictionaryResponse"Fetch the content translation dictionary for authenticated users (auth-based embedding flows)."[_route-params- {:keys [locale]} :- [:map [:locale :string]]]+ {:keys [locale]} :- [:map {:closed true} [:locale :string]]](api/check api/*current-user-id* 401 "Unauthenticated"){:data (ct/get-translations (i18n/normalized-locale-string (str/trim locale)))})diff --git a/enterprise/backend/src/metabase_enterprise/content_verification/api/moderation_review.clj b/enterprise/backend/src/metabase_enterprise/content_verification/api/moderation_review.cljindex ea12cdac65f..9ea1bb8e719 100644--- a/enterprise/backend/src/metabase_enterprise/content_verification/api/moderation_review.clj+++ b/enterprise/backend/src/metabase_enterprise/content_verification/api/moderation_review.clj@@ -16,7 +16,7 @@[_route-params_query-params{:keys [text moderated_item_id moderated_item_type status]}- :- [:map+ :- [:map {:closed true}[:text {:optional true} [:maybe :string]][:moderated_item_id ms/PositiveInt][:moderated_item_type moderation/moderated-item-types]diff --git a/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/api.clj b/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/api.cljindex d6257fd0848..7979ff4be7e 100644--- a/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/api.clj+++ b/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/api.clj@@ -50,8 +50,8 @@(def ^:private BundleUploadParts"The multipart parts carrying a tar.gz bundle. `:size` is what [[check-upload!]] enforces the size limit with, so ithas to be declared here for it to survive param decoding."- [:map- [:file [:map+ [:map {:closed true}+ [:file [:map {:closed true}[:filename :string][:size ms/IntGreaterThanOrEqualToZero][:tempfile (ms/InstanceOfClass File)]]]])@@ -165,7 +165,7 @@Requires custom viz plugin dev mode to be enabled."[_route-params_query-params- {:keys [identifier dev_bundle_url]} :- [:map+ {:keys [identifier dev_bundle_url]} :- [:map {:closed true}[:identifier {:optional true} [:maybe ms/NonBlankString]][:dev_bundle_url ms/NonBlankString]]](api/check-superuser)@@ -222,7 +222,7 @@(api.macros/defendpoint :delete "/:id" :- :nil"Remove a custom visualization plugin and evict its on-disk cache."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]](let [plugin (api/write-check (custom-viz-plugin.db/non-blob-plugin id))](custom-viz-plugin.db/delete-plugin! id)(cache/purge-plugin-cache! plugin)@@ -232,9 +232,9 @@(api.macros/defendpoint :put "/:id" :- CustomVizPluginResponse"Update a custom visualization plugin. Currently only `enabled` may be toggled."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]_query-params- body :- [:map+ body :- [:map {:closed true}[:enabled {:optional true} [:maybe :boolean]]]](let [existing (api/write-check (custom-viz-plugin.db/non-blob-plugin id))updates (select-keys body [:enabled])]@@ -252,7 +252,7 @@match the plugin's existing `identifier`."{:multipart {:max-file-size cache/max-bundle-bytes:max-file-count 1}}- [{:keys [id]} :- [:map [:id ms/PositiveInt]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]_query-params{:keys [file]} :- BundleUploadParts](let [existing (api/write-check (custom-viz-plugin.db/non-blob-plugin id))@@ -281,7 +281,7 @@"Serve the JS bundle for a plugin from the on-disk cache.Returns application/javascript with ETag and Cache-Control headers.In dev mode, proxies from `dev_bundle_url` if set."- [{:keys [id], :as _route-params} :- [:map [:id ms/PositiveInt]]+ [{:keys [id], :as _route-params} :- [:map {:closed true} [:id ms/PositiveInt]]_query-params_body_request@@ -313,8 +313,8 @@and must match the manifest `icon`. Only the icon is served — plugins do notship arbitrary assets.In dev mode, proxies from the dev base URL if set."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]- {:keys [path]} :- [:map [:path ms/NonBlankString]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]+ {:keys [path]} :- [:map {:closed true} [:path ms/NonBlankString]]_body_requestrespond@@ -340,14 +340,14 @@(catch Throwable e(raise e))))-(api.macros/defendpoint :put "/:id/dev-url" :- [:map [:dev_bundle_url [:maybe :string]]]+(api.macros/defendpoint :put "/:id/dev-url" :- [:map {:closed true} [:dev_bundle_url [:maybe :string]]]"Set or clear the dev base URL for a plugin (e.g. `http://localhost:5174`).The bundle is fetched from `{base}/index.js` and assets from `{base}/assets/{name}`.Persisted to the database so it survives server restarts.Requires custom viz plugin dev mode to be enabled."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]_query-params- {:keys [dev_bundle_url]} :- [:map [:dev_bundle_url [:maybe :string]]]]+ {:keys [dev_bundle_url]} :- [:map {:closed true} [:dev_bundle_url [:maybe :string]]]](api/write-check (custom-viz-plugin.db/non-blob-plugin id))(check-dev-mode-enabled!)(cache/set-or-clear-dev-bundle! id dev_bundle_url)@@ -358,7 +358,7 @@Connects to `{dev_bundle_url}/__sse` and forwards events to the browser.This avoids the need for a CSP exception for the dev server origin.Requires custom viz plugin dev mode to be enabled."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]](check-dev-mode-enabled!)(let [dev-url (cache/resolve-dev-bundle id)](when-not dev-url@@ -395,7 +395,7 @@"Re-fetch the manifest from the dev server for a dev-only plugin. For uploadedplugins this is a no-op — to update an upload-backed plugin, PUT a new bundleto `/:id/bundle`."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]](let [plugin (api/write-check (custom-viz-plugin.db/non-blob-plugin id))](api/check-400 (dev-only-plugin? plugin)"Refresh is only supported for dev-only plugins; upload a new bundle to update an upload-backed plugin.")diff --git a/enterprise/backend/src/metabase_enterprise/data_apps/api.clj b/enterprise/backend/src/metabase_enterprise/data_apps/api.cljindex 228465ae553..bd22c89cd9e 100644--- a/enterprise/backend/src/metabase_enterprise/data_apps/api.clj+++ b/enterprise/backend/src/metabase_enterprise/data_apps/api.clj@@ -135,7 +135,7 @@"List the data apps provided by the connected repository. Pass `available=true`to return only enabled apps without sync errors."[_route-params- {:keys [available]} :- [:map [:available {:optional true} [:maybe :boolean]]]]+ {:keys [available]} :- [:map {:closed true} [:available {:optional true} [:maybe :boolean]]]](->> (data-apps.db/non-blob-data-apps available)(map api/read-check)(mapv data-app-response)))@@ -145,9 +145,9 @@;; The regex also excludes the literal `repo-status` sub-route above.(api.macros/defendpoint :put ["/:slug" :slug slug-regex] :- DataAppResponse"Enable or disable a single data app. Disabled apps are not served."- [{:keys [slug]} :- [:map [:slug ms/NonBlankString]]+ [{:keys [slug]} :- [:map {:closed true} [:slug ms/NonBlankString]]_query-params- {:keys [enabled]} :- [:map [:enabled :boolean]]]+ {:keys [enabled]} :- [:map {:closed true} [:enabled :boolean]]](api/check-superuser)(let [app (api/check-404 (data-apps.db/non-blob-data-app-by-slug slug))](data-apps.db/update-data-app! (:id app) {:enabled enabled})@@ -158,7 +158,7 @@apps left behind by a repository that is no longer connected: while a repo isconnected, an app still in it is re-materialized by the next sync, and one nolonger in it is pruned by that sync anyway."- [{:keys [slug]} :- [:map [:slug ms/NonBlankString]]]+ [{:keys [slug]} :- [:map {:closed true} [:slug ms/NonBlankString]]](api/check-superuser);; `t2/delete!` returns the row count; a 0 means the slug wasn't there → 404.(api/check-404 (pos? (data-apps.db/delete-data-app-by-slug! slug)))@@ -168,13 +168,13 @@(api.macros/defendpoint :get ["/:slug" :slug slug-regex] :- [:or DataAppResponse PublicDataAppResponse]"Fetch metadata for a single enabled data app by its slug."- [{:keys [slug]} :- [:map [:slug ms/NonBlankString]]]+ [{:keys [slug]} :- [:map {:closed true} [:slug ms/NonBlankString]]](data-app-response (api/read-check (data-apps.db/enabled-non-blob-data-app-by-slug slug))))(api.macros/defendpoint :get ["/:slug/bundle" :slug slug-regex] :- :any"Serve the cached JS bundle for a single enabled data app by slug. Honors`If-None-Match` against the content-hash ETag with a 304."- [{:keys [slug]} :- [:map [:slug ms/NonBlankString]]+ [{:keys [slug]} :- [:map {:closed true} [:slug ms/NonBlankString]]_query-params_bodyrequestdiff --git a/enterprise/backend/src/metabase_enterprise/data_complexity_score/api.clj b/enterprise/backend/src/metabase_enterprise/data_complexity_score/api.cljindex 6b28bc2f3cc..d6745d700ce 100644--- a/enterprise/backend/src/metabase_enterprise/data_complexity_score/api.clj+++ b/enterprise/backend/src/metabase_enterprise/data_complexity_score/api.clj@@ -105,7 +105,7 @@Pass `force-recalculation=true` to recompute, persist, and return a fresh score.Superuser-only."[_route- {force-recalculation? :force-recalculation} :- [:map+ {force-recalculation? :force-recalculation} :- [:map {:closed true}[:force-recalculation {:default false} ms/BooleanValue]]_body](api/check-superuser)diff --git a/enterprise/backend/src/metabase_enterprise/data_studio/api/table.clj b/enterprise/backend/src/metabase_enterprise/data_studio/api/table.cljindex 2a776a2fb2d..a37008a02e0 100644--- a/enterprise/backend/src/metabase_enterprise/data_studio/api/table.clj+++ b/enterprise/backend/src/metabase_enterprise/data_studio/api/table.clj@@ -17,7 +17,7 @@(set! *warn-on-reflection* true)(mr/def ::table-selectors- [:map+ [:map {:closed true};; disjunctive filters (e.g. db_id IN $database_ids OR id IN $table_ids)[:database_ids {:optional true} [:sequential ms/PositiveInt]][:schema_ids {:optional true} [:sequential :string]]@@ -142,7 +142,7 @@(api.macros/defendpoint :get "/:id/publishing-info" :- [:maybe PublishingInfo]"Return the latest valid publishing information for a published table, or no content when unavailable."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]_query-params_body_request]diff --git a/enterprise/backend/src/metabase_enterprise/database_replication/api.clj b/enterprise/backend/src/metabase_enterprise/database_replication/api.cljindex 53c0a8a4aa1..e6c8c78968a 100644--- a/enterprise/backend/src/metabase_enterprise/database_replication/api.clj+++ b/enterprise/backend/src/metabase_enterprise/database_replication/api.clj@@ -133,10 +133,10 @@:schema-filters schema-filters}))(def ^:private body-schema- [:map+ [:map {:closed true}[:replicationSchemaFilters{:optional true}- [:map+ [:map {:closed true}[:schema-filters-type [:enum "inclusion" "exclusion" "all"]][:schema-filters-patterns :string]]]])@@ -146,7 +146,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :post "/connection/:database-id/preview""Return info about pg-replication connection that is about to be created."- [{:keys [database-id]} :- [:map [:database-id ms/PositiveInt]] _ {:keys [replicationSchemaFilters]} :- body-schema]+ [{:keys [database-id]} :- [:map {:closed true} [:database-id ms/PositiveInt]] _ {:keys [replicationSchemaFilters]} :- body-schema](let [database (database-replication.db/database database-id)secret (->secret database)replication-schema-filters (m->schema-filter replicationSchemaFilters)]@@ -158,7 +158,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :post "/connection/:database-id""Create a new PG replication connection for the specified database."- [{:keys [database-id]} :- [:map [:database-id ms/PositiveInt]] _ {:keys [replicationSchemaFilters]} :- body-schema]+ [{:keys [database-id]} :- [:map {:closed true} [:database-id ms/PositiveInt]] _ {:keys [replicationSchemaFilters]} :- body-schema](api/check-400 (database-replication.settings/database-replication-enabled) "PG replication integration is not enabled.")(let [database (database-replication.db/database database-id)db-details (:details database)]@@ -189,7 +189,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/connection/:database-id""Delete PG replication connection for the specified database."- [{:keys [database-id]} :- [:map [:database-id ms/PositiveInt]]]+ [{:keys [database-id]} :- [:map {:closed true} [:database-id ms/PositiveInt]]](api/check-400 (database-replication.settings/database-replication-enabled) "PG replication integration is not enabled.")(let [conns (pruned-database-replication-connections)](when-let [connection-id (database-id->connection-id conns database-id)]diff --git a/enterprise/backend/src/metabase_enterprise/database_routing/api.clj b/enterprise/backend/src/metabase_enterprise/database_routing/api.cljindex 733dbca491e..a1bb32e9356 100644--- a/enterprise/backend/src/metabase_enterprise/database_routing/api.clj+++ b/enterprise/backend/src/metabase_enterprise/database_routing/api.clj@@ -27,15 +27,15 @@reachable before adding it — destination details are not required to be valid at creation time, and anunreachable destination is fine."[_route-params- {:keys [check_connection_details]} :- [:map+ {:keys [check_connection_details]} :- [:map {:closed true}[:check_connection_details {:optional true} ms/MaybeBooleanValue]]- {:keys [router_database_id destinations]} :- [:map+ {:keys [router_database_id destinations]} :- [:map {:closed true}[:router_database_id ms/PositiveInt][:destinations[:sequential- [:map+ [:map {:closed true}[:name ms/NonBlankString]- [:details ms/Map]]]]]]+ [:details ms/DatabaseDetails]]]]]](api/check-400 (database-routing.db/router-exists? router_database_id))(api/check-400 (not (database-routing.db/destination-name-exists? router_database_id (map :name destinations)))"A destination database with that name already exists.")@@ -105,9 +105,9 @@- change the `user_attribute` used to route for an existing Router database, or- turn a Router database into a regular Databasedepending on the value of `user_attribute`"- [{:keys [id]} :- [:map [:id ms/PositiveInt]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]_query-params- {:keys [user_attribute]} :- [:map [:user_attribute {:optional true} [:maybe ms/NonBlankString]]]]+ {:keys [user_attribute]} :- [:map {:closed true} [:user_attribute {:optional true} [:maybe ms/NonBlankString]]]](let [db (database-routing.db/database id)](api/check-404 db)(api/check-400 (not (:router_database_id db)) "Cannot make a destination database a router database")diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/api.clj b/enterprise/backend/src/metabase_enterprise/dependencies/api.cljindex 8d3cd397c54..3ccd75bede8 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/api.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/api.clj@@ -323,7 +323,7 @@The graph is represented by a list of :nodes and a list of :edges. Each node has an :id, :type, :data (whichdepends on the node type), and a map of :dependent_counts per entity type. Each edge is a :model/Dependency."[_route-params- {:keys [id type]} :- [:map+ {:keys [id type]} :- [:map {:closed true}[:id {:optional true} ms/PositiveInt][:type {:optional true} ::deps.dependency-types/dependency-types]]](api/read-check (deps.dependency-types/dependency-type->model type) id)@@ -398,7 +398,7 @@(sort-by key-fn comp-fn entities)))(def ^:private dependents-args- [:map+ [:map {:closed true}[:id ms/PositiveInt][:type ::deps.dependency-types/dependency-types][:dependent-types {:optional true}@@ -475,7 +475,7 @@#{:name :location :dependents-with-errors :dependents-errors})(def ^:private dependency-items-args- [:map+ [:map {:closed true}[:types {:optional true} [:or::deps.dependency-types/dependency-types[:sequential ::deps.dependency-types/dependency-types]]]@@ -608,7 +608,7 @@:total total}))(def ^:private broken-dependents-args- [:map+ [:map {:closed true}[:id ms/PositiveInt][:type ::deps.dependency-types/dependency-types][:dependent-types {:optional true}diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/calculation.clj b/enterprise/backend/src/metabase_enterprise/dependencies/calculation.cljindex d6c55db0813..937834ed9ac 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/calculation.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/calculation.clj@@ -65,13 +65,13 @@(prose-mirror/collect-ast document (fn [{:keys [type attrs]}](cond(and (= prose-mirror/smart-link-type type)- (#{"card" "dashboard" "table" "document"} (:model attrs))- (pos-int? (:entityId attrs)))- [(keyword (:model attrs)) (:entityId attrs)]+ (#{"card" "dashboard" "table" "document"} (get attrs "model"))+ (pos-int? (get attrs "entityId")))+ [(keyword (get attrs "model")) (get attrs "entityId")](and (= prose-mirror/card-embed-type type)- (pos-int? (:id attrs)))- [:card (:id attrs)]+ (pos-int? (get attrs "id")))+ [:card (get attrs "id")]:elsenil)))))diff --git a/enterprise/backend/src/metabase_enterprise/email/api.clj b/enterprise/backend/src/metabase_enterprise/email/api.cljindex 2f32b2caa6a..403b7072fa3 100644--- a/enterprise/backend/src/metabase_enterprise/email/api.clj+++ b/enterprise/backend/src/metabase_enterprise/email/api.clj@@ -33,7 +33,7 @@Calling this automatically sets `cloud-smtp-enabled` to true if the settings are valid."[_route-params_query-params- settings :- [:map+ settings :- [:map {:closed true}[:email-smtp-host-override {:optional true} [:or string? nil?]][:email-smtp-password-override {:optional true} [:or string? nil?]][:email-smtp-port-override {:optional true} [:or int? nil?]]diff --git a/enterprise/backend/src/metabase_enterprise/erd/impl.clj b/enterprise/backend/src/metabase_enterprise/erd/impl.cljindex 3c1283dead7..abd401842ab 100644--- a/enterprise/backend/src/metabase_enterprise/erd/impl.clj+++ b/enterprise/backend/src/metabase_enterprise/erd/impl.clj@@ -68,7 +68,7 @@[:edges [:sequential ::erd-edge]]])(mr/def ::erd-request- [:map+ [:map {:closed true}[:database-id ms/PositiveInt][:table-ids {:optional true} [:maybe (ms/QueryVectorOf ms/PositiveInt)]][:schema {:optional true} [:maybe :string]]])diff --git a/enterprise/backend/src/metabase_enterprise/gsheets/api.clj b/enterprise/backend/src/metabase_enterprise/gsheets/api.cljindex c896b0db93c..9027177a576 100644--- a/enterprise/backend/src/metabase_enterprise/gsheets/api.clj+++ b/enterprise/backend/src/metabase_enterprise/gsheets/api.clj@@ -226,7 +226,7 @@(api.macros/defendpoint :post "/connection" :- :gsheets/response"Hook up a new google drive folder or sheet that will be watched and have its content ETL'd into Metabase."- [{} {} {:keys [url]} :- [:map [:url ms/NonBlankString]]]+ [{} {} {:keys [url]} :- [:map {:closed true} [:url ms/NonBlankString]]](let [attached-dwh (gsheets.db/attached-dwh-database-id)](when-not (some? attached-dwh)(analytics.event/track-event! :snowplow/simple_event {:event "sheets_connected" :event_detail "fail - no dwh"})diff --git a/enterprise/backend/src/metabase_enterprise/impersonation/api.clj b/enterprise/backend/src/metabase_enterprise/impersonation/api.cljindex 9c60fd9fade..ab5b3e493f9 100644--- a/enterprise/backend/src/metabase_enterprise/impersonation/api.clj+++ b/enterprise/backend/src/metabase_enterprise/impersonation/api.clj@@ -17,7 +17,7 @@"Fetch a list of all Impersonation policies currently in effect, or a single policy if both `group_id` and `db_id`are provided."[_route-params- {:keys [group_id db_id]} :- [:map+ {:keys [group_id db_id]} :- [:map {:closed true}[:group_id {:optional true} [:maybe ms/PositiveInt]][:db_id {:optional true} [:maybe ms/PositiveInt]]]](api/check-superuser)@@ -31,7 +31,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/:id""Delete a Connection Impersonation entry."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](api/check-superuser)(api/check-404 (impersonation.db/impersonation id))diff --git a/enterprise/backend/src/metabase_enterprise/metabot/api/permissions.clj b/enterprise/backend/src/metabase_enterprise/metabot/api/permissions.cljindex 17c253f94eb..ca3a56d9f0f 100644--- a/enterprise/backend/src/metabase_enterprise/metabot/api/permissions.clj+++ b/enterprise/backend/src/metabase_enterprise/metabot/api/permissions.clj@@ -64,8 +64,8 @@permissions list with defaults filled in."[_route-params_query-params- {:keys [permissions]} :- [:map- [:permissions [:sequential [:map+ {:keys [permissions]} :- [:map {:closed true}+ [:permissions [:sequential [:map {:closed true}[:group_id pos-int?][:perm_type (into [:enum] valid-perm-types)][:perm_value (into [:enum] all-valid-perm-values)]]]]]]diff --git a/enterprise/backend/src/metabase_enterprise/metabot/api/usage.clj b/enterprise/backend/src/metabase_enterprise/metabot/api/usage.cljindex 40f5c5d63c7..db47c61e21e 100644--- a/enterprise/backend/src/metabase_enterprise/metabot/api/usage.clj+++ b/enterprise/backend/src/metabase_enterprise/metabot/api/usage.clj@@ -12,7 +12,7 @@(some-> row (dissoc :id)))(api.macros/defendpoint :get "/instance"- :- [:map [:max_usage [:maybe nat-int?]]]+ :- [:map {:closed true} [:max_usage [:maybe nat-int?]]]"Get the instance-wide metabot usage limit. Returns `max_usage: null` if no limit is set (unlimited)."[](api/check-superuser)@@ -20,11 +20,11 @@{:max_usage nil}))(api.macros/defendpoint :put "/instance"- :- [:map [:max_usage [:maybe nat-int?]]]+ :- [:map {:closed true} [:max_usage [:maybe nat-int?]]]"Set or update the instance-wide metabot usage limit. Pass `max_usage: null` to remove the limit (unlimited)."[_route-params_query-params- body :- [:map [:max_usage [:maybe nat-int?]]]]+ body :- [:map {:closed true} [:max_usage [:maybe nat-int?]]]](api/check-superuser)(let [result (or (some-> (instance-limit/set-instance-limit! nil (:max_usage body)) (dissoc :id :tenant_id)){:max_usage nil})]@@ -41,7 +41,7 @@(api.macros/defendpoint :get "/tenant/:tenant-id":- [:map [:tenant_id pos-int?] [:max_usage [:maybe nat-int?]]]"Get the metabot usage limit for a specific tenant. Returns `max_usage: null` if no limit is set."- [{:keys [tenant-id]} :- [:map [:tenant-id pos-int?]]]+ [{:keys [tenant-id]} :- [:map {:closed true} [:tenant-id pos-int?]]](api/check-superuser)(or (without-id (instance-limit/instance-limit tenant-id)){:tenant_id tenant-id :max_usage nil}))@@ -49,9 +49,9 @@(api.macros/defendpoint :put "/tenant/:tenant-id":- [:map [:tenant_id pos-int?] [:max_usage [:maybe nat-int?]]]"Set or update the metabot usage limit for a specific tenant. Pass `max_usage: null` to remove the limit."- [{:keys [tenant-id]} :- [:map [:tenant-id pos-int?]]+ [{:keys [tenant-id]} :- [:map {:closed true} [:tenant-id pos-int?]]_query-params- body :- [:map [:max_usage [:maybe nat-int?]]]]+ body :- [:map {:closed true} [:max_usage [:maybe nat-int?]]]](api/check-superuser)(let [result (or (without-id (instance-limit/set-instance-limit! tenant-id (:max_usage body))){:tenant_id tenant-id :max_usage nil})]@@ -68,7 +68,7 @@(api.macros/defendpoint :get "/group/:group-id":- [:map [:group_id pos-int?] [:max_usage [:maybe nat-int?]]]"Get the metabot usage limit for a specific group. Returns `max_usage: null` if no limit is set."- [{:keys [group-id]} :- [:map [:group-id pos-int?]]]+ [{:keys [group-id]} :- [:map {:closed true} [:group-id pos-int?]]](api/check-superuser)(or (without-id (group-limit/group-limit group-id)){:group_id group-id :max_usage nil}))@@ -76,9 +76,9 @@(api.macros/defendpoint :put "/group/:group-id":- [:map [:group_id pos-int?] [:max_usage [:maybe nat-int?]]]"Set or update the metabot usage limit for a specific group. Pass `max_usage: null` to remove the limit."- [{:keys [group-id]} :- [:map [:group-id pos-int?]]+ [{:keys [group-id]} :- [:map {:closed true} [:group-id pos-int?]]_query-params- body :- [:map [:max_usage [:maybe nat-int?]]]]+ body :- [:map {:closed true} [:max_usage [:maybe nat-int?]]]](api/check-superuser)(let [result (or (without-id (group-limit/set-group-limit! group-id (:max_usage body))){:group_id group-id :max_usage nil})]diff --git a/enterprise/backend/src/metabase_enterprise/metabot_analytics/api.clj b/enterprise/backend/src/metabase_enterprise/metabot_analytics/api.cljindex 2a9ae3d8e8e..ad821924116 100644--- a/enterprise/backend/src/metabase_enterprise/metabot_analytics/api.clj+++ b/enterprise/backend/src/metabase_enterprise/metabot_analytics/api.clj@@ -59,7 +59,7 @@(def ^:private ListConversationsQueryParams"Query-param schema for `GET /conversations`."- [:map+ [:map {:closed true}[:sort_by {:optional true} [:maybe SortColumn]][:sort_dir {:optional true} [:maybe SortDirection]][:user_id {:optional true} [:maybe ms/PositiveInt]]@@ -141,7 +141,7 @@(def ^:private ConversationIdParams"Route-param schema for endpoints addressing a single conversation by id."- [:map [:id ms/UUIDString]])+ [:map {:closed true} [:id ms/UUIDString]]);;; -------------------------------------------------- Endpoints --------------------------------------------------diff --git a/enterprise/backend/src/metabase_enterprise/mfa/management.clj b/enterprise/backend/src/metabase_enterprise/mfa/management.cljindex 4dbb4d9ccfa..ba173209d76 100644--- a/enterprise/backend/src/metabase_enterprise/mfa/management.clj+++ b/enterprise/backend/src/metabase_enterprise/mfa/management.clj@@ -97,7 +97,7 @@`otpauth_uri` for QR display; enrollment is not active until confirmed with a live code."[_route-params_query-params- {:keys [password]} :- [:map [:password ms/NonBlankString]]]+ {:keys [password]} :- [:map {:closed true} [:password ms/NonBlankString]]](premium-features/assert-has-feature :multi-factor-auth (tru "Multi-factor authentication"))(when-not (mfa.settings/mfa-enabled?)(throw (ex-info (tru "Two-factor authentication is not enabled on this instance.")@@ -125,7 +125,7 @@factor and returns the single-use recovery codes — the only time they exist in plaintext."[_route-params_query-params- {:keys [code]} :- [:map [:code ms/NonBlankString]]]+ {:keys [code]} :- [:map {:closed true} [:code ms/NonBlankString]]](premium-features/assert-has-feature :multi-factor-auth (tru "Multi-factor authentication"))(let [codes (throttled :enroll(fn []@@ -141,7 +141,7 @@TOTP code or an unused recovery code — never just the password."[_route-params_query-params- {:keys [code]} :- [:map [:code ms/NonBlankString]]]+ {:keys [code]} :- [:map {:closed true} [:code ms/NonBlankString]]](throttled :disable(fn [];; one transaction so a consumed recovery code and the enrollment removal land together@@ -185,7 +185,7 @@strip its own 2FA with only a cookie, turning transient access into a permanent password bypass."[_route-params_query-params- {user-id :user_id} :- [:map [:user_id ms/PositiveInt]]]+ {user-id :user_id} :- [:map {:closed true} [:user_id ms/PositiveInt]]](api/check-superuser)(when (= user-id api/*current-user-id*)(throw (ex-info (tru "You cannot administratively remove your own two-factor authentication. Please use the normal removal method in your account settings.")@@ -261,7 +261,7 @@Takes `limit`/`offset` for pagination, and `query` to search on first name, last name, and email."[_route-params- {:keys [query]} :- [:map [:query {:optional true} [:maybe :string]]]]+ {:keys [query]} :- [:map {:closed true} [:query {:optional true} [:maybe :string]]]](api/check-superuser)(user-list-response true query))@@ -272,7 +272,7 @@Takes `limit`/`offset` for pagination, and `query` to search on first name, last name, and email."[_route-params- {:keys [query]} :- [:map [:query {:optional true} [:maybe :string]]]]+ {:keys [query]} :- [:map {:closed true} [:query {:optional true} [:maybe :string]]]](api/check-superuser)(user-list-response false query))@@ -284,7 +284,7 @@never rotate the codes. The plaintext codes are returned exactly once; only hashes are stored."[_route-params_query-params- {:keys [code]} :- [:map [:code ms/NonBlankString]]]+ {:keys [code]} :- [:map {:closed true} [:code ms/NonBlankString]]](throttled :regenerate(fn [](t2/with-transaction [_conn]diff --git a/enterprise/backend/src/metabase_enterprise/permission_debug/api.clj b/enterprise/backend/src/metabase_enterprise/permission_debug/api.cljindex 0c8eaf4cf2a..d87e5d3fd08 100644--- a/enterprise/backend/src/metabase_enterprise/permission_debug/api.clj+++ b/enterprise/backend/src/metabase_enterprise/permission_debug/api.clj@@ -66,7 +66,7 @@```"[_route-params{:keys [user_id model_id action_type]- :or {}} :- [:map+ :or {}} :- [:map {:closed true}[:user_id pos-int?][:model_id :string][:action_type permission-debug.impl/ActionType]]diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/api.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/api.cljindex d312f550611..01aa0db5cc1 100644--- a/enterprise/backend/src/metabase_enterprise/remote_sync/api.clj+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/api.clj@@ -55,7 +55,7 @@[_route_query{:keys [branch force merge expected_branch]}- :- [:map [:branch {:optional true} ms/NonBlankString]+ :- [:map {:closed true} [:branch {:optional true} ms/NonBlankString][:force {:optional true} :boolean][:merge {:optional true} :boolean];; the branch the client believes is currently active; rejected if it disagrees with the@@ -94,7 +94,7 @@- local_version: Git SHA of last successful import (nil if never imported)- cached: true if result was served from cache"[_route-params- {:keys [force-refresh]} :- [:map [:force-refresh {:optional true} :boolean]]+ {:keys [force-refresh]} :- [:map {:closed true} [:force-refresh {:optional true} :boolean]]_body](api/check-superuser)(api/check-400 (settings/remote-sync-enabled) "Remote sync is not configured.")@@ -128,7 +128,7 @@Requires superuser permissions."[_route_query- {:keys [message branch force merge]} :- [:map+ {:keys [message branch force merge]} :- [:map {:closed true}[:message {:optional true} ms/NonBlankString][:branch ms/NonBlankString][:force {:optional true} :boolean]@@ -164,7 +164,7 @@Requires superuser permissions."[_route- {:keys [branch]} :- [:map [:branch ms/NonBlankString]]]+ {:keys [branch]} :- [:map {:closed true} [:branch ms/NonBlankString]]](api/check-superuser)(api/check-400 (settings/remote-sync-enabled) "Remote sync is not configured.")(let [branch-name (check-branch-matches-setting! branch)@@ -210,7 +210,7 @@[_route-params_query-params{:keys [remote-sync-url remote-sync-token] :as body}- :- [:map+ :- [:map {:closed true}[:remote-sync-url {:optional true} [:maybe :string]][:remote-sync-token {:optional true} [:maybe :string]]]](api/check-superuser)@@ -240,7 +240,7 @@[_route-params_query-params{:keys [remote-sync-type collections] :as settings}- :- [:map+ :- [:map {:closed true}[:remote-sync-url {:optional true} [:maybe :string]][:remote-sync-token {:optional true} [:maybe :string]][:remote-sync-type {:optional true} [:maybe [:enum :read-only :read-write]]]@@ -328,7 +328,7 @@Requires superuser permissions."[_route_query- {:keys [name]} :- [:map [:name ms/NonBlankString]]]+ {:keys [name]} :- [:map {:closed true} [:name ms/NonBlankString]]](api/check-superuser)(let [base-branch (or (remote-sync.task/last-version) (settings/remote-sync-branch))](api/check-400 (source/source-from-settings) "Source not configured")@@ -350,7 +350,7 @@Requires superuser permissions."[_route_query- {new-branch :new_branch message :message} :- [:map+ {new-branch :new_branch message :message} :- [:map {:closed true}[:new_branch ms/NonBlankString][:message ms/NonBlankString]]](api/check-superuser)diff --git a/enterprise/backend/src/metabase_enterprise/replacement/api.clj b/enterprise/backend/src/metabase_enterprise/replacement/api.cljindex f69bd8bb9c4..5194525bd8b 100644--- a/enterprise/backend/src/metabase_enterprise/replacement/api.clj+++ b/enterprise/backend/src/metabase_enterprise/replacement/api.clj@@ -24,7 +24,7 @@[_route-params_query-params{:keys [source_entity_id source_entity_type target_entity_id target_entity_type]}- :- [:map+ :- [:map {:closed true}[:source_entity_id ::replacement.schema/source-entity-id][:source_entity_type ::replacement.schema/source-entity-type][:target_entity_id ::replacement.schema/source-entity-id]@@ -43,7 +43,7 @@[_route-params_query-params{:keys [source_entity_id source_entity_type target_entity_id target_entity_type]}- :- [:map+ :- [:map {:closed true}[:source_entity_id ::replacement.schema/source-entity-id][:source_entity_type ::replacement.schema/source-entity-type][:target_entity_id ::replacement.schema/source-entity-id]@@ -95,7 +95,7 @@[_route-params_query-params{:keys [card_id transform_name transform_target target_collection_id transform_tag_ids]}- :- [:map+ :- [:map {:closed true}[:card_id ::replacement.schema/source-entity-id][:transform_name :string][:transform_target ::transforms.schema/transform-target]@@ -138,20 +138,20 @@(api.macros/defendpoint :get "/runs" :- [:sequential ::replacement.schema/run]"List replacement runs, optionally filtered by is-active."[_route-params- {:keys [is-active]} :- [:map [:is-active {:optional true} [:maybe :boolean]]]]+ {:keys [is-active]} :- [:map {:closed true} [:is-active {:optional true} [:maybe :boolean]]]](api/check-superuser)(replacement.db/runs is-active))(api.macros/defendpoint :get "/runs/:id" :- ::replacement.schema/run"Get the status of a source replacement run."- [{:keys [id]} :- [:map [:id ::replacement.schema/run-id]]]+ [{:keys [id]} :- [:map {:closed true} [:id ::replacement.schema/run-id]]](api/check-superuser)(or (replacement.db/run id)(throw (ex-info "Run not found" {:status-code 404}))))(api.macros/defendpoint :post "/runs/:id/cancel" :- [:map [:success boolean?]]"Cancel a running source replacement."- [{:keys [id]} :- [:map [:id ::replacement.schema/run-id]]]+ [{:keys [id]} :- [:map {:closed true} [:id ::replacement.schema/run-id]]](api/check-superuser)(let [run (replacement.db/run id)](when-not rundiff --git a/enterprise/backend/src/metabase_enterprise/replacement/walk.clj b/enterprise/backend/src/metabase_enterprise/replacement/walk.cljindex ec4710484c6..2e40e8d21c5 100644--- a/enterprise/backend/src/metabase_enterprise/replacement/walk.clj+++ b/enterprise/backend/src/metabase_enterprise/replacement/walk.clj@@ -79,7 +79,7 @@(update-legacy-refs-or-names [refs-or-names](into [] (keep update-legacy-ref-or-name) refs-or-names))(column-setting-ref [#::vs{:keys [field-id field-metadata]}]- (-> [:field (or field-metadata {}) field-id]+ (-> (lib/normalize :mbql.clause/field [:field (or field-metadata {}) field-id])lib/ensure-uuid))(update-column-setting [k v](or (when (::vs/field-id k)diff --git a/enterprise/backend/src/metabase_enterprise/sandbox/api/gtap.clj b/enterprise/backend/src/metabase_enterprise/sandbox/api/gtap.cljindex d6bbf0006e2..d5770a7e283 100644--- a/enterprise/backend/src/metabase_enterprise/sandbox/api/gtap.clj+++ b/enterprise/backend/src/metabase_enterprise/sandbox/api/gtap.clj@@ -24,7 +24,7 @@(api.macros/defendpoint :get "/""Fetch a list of all GTAPs currently in use, or a single GTAP if both `group_id` and `table_id` are provided."[_route-params- {:keys [group_id table_id]} :- [:map+ {:keys [group_id table_id]} :- [:map {:closed true}[:group_id {:optional true} [:maybe ms/PositiveInt]][:table_id {:optional true} [:maybe ms/PositiveInt]]]](if (and group_id table_id)@@ -37,7 +37,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id""Fetch GTAP by `id`"- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](api/check-404 (sandbox.db/sandbox id)))@@ -51,7 +51,7 @@"Create a new GTAP."[_route-params_query-params- body :- [:map+ body :- [:map {:closed true}[:table_id ms/PositiveInt][:card_id {:optional true} [:maybe ms/PositiveInt]][:group_id ms/PositiveInt]@@ -66,10 +66,10 @@"Update a GTAP entry. The only things you're allowed to update for a GTAP are the Card being used (`card_id`) or theparameter mappings; changing `table_id` or `group_id` would effectively be deleting this entry and creating a newone. If that's what you want to do, do so explicitly with appropriate calls to the `DELETE` and `POST` endpoints."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-params- body :- [:map+ body :- [:map {:closed true}[:card_id {:optional true} [:maybe ms/PositiveInt]][:attribute_remappings {:optional true} ::sandbox.schema/attribute-remappings]]](api/check-404 (sandbox.db/sandbox id))@@ -90,7 +90,7 @@sandbox is saved, but doesn't actually save the sandbox."[_route-params_query-params- {:keys [table_id card_id]} :- [:map+ {:keys [table_id card_id]} :- [:map {:closed true}[:table_id ms/PositiveInt][:card_id {:optional true} [:maybe ms/PositiveInt]]]](when card_id@@ -108,7 +108,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/:id""Delete a GTAP entry."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](api/check-404 (sandbox.db/sandbox id))(sandbox.db/delete-sandbox! id)diff --git a/enterprise/backend/src/metabase_enterprise/sandbox/api/table.clj b/enterprise/backend/src/metabase_enterprise/sandbox/api/table.cljindex 211347c2b52..6a65ca89e76 100644--- a/enterprise/backend/src/metabase_enterprise/sandbox/api/table.clj+++ b/enterprise/backend/src/metabase_enterprise/sandbox/api/table.clj@@ -76,10 +76,10 @@excluded from what is show in the query builder. When the user has full permissions (or no permissions) this routedoesn't add/change anything from the OSS version. See the docs on the OSS version of the endpoint for moreinformation."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]{:keys [include_sensitive_fields include_hidden_fields include_editable_data_model]}- :- [:map+ :- [:map {:closed true}[:include_sensitive_fields {:default false} [:maybe ms/BooleanValue]][:include_hidden_fields {:default false} [:maybe ms/BooleanValue]][:include_editable_data_model {:default false} [:maybe ms/BooleanValue]]]]diff --git a/enterprise/backend/src/metabase_enterprise/sandbox/api/user.clj b/enterprise/backend/src/metabase_enterprise/sandbox/api/user.cljindex 74de24b5e18..f2e4ca301cf 100644--- a/enterprise/backend/src/metabase_enterprise/sandbox/api/user.clj+++ b/enterprise/backend/src/metabase_enterprise/sandbox/api/user.clj@@ -5,15 +5,15 @@[metabase.api.common :as api][metabase.api.macros :as api.macros][metabase.tenants.core :as tenants]+ [metabase.users.schema :as users.schema][metabase.util.i18n :refer [deferred-tru]][metabase.util.malli :as mu][metabase.util.malli.schema :as ms]))(def ^:private UserAttributes+ "Login attributes keyed by the attribute names the admin chose, so string-keyed; they are stored as JSON."(mu/with-api-error-message- [:map-of- :keyword- :any]+ users.schema/LoginAttributes(deferred-tru "value must be a valid user attributes map (name -> value)")));; TODO - not sure we need this endpoint now that we're just letting you edit from the regular `PUT /api/user/:id@@ -25,10 +25,10 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :put "/:id/attributes""Update the `login_attributes` for a User. Only personal users can have attributes."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-params- {:keys [login_attributes]} :- [:map+ {:keys [login_attributes]} :- [:map {:closed true}[:login_attributes {:optional true} [:maybe UserAttributes]]]](api/check-404 (sandbox.db/personal-user id))(pos? (sandbox.db/set-user-login-attributes! id login_attributes)))diff --git a/enterprise/backend/src/metabase_enterprise/scim/v2/api.clj b/enterprise/backend/src/metabase_enterprise/scim/v2/api.cljindex cfd5fc37228..0eb91439a33 100644--- a/enterprise/backend/src/metabase_enterprise/scim/v2/api.clj+++ b/enterprise/backend/src/metabase_enterprise/scim/v2/api.clj@@ -7,6 +7,7 @@[metabase-enterprise.scim.db :as scim.db][metabase-enterprise.scim.settings :as scim.settings][metabase.analytics-interface.core :as analytics]+ [metabase.api.common :as api][metabase.api.macros :as api.macros][metabase.models.interface :as mi][metabase.permissions.core :as perms]@@ -33,26 +34,28 @@"Malli schema for a SCIM user. This represents both users returned by the service provider (Metabase)as well as users sent by the client (i.e. Okta), with fields marked as optional if they may not be presentin the latter."- [:map+ [:map {:closed true}[:schemas [:sequential ms/NonBlankString]][:id {:optional true} ms/NonBlankString][:userName ms/NonBlankString]- [:name [:map+ [:name [:map {:closed true}[:givenName string?][:familyName string?]]][:emails [:sequential- [:map+ [:map {:closed true}[:value ms/NonBlankString][:type {:optional true} ms/NonBlankString][:primary {:optional true} boolean?]]]][:groups{:optional true}- [:sequential [:map+ [:sequential [:map {:closed true}[:value ms/NonBlankString][:$ref {:optional true} ms/NonBlankString][:display ms/NonBlankString]]]][:locale {:optional true} [:maybe ms/NonBlankString]]- [:active {:optional true} boolean?]])+ [:active {:optional true} boolean?]+ [:meta {:optional true} [:map {:closed true}+ [:resourceType {:optional true} ms/NonBlankString]]]])(def SCIMUserList"Malli schema for a list of SCIM users"@@ -67,38 +70,35 @@"A single attribute value in a PATCH operation. The strings clients send for booleans are parsed by the handler."[:or ms/NonBlankString :boolean])-(def ^:private patch-value?- (mr/validator ::patch-value))-(def UserPatch"Malli schema for a user patch operation"- [:map+ [:map {:closed true}[:schemas [:sequential ms/NonBlankString]][:Operations- [:sequential [:map+ [:sequential [:map {:closed true}[:op ms/NonBlankString];; which attribute the operation targets; `nil` means the value is a map of attribute -> value[:path {:optional true} [:maybe ms/NonBlankString]];; dispatched on shape rather than written as `[:or [:map-of ...] ...]`: request decoding would;; run the `:map-of` decoder over a scalar value and throw[:value [:multi {:dispatch #(if (map? %) :map :scalar)}- [:map [:and- [:map-of [:or :keyword :string] :any]- [:fn {:error/message "attribute value must be a non-blank string or a boolean"}- #(every? patch-value? (vals %))]]]+ [:map (ms/string-keyed-map ::patch-value)][:scalar ::patch-value]]]]]]])(def SCIMGroup"Malli schema for a SCIM group."- [:map+ [:map {:closed true}[:schemas [:sequential ms/NonBlankString]][:id {:optional true} ms/NonBlankString][:displayName ms/NonBlankString][:members{:optional true}- [:sequential [:map+ [:sequential [:map {:closed true}[:value ms/NonBlankString]- [:$ref {:optional true} ms/NonBlankString]]]]])+ [:$ref {:optional true} ms/NonBlankString]+ [:display {:optional true} ms/NonBlankString]]]]+ [:meta {:optional true} [:map {:closed true}+ [:resourceType {:optional true} ms/NonBlankString]]]])(def SCIMGroupList"Malli schema for a list of SCIM groups"@@ -215,7 +215,7 @@(api.macros/defendpoint :get "/Users""Fetch a list of users."[_route-params- {start-index :startIndex, c :count, filter-param :filter} :- [:map+ {start-index :startIndex, c :count, filter-param :filter} :- [:map {:closed true}[:startIndex {:optional true} [:maybe ms/PositiveInt]][:count {:optional true} [:maybe ms/PositiveInt]][:filter {:optional true} [:maybe ms/NonBlankString]]]]@@ -242,7 +242,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get ["/Users/:id" :id #"[^/]+"]"Fetch a single user."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/NonBlankString]]](with-prometheus-counters(-> (get-user-by-entity-id id)@@ -275,7 +275,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :put ["/Users/:id" :id #"[^/]+"]"Update a user."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/NonBlankString]]_query-paramsscim-user :- SCIMUser]@@ -331,10 +331,14 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :patch ["/Users/:id" :id #"[^/]+"]"Activate or deactivate a user. Supports specific replace operations, but not arbitrary patches."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/NonBlankString]]_query-params- patch-ops :- UserPatch]+ patch-ops :- UserPatch+ request]+ (doseq [[raw-operation operation] (map vector (get-in request [:body :Operations]) (:Operations patch-ops))+ :when (map? (:value operation))]+ (api/check-no-dropped-entries (:value raw-operation) (:value operation)))(with-prometheus-counters(t2/with-transaction [_conn](let [user (get-user-by-entity-id id)@@ -404,7 +408,7 @@"Fetch a list of groups."[_route-params{start-index :startIndex, c :count, filter-param :filter}- :- [:map+ :- [:map {:closed true}[:startIndex {:optional true} [:maybe ms/PositiveInt]][:count {:optional true} [:maybe ms/PositiveInt]][:filter {:optional true} [:maybe ms/NonBlankString]]]]@@ -431,7 +435,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get ["/Groups/:id" :id #"[^/]+"]"Fetch a single group."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/NonBlankString]]](with-prometheus-counters(-> (get-group-by-entity-id id)@@ -478,7 +482,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :put ["/Groups/:id" :id #"[^/]+"]"Update a group."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/NonBlankString]]_query-paramsscim-group :- SCIMGroup]@@ -501,7 +505,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete ["/Groups/:id" :id #"[^/]+"]"Delete a group."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/NonBlankString]]](with-prometheus-counters(let [group (get-group-by-entity-id id)]diff --git a/enterprise/backend/src/metabase_enterprise/security_center/api.clj b/enterprise/backend/src/metabase_enterprise/security_center/api.cljindex 22e04467312..186ec778468 100644--- a/enterprise/backend/src/metabase_enterprise/security_center/api.clj+++ b/enterprise/backend/src/metabase_enterprise/security_center/api.clj@@ -82,7 +82,7 @@(api.macros/defendpoint :post "/:advisory-id/acknowledge" :- AcknowledgeResponse"Acknowledge a security advisory. Stops repeat notifications."- [{:keys [advisory-id]} :- [:map [:advisory-id ms/NonBlankString]]]+ [{:keys [advisory-id]} :- [:map {:closed true} [:advisory-id ms/NonBlankString]]](api/check-superuser)(let [advisory (security-center.db/advisory-by-advisory-id advisory-id)](api/check-404 advisory)@@ -92,7 +92,7 @@"Acknowledge multiple security advisories. Skips already-acknowledged advisories."[_route-params_query-params- {:keys [advisory_ids]} :- [:map [:advisory_ids [:sequential ms/NonBlankString]]]]+ {:keys [advisory_ids]} :- [:map {:closed true} [:advisory_ids [:sequential ms/NonBlankString]]]](api/check-superuser)(api/check (seq advisory_ids) [400 "advisory_ids must be a non-empty array"])(mapv acknowledge-response@@ -123,7 +123,7 @@[_route-params_query-paramsbody- :- [:map+ :- [:map {:closed true}[:email_recipients {:optional true} [:maybe [:sequential ::models.notification/NotificationRecipient]]][:slack_channel {:optional true} [:maybe :string]]]](api/check-superuser)diff --git a/enterprise/backend/src/metabase_enterprise/serialization/api.clj b/enterprise/backend/src/metabase_enterprise/serialization/api.cljindex 32b64772409..c3fa0ebdebf 100644--- a/enterprise/backend/src/metabase_enterprise/serialization/api.clj+++ b/enterprise/backend/src/metabase_enterprise/serialization/api.clj@@ -220,7 +220,7 @@continue-on-error? :continue_on_errorfull-stacktrace? :full_stacktrace:as _query-params}- :- [:map+ :- [:map {:closed true}[:dirname {:optional true} [:maybe{:description "name of directory and archive file (default: `<instance-name>-<YYYY-MM-dd_HH-mm>`)"}string?]]@@ -286,14 +286,14 @@full-stacktrace? :full_stacktracereindex-search? :reindex:as _query-params}- :- [:map+ :- [:map {:closed true}[:continue_on_error {:default false} (mu/with ms/BooleanValue {:description "Do not break execution on errors"})][:full_stacktrace {:default false} (mu/with ms/BooleanValue {:description "Show full stacktraces in the logs"})];; TODO this parameter is a kludge to fix https://linear.app/metabase/issue/GDGT-573;; ideally we'd fix the underlying issue (by delaying realtime indexing updates until the tx closes);; for now, we let users opt out, in case they're indexing a lot, so they can only reindex on the last step[:reindex {:default true} (mu/with ms/BooleanValue {:description "Rebuild the search index afterwards"})]]- {:keys [file]} :- [:map+ {:keys [file]} :- [:map {:closed true}[:file (mu/with ms/File {:description ".tgz with serialization data"})]]](api/check-superuser)(trydiff --git a/enterprise/backend/src/metabase_enterprise/sso/api/oidc.clj b/enterprise/backend/src/metabase_enterprise/sso/api/oidc.cljindex 182e131cee9..1816faa0834 100644--- a/enterprise/backend/src/metabase_enterprise/sso/api/oidc.clj+++ b/enterprise/backend/src/metabase_enterprise/sso/api/oidc.clj@@ -94,7 +94,7 @@;; GET /api/ee/sso/oidc/:key(api.macros/defendpoint :get "/:key" :- oidc-provider-response-schema"Get a single OIDC provider by key (with client secret masked)."- [{provider-key :key} :- [:map [:key :string]]]+ [{provider-key :key} :- [:map {:closed true} [:key :string]]](premium-features/assert-has-feature :sso-oidc (tru "OIDC authentication"))(let [provider (sso-settings/get-oidc-provider provider-key)](api/check-404 provider)@@ -121,7 +121,7 @@;; PUT /api/ee/sso/oidc/:key(api.macros/defendpoint :put "/:key" :- oidc-provider-response-schema"Update an existing OIDC provider."- [{provider-key :key} :- [:map [:key :string]]+ [{provider-key :key} :- [:map {:closed true} [:key :string]]_query-paramsbody :- oidc-provider-update-schema](premium-features/assert-has-feature :sso-oidc (tru "OIDC authentication"))@@ -182,7 +182,7 @@;; DELETE /api/ee/sso/oidc/:key(api.macros/defendpoint :delete "/:key" :- :nil"Delete an OIDC provider."- [{provider-key :key} :- [:map [:key :string]]]+ [{provider-key :key} :- [:map {:closed true} [:key :string]]](premium-features/assert-has-feature :sso-oidc (tru "OIDC authentication"))(let [providers (sso-settings/oidc-providers)filtered (vec (remove #(= (:key %) provider-key) providers))]diff --git a/enterprise/backend/src/metabase_enterprise/sso/api/saml.clj b/enterprise/backend/src/metabase_enterprise/sso/api/saml.cljindex 2b6eb1cb86f..1e02be993c6 100644--- a/enterprise/backend/src/metabase_enterprise/sso/api/saml.clj+++ b/enterprise/backend/src/metabase_enterprise/sso/api/saml.clj@@ -6,8 +6,8 @@[metabase.api.macros :as api.macros][metabase.premium-features.core :as premium-features][metabase.settings.core :as setting]+ [metabase.sso.schema :as sso.schema][metabase.util.i18n :refer [tru]]- [metabase.util.malli.schema :as ms][saml20-clj.core :as saml]))(set! *warn-on-reflection* true)@@ -20,7 +20,7 @@"Update SAML related settings. You must be a superuser to do this."[_route-params_query-params- settings :- [:map+ settings :- [:map {:closed true}[:saml-identity-provider-issuer {:optional true} :string][:saml-identity-provider-uri {:optional true} :string][:saml-identity-provider-certificate {:optional true} :string]@@ -28,8 +28,7 @@[:saml-attribute-email {:optional true} [:maybe :string]][:saml-attribute-firstname {:optional true} [:maybe :string]][:saml-attribute-group {:optional true} [:maybe :string]]- ;; SAML group name -> the Metabase group ids it maps to, like `ldap-group-mappings`- [:saml-group-mappings {:optional true} [:maybe [:map-of :keyword [:sequential ms/PositiveInt]]]]+ [:saml-group-mappings {:optional true} [:maybe ::sso.schema/group-mappings]][:saml-attribute-tenant {:optional true} [:maybe :string]][:saml-attribute-lastname {:optional true} [:maybe :string]][:saml-enabled {:optional true} [:maybe :boolean]]diff --git a/enterprise/backend/src/metabase_enterprise/sso/api/sso.clj b/enterprise/backend/src/metabase_enterprise/sso/api/sso.cljindex 4281f0be535..a9331e77b0a 100644--- a/enterprise/backend/src/metabase_enterprise/sso/api/sso.clj+++ b/enterprise/backend/src/metabase_enterprise/sso/api/sso.clj@@ -38,7 +38,7 @@(api.macros/defendpoint :get "/""SSO entry-point for an SSO user that has not logged in yet"[_route-params- _query-params :- [:map+ _query-params :- [:map {:closed true}[:jwt {:optional true} [:maybe :string]][:preferred_method {:optional true} [:maybe :string]][:redirect {:optional true} [:maybe :string]]@@ -71,10 +71,10 @@(api.macros/defendpoint :post "/""Route the SSO backends call with successful login details"[_route-params- _query-params :- [:map+ _query-params :- [:map {:closed true}[:SAMLResponse {:optional true} [:maybe :string]][:RelayState {:optional true} [:maybe :string]]]- _body :- [:maybe [:map+ _body :- [:maybe [:map {:closed true}[:jwt {:optional true} [:maybe :string]][:SAMLResponse {:optional true} [:maybe :string]][:RelayState {:optional true} [:maybe :string]]]]@@ -133,7 +133,7 @@this provides a path for them to do so."[_route-params_query-params- {:keys [jwt]} :- [:map+ {:keys [jwt]} :- [:map {:closed true}[:jwt ms/NonBlankString]]request](when-not (sso-settings/jwt-enabled-and-configured)@@ -153,11 +153,11 @@(api.macros/defendpoint :post "/handle_slo""Handles client confirmation of saml logout via slo"[_route-params- _query-params :- [:map+ _query-params :- [:map {:closed true}[:SAMLRequest {:optional true} [:maybe :string]][:SAMLResponse {:optional true} [:maybe :string]][:RelayState {:optional true} [:maybe :string]]]- _body :- [:maybe [:map+ _body :- [:maybe [:map {:closed true}[:SAMLRequest {:optional true} [:maybe :string]][:SAMLResponse {:optional true} [:maybe :string]][:RelayState {:optional true} [:maybe :string]]]]@@ -180,9 +180,9 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:key""Initiate OIDC SSO for a specific provider."- [{provider-key :key} :- [:map+ [{provider-key :key} :- [:map {:closed true}[:key ProviderKey]]- _query-params :- [:map+ _query-params :- [:map {:closed true}[:redirect {:optional true} [:maybe :string]]]_body request](try@@ -196,9 +196,9 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:key/callback""OIDC callback for a specific provider."- [{provider-key :key} :- [:map+ [{provider-key :key} :- [:map {:closed true}[:key ProviderKey]]- _query-params :- [:map+ _query-params :- [:map {:closed true}[:code {:optional true} [:maybe :string]][:state {:optional true} [:maybe :string]]]_body request]diff --git a/enterprise/backend/src/metabase_enterprise/stale/api.clj b/enterprise/backend/src/metabase_enterprise/stale/api.cljindex 6a9a2d35445..1c144d43671 100644--- a/enterprise/backend/src/metabase_enterprise/stale/api.clj+++ b/enterprise/backend/src/metabase_enterprise/stale/api.clj@@ -94,9 +94,9 @@- `is_recursive` - if true, return entities from all children of the collection, not just the direct children (default: false)- `sort_column` - the column to sort by (default: name)- `sort_direction` - the direction to sort by (default: asc)"- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id [:or ms/PositiveInt [:= :root]]]]- {:keys [before_date is_recursive sort_column sort_direction]} :- [:map+ {:keys [before_date is_recursive sort_column sort_direction]} :- [:map {:closed true}[:before_date {:optional true} [:maybe :string]][:is_recursive {:default false} :boolean][:sort_column {:default :name} [:enum :name :last_used_at]]diff --git a/enterprise/backend/src/metabase_enterprise/support_access_grants/api.clj b/enterprise/backend/src/metabase_enterprise/support_access_grants/api.cljindex 37d3688dad8..29ef3bf93c6 100644--- a/enterprise/backend/src/metabase_enterprise/support_access_grants/api.clj+++ b/enterprise/backend/src/metabase_enterprise/support_access_grants/api.clj@@ -29,7 +29,7 @@"Revoke an existing support access grant.Requires superuser permissions. Any admin can revoke any grant."- [{id :id} :- [:map [:id ms/PositiveInt]]]+ [{id :id} :- [:map {:closed true} [:id ms/PositiveInt]]](api/check-superuser)(api/write-check :model/SupportAccessGrantLog id)(grants/revoke-grant! api/*current-user-id* id))@@ -47,7 +47,7 @@[_route-params{:keys [ticket-numberuser-id- include-revoked]} :- [:map+ include-revoked]} :- [:map {:closed true}[:ticket-number {:optional true} [:maybe :string]][:user-id {:optional true} [:maybe ms/PositiveInt]][:include-revoked {:optional true} [:maybe :boolean]]]]diff --git a/enterprise/backend/src/metabase_enterprise/support_access_grants/schema.clj b/enterprise/backend/src/metabase_enterprise/support_access_grants/schema.cljindex 74bf9cc513a..574084b4dfb 100644--- a/enterprise/backend/src/metabase_enterprise/support_access_grants/schema.clj+++ b/enterprise/backend/src/metabase_enterprise/support_access_grants/schema.clj@@ -19,7 +19,7 @@(mr/def ::create-grant-request"Schema for POST /api/ee/support-access-grants request body."- [:map+ [:map {:closed true}[:grant_duration_minutes [:int {:min 1 :max max-grant-duration-minutes}]][:ticket_number {:optional true} [:maybe [:string {:min 1 :max 100}]]][:notes {:optional true} [:maybe [:string {:min 1 :max 255}]]]])diff --git a/enterprise/backend/src/metabase_enterprise/tenants/api.clj b/enterprise/backend/src/metabase_enterprise/tenants/api.cljindex 43dbfd80f54..ee8a77234e3 100644--- a/enterprise/backend/src/metabase_enterprise/tenants/api.clj+++ b/enterprise/backend/src/metabase_enterprise/tenants/api.clj@@ -67,7 +67,7 @@(api.macros/defendpoint :get "/" :- [:map {:closed true} [:data [:sequential Tenant]]]"Get all tenants"[_- {:keys [status]} :- [:map+ {:keys [status]} :- [:map {:closed true}[:status {:default "all"} [:enum "all" "deactivated" "active"]]]_](api/check-403 (or api/*is-superuser?* (not (:tenant_id @api/*current-user*))))diff --git a/enterprise/backend/src/metabase_enterprise/tenants/models.clj b/enterprise/backend/src/metabase_enterprise/tenants/models.cljindex 2e625c1f227..51b5762f6ef 100644--- a/enterprise/backend/src/metabase_enterprise/tenants/models.clj+++ b/enterprise/backend/src/metabase_enterprise/tenants/models.clj@@ -4,6 +4,7 @@[metabase.api.common :as api][metabase.audit-app.core :as audit-app][metabase.collections.models.collection :as collection]+ [metabase.lib.schema.parameter :as lib.schema.parameter][metabase.models.interface :as mi][metabase.premium-features.core :refer [defenterprise]][metabase.util :as u]@@ -76,7 +77,7 @@therefore sees a permissive `:map-of` that keeps every entry, and the `:fn` re-checks the strict shape afterwards,so an `@`-prefixed key is a 400."[:and- [:map-of ms/KeywordOrString :any]+ (ms/string-keyed-map [:ref ::lib.schema.parameter/parameter.value])(mu/with-api-error-message[:fn #(mr/validate StrictAttributes %)](deferred-tru "attribute keys must be a keyword or string and must not start with `@`"))])diff --git a/enterprise/backend/src/metabase_enterprise/transforms_inspector/api.clj b/enterprise/backend/src/metabase_enterprise/transforms_inspector/api.cljindex 6a42402a786..b81ca9519a5 100644--- a/enterprise/backend/src/metabase_enterprise/transforms_inspector/api.clj+++ b/enterprise/backend/src/metabase_enterprise/transforms_inspector/api.clj@@ -62,7 +62,7 @@:- ::inspector.schema/discovery-response"Phase 1: Discover available lenses for a transform.Returns structural metadata and available lens types."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]](let [transform (api/read-check :model/Transform id)_ (transforms.core/check-feature-enabled! transform)result (tracing/with-span :transforms "transforms.inspector.discover"@@ -85,10 +85,10 @@"Phase 2: Get full lens contents for a transform.Returns sections, cards with dataset_query, and trigger definitions.Accepts optional params for drill lenses as query params."- [{:keys [id lens-id]} :- [:map+ [{:keys [id lens-id]} :- [:map {:closed true}[:id ms/PositiveInt][:lens-id ms/NonBlankString]]- params :- ::inspector.schema/lens-params]+ params :- ::inspector.schema/lens-params.request](let [transform (api/read-check :model/Transform id)_ (transforms.core/check-feature-enabled! transform)result (tracing/with-span :transforms "transforms.inspector.lens"@@ -116,14 +116,14 @@(api.macros/defendpoint :post "/:id/inspect/:lens-id/query":- (server/streaming-response-schema ::qp.schema/query-result)"Execute a query in the context of a transform inspector lens."- [{:keys [id lens-id]} :- [:map+ [{:keys [id lens-id]} :- [:map {:closed true}[:id ms/PositiveInt][:lens-id ms/NonBlankString]]_query-params{query :query, lens-params :lens_params}- :- [:map+ :- [:map {:closed true}[:query ::lib-be.schema/maybe-legacy-query]- [:lens_params {:optional true} [:maybe ::inspector.schema/lens-params]]]]+ [:lens_params {:optional true} [:maybe ::inspector.schema/lens-params.request]]]](let [transform (api/read-check :model/Transform id)](transforms.core/check-feature-enabled! transform)(let [info {:executed-by api/*current-user-id*diff --git a/enterprise/backend/src/metabase_enterprise/transforms_inspector/schema.clj b/enterprise/backend/src/metabase_enterprise/transforms_inspector/schema.cljindex 07378d020e2..b7631c76aa3 100644--- a/enterprise/backend/src/metabase_enterprise/transforms_inspector/schema.clj+++ b/enterprise/backend/src/metabase_enterprise/transforms_inspector/schema.clj@@ -196,9 +196,14 @@[:metadata {:optional true} ::trigger-metadata]])(mr/def ::lens-params- "Params passed to a drill lens (e.g. `{:join_step 2}`), emitted on drill-lens triggers and echoed back by the FE- to the lens endpoints. Scalar values only."- [:map-of :keyword [:maybe [:or :string :int :boolean :double]]])+ "Params passed to a drill lens, emitted on drill-lens triggers and echoed back by the FE to the lens endpoints.+ `:join_step` scopes the unmatched-rows lens to one join; it is the only param any lens takes."+ [:map {:closed true}+ [:join_step {:optional true} [:maybe :int]]])++(mr/def ::lens-params.request+ "[[::lens-params]] as the FE echoes them back to the lens endpoints."+ ::lens-params)(mr/def ::drill-lens-trigger"Definition for conditional drill lens availability.diff --git a/enterprise/backend/src/metabase_enterprise/transforms_python/api.clj b/enterprise/backend/src/metabase_enterprise/transforms_python/api.cljindex 5748034fec9..220dccc9560 100644--- a/enterprise/backend/src/metabase_enterprise/transforms_python/api.clj+++ b/enterprise/backend/src/metabase_enterprise/transforms_python/api.clj@@ -28,7 +28,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/library/:path""Get the Python library for user modules."- [{:keys [path]} :- [:map [:path ms/NonBlankString]]+ [{:keys [path]} :- [:map {:closed true} [:path ms/NonBlankString]]_query-params](get-python-library-by-path path))@@ -38,7 +38,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :put "/library/:path""Update the Python library source code for user modules."- [{:keys [path]} :- [:map [:path ms/NonBlankString]]+ [{:keys [path]} :- [:map {:closed true} [:path ms/NonBlankString]]_query-paramsbody :- [:map {:closed true}[:source :string]]]@@ -63,7 +63,7 @@per_input_row_limit]:or {output_row_limit 100per_input_row_limit 100}}- :- [:map+ :- [:map {:closed true}[:code :string][:source_tables [:sequential {:min 1} ::transforms-base.u/source-table-entry]][:output_row_limit {:optional true} [:and :int [:> 1] [:<= 100]]]diff --git a/enterprise/backend/src/metabase_enterprise/upload_management/api.clj b/enterprise/backend/src/metabase_enterprise/upload_management/api.cljindex a1d3377f481..aa9ace26508 100644--- a/enterprise/backend/src/metabase_enterprise/upload_management/api.clj+++ b/enterprise/backend/src/metabase_enterprise/upload_management/api.clj@@ -43,9 +43,9 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/tables/:id""Delete the uploaded table from the database, optionally archiving cards for which it is the primary source."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]- {:keys [archive-cards]} :- [:map+ {:keys [archive-cards]} :- [:map {:closed true}[:archive-cards {:optional true} [:maybe {:default false} ms/BooleanValue]]]](try;; To be idempotent, we do not check whether the table has already been deactivated.diff --git a/enterprise/backend/test/metabase_enterprise/cache/strategies_test.clj b/enterprise/backend/test/metabase_enterprise/cache/strategies_test.cljindex 2d1ac9588c0..677ad04e70d 100644--- a/enterprise/backend/test/metabase_enterprise/cache/strategies_test.clj+++ b/enterprise/backend/test/metabase_enterprise/cache/strategies_test.clj@@ -53,8 +53,7 @@(testing "strategy = duration"(let [query (assoc query :cache-strategy {:type :duration:duration 1- :unit "minutes"- :min_duration_ms 0})]+ :unit "minutes"})](testing "Results are stored and available immediately"(mt/with-clock #t "2024-02-13T10:00:00Z"(is (=? (mkres nil)diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/api_test.cljindex 45a96437215..3686d182122 100644--- a/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj+++ b/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj@@ -1201,8 +1201,8 @@:document {:type "doc":content [{:type "paragraph":content [{:type "smartLink"- :attrs {:entityId referenced-dashboard-id- :model "dashboard"}}]}]}+ :attrs {"entityId" referenced-dashboard-id+ "model" "dashboard"}}]}]}:content_type "application/json+vnd.prose-mirror"}](events/publish-event! :event/document-create {:object (t2/select-one :model/Document :id document-id) :user-id (mt/user->id :crowberto)})(deps.test/synchronously-run-backfill!)@@ -1220,8 +1220,8 @@:document {:type "doc":content [{:type "paragraph":content [{:type "smartLink"- :attrs {:entityId referenced-document-id- :model "document"}}]}]}+ :attrs {"entityId" referenced-document-id+ "model" "document"}}]}]}:content_type "application/json+vnd.prose-mirror"}](events/publish-event! :event/document-create {:object (t2/select-one :model/Document :id unreffed-document-id) :user-id (mt/user->id :crowberto)})(deps.test/synchronously-run-backfill!)diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/calculation_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/calculation_test.cljindex bf118d7da8b..27eff7f98e4 100644--- a/enterprise/backend/test/metabase_enterprise/dependencies/calculation_test.clj+++ b/enterprise/backend/test/metabase_enterprise/dependencies/calculation_test.clj@@ -436,16 +436,16 @@:document {:type "doc":content [{:type "paragraph":content [{:type "smartLink"- :attrs {:entityId card-id- :model "card"}}+ :attrs {"entityId" card-id+ "model" "card"}}{:type "smartLink"- :attrs {:entityId dashboard-id- :model "dashboard"}}+ :attrs {"entityId" dashboard-id+ "model" "dashboard"}}{:type "smartLink"- :attrs {:entityId products-id- :model "table"}}]}+ :attrs {"entityId" products-id+ "model" "table"}}]}{:type "cardEmbed"- :attrs {:id embedded-card-id}}]}}]+ :attrs {"id" embedded-card-id}}]}}](is (= {:card #{card-id embedded-card-id}:dashboard #{dashboard-id}:table #{products-id}}@@ -457,14 +457,14 @@:document {:type "doc":content [{:type "paragraph":content [{:type "smartLink"- :attrs {:entityId nil :model "card"}}+ :attrs {"entityId" nil "model" "card"}}{:type "smartLink"- :attrs {:entityId 0 :model "dashboard"}}+ :attrs {"entityId" 0 "model" "dashboard"}}{:type "smartLink"- :attrs {:entityId 17 :model "card"}}]}- {:type "cardEmbed" :attrs {:id nil}}- {:type "cardEmbed" :attrs {:id 0}}- {:type "cardEmbed" :attrs {:id 23}}]}}]+ :attrs {"entityId" 17 "model" "card"}}]}+ {:type "cardEmbed" :attrs {"id" nil}}+ {:type "cardEmbed" :attrs {"id" 0}}+ {:type "cardEmbed" :attrs {"id" 23}}]}}](is (= {:card #{17 23}}(calculation/calculate-deps :document document))))))@@ -662,7 +662,7 @@{:content_type prose-mirror/prose-mirror-content-type:document {:type "doc":content [{:type "smartLink"- :attrs {:model "card" :entityId {:raw "x"}}}]}}))))+ :attrs {"model" "card" "entityId" {:raw "x"}}}]}}))))(testing "a dashcard click_behavior whose targetId is a map is dropped"(let [deps (calculation/calculate-deps*:dashboarddiff --git a/enterprise/backend/test/metabase_enterprise/dependencies/events_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/events_test.cljindex c8a18c2af62..943682dc3a8 100644--- a/enterprise/backend/test/metabase_enterprise/dependencies/events_test.clj+++ b/enterprise/backend/test/metabase_enterprise/dependencies/events_test.clj@@ -165,10 +165,10 @@:document {:type "doc":content [{:type "paragraph":content [{:type "smartLink"- :attrs {:entityId card-id- :model "card"}}]}+ :attrs {"entityId" card-id+ "model" "card"}}]}{:type "cardEmbed"- :attrs {:id embedded-card-id}}]}}]+ :attrs {"id" embedded-card-id}}]}}](events/publish-event! :event/document-create {:object document :user-id api/*current-user-id*})(assert-stale :document document-id)(deps.test/synchronously-run-backfill!)@@ -185,11 +185,11 @@(let [updated-doc (assoc document :document {:type "doc":content [{:type "paragraph":content [{:type "smartLink"- :attrs {:entityId dashboard-id- :model "dashboard"}}+ :attrs {"entityId" dashboard-id+ "model" "dashboard"}}{:type "smartLink"- :attrs {:entityId products-id- :model "table"}}]}]})]+ :attrs {"entityId" products-id+ "model" "table"}}]}]})](t2/update! :model/Document document-id updated-doc)(events/publish-event! :event/document-update {:object updated-doc :user-id api/*current-user-id*})(deps.test/synchronously-run-backfill!)diff --git a/enterprise/backend/test/metabase_enterprise/serialization/v2/extract_test.clj b/enterprise/backend/test/metabase_enterprise/serialization/v2/extract_test.cljindex 11ea564d05e..4168d017321 100644--- a/enterprise/backend/test/metabase_enterprise/serialization/v2/extract_test.clj+++ b/enterprise/backend/test/metabase_enterprise/serialization/v2/extract_test.clj@@ -618,7 +618,7 @@:name "snippet",:snippet-id s1-id,:snippet-name "snip",- :type :number}}})}]+ :type :snippet}}})}](testing "native query snippets"(testing "can belong to :snippets collections"(let [ser (serdes/extract-one "NativeQuerySnippet" {} (t2/select-one :model/NativeQuerySnippet :id s1-id))]@@ -2075,16 +2075,16 @@:model/Table table {:name "linked_table"}](t2/update! :model/Document :id (u/the-id document) {:document {:type "doc":content [{:type "cardEmbed"- :attrs {:id (u/the-id card)}}+ :attrs {"id" (u/the-id card)}}{:type "smartLink"- :attrs {:entityId (u/the-id linked-card)- :model "card"}}+ :attrs {"entityId" (u/the-id linked-card)+ "model" "card"}}{:type "smartLink"- :attrs {:entityId (u/the-id table)- :model "table"}}+ :attrs {"entityId" (u/the-id table)+ "model" "table"}}{:type "smartLink"- :attrs {:entityId (u/the-id dashboard)- :model "dashboard"}}]}})+ :attrs {"entityId" (u/the-id dashboard)+ "model" "dashboard"}}]}})(testing "document extraction"(let [ser (ts/extract-one "Document" (u/the-id document))](is (=? {:serdes/meta [{:model "Document" :id (:entity_id document)}]@@ -2092,16 +2092,16 @@:entity_id (:entity_id document):document {:type "doc":content [{:type "cardEmbed"- :attrs {:id [{:model "Card" :id (:entity_id card)}]}}+ :attrs {"id" [{:model "Card" :id (:entity_id card)}]}}{:type "smartLink"- :attrs {:entityId [{:model "Card" :id (:entity_id linked-card)}]- :model "card"}}+ :attrs {"entityId" [{:model "Card" :id (:entity_id linked-card)}]+ "model" "card"}}{:type "smartLink"- :attrs {:entityId (serdes/generate-path "Table" table)- :model "table"}}+ :attrs {"entityId" (serdes/generate-path "Table" table)+ "model" "table"}}{:type "smartLink"- :attrs {:entityId [{:model "Dashboard" :id (:entity_id dashboard)}]- :model "dashboard"}}]}+ :attrs {"entityId" [{:model "Dashboard" :id (:entity_id dashboard)}]+ "model" "dashboard"}}]}:creator_id (:email user):collection_id (:entity_id collection):content_type "application/json+vnd.prose-mirror"diff --git a/modules/drivers/bigquery-cloud-sdk/src/metabase/driver/bigquery_cloud_sdk.clj b/modules/drivers/bigquery-cloud-sdk/src/metabase/driver/bigquery_cloud_sdk.cljindex dc7631e82f3..da2c4f408ed 100644--- a/modules/drivers/bigquery-cloud-sdk/src/metabase/driver/bigquery_cloud_sdk.clj+++ b/modules/drivers/bigquery-cloud-sdk/src/metabase/driver/bigquery_cloud_sdk.clj@@ -993,7 +993,8 @@columns (for [column (some-> schema .getFields fields->metabase-field-info)](-> column(set/rename-keys {:base-type :base_type})- (dissoc :database-type :database-position)))+ ;; `:nested-fields` describes a RECORD's sub-fields for sync, not a result column+ (dissoc :database-type :database-position :nested-fields)))cols {:cols columns}results (eduction (map (fn [^FieldValueList row](perf/mapv parse-field-value row parsers)))diff --git a/modules/drivers/bigquery-cloud-sdk/test/metabase/driver/bigquery_cloud_sdk_test.clj b/modules/drivers/bigquery-cloud-sdk/test/metabase/driver/bigquery_cloud_sdk_test.cljindex ef53a0300d1..1d4883f3656 100644--- a/modules/drivers/bigquery-cloud-sdk/test/metabase/driver/bigquery_cloud_sdk_test.clj+++ b/modules/drivers/bigquery-cloud-sdk/test/metabase/driver/bigquery_cloud_sdk_test.clj@@ -1580,8 +1580,8 @@(mt/run-mbql-query bigthings{:aggregation [[:count]]:breakout [[:field %bigthings.bd- {:type :type/Decimal- :binning {:strategy "default"}}]]})))))))+ {:base-type :type/Decimal+ :binning {:strategy :default}}]]})))))))(deftest bigquery-process-stop-test(mt/test-driverdiff --git a/modules/drivers/mongo/test/metabase/driver/mongo/execute_test.clj b/modules/drivers/mongo/test/metabase/driver/mongo/execute_test.cljindex ec8b1723d54..5df295d1ae6 100644--- a/modules/drivers/mongo/test/metabase/driver/mongo/execute_test.clj+++ b/modules/drivers/mongo/test/metabase/driver/mongo/execute_test.clj@@ -120,7 +120,7 @@(let [model-based-query (-> (mt/mbql-query orders {:source-table (str "card__" (:id c))})(update :cache_strategy assoc;; Enable caching for current query- :avg-execution-time 5000+ :avg-execution-ms 5000:min_duration_ms 1:multiplier 100000:type :ttl))]diff --git a/src/metabase/actions/execution.clj b/src/metabase/actions/execution.cljindex fe95bdf4136..0239ed92964 100644--- a/src/metabase/actions/execution.clj+++ b/src/metabase/actions/execution.clj@@ -40,7 +40,10 @@(driver.conn/with-write-connection(try(let [parameters (for [parameter (:parameters action)]- (assoc parameter :value (get request-parameters (:id parameter))))+ ;; the query gets the parameter values, not the frontend's widget settings+ (-> parameter+ (select-keys [:id :type :target :slug :name :default :required :options])+ (assoc :value (get request-parameters (:id parameter)))))query (-> query(assoc :parameters parameters))](binding [qp.perms/*card-id* model-id]diff --git a/src/metabase/actions/models.clj b/src/metabase/actions/models.cljindex 90e252673d3..91665ee7fd3 100644--- a/src/metabase/actions/models.clj+++ b/src/metabase/actions/models.clj@@ -53,11 +53,18 @@(m/update-existing viz-settings :fields update-keys u/qualified-name))mi/json-out-with-keywordization)})+(def ^:private transform-action-parameters+ "Like `parameters/transform-parameters`, but normalizes against `::actions.schema/action.parameters`: an implicit+ action's parameters carry the annotations [[implicit-action-parameters]] computes them with."+ {:in (comp mi/json-in actions.schema/normalize-parameters)+ :out (comp (mi/catch-normalization-exceptions actions.schema/normalize-parameters)+ mi/json-out-with-keywordization)})+(t2/deftransforms :model/Action{:type mi/transform-keyword:public_uuid (mi/transform-encrypted-text "action.public_uuid"):parameter_mappings parameters/transform-parameter-mappings- :parameters parameters/transform-parameters+ :parameters transform-action-parameters:visualization_settings transform-action-visualization-settings})(t2/deftransforms :model/QueryActiondiff --git a/src/metabase/actions/schema.clj b/src/metabase/actions/schema.cljindex ce203b98cc9..5d9506c01d1 100644--- a/src/metabase/actions/schema.clj+++ b/src/metabase/actions/schema.clj@@ -1,10 +1,12 @@(ns metabase.actions.schema(:require[metabase.lib-be.schema :as lib-be.schema]+ [metabase.lib.core :as lib][metabase.lib.schema.common :as lib.schema.common][metabase.lib.schema.id :as lib.schema.id][metabase.lib.schema.parameter :as lib.schema.parameter][metabase.parameters.schema :as parameters.schema]+ [metabase.users.schema :as users.schema][metabase.util.i18n :refer [deferred-tru]][metabase.util.json :as json][metabase.util.malli :as mu]@@ -37,7 +39,7 @@(cond-> {:description message}decode (assoc :decode/api decode))[:and- [:map-of decoded-key-schema :any]+ [:map-of decoded-key-schema value-schema][:fn {:error/fn (fn [_ _] message)}#(mr/validate strict %)]]]))@@ -52,18 +54,29 @@(def ^:private execute-parameter-values-message(deferred-tru "value must map parameter ids to scalar values."))+(def ^:private execute-parameter-value+ "A parameter value on an execute request. [[::lib.schema.parameter/parameter.value]] would do, but its normalizer+ turns a collection into `nil` while the request is decoded, and the action would then run with the parameter missing+ instead of the request being rejected."+ [:or+ [:ref ::lib.schema.parameter/parameter.value.scalar]+ [:sequential [:ref ::lib.schema.parameter/parameter.value.scalar]]])+(mr/def ::execute-parameter-values+ "Parameter values for executing an action, keyed by the action's parameter names -- string-keyed, like every map whose+ keys are not ours to declare (see [[metabase.util.malli.schema/string-keyed-map]])."(parameter-values-schema- {:decoded-key-schema :keyword- :key-schema :keyword- :value-schema [:ref ::lib.schema.parameter/parameter.value]- :message execute-parameter-values-message}))+ {:decoded-key-schema :string+ :key-schema :string+ :value-schema execute-parameter-value+ :message execute-parameter-values-message+ :decode (fn [m] (cond-> m (map? m) (update-keys name)))}))(mr/def ::execute-parameter-values.string-keys(parameter-values-schema{:decoded-key-schema :string:key-schema [:ref ::lib.schema.parameter/id]- :value-schema [:ref ::lib.schema.parameter/parameter.value]+ :value-schema execute-parameter-value:message execute-parameter-values-message}))(mr/def ::type@@ -94,10 +107,11 @@(def ^:private http-action-entries[[:template {:optional true} [:maybe ::http-action.template]][:response_handle {:optional true} [:maybe ::http-action.json-query]]- [:error_handle {:optional true} [:maybe ::http-action.json-query]]])+ [:error_handle {:optional true} [:maybe ::http-action.json-query]]+ [:disabled {:optional true} :boolean]])(mr/def ::http-action- (into [:map] http-action-entries))+ (into [:map {:closed true}] http-action-entries))(mr/def ::implicit-action.kind[:enum@@ -114,14 +128,35 @@[[:kind {:optional true} [:maybe ::implicit-action.kind]]])(mr/def ::implicit-action- (into [:map] implicit-action-entries))+ (into [:map {:closed true}] implicit-action-entries))(def ^:private query-action-entries[[:database_id {:optional true} [:maybe ::lib.schema.id/database]][:dataset_query {:optional true} [:maybe ::lib-be.schema/maybe-legacy-or-empty-query]]])(mr/def ::query-action- (into [:map] query-action-entries))+ (into [:map {:closed true}] query-action-entries))++(mr/def ::action.parameter+ "One entry of an Action's `:parameters`. An implicit action's are computed from the model's Fields rather than+ authored, and carry annotations `metabase.actions.models/implicit-action-parameters` adds and+ `select-actions-implicit-params` reads when it filters and orders them."+ [:merge+ ::parameters.schema/parameter+ [:map+ [:is-auto-increment {:optional true} [:maybe :boolean]]+ [:metabase.actions.models/field-id {:optional true} [:maybe ::lib.schema.id/field]]+ [:metabase.actions.models/pk? {:optional true} [:maybe :boolean]]]])++(mr/def ::action.parameters+ [:sequential [:ref ::action.parameter]])++(mu/defn normalize-parameters :- ::action.parameters+ "Normalize an Action's `:parameters` coming out of the application database or in via an API request. Like+ [[metabase.parameters.schema/normalize-parameters]], but keeps the annotations an implicit action's parameters+ carry."+ [parameters]+ (lib/normalize ::action.parameters parameters))(mu/defn- action-schema [schema-type :- [:enum :select :update :insert]];; `required-for-insert` = you have to specify this when you insert a row@@ -135,7 +170,8 @@[]cat[(case schema-type- :select [[:id ::id]]+ :select [[:id ::id]+ [:creator {:optional true} [:maybe ::users.schema/user]]]:update [[:id {:optional true} ::id]]:insert nil)[[:name required-for-insert :string]@@ -143,28 +179,27 @@[:model_id required-for-insert ::lib.schema.id/card][:archived {:optional true} :boolean][:description {:optional true} [:maybe :string]]- [:parameters {:optional true} [:maybe ::parameters.schema/parameters]]+ [:parameters {:optional true} [:maybe [:sequential ::action.parameter]]]+ [:database_id {:optional true} [:maybe ::lib.schema.id/database]][:parameter_mappings {:optional true} [:maybe ::parameters.schema/parameter-mappings]]- [:visualization_settings {:optional true} [:maybe map?]]]- (when (= schema-type :select)- ;; technically these are always required, but they are not always selected.- [[:created_at {:optional true} (ms/InstanceOfClass java.time.temporal.Temporal)]- [:updated_at {:optional true} (ms/InstanceOfClass java.time.temporal.Temporal)]- ;; TODO (Cam 10/2/25) -- these are things you can set in updates or inserts but aren't things you can pass in- ;; via the API... Maybe we need even more versions of this schema e.g. `::action.for-update.api` versus- ;; `::action.for-update.internal`. or something. Idk.- [:public_uuid {:optional true} [:maybe ms/UUIDString]]- [:made_public_by_id {:optional true} [:maybe ::lib.schema.id/user]]- [:creator_id {:optional true} [:maybe ::lib.schema.id/user]]])])]+ [:visualization_settings {:optional true} [:maybe ms/VisualizationSettings]]]+ [[:created_at {:optional true} (ms/InstanceOfClass java.time.temporal.Temporal)]+ [:updated_at {:optional true} (ms/InstanceOfClass java.time.temporal.Temporal)]+ [:public_uuid {:optional true} [:maybe ms/UUIDString]]+ [:public_uuid_prefix {:optional true} [:maybe :string]]+ [:made_public_by_id {:optional true} [:maybe ::lib.schema.id/user]]+ [:creator_id {:optional true} [:maybe ::lib.schema.id/user]]+ [:entity_id {:optional true} [:maybe :string]]+ [:legacy_query {:optional true} [:maybe :string]]]])][:merge- (into [:map] common)+ (into [:map {:closed true}] common)[:multi {:decode/normalize lib.schema.common/normalize-map-no-kebab-case:dispatch (comp keyword :type)}- [:http (into [:map] http-action-entries)]- [:implicit (into [:map] implicit-action-entries)]- [:query (into [:map] query-action-entries)]+ [:http (into [:map {:closed true}] http-action-entries)]+ [:implicit (into [:map {:closed true}] implicit-action-entries)]+ [:query (into [:map {:closed true}] query-action-entries)];; a partial update need not repeat `:type`; accept every type's keys rather than dropping them- [nil (into [:map] cat [http-action-entries implicit-action-entries query-action-entries])]]]))+ [nil (into [:map {:closed true}] cat [http-action-entries implicit-action-entries query-action-entries])]]]))(mr/def ::action"An Action as it should appear when we `SELECT` it from the app DB."diff --git a/src/metabase/actions/types.clj b/src/metabase/actions/types.cljindex d8237b62c0b..7a60ea04160 100644--- a/src/metabase/actions/types.clj+++ b/src/metabase/actions/types.clj@@ -1,6 +1,5 @@(ns metabase.actions.types(:require- [malli.util :as mut][metabase.util.malli.registry :as mr][metabase.util.malli.schema :as ms]))@@ -21,10 +20,20 @@[:map [:webhook-id ms/PositiveInt]][:map [:unknown [:enum :model-action]]]])+(def ^:private raw-scope-keys+ (mapv (comp first second) raw-scope-types))+;; Relaxed, as we support it being(mr/def ::scope.raw- (into [:or] (for [s raw-scope-types]- (mut/merge s [:map [:type {:optional true} :keyword]]))))+ [:and+ (into [:map {:closed true}+ [:type {:optional true} :keyword]+ [:collection-id {:optional true} ::fk-or-missing-id]+ [:database-id {:optional true} ::fk-or-missing-id]]+ (for [[_ [k schema]] raw-scope-types]+ [k {:optional true} schema]))+ [:fn {:error/message "scope must name at least one of its ids"}+ (fn [scope] (some #(contains? scope %) raw-scope-keys))]]);; All derivable or unknown data removed, so that this is safe to use as a key.(mr/def ::scope.normalizeddiff --git a/src/metabase/actions_rest/api.clj b/src/metabase/actions_rest/api.cljindex 9189e294ccd..dca582e9b5b 100644--- a/src/metabase/actions_rest/api.clj+++ b/src/metabase/actions_rest/api.clj@@ -33,7 +33,7 @@"Returns actions that can be used for QueryActions. By default lists all viewable actions. Pass optional`?model-id=<model-id>` to limit to actions on a particular model."[_route-params- {:keys [model-id]} :- [:map+ {:keys [model-id]} :- [:map {:closed true}[:model-id {:optional true} [:maybe ::lib.schema.id/card]]]](letfn [(actions-for [models](if (seq models)@@ -55,7 +55,7 @@(api.macros/defendpoint :get "/:action-id" :- ::actions.schema/action"Fetch an Action."- [{:keys [action-id]} :- [:map+ [{:keys [action-id]} :- [:map {:closed true}[:action-id ms/PositiveInt]]](-> (actions/select-action :id action-id :archived false)(t2/hydrate :creator)@@ -67,7 +67,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/:action-id""Delete an Action."- [{:keys [action-id]} :- [:map+ [{:keys [action-id]} :- [:map {:closed true}[:action-id ms/PositiveInt]]](let [action (api/write-check :model/Action action-id)](analytics/track-event! :snowplow/action@@ -120,7 +120,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :put "/:id""Update an Action."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ::actions.schema/id]]_query-paramsaction :- ::actions.schema/action.for-update]@@ -159,7 +159,7 @@"Generate publicly-accessible links for this Action. Returns UUID to be used in public links. (If thisAction has already been shared, it will return the existing public link rather than creating a new one.) Publicsharing must be enabled."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ::actions.schema/id]]](api/check-superuser)(public-sharing.validation/check-public-sharing-enabled)@@ -178,7 +178,7 @@:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/:id/public_link""Delete the publicly-accessible link to this Dashboard."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ::actions.schema/id]]];; check the /application/setting permission, not superuser because removing a public link is possible from;; /admin/settings@@ -193,10 +193,10 @@"Fetches the values for filling in execution parameters. Pass PK parameters and values to select.Parameters are sent in the request body rather than the query string so their values stay out of URLs and logs."- [{:keys [action-id]} :- [:map+ [{:keys [action-id]} :- [:map {:closed true}[:action-id ms/PositiveInt]]_query-params- {:keys [parameters]} :- [:map+ {:keys [parameters]} :- [:map {:closed true}[:parameters ::actions.schema/prefetch-parameter-values]]](actions/check-actions-enabled! action-id)(-> (actions/select-action :id action-id :archived false)@@ -235,10 +235,10 @@"Execute the Action.`parameters` should be the mapped dashboard parameters with values."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id [:or ::actions.schema/id ms/NanoIdString]]]_query-params- {:keys [parameters], :as _body} :- [:maybe [:map+ {:keys [parameters], :as _body} :- [:maybe [:map {:closed true}[:parameters {:optional true} [:maybe ::actions.schema/execute-parameter-values]]]]](let [resolved-id (eid-translation/->id-or-404 :action id){:keys [type] :as action} (api/read-check (actions/select-action :id resolved-id :archived false))]diff --git a/src/metabase/activity_feed/api.clj b/src/metabase/activity_feed/api.cljindex 34c051db607..1e1204f7a58 100644--- a/src/metabase/activity_feed/api.clj+++ b/src/metabase/activity_feed/api.clj@@ -84,7 +84,7 @@"Get a list of recent items the current user has been viewing most recently under the `:recents` key.Allows for filtering by context: views or selections"[_route-params- {:keys [context include_metadata]} :- [:map+ {:keys [context include_metadata]} :- [:map {:closed true}[:context (ms/QueryVectorOf [:enum :selections :views])][:include_metadata {:default false} [:maybe :boolean]]]](when-not (seq context) (throw (ex-info "context is required." {})))@@ -98,7 +98,7 @@"Adds a model to the list of recently selected items."[_route-params_query-params- {:keys [model model_id context]} :- [:map+ {:keys [model model_id context]} :- [:map {:closed true}[:model (into [:enum] recent-views/rv-models)][:model_id ms/PositiveInt][:context [:enum :selection]]]]diff --git a/src/metabase/agent_api/api.clj b/src/metabase/agent_api/api.cljindex 80906880ef6..519f54827e3 100644--- a/src/metabase/agent_api/api.clj+++ b/src/metabase/agent_api/api.clj@@ -163,7 +163,7 @@_query-params{term-queries :term_queriessemantic-queries :semantic_queries}- :- [:map+ :- [:map {:closed true}[:term_queries {:optional true:tool/description "Keyword search queries as an array of strings, for example [\"orders\", \"revenue\"]."}[:maybe [:or [:sequential ms/NonBlankString] ms/NonBlankString]]]@@ -195,7 +195,7 @@`referenced_entities` envelope from before the repr migration) are dropped during requestdecoding, so a caller still sending the old shape is served.- The inner `:query` value is intentionally typed as an open map ([[ms/Map]]) at this boundary+ The inner `:query` value is an opaque, string-keyed JSON object ([[ms/OpaqueJSONObject]]) at this boundaryrather than `::lib.schema/external-query`. Being open matters: a closed map with no declaredentries would have every key stripped before the handler saw it. Reasons for not naming thereal schema:@@ -212,7 +212,7 @@[:map {:closed true}[:query {:tool/description (str "A Metabase MBQL 5 query as a JSON object. See the ""`construct_notebook_query` tool for the format reference.")}- ms/Map]+ ms/OpaqueJSONObject];; The user's original message, when available, captured so `visualize_query` can later;; surface it back to the iframe alongside the query body for feedback submission. The MCP;; layer stores it with the handle (see `metabase.mcp.tools/make-store-construct-query-result`).@@ -567,7 +567,7 @@(mr/def ::execute-query-request"Request schema for /v1/execute. Accepts a base64-encoded MBQL query."- [:map+ [:map {:closed true}[:query {:tool/description "A base64-encoded query string returned by /v1/construct-query. Do not construct this value manually."}ms/NonBlankString]])@@ -630,7 +630,7 @@(mr/def ::execute-sql-request"Request shape for /v1/execute-sql. The LLM passes a raw SQL string against a target database."- [:map+ [:map {:closed true}[:database_id ms/PositiveInt][:sql ms/NonBlankString]])@@ -672,7 +672,7 @@(mr/def ::read-resource-request"Request shape for /v1/read-resource. Accepts up to 5 metabase:// URIs."- [:map+ [:map {:closed true}[:uris [:sequential ms/NonBlankString]]])(mr/def ::read-resource-item@@ -874,13 +874,13 @@(update-card-response (agent-api.db/card id))))(mr/def ::create-question-request- [:map+ [:map {:closed true}[:name ms/NonBlankString][:query ms/NonBlankString][:display {:optional true} [:maybe ::card-display]][:description {:optional true} [:maybe :string]][:collection_id {:optional true} [:maybe ms/PositiveInt]]- [:visualization_settings {:optional true} [:maybe ms/Map]]])+ [:visualization_settings {:optional true} [:maybe ms/VisualizationSettings]]])(mr/def ::create-question-response[:map@@ -924,13 +924,13 @@;;; -------------------------------------------------- Create Metric -------------------------------------------------(mr/def ::create-metric-request- [:map+ [:map {:closed true}[:name ms/NonBlankString][:query ms/NonBlankString][:display {:optional true} [:maybe ::card-display]][:description {:optional true} [:maybe :string]][:collection_id {:optional true} [:maybe ms/PositiveInt]]- [:visualization_settings {:optional true} [:maybe ms/Map]]])+ [:visualization_settings {:optional true} [:maybe ms/VisualizationSettings]]])(mr/def ::create-metric-response[:map@@ -991,12 +991,12 @@"Patch shape for `update_metric`. Every field is optional; only the fields the callerpasses are changed. `:query` accepts a base64-encoded MBQL string (or query_handle UUIDresolved upstream in the MCP layer) and must still describe a valid metric."- [:map+ [:map {:closed true}[:name {:optional true} [:maybe ms/NonBlankString]][:description {:optional true} [:maybe :string]][:collection_id {:optional true} [:maybe ms/PositiveInt]][:display {:optional true} [:maybe ::card-display]]- [:visualization_settings {:optional true} [:maybe ms/Map]]+ [:visualization_settings {:optional true} [:maybe ms/VisualizationSettings]][:archived {:optional true} [:maybe :boolean]][:query {:optional true} [:maybe ms/NonBlankString]]])@@ -1032,7 +1032,7 @@"(a query_handle from construct_query) - it must still have exactly one ""aggregation and at most one date/datetime grouping. The target must be a ""metric; use update_question for regular questions.")}}- [{:keys [id]} :- [:map [:id ms/PositiveInt]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]_query-paramsbody :- ::update-metric-request](let [card-before-update (api/write-check :model/Card id)]@@ -1049,12 +1049,12 @@"Patch shape for `update_question`. Every field is optional; only the fields the callerpasses are changed. `:query` accepts a base64-encoded MBQL string (or query_handle UUIDresolved upstream in the MCP layer)."- [:map+ [:map {:closed true}[:name {:optional true} [:maybe ms/NonBlankString]][:description {:optional true} [:maybe :string]][:collection_id {:optional true} [:maybe ms/PositiveInt]][:display {:optional true} [:maybe ::card-display]]- [:visualization_settings {:optional true} [:maybe ms/Map]]+ [:visualization_settings {:optional true} [:maybe ms/VisualizationSettings]][:archived {:optional true} [:maybe :boolean]][:query {:optional true} [:maybe ms/NonBlankString]]])@@ -1088,7 +1088,7 @@"delete or remove a question; set archived false to restore. ""To replace the underlying query, pass query ""(a query_handle from construct_query or construct_native_query).")}}- [{:keys [id]} :- [:map [:id ms/PositiveInt]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]_query-paramsbody :- ::update-question-request](apply-agent-card-patch! (api/write-check :model/Card id) body nil))@@ -1124,7 +1124,7 @@"if the question takes parameters or template-tag input, this returns an ""error."):annotations {:read-only? true :idempotent? true}}}- [{:keys [id]} :- [:map [:id ms/PositiveInt]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]_query-params_body](let [card (api/read-check :model/Card id)]@@ -1154,7 +1154,7 @@(autoplace/get-position-for-new-dashcard placed display)))(mr/def ::create-dashboard-request- [:map+ [:map {:closed true}[:name ms/NonBlankString][:description {:optional true} [:maybe :string]][:collection_id {:optional true} [:maybe ms/PositiveInt]]@@ -1292,7 +1292,7 @@(mr/def ::update-dashboard-request"Patch shape for `update_dashboard`. Metadata fields and an optional `dashcards` list ofadd/add_heading/add_text/update_text/remove/move mutations applied in order."- [:map+ [:map {:closed true}[:name {:optional true} [:maybe ms/NonBlankString]][:description {:optional true} [:maybe :string]][:collection_id {:optional true} [:maybe ms/PositiveInt]]@@ -1505,7 +1505,7 @@"The response dashcard_ids lists all dashcards in row/col order; ""metabase://dashboard/{id}/items (via read_resource) shows each ""dashcard with its dashcard_id.")}}- [{:keys [id]} :- [:map [:id ms/PositiveInt]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]_query-paramsbody :- ::update-dashboard-request](let [current-dash (api/write-check :model/Dashboard id)@@ -1581,7 +1581,7 @@"Request shape for `create_collection`. `:parent_collection_id` is named separately fromthe internal `:parent_id` field to make the LLM-facing API less ambiguous (the caller issaying \"put it under this parent\", not echoing back a server-set field)."- [:map+ [:map {:closed true}[:name ms/NonBlankString][:description {:optional true} [:maybe :string]][:parent_collection_id {:optional true} [:maybe ms/PositiveInt]]])diff --git a/src/metabase/ai_tracing/api.clj b/src/metabase/ai_tracing/api.cljindex 8d83aec704e..e13dd26715e 100644--- a/src/metabase/ai_tracing/api.clj+++ b/src/metabase/ai_tracing/api.clj@@ -40,7 +40,7 @@served only when `MB_AI_EVAL_CAPTURE` is enabled.";; Bound the length here too (not only via `trace-file`): `session-id` is a raw user-supplied path;; segment, and `ait/max-session-id-length` is the single cap enforced at both write and read.- [{:keys [session-id]} :- [:map [:session-id [:string {:min 1, :max ait/max-session-id-length}]]]]+ [{:keys [session-id]} :- [:map {:closed true} [:session-id [:string {:min 1, :max ait/max-session-id-length}]]]](api/check-superuser)(let [f (trace-file session-id)](api/check (and f (.exists ^File f)) [404 (tru "Eval trace not found")])diff --git a/src/metabase/analytics/api.clj b/src/metabase/analytics/api.cljindex 96cd887bafe..e818fcde97d 100644--- a/src/metabase/analytics/api.clj+++ b/src/metabase/analytics/api.clj@@ -4,7 +4,8 @@[metabase.analytics.stats :as stats][metabase.api.macros :as api.macros][metabase.permissions.core :as perms]- [metabase.util.log :as log]))+ [metabase.util.log :as log]+ [metabase.util.malli.schema :as ms]));; I don't think this endpoint is actually used anywhere for anything.;;@@ -20,18 +21,19 @@(stats/legacy-anonymous-usage-stats))(def ^:private InternalAnalyticsEvent- [:map+ [:map {:closed true}[:op [:enum :inc :dec :set :observe :clear]][:metric :keyword]- [:labels {:optional true} [:maybe [:map-of :keyword :string]]]+ [:labels {:optional true} [:maybe (ms/string-keyed-map :string)]][:amount {:optional true} [:maybe number?]]])(api.macros/defendpoint :post "/internal" :- :nil"Receive a batch of internal analytics events from the frontend and record them as Prometheus metrics."[_route-params_query-params- {:keys [events]} :- [:map [:events [:sequential InternalAnalyticsEvent]]]]- (doseq [{:keys [op metric labels amount]} events]+ {:keys [events]} :- [:map {:closed true} [:events [:sequential InternalAnalyticsEvent]]]]+ (doseq [{:keys [op metric labels amount]} events+ :let [labels (some-> labels (update-keys keyword))]](try(case op:inc (prometheus/inc! metric labels (or amount 1))diff --git a/src/metabase/analytics/api/proxy.clj b/src/metabase/analytics/api/proxy.cljindex 09fa0f654e6..8133015063f 100644--- a/src/metabase/analytics/api/proxy.clj+++ b/src/metabase/analytics/api/proxy.clj@@ -22,9 +22,9 @@"Schema for the Snowplow `tp2` request envelope, mirroring the collector's own `payload_data` JSON schema: the igluURI of that schema plus one entry per event, keyed by tracker field name (`e`, `p`, `tv`, `ue_px`, ...). The trackerstringifies every field value, so the values are always strings."- [:map+ [:map {:closed true}[:schema ms/NonBlankString]- [:data [:sequential {:max 100} [:map-of :keyword :string]]]])+ [:data [:sequential {:max 100} (ms/string-keyed-map :string)]]]);; No response schema: the body is an opaque relay of the collector's own response. The tracker drives its retry;; outbox off the HTTP status, so we forward status + body verbatim; a fabricated schema would be misleading.diff --git a/src/metabase/api/common.clj b/src/metabase/api/common.cljindex 6004728f7ce..d170fcda6e9 100644--- a/src/metabase/api/common.clj+++ b/src/metabase/api/common.clj@@ -261,6 +261,15 @@([arg msg](check arg [400 msg])))+(defn check-no-dropped-entries+ "Throw a 400 when request decoding dropped entries from a map whose keys are not declared. `raw` is the map as the+ client sent it, taken from the request body; `decoded` is the map the endpoint received. The request decoder removes+ an entry of such a map whose key or value does not fit the schema instead of rejecting the request, so an endpoint+ that must not silently ignore a bad entry compares the two."+ [raw decoded]+ (check-400 (or (not (map? raw)) (= (count raw) (count decoded)))+ (tru "The request contains keys or values this endpoint does not accept.")))+;; #### GENERIC 404 RESPONSE HELPERS(def ^:private generic-404[404 (deferred-tru "Not found.")])diff --git a/src/metabase/api/macros.clj b/src/metabase/api/macros.cljindex 679d62fa64f..3071ce55d26 100644--- a/src/metabase/api/macros.clj+++ b/src/metabase/api/macros.clj@@ -27,6 +27,7 @@[malli.util][medley.core :as m][metabase.api.common.internal]+ [metabase.api.macros.defendpoint.closed-schemas :as closed-schemas][metabase.api.macros.defendpoint.open-api][metabase.api.macros.scope][metabase.api.open-api :as open-api]@@ -239,9 +240,9 @@:raise symbol?))))))(def ^:private default-params-schema- "Schema for route params, query params, and the request body when an endpoint binds them without declaring one. A- bare `:map` strips every key on decode, so endpoints have to declare the keys they read."- [:map])+ "Schema for route params, query params, and the request body when an endpoint binds them without declaring one. It+ declares no keys, so every key is stripped on decode: an endpoint has to declare the keys it reads."+ [:map {:closed true}])(mu/defn- parse-params :- ::params[params]@@ -319,7 +320,7 @@{:name :normalize};; A param map drops the keys it doesn't declare instead of rejecting them, so a client sending a field the;; endpoint has no use for is still served -- which in turn means every key an endpoint reads has to be declared,- ;; at every level of nesting. `ms/Map` (and any other `{:closed false}` map) opts out, for values we deliberately+ ;; at every level of nesting. A `{:closed false}` map opts out, for values we deliberately;; pass through as they arrived: a query, viz settings, database details, a settings bag.;;;; Runs last: `:normalize` renames keys into the ones the schema declares, so stripping any earlier would drop@@ -512,14 +513,16 @@"Impl for [[endpoint-core-fn]]: validate the schemas used for validation at evaluation time, so we can get instantfeedback if they're bad as opposed to waiting for someone to actually use the endpoint."[schema-type schema]- (try- (mc/schema schema)- (catch Throwable e#- (throw (ex-info (format "Invalid %s schema: %s\n\n%s"- (name schema-type)- (ex-message e#)- (u/pprint-to-str schema))- {:schema schema})))))+ (let [schema (try+ (mc/schema schema)+ (catch Throwable e#+ (throw (ex-info (format "Invalid %s schema: %s\n\n%s"+ (name schema-type)+ (ex-message e#)+ (u/pprint-to-str schema))+ {:schema schema}))))]+ (closed-schemas/check! schema-type schema)+ schema))(defmacro endpoint-core-fn-with-optimized-schemas"Helper macro for [[endpoint-core-fn]]. This is not strictly necessary, but improves performance somewhat bydiff --git a/src/metabase/api/macros/defendpoint/closed_schemas.clj b/src/metabase/api/macros/defendpoint/closed_schemas.cljnew file mode 100644index 00000000000..761671ad4e0--- /dev/null+++ b/src/metabase/api/macros/defendpoint/closed_schemas.clj@@ -0,0 +1,183 @@+(ns metabase.api.macros.defendpoint.closed-schemas+ "Check, when a `defendpoint` is evaluated, that every schema it can reach from a request declares its shape.++ A `[:map ...]` that is not `{:closed true}` accepts any key and, once [[metabase.api.macros/decode-transformer]] has+ stripped the request, silently discards the ones it does not declare -- so an endpoint reading a key it never+ declared just sees `nil`. Closing every map an endpoint can reach turns that class of bug into a schema error. Two+ other shapes are the same escape hatch wearing a different hat and are reported too: a `:map-of` keyed by+ `:keyword` (or anything as loose), and `:any`, which lets a value of any shape through unexamined.++ What is accepted instead:++ - a map with a `::mc/default` entry, which says what the other keys are, as long as that schema passes too;+ - `:any` as a conjunct of an `:and` (or inside a normalization carrier that is one), where the other conjuncts+ constrain the value and the `:any` only carries a decoder;+ - the entries of a map whose `:decode/api` is [[metabase.lib.schema.common/remove-internal-keys]] that are internal+ keys: the API decoder removes them from every request, so what they hold never arrives from a client;+ - the schemas marked `::mr/deliberately-open`: the deliberately open maps in [[metabase.util.malli.schema]] and two+ `cljc` twins in Lib, `:metabase.lib.schema.common/visualization-settings` and the non-string `:native` body of a+ native stage, for values whose shape belongs to a driver, the frontend or a settings registry. Nothing else should+ carry that marker.++ Registry schemas are walked once per JVM: a key already visited by an earlier endpoint is not walked again, so the+ first endpoint to reach an offending registry schema is the one that fails on it."+ (:require+ [clojure.string :as str]+ [malli.core :as mc]+ [metabase.config.core :as config]+ [metabase.lib.schema.common :as lib.schema.common]+ [metabase.util :as u]+ [metabase.util.malli.registry :as mr]))++(set! *warn-on-reflection* true)++(def ^:dynamic *enabled*+ "Whether [[check!]] does anything. On outside prod, where the walk is a startup cost with nothing left to find."+ (not config/is-prod?))++(defn- ref-name+ "The registry key a schema refers to, for `[:ref ::foo]` and for a bare `::foo` reference alike."+ [schema]+ (if (= (mc/type schema) :ref)+ (let [child (first (mc/children schema))]+ (when (qualified-keyword? child) child))+ (when (mc/-ref-schema? schema)+ (let [form (mc/form schema)]+ (when (qualified-keyword? form) form)))))++(defn- deref-safe [schema]+ (let [dereffed (try (mc/deref schema) (catch Throwable _ nil))]+ (when-not (identical? dereffed schema)+ dereffed)))++(def ^:private open-map-of-key-schemas+ "`:map-of` key schemas that make the map an open bag of arbitrary keys."+ #{:keyword 'keyword? :any :some 'any? 'some?})++(def ^:private any-schemas+ "Schemas that let a value of any shape through: `:any`, `:some`, and the `map?` predicate, which is an open map."+ #{:any 'any? :some 'some? 'map?})++(def ^:private value-schemas+ "Schemas whose children are values, not schemas, and are not walked."+ #{:= :not= :enum :fn :re})++(defn- deliberately-open? [schema]+ (true? (::mr/deliberately-open (mc/properties schema))))++(defn- default-entry? [child]+ (and (vector? child) (= (first child) ::mc/default)))++(defn- strips-internal-keys?+ "Whether the API decoder removes internal keys from this map before validation."+ [schema]+ (contains? #{#'lib.schema.common/remove-internal-keys lib.schema.common/remove-internal-keys}+ (:decode/api (mc/properties schema))))++(defn- finding [schema trail kind]+ {:trail trail, :kind kind, :form (mc/form schema)})++(defn- walk-schema!+ "Walk `schema`, adding to `findings`. `conjunct?` is true while inside a conjunct of an `:and`, where an `:any` is a+ carrier rather than a hole; it turns false again on entering a map entry or a `:map-of` value, which are holes."+ [schema trail visited findings conjunct?]+ (when-let [schema (try (mc/schema schema) (catch Throwable _ nil))]+ (let [schema-type (mc/type schema)+ registry-key (ref-name schema)]+ (cond+ registry-key+ (when-not (contains? @visited registry-key)+ (swap! visited conj registry-key)+ (when-let [dereffed (deref-safe schema)]+ (walk-schema! dereffed (conj trail registry-key) visited findings conjunct?)))++ (deliberately-open? schema)+ nil++ :else+ (do+ (cond+ (and (= schema-type :map)+ (not (true? (:closed (mc/properties schema))))+ (not (some default-entry? (mc/children schema))))+ (swap! findings conj (finding schema trail :open-map))++ (and (= schema-type :map-of)+ (let [key-schema (first (mc/children schema))]+ (or (contains? open-map-of-key-schemas (mc/form key-schema))+ (contains? open-map-of-key-schemas (mc/type key-schema)))))+ (swap! findings conj (finding schema trail :keyword-keyed-map-of))++ (and (contains? any-schemas schema-type) (not conjunct?))+ (swap! findings conj (finding schema trail :any)))+ (cond+ (mc/-ref-schema? schema)+ (when-let [dereffed (deref-safe schema)]+ (walk-schema! dereffed trail visited findings conjunct?))++ (contains? value-schemas schema-type)+ nil++ :else+ (let [conjunct? (case schema-type+ :and true+ (:schema :multi) conjunct?+ (:sequential :vector :set :tuple :maybe :or) false+ conjunct?)+ skip-key? (if (and (= schema-type :map) (strips-internal-keys? schema))+ lib.schema.common/internal-key?+ (constantly false))]+ (doseq [[i child] (map-indexed vector (mc/children schema))]+ (cond+ (and (vector? child) (= 3 (count child)) (mc/schema? (nth child 2)))+ (when-not (and (not (default-entry? child)) (skip-key? (first child)))+ (walk-schema! (nth child 2) (conj trail (first child)) visited findings+ (if (= schema-type :map)+ (and conjunct? (default-entry? child))+ conjunct?)))++ (= schema-type :map-of)+ (walk-schema! child (conj trail i) visited findings (and conjunct? (zero? i)))++ (or (mc/schema? child) (vector? child) (qualified-keyword? child))+ (walk-schema! child (conj trail i) visited findings conjunct?))))))))))++(def ^:private visited-registry-keys+ "Registry keys some endpoint has already walked, so each is walked once per JVM."+ (atom #{}))++(defn findings+ "Every open map, keyword-keyed `:map-of` and `:any` reachable from `schema`, each with the `:trail` of map keys and+ registry keys that leads to it from the root. Registry keys in `visited` are skipped and added to as they are+ walked."+ ([schema]+ (findings schema (atom #{})))+ ([schema visited]+ (let [found (atom [])]+ (walk-schema! schema [] visited found false)+ @found)))++(defn- describe-finding [{:keys [trail kind form]}]+ (format " %s at %s: %s"+ (case kind+ :open-map "open map"+ :keyword-keyed-map-of "keyword-keyed map-of"+ :any ":any")+ (if (seq trail) (pr-str trail) "the root")+ (u/pprint-to-str form)))++(defn check!+ "Throw when `schema`, the `schema-type` (`:route`, `:query`, `:body` or `:request`) schema of an endpoint, can reach+ a schema that does not declare its shape. Only request schemas are checked: stripping is what makes an open map a+ problem, and only a request is stripped; a `:response` schema is left alone. Impl for+ [[metabase.api.macros/validate-schema]]."+ [schema-type schema]+ (when (and *enabled* (not= schema-type :response))+ (when-let [found (not-empty (findings schema visited-registry-keys))]+ (throw (ex-info (format (str "The %s schema of this endpoint reaches schemas that do not declare their shape."+ " Close every map with {:closed true}, key a map-of by :string, and give :any a"+ " type; a value whose keys or type really are not ours to know is one of the"+ " deliberately open schemas in metabase.util.malli.schema:\n%s")+ (name schema-type)+ (str/join "\n" (map describe-finding found)))+ {:schema-type schema-type, :schema schema, :findings found})))))diff --git a/src/metabase/api_keys/api.clj b/src/metabase/api_keys/api.cljindex f591904a622..0b2491a038b 100644--- a/src/metabase/api_keys/api.clj+++ b/src/metabase/api_keys/api.clj@@ -41,7 +41,7 @@"Create a new API key (and an associated `User`) with the provided name and group ID."[_route-params_query-params- {group-id :group_id, key-name :name, :as _body} :- [:map+ {group-id :group_id, key-name :name, :as _body} :- [:map {:closed true}[:group_id ::api-keys.schema/id][:name ms/NonBlankString]]](api/check-superuser)@@ -64,10 +64,10 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :put "/:id""Update an API key by changing its group and/or its name"- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-params- {group-id :group_id, key-name :name} :- [:map+ {group-id :group_id, key-name :name} :- [:map {:closed true}[:group_id {:optional true} [:maybe ms/PositiveInt]][:name {:optional true} [:maybe ::api-keys.schema/name]]]](api/check-superuser)@@ -83,7 +83,7 @@[:masked_key ::api-keys.schema/key.masked][:prefix ::api-keys.schema/prefix]]"Regenerate an API Key"- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ::api-keys.schema/id]]](api/check-superuser)(api/check-404 (api-keys.db/api-key-exists? id))@@ -110,7 +110,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/:id""Delete an ApiKey"- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ::api-keys.schema/id]]](api/check-superuser)(api/check-404 (api-keys.db/api-key-exists? id))diff --git a/src/metabase/bookmarks/api.clj b/src/metabase/bookmarks/api.cljindex ce8b7d28de3..dc1dd380ed5 100644--- a/src/metabase/bookmarks/api.clj+++ b/src/metabase/bookmarks/api.clj@@ -18,7 +18,7 @@(def BookmarkOrderings"Schema for an ordered of bookmark orderings"- [:sequential [:map+ [:sequential [:map {:closed true}[:type Models][:item_id ms/PositiveInt]]])@@ -71,7 +71,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :post "/:model/:id""Create a new bookmark for user."- [{:keys [model id]} :- [:map+ [{:keys [model id]} :- [:map {:closed true}[:model Models][:id ms/PositiveInt]]](api/read-check (item-model model) id)@@ -85,7 +85,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/:model/:id""Delete a bookmark. Will delete a bookmark assigned to the user making the request by model and id."- [{:keys [model id]} :- [:map+ [{:keys [model id]} :- [:map {:closed true}[:model Models][:id ms/PositiveInt]]];; todo: allow admins to include an optional user id to delete for so they can delete other's bookmarks.@@ -100,7 +100,7 @@"Sets the order of bookmarks for user."[_route-params_query-params- {:keys [orderings]} :- [:map+ {:keys [orderings]} :- [:map {:closed true}[:orderings BookmarkOrderings]]](bookmark/save-ordering! api/*current-user-id* orderings)api/generic-204-no-content)diff --git a/src/metabase/cache/api.clj b/src/metabase/cache/api.cljindex 97a102e04de..b18ff092bb7 100644--- a/src/metabase/cache/api.clj+++ b/src/metabase/cache/api.clj@@ -5,6 +5,7 @@[metabase.cache.db :as cache.db][metabase.cache.models.cache-config :as cache-config][metabase.config.core :as config]+ [metabase.lib.schema :as lib.schema][metabase.lib.schema.common :as lib.schema.common][metabase.models.interface :as mi][metabase.premium-features.core :as premium-features]@@ -32,16 +33,15 @@(keyword strategy-type))))(mr/def ::cache-strategy.nocache- [:map- [:type [:= :nocache]]- ;; a free-form label round-tripped through `:config`; tests use it to tell configs apart- [:name {:optional true} [:maybe :string]]])+ ::lib.schema/cache-strategy.nocache)(mr/def ::cache-strategy.ttl- [:map {:closed true}- [:type [:= :ttl]]- [:multiplier ms/PositiveInt]- [:min_duration_ms ms/IntGreaterThanOrEqualToZero]])+ "[[::lib.schema/cache-strategy.ttl]] as it may be configured: whole numbers."+ [:merge+ ::lib.schema/cache-strategy.ttl+ [:map {:closed true}+ [:multiplier ms/PositiveInt]+ [:min_duration_ms ms/IntGreaterThanOrEqualToZero]]])(mr/def ::cache-strategy.oss"Schema for a caching strategy (OSS)"@@ -55,18 +55,18 @@[:ttl ::cache-strategy.ttl]])(mr/def ::cache-strategy.ee.duration- [:map {:closed true}- [:type [:= :duration]]- [:duration ms/PositiveInt]- ;; TODO (Cam 10/3/25) -- change these to keywords and let API coercion convert them for us automatically.- [:unit [:enum "hours" "minutes" "seconds" "days"]]- [:refresh_automatically {:optional true} [:maybe :boolean]]])+ "[[::lib.schema/cache-strategy.duration]] as it may be configured: a whole number of units."+ [:merge+ ::lib.schema/cache-strategy.duration+ [:map {:closed true}+ [:duration ms/PositiveInt]]])(mr/def ::cache-strategy.ee.schedule- [:map {:closed true}- [:type [:= :schedule]]- [:schedule u.cron/CronScheduleString]- [:refresh_automatically {:optional true} [:maybe :boolean]]])+ "[[::lib.schema/cache-strategy.schedule]] as it may be configured: a valid cron schedule."+ [:merge+ ::lib.schema/cache-strategy.schedule+ [:map {:closed true}+ [:schedule u.cron/CronScheduleString]]]);;; This is basically the same schema as `:metabase-enterprise.cache.strategies/cache-strategy` except it doesn't have;;; the optional `:invalidated-at` keys@@ -156,7 +156,7 @@[_route-params{:keys [model collection id] :as params}:- [:merge- [:map+ [:map {:closed true}[:model {:default ["root"]} (mu/with (ms/QueryVectorOf cache-config/CachingModel){:description "Type of model"})][:collection {:optional true} (mu/with [:maybe ms/PositiveInt]@@ -183,7 +183,7 @@"Store cache configuration."[_route-params_query-params- {:keys [model model_id] :as config} :- [:map+ {:keys [model model_id] :as config} :- [:map {:closed true}[:model cache-config/CachingModel][:model_id ms/IntGreaterThanOrEqualToZero][:strategy ::cache-strategy]]]@@ -195,7 +195,7 @@"Delete cache configurations."[_route-params_query-params- {:keys [model model_id]} :- [:map+ {:keys [model model_id]} :- [:map {:closed true}[:model cache-config/CachingModel][:model_id (ms/QueryVectorOf ms/IntGreaterThanOrEqualToZero)]]](assert-valid-models model model_id (premium-features/enable-cache-granular-controls?))@@ -213,7 +213,7 @@touching all nested configurations, or you want your invalidation to trickle down to every card."[_route-params{:keys [include database dashboard question]}- :- [:map+ :- [:map {:closed true}[:include {:optional true} [:maybe {:description "All cache configuration overrides should invalidate cache too"}[:= :overrides]]][:database {:optional true} [:maybe {:description "A list of database ids"}diff --git a/src/metabase/channel/api/channel.clj b/src/metabase/channel/api/channel.cljindex d4650fb3420..c5c04fba546 100644--- a/src/metabase/channel/api/channel.clj+++ b/src/metabase/channel/api/channel.clj@@ -7,12 +7,8 @@[metabase.api.macros :as api.macros][metabase.channel.core :as channel][metabase.channel.db :as channel.db]- [metabase.channel.impl.email :as channel.email]- [metabase.channel.impl.http :as channel.http]- [metabase.channel.impl.slack :as channel.slack]- [metabase.config.core :as config]+ [metabase.channel.schema :as channel.schema][metabase.events.core :as events]- [metabase.lib.schema.common :as lib.schema.common][metabase.models.interface :as mi][metabase.permissions.core :as perms][metabase.util :as u]@@ -36,7 +32,7 @@"Get all channels"[_route-params_query-params- {:keys [include_inactive]} :- [:map+ {:keys [include_inactive]} :- [:map {:closed true}[:include_inactive {:optional true} [:maybe {:default false} :boolean]]]](->> (if include_inactive(channel.db/channels)@@ -50,47 +46,17 @@#(= "channel" (namespace (keyword %)))](deferred-tru "Must be a namespaced channel. E.g: channel/http")))-(def ^:private TestChannelDetails- [:map- [:return-type [:enum "return-value" "throw"]]- [:return-value {:optional true} :any]])-(defn- channel-body-schema[common-entries & {:keys [details-optional?]}]- (let [details-entry (fn [schema]- (if details-optional?- [:details {:optional true} [:maybe schema]]- [:details schema]))]- [:merge- (into [:map] common-entries)- (into [:multi {:decode/normalize lib.schema.common/normalize-map-no-kebab-case- :dispatch (fn [m]- (let [channel-type (some-> (:type m) keyword)]- (when (and channel-type (= "channel" (namespace channel-type)))- channel-type)))}]- (concat- [[:channel/http [:map (details-entry channel.http/HTTPDetails)]]- [:channel/email [:map [:details {:optional true} [:maybe channel.email/EmailDetails]]]]- [:channel/slack [:map (details-entry channel.slack/SlackDetails)]]]- (when config/is-test?- [[:channel/metabase-test [:map (details-entry TestChannelDetails)]]])- [[nil [:map [:details {:optional true}- [:maybe (into [:or]- (concat- (when config/is-test?- [TestChannelDetails])- [channel.slack/SlackDetails- channel.http/HTTPDetails- channel.email/EmailDetails]))]]]]]))]))+ [:merge+ (into [:map {:closed true}] common-entries)+ (conj (channel.schema/details-by-type :details-optional? details-optional?)+ [nil [:map {:closed true}+ [:details {:optional true} [:maybe ::channel.schema/channel.details]]]])])(defn- details-schema-for-type[channel-type]- (condp = channel-type- :channel/http channel.http/HTTPDetails- :channel/email channel.email/EmailDetails- :channel/slack channel.slack/SlackDetails- :channel/metabase-test (when config/is-test? TestChannelDetails)- nil))+ (channel.schema/channel-type->details-schema channel-type));; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to;; use our API + we will need it when we make auto-TypeScript-signature generation happen@@ -118,7 +84,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id""Get a channel"- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](-> (channel.db/channel id) api/read-check remove-details-if-needed))@@ -128,7 +94,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :put "/:id""Update a channel"- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-paramsbody :- (channel-body-schemadiff --git a/src/metabase/channel/api/email.clj b/src/metabase/channel/api/email.cljindex fc9de5a8178..71374d27956 100644--- a/src/metabase/channel/api/email.clj+++ b/src/metabase/channel/api/email.clj@@ -25,7 +25,7 @@"Update multiple email Settings. You must be a superuser or have `setting` permission to do this."[_route-params_query-params- settings :- [:map+ settings :- [:map {:closed true}[:email-smtp-host {:optional true} [:or string? nil?]][:email-smtp-password {:optional true} [:or string? nil?]][:email-smtp-port {:optional true} [:or int? nil?]]diff --git a/src/metabase/channel/api/slack.clj b/src/metabase/channel/api/slack.cljindex 423b23c5642..769f0560e88 100644--- a/src/metabase/channel/api/slack.clj+++ b/src/metabase/channel/api/slack.clj@@ -32,7 +32,7 @@(defn- create-slack-message-blocks"Create blocks for the Slack message with diagnostic information"[diagnostic-info file-info]- (let [version-info (get-in diagnostic-info [:bugReportDetails :metabase-info :version])+ (let [version-info (get-in diagnostic-info [:bugReportDetails "metabase-info" "version"])description (get diagnostic-info :description)reporter (get diagnostic-info :reporter)file-url (if (string? file-info)@@ -97,7 +97,7 @@[_route-params_query-params{:keys [slack-app-token slack-bug-report-channel] :as body}- :- [:map+ :- [:map {:closed true}[:slack-app-token {:optional true} [:maybe ms/NonBlankString]][:slack-bug-report-channel {:optional true} [:maybe :string]]]](perms/check-has-application-permission :setting)@@ -261,15 +261,15 @@[:url {:optional true} [:maybe :string]][:description {:optional true} [:maybe :string]][:frontendErrors {:optional true} [:maybe [:sequential :string]]]- [:backendErrors {:optional true} [:maybe [:sequential ms/Map]]]- [:userLogs {:optional true} [:maybe [:sequential ms/Map]]]- [:logs {:optional true} [:maybe [:sequential ms/Map]]]+ [:backendErrors {:optional true} [:maybe [:sequential ms/OpaqueJSONObject]]]+ [:userLogs {:optional true} [:maybe [:sequential ms/OpaqueJSONObject]]]+ [:logs {:optional true} [:maybe [:sequential ms/OpaqueJSONObject]]][:entityName {:optional true} [:maybe :string]][:localizedEntityName {:optional true} [:maybe :string]]- [:entityInfo {:optional true} [:maybe ms/Map]]- [:queryResults {:optional true} [:maybe ms/Map]]- [:bugReportDetails {:optional true} [:maybe ms/Map]]- [:browserInfo {:optional true} [:maybe ms/Map]]])+ [:entityInfo {:optional true} [:maybe ms/OpaqueJSONObject]]+ [:queryResults {:optional true} [:maybe ms/OpaqueJSONObject]]+ [:bugReportDetails {:optional true} [:maybe ms/OpaqueJSONObject]]+ [:browserInfo {:optional true} [:maybe ms/OpaqueJSONObject]]])(defn- current-user-reporter"Name and email of the user making the request, for attributing a bug report."diff --git a/src/metabase/channel/impl/email.clj b/src/metabase/channel/impl/email.cljindex b658f0bcdac..06f035db926 100644--- a/src/metabase/channel/impl/email.clj+++ b/src/metabase/channel/impl/email.clj@@ -43,10 +43,6 @@{:template-type template-type:channel-type :channel/email}))-(def EmailDetails- "Schema for the connection `:details` of a `:channel/email` channel."- [:map {:closed true}])-(def ^:private EmailMessage[:map[:subject :string]diff --git a/src/metabase/channel/impl/http.clj b/src/metabase/channel/impl/http.cljindex 10148a3d744..981be90ec70 100644--- a/src/metabase/channel/impl/http.clj+++ b/src/metabase/channel/impl/http.clj@@ -6,6 +6,7 @@[java-time.api :as t][metabase.channel.core :as channel][metabase.channel.render.core :as channel.render]+ [metabase.channel.schema :as channel.schema][metabase.channel.settings :as channel.settings][metabase.channel.shared :as channel.shared][metabase.channel.urls :as urls]@@ -21,21 +22,20 @@many columns) is truncated."1200)-(def HTTPDetails- "Schema for the connection `:details` of a `:channel/http` channel."- [:map {:closed true}- [:url ms/Url]- [:auth-method [:enum "none" "header" "query-param" "request-body"]]- [:auth-info {:optional true} ms/Map]- ;; used by the frontend to display the auth info properly- [:fe-form-type {:optional true} [:enum "api-key" "bearer" "basic" "none"]]- ;; request method- [:method {:optional true} [:enum "get" "post" "put"]]])-(def ^:private HTTPChannel- [:map- [:type [:= :channel/http]]- [:details HTTPDetails]])+ "What [[channel/send!]] receives: a Channel hydrated from its row, or in a test just the `:type` and `:details` this+ implementation reads."+ [:merge+ [:map {:closed true}+ [:type [:= :channel/http]]+ [:id {:optional true} ms/PositiveInt]+ [:name {:optional true} :string]+ [:description {:optional true} [:maybe :string]]+ [:active {:optional true} :boolean]+ [:created_at {:optional true} :any]+ [:updated_at {:optional true} :any]]+ [:map {:closed true}+ [:details ::channel.schema/http-details]]])(defn- check-url![strategy url]@@ -87,7 +87,7 @@(defmethod channel/can-connect? :channel/http[_channel-type details]- (channel.shared/validate-channel-details HTTPDetails details)+ (channel.shared/validate-channel-details ::channel.schema/http-details details)(try(channel/send! {:type :channel/http :details details} {})truediff --git a/src/metabase/channel/impl/slack.clj b/src/metabase/channel/impl/slack.cljindex 92fd366a04b..bacd169cda7 100644--- a/src/metabase/channel/impl/slack.clj+++ b/src/metabase/channel/impl/slack.clj@@ -16,11 +16,6 @@[metabase.util.malli :as mu][metabase.util.markdown :as markdown]))-(def SlackDetails- "Schema for the connection `:details` of a `:channel/slack` channel."- [:map {:closed true}- [:channel :string]])-(defn- notification-recipient->channel"Returns the Slack channel target for a raw-value notification recipient.Prefers the immutable `:channel_id` (e.g. \"C0ABC123\") over the display `:value`diff --git a/src/metabase/channel/models/channel.clj b/src/metabase/channel/models/channel.cljindex dd04253aa23..3341321ecd5 100644--- a/src/metabase/channel/models/channel.clj+++ b/src/metabase/channel/models/channel.clj@@ -5,7 +5,7 @@[metabase.analytics.core :as analytics.core][metabase.api.common :as api][metabase.channel.db :as channel.db]- [metabase.channel.template.handlebars :as handlebars]+ [metabase.channel.schema :as channel.schema][metabase.lib.schema.common :as lib.schema.common][metabase.models.interface :as mi][metabase.models.serialization :as serdes]@@ -35,19 +35,34 @@;; :model/Channel ;;;; ------------------------------------------------------------------------------------------------;;+(def ^:private RowTimestamp+ "A `created_at`/`updated_at` column: a `java.time` value on the way out, and -- because a notification update echoes+ back the channel and template it was handed -- the ISO string it was encoded as on the way back in."+ [:maybe [:or ms/TemporalInstant ms/TemporalString]])++(defn- stringify-auth-info-keys+ "An HTTP channel's `:auth-info` is keyed by the header or parameter names the user chose, so it is string-keyed, as+ `::channel.schema/http-details` says, rather than keywordized like the rest of the details."+ [details]+ (cond-> details+ (map? (:auth-info details)) (update :auth-info update-keys u/qualified-name)))+(t2/deftransforms :model/Channel{:type (mi/transform-validator mi/transform-keyword (partial mi/assert-namespaced "channel"))- :details (mi/transform-encrypted-json "channel.details")})+ :details (update (mi/transform-encrypted-json "channel.details") :out #(comp stringify-auth-info-keys %))})(mr/def ::Channel"Channel schema."- [:map- [:name string?]- [:type :keyword]- ;; per-channel-type connection config (a Slack token, an HTTP url and auth, ...) -- free-form like database details- [:details ms/Map]- [:active {:optional true} :boolean]- [:description {:optional true} [:maybe string?]]])+ [:merge+ [:map {:closed true}+ [:name string?]+ [:type :keyword]+ [:active {:optional true} :boolean]+ [:description {:optional true} [:maybe string?]]+ [:id {:optional true} ms/PositiveInt]+ [:created_at {:optional true} RowTimestamp]+ [:updated_at {:optional true} RowTimestamp]]+ ::channel.schema/channel.details-by-type])(defmethod mi/can-write? :model/Channel[& _]@@ -106,60 +121,36 @@{:channel_type (mi/transform-validator mi/transform-keyword (partial mi/assert-namespaced "channel")):details mi/transform-json})-(def ^:private channel-template-details-type- #{:email/handlebars-text- :email/handlebars-resource})--(mr/def ::ChannelTemplateEmailDetails- [:merge- [:map- [:type (apply ms/enum-keywords-and-strings channel-template-details-type)]- [:subject string?]- [:recipient-type {:optional true} (ms/enum-keywords-and-strings :cc :bcc)]]- [:multi {:decode/normalize lib.schema.common/normalize-map-no-kebab-case- :dispatch (comp keyword :type)}- [:email/handlebars-resource- [:map- [:path [:and- string?- [:fn {:error/message "invalid template path"}- handlebars/valid-template-name?]]]]]- [:email/handlebars-text- [:map- [:body string?]]]]])-(def ^:private channel-template-entries"Entries every channel template has, whatever its `:channel_type`."[[:id {:optional true} ms/PositiveInt][:name {:optional true} ms/NonBlankString][:channel_type [:fn #(= "channel" (-> % keyword namespace))]]])+(def ^:private channel-template-row-entries+ "[[channel-template-entries]] plus the timestamps a stored template carries. Kept out of the user-provided schema+ below, which describes a request body rather than a row."+ (into channel-template-entries+ [[:created_at {:optional true} RowTimestamp]+ [:updated_at {:optional true} RowTimestamp]]))+(mr/def ::ChannelTemplate"Channel Template schema."[:merge- (into [:map] channel-template-entries)+ (into [:map {:closed true}] channel-template-row-entries)[:multi {:decode/normalize lib.schema.common/normalize-map-no-kebab-case:dispatch (comp keyword :channel_type)}- [:channel/email [:map [:details ::ChannelTemplateEmailDetails]]]- [::mc/default [:map]]]])--(mr/def ::ChannelTemplateEmailDetailsUserProvided- "Email template details schema for API-provided templates. Only handlebars-text is allowed;- handlebars-resource is restricted to internal use only."- [:map- [:type (ms/enum-keywords-and-strings :email/handlebars-text)]- [:subject string?]- [:recipient-type {:optional true} (ms/enum-keywords-and-strings :cc :bcc)]- [:body string?]])+ [:channel/email [:map {:closed true} [:details ::channel.schema/channel-template.email-details]]]+ [::mc/default [:map {:closed true} [:details {:optional true} :nil]]]]])(mr/def ::ChannelTemplateUserProvided"Channel Template schema for API-provided templates. Does not allow handlebars-resource."[:merge- (into [:map] channel-template-entries)+ (into [:map {:closed true}] channel-template-entries)[:multi {:decode/normalize lib.schema.common/normalize-map-no-kebab-case:dispatch (comp keyword :channel_type)}- [:channel/email [:map [:details ::ChannelTemplateEmailDetailsUserProvided]]]- [::mc/default [:map]]]])+ [:channel/email [:map {:closed true} [:details ::channel.schema/channel-template.email-details.user-provided]]]+ [::mc/default [:map {:closed true}]]]])(defn- check-valid-channel-template[channel-template]diff --git a/src/metabase/channel/schema.clj b/src/metabase/channel/schema.cljindex d02338fb86f..8b0fb8d68d3 100644--- a/src/metabase/channel/schema.clj+++ b/src/metabase/channel/schema.clj@@ -1,24 +1,97 @@(ns metabase.channel.schema"Malli schemas for the channel module."(:require+ [metabase.channel.template.handlebars :as handlebars]+ [metabase.config.core :as config]+ [metabase.lib.schema.common :as lib.schema.common][metabase.util.malli.registry :as mr][metabase.util.malli.schema :as ms]))+(mr/def ::http-details+ "The connection `:details` of a `:channel/http` channel."+ [:map {:closed true}+ [:url ms/Url]+ [:auth-method [:enum "none" "header" "query-param" "request-body"]]+ [:auth-info {:optional true} (ms/string-keyed-map :string)]+ [:fe-form-type {:optional true} [:enum "api-key" "bearer" "basic" "none"]]+ [:method {:optional true} [:enum "get" "post" "put"]]])++(mr/def ::slack-details+ "The connection `:details` of a `:channel/slack` channel."+ [:map {:closed true}+ [:channel :string]])++(mr/def ::email-details+ "The connection `:details` of a `:channel/email` channel: there are none, email is configured by settings."+ [:map {:closed true}])++(mr/def ::test-details+ "The `:details` of the test-only `:channel/metabase-test` channel, which exists so a test can drive a connection test+ down each of its branches. `metabase.notification.test-util`'s `can-connect?` reads `:return-type` and then either+ returns `:return-value` or throws with it as `ex-data`, so what `:return-value` may be depends on which:++ - `\"return-value\"` -- the boolean `can-connect?` returns. `true` is the success branch (`{:ok true}`); `false` is+ the failure one, echoed back as the 400's `{:connection-result false}`.+ - `\"throw\"` -- the `ex-data` of the thrown exception, which the endpoint hands back as the 400's `:data`. The+ field-keyed error map a connection check reports a bad detail with, as in `{:errors {:email \"Invalid email\"}}`."+ [:multi {:dispatch #(get % :return-type "unset")}+ ["unset" [:map {:closed true}]]+ ["return-value" [:map {:closed true}+ [:return-type [:= "return-value"]]+ [:return-value :boolean]]]+ ["throw" [:map {:closed true}+ [:return-type [:= "throw"]]+ [:return-value [:map {:closed true}+ [:errors [:map {:closed true}+ [:email {:optional true} :string]]]]]]]])++(def channel-type->details-schema+ "The details schema of each channel type. The test channel is only a channel in the test JVM."+ (cond-> {:channel/http ::http-details+ :channel/slack ::slack-details+ :channel/email ::email-details}+ config/is-test? (assoc :channel/metabase-test ::test-details)))+(mr/def ::channel.details- "The `:details` column of a Channel, decoded."- :map)+ "The `:details` column of a Channel, decoded, when the channel's `:type` is not at hand to pick the schema by. Decoding+ an `:or` keeps the first branch the value satisfies once decoded, and the request decoder strips undeclared keys, so+ the branches run from the most to the least demanding: the empty `::email-details` would swallow anything."+ (into [:or]+ (keep channel-type->details-schema)+ [:channel/metabase-test :channel/slack :channel/http :channel/email]))++(defn details-by-type+ "A `:multi` schema on a channel's `:type` whose branches each declare that type's `:details`, for `:merge`ing into a+ channel schema: Malli pushes the merge into every branch, so the branch's `:details` entry lands in the closed map+ alongside the other columns. An email channel has no details to speak of, so its entry is optional."+ [& {:keys [details-optional?]}]+ (into [:multi {:decode/normalize lib.schema.common/normalize-map-no-kebab-case+ :dispatch (fn [channel]+ (let [channel-type (some-> (:type channel) keyword)]+ (when (and channel-type (= "channel" (namespace channel-type)))+ channel-type)))}]+ (for [[channel-type details-schema] channel-type->details-schema]+ [channel-type [:map {:closed true}+ (if (or details-optional? (= channel-type :channel/email))+ [:details {:optional true} [:maybe details-schema]]+ [:details details-schema])]])))++(mr/def ::channel.details-by-type+ "[[details-by-type]] as a schema, for the row schemas below."+ (details-by-type))(mr/def ::channel"A Channel as selected from the app DB: every column of `:channel`."- [:map {:closed true}- [:id ms/PositiveInt]- [:name :string]- [:description [:maybe :string]]- [:type [:or :keyword :string]]- [:details ::channel.details]- [:active :boolean]- [:created_at ms/TemporalInstant]- [:updated_at ms/TemporalInstant]])+ [:merge+ [:map {:closed true}+ [:id ms/PositiveInt]+ [:name :string]+ [:description [:maybe :string]]+ [:type [:or :keyword :string]]+ [:active :boolean]+ [:created_at ms/TemporalInstant]+ [:updated_at ms/TemporalInstant]]+ ::channel.details-by-type])(mr/def ::channel.update"What an update (or insert) of a Channel accepts: every column of `:channel` except `id`, all optional."@@ -31,9 +104,42 @@[:created_at {:optional true} [:maybe ms/TemporalInstant]][:updated_at {:optional true} [:maybe ms/TemporalInstant]]])+(def channel-template-details-types+ "The `:type`s an email template's details can have: a Handlebars template written inline, or one shipped as a resource."+ #{:email/handlebars-text+ :email/handlebars-resource})++(mr/def ::channel-template.email-details+ "The `:details` of a `:channel/email` ChannelTemplate."+ [:merge+ [:map {:closed true}+ [:type (apply ms/enum-keywords-and-strings channel-template-details-types)]+ [:subject string?]+ [:recipient-type {:optional true} (ms/enum-keywords-and-strings :cc :bcc)]]+ [:multi {:decode/normalize lib.schema.common/normalize-map-no-kebab-case+ :dispatch (comp keyword :type)}+ [:email/handlebars-resource+ [:map {:closed true}+ [:path [:and+ string?+ [:fn {:error/message "invalid template path"}+ handlebars/valid-template-name?]]]]]+ [:email/handlebars-text+ [:map {:closed true}+ [:body string?]]]]])++(mr/def ::channel-template.email-details.user-provided+ "Email template details as the API accepts them. Only an inline Handlebars template is allowed; a resource template is+ for internal use."+ [:map {:closed true}+ [:type (ms/enum-keywords-and-strings :email/handlebars-text)]+ [:subject string?]+ [:recipient-type {:optional true} (ms/enum-keywords-and-strings :cc :bcc)]+ [:body string?]])+(mr/def ::channel-template.details- "The `:details` column of a ChannelTemplate, decoded."- :map)+ "The `:details` column of a ChannelTemplate, decoded. Only email templates exist."+ ::channel-template.email-details)(mr/def ::channel-template"A ChannelTemplate as selected from the app DB: every column of `:channel_template`."diff --git a/src/metabase/collections/models/collection.clj b/src/metabase/collections/models/collection.cljindex 804ec3fc2c2..17b17732b22 100644--- a/src/metabase/collections/models/collection.clj+++ b/src/metabase/collections/models/collection.clj@@ -563,7 +563,7 @@(and first-name last-name) (trs "{0} {1}''s Personal Collection" first-name last-name):else (trs "{0}''s Personal Collection" (or first-name last-name email)))))-(mu/defn user->personal-collection-names :- ms/Map+(mu/defn user->personal-collection-names :- [:map-of ms/PositiveInt :string]"Come up with a nice name for the Personal Collection for the passed `user-or-ids`.Returns a map of user-id -> name"[user-or-ids user-or-site]diff --git a/src/metabase/collections_rest/api.clj b/src/metabase/collections_rest/api.cljindex 4d797b261c2..3688f8ec418 100644--- a/src/metabase/collections_rest/api.clj+++ b/src/metabase/collections_rest/api.clj@@ -119,7 +119,7 @@If personal-only is `true`, then return only personal collections where `personal_owner_id` is not `nil`."[_route-params- {:keys [archived exclude-other-user-collections namespace personal-only]} :- [:map+ {:keys [archived exclude-other-user-collections namespace personal-only]} :- [:map {:closed true}[:archived {:default false} [:maybe ms/BooleanValue]][:exclude-other-user-collections {:default false} [:maybe ms/BooleanValue]][:namespace {:optional true} [:maybe ms/NonBlankString]]@@ -216,7 +216,7 @@[_route-params{:keys [exclude-archived exclude-other-user-collections include-librarynamespace namespaces shallow collection-id]}- :- [:map+ :- [:map {:closed true}[:exclude-archived {:default false} [:maybe :boolean]][:exclude-other-user-collections {:default false} [:maybe :boolean]][:include-library {:default false} [:maybe :boolean]]@@ -732,7 +732,7 @@To be eligible, a card must only appear in one dashboard (which is also in this collection), and must not already be adashboard question."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]](api/read-check :model/Collection id)(present-dashboard-question-candidates(dashboard-question-candidates id)))@@ -764,11 +764,11 @@(api.macros/defendpoint :post "/:id/move-dashboard-question-candidates" :- ::MoveDashboardQuestionCandidatesResponse"Move candidate cards to the dashboards they appear in."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]_query-params{:keys [card_ids]} :- [:maybe- [:map [:card_ids {:optional true}- [:set ms/PositiveInt]]]]]+ [:map {:closed true} [:card_ids {:optional true}+ [:set ms/PositiveInt]]]]](api/read-check :model/Collection id){:moved (move-dashboard-question-candidates id card_ids)})@@ -777,8 +777,8 @@[_route-params_query-params{:keys [card_ids]} :- [:maybe- [:map [:card_ids {:optional true}- [:set ms/PositiveInt]]]]]+ [:map {:closed true} [:card_ids {:optional true}+ [:set ms/PositiveInt]]]]]{:moved (move-dashboard-question-candidates nil card_ids)});;; -------------------------------------------- GET /api/collection/root --------------------------------------------@@ -789,7 +789,7 @@(api.macros/defendpoint :get "/root" :- ::Collection"Return the 'Root' Collection object with standard details added"[_route-params- {:keys [namespace]} :- [:map+ {:keys [namespace]} :- [:map {:closed true}[:namespace {:optional true} [:maybe ms/NonBlankString]]]](-> (root-collection namespace)(api/read-check)@@ -842,7 +842,7 @@{:keys [models archived namespace pinned-state sort-column sort-direction official-collections-firstinclude-library collection-typeshow-dashboard-questions show-exploration-documents- q include-available-models]} :- [:map+ q include-available-models]} :- [:map {:closed true}[:models {:optional true} [:maybe Models]][:collection-type {:optional true} children-query/CollectionType][:archived {:default false} [:maybe ms/BooleanValue]]@@ -889,7 +889,7 @@scope params so the metadata describes the list being shown."[_route-params{:keys [models archived namespace pinned-state collection-type include-library- show-dashboard-questions show-exploration-documents]} :- [:map+ show-dashboard-questions show-exploration-documents]} :- [:map {:closed true}[:models {:optional true} [:maybe Models]][:archived {:default false} [:maybe ms/BooleanValue]][:namespace {:optional true} [:maybe ms/NonBlankString]]@@ -924,7 +924,7 @@"Create a new Collection."[_route-params_query-params- body :- [:map+ body :- [:map {:closed true}[:name ms/NonBlankString][:description {:optional true} [:maybe ms/NonBlankString]][:parent_id {:optional true} [:maybe ms/PositiveInt]]@@ -1023,11 +1023,27 @@(api.macros/defendpoint :get "/graph" :- PermissionsGraph"Fetch a graph of all Collection Permissions."[_route-params- {:keys [namespace]} :- [:map+ {:keys [namespace]} :- [:map {:closed true}[:namespace {:optional true} [:maybe ms/NonBlankString]]]](api/check-superuser)(perms/graph namespace))+(def ^:private RequestId+ "A group or collection ID as it arrives as a JSON object key in a `PUT /graph` body: the request middleware keywordizes+ it, so it is turned back into the string it was and has to spell the integer [[decode-graph]] parses."+ [:and+ [:string {:decode/api #(cond-> % (keyword? %) name)}]+ [:re {:error/message "an ID"} #"\d+"]])++(def ^:private RequestPermissionsGroups+ "The `:groups` of a [[PermissionsGraph]] as it arrives in a `PUT /graph` body, before [[decode-graph]] coerces its+ keys."+ [:multi {:dispatch map?}+ [true [:map-of RequestId [:multi {:dispatch map?}+ [true [:map-of [:or [:= :root] RequestId] (ms/enum-keywords-and-strings :write :read :none)]]+ [false [:fn {:error/message "map"} map?]]]]]+ [false [:fn {:error/message "map"} map?]]])+(def ^:private graph-decoder"Building it this way is a lot faster then calling mc/decode <value> <schema> <transformer>"(mc/decoder PermissionsGraph (mtx/string-transformer)))@@ -1054,14 +1070,19 @@If the `skip_graph` query parameter is `true`, it will only return the current revision, not the entire permissionsgraph."[_route-params- {:keys [skip-graph force]} :- [:map+ {:keys [skip-graph force]} :- [:map {:closed true}[:force {:default false} [:maybe ms/BooleanValue]][:skip-graph {:default false} [:maybe ms/BooleanValue]]]- {:keys [namespace revision groups]} :- [:map+ {:keys [namespace revision groups]} :- [:map {:closed true}[:namespace {:optional true} [:maybe ms/NonBlankString]][:revision {:optional true} [:maybe ms/Int]]- [:groups ms/Map]]]+ [:groups RequestPermissionsGroups]]+ request](api/check-superuser)+ (let [raw-groups (get-in request [:body :groups])]+ (api/check-no-dropped-entries raw-groups groups)+ (doseq [[group-id collection-id->perm] groups]+ (api/check-no-dropped-entries (get raw-groups (keyword group-id)) collection-id->perm)))(update-graph! namespace(decode-graph {:revision revision :groups groups})skip-graph@@ -1071,17 +1092,17 @@(api.macros/defendpoint :get "/:id" :- ::Collection"Fetch a specific Collection with standard details added"- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id [:or ms/PositiveInt ms/NanoIdString]]]](let [resolved-id (eid-translation/->id-or-404 :collection id)](collection-detail (api/read-check :model/Collection resolved-id))))(api.macros/defendpoint :put "/:id" :- ::Collection"Modify an existing Collection, including archiving or unarchiving it, or moving it."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-params- {authority-level :authority_level, :as collection-updates} :- [:map+ {authority-level :authority_level, :as collection-updates} :- [:map {:closed true}[:name {:optional true} [:maybe ms/NonBlankString]][:description {:optional true} [:maybe ms/NonBlankString]][:archived {:default false} [:maybe ms/BooleanValue]]@@ -1113,7 +1134,7 @@;; Returns the number of Collection rows deleted, which `t2/delete!` hands back -- 1 whenever the checks above pass.(api.macros/defendpoint :delete "/:id" :- ms/IntGreaterThanOrEqualToZero"Deletes a collection permanently"- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](api/check-403 api/*is-superuser?*)(let [collection (collections-rest.db/collection id)@@ -1146,11 +1167,11 @@Note that this endpoint should return results in a similar shape to `/api/dashboard/:id/items`, so if this ischanged, that should too."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id [:or ms/PositiveInt ms/NanoIdString]]]{:keys [models archived pinned-state sort-column sort-direction official-collections-firstshow-dashboard-questions show-exploration-documents- q include-available-models]} :- [:map+ q include-available-models]} :- [:map {:closed true}[:models {:optional true} [:maybe Models]][:archived {:default false} [:maybe ms/BooleanValue]][:pinned-state {:optional true} [:maybe (into [:enum] children-query/valid-pinned-state-values)]]@@ -1189,10 +1210,10 @@`GET /api/collection/:id/items`, the result does not depend on search text; pass that endpoint's other scopeparams -- `models`, `archived`, `pinned-state`, `show-dashboard-questions`, `show-exploration-documents` -- so themetadata describes the list being shown."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id [:or ms/PositiveInt ms/NanoIdString]]]{:keys [models archived pinned-state- show-dashboard-questions show-exploration-documents]} :- [:map+ show-dashboard-questions show-exploration-documents]} :- [:map {:closed true}[:models {:optional true} [:maybe Models]][:archived {:default false} [:maybe ms/BooleanValue]][:pinned-state {:optional true} [:maybe (into [:enum] children-query/valid-pinned-state-values)]]diff --git a/src/metabase/comments/api.clj b/src/metabase/comments/api.cljindex d681c5d5316..14380916357 100644--- a/src/metabase/comments/api.clj+++ b/src/metabase/comments/api.clj@@ -11,7 +11,9 @@[metabase.comments.models.comment :as comment][metabase.comments.models.comment-reaction :as comment-reaction][metabase.comments.render :as comments.render]+ [metabase.comments.schema :as comments.schema][metabase.events.core :as events]+ [metabase.lib.schema.literal :as lib.schema.literal][metabase.models.interface :as mi][metabase.request.core :as request][metabase.util :as u]@@ -57,7 +59,7 @@[:and{:error/message "Comment content must be valid JSON":json-schema {:type "object"}}- ms/Map]+ ::comments.schema/prose-mirror-node](deferred-tru "Comment content must be valid JSON.")))(def ^:private CommentHighlight@@ -69,7 +71,7 @@[:dimensions {:optional true}[:maybe [:sequential [:map {:closed true}[:columnName {:optional true} [:maybe :string]]- [:value {:optional true} :any]]]]]])+ [:value {:optional true} [:ref ::lib.schema.literal/literal]]]]]]])(def CommentContext"Context stored alongside a comment"@@ -86,7 +88,7 @@(def CreateComment"Schema for creating a new comment"- [:map+ [:map {:closed true}[:target_type TargetType][:target_id ms/PositiveInt][:content CommentContent]@@ -96,7 +98,7 @@(def UpdateComment"Schema for updating a comment"- [:map+ [:map {:closed true}[:content {:optional true} CommentContent][:is_resolved {:optional true} :boolean]])@@ -136,7 +138,7 @@(api.macros/defendpoint :get "/""Get comments for an entity"[_route-params- {:keys [target_type target_id]} :- [:map+ {:keys [target_type target_id]} :- [:map {:closed true}[:target_type TargetType][:target_id ms/PositiveInt]]_body@@ -239,7 +241,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :put "/:comment-id""Update a comment"- [{:keys [comment-id]} :- [:map [:comment-id ms/PositiveInt]]+ [{:keys [comment-id]} :- [:map {:closed true} [:comment-id ms/PositiveInt]]_query-params{:keys [content is_resolved]} :- UpdateComment](let [comment (api/check-404 (comments.db/comment-by-id comment-id))@@ -273,7 +275,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/:comment-id""Soft delete a comment"- [{:keys [comment-id]} :- [:map [:comment-id ms/PositiveInt]]+ [{:keys [comment-id]} :- [:map {:closed true} [:comment-id ms/PositiveInt]]_query-params](let [comment (api/check-404 (comments.db/comment-by-id comment-id))](-> (api/read-check (type->model (:target_type comment)) (:target_id comment))@@ -297,9 +299,9 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :post "/:comment-id/reaction""Toggle a reaction on a comment"- [{:keys [comment-id]} :- [:map [:comment-id ms/PositiveInt]]+ [{:keys [comment-id]} :- [:map {:closed true} [:comment-id ms/PositiveInt]]_query-params- {:keys [emoji]} :- [:map [:emoji [:string {:min 1 :max 10}]]]]+ {:keys [emoji]} :- [:map {:closed true} [:emoji [:string {:min 1 :max 10}]]]](let [comment (api/check-404 (comments.db/comment-by-id comment-id))](api/check-400 (not (:deleted_at comment))"Cannot react to deleted comments")diff --git a/src/metabase/comments/models/comment.clj b/src/metabase/comments/models/comment.cljindex c451442d216..171fa88bc46 100644--- a/src/metabase/comments/models/comment.clj+++ b/src/metabase/comments/models/comment.clj@@ -5,6 +5,7 @@[metabase.channel.urls :as channel.urls][metabase.comments.db :as comments.db][metabase.comments.models.comment-reaction :as comment-reaction]+ [metabase.comments.schema :as comments.schema][metabase.models.interface :as mi][methodical.core :as methodical][ring.util.codec :as codec]@@ -22,7 +23,9 @@;; future migration.(t2/deftransforms :model/Comment- {:content mi/transform-json+ {:content {:in (comp mi/json-in comments.schema/normalize-content)+ :out (comp (mi/catch-normalization-exceptions comments.schema/normalize-content)+ mi/json-out-with-keywordization)}:context mi/transform-json})(methodical/defmethod t2/batched-hydrate [:model/Comment :creator]@@ -124,8 +127,8 @@[content](into [](comp (filter #(and (= "smartLink" (:type %))- (= "user" (-> % :attrs :model))))- (keep #(let [entity-id (-> % :attrs :entityId)]+ (= "user" (get-in % [:attrs "model"]))))+ (keep #(let [entity-id (get-in % [:attrs "entityId"])](when (pos-int? entity-id)entity-id))))(tree-seq :content :content content)))diff --git a/src/metabase/comments/render.clj b/src/metabase/comments/render.cljindex 4d45674942e..cfe0023204e 100644--- a/src/metabase/comments/render.clj+++ b/src/metabase/comments/render.clj@@ -69,7 +69,7 @@"Convert a smartLink node to hiccup. Builds URLs from model + entityId rather thantrusting the href attribute, which could be crafted to inject phishing links."[{:keys [attrs]}]- (let [{:keys [label model entityId]} attrs+ (let [{:strs [label model entityId]} attrsdisplay-text (or label(when (= model "user") (str "@" entityId))(str model " " entityId))@@ -90,7 +90,7 @@(case type"doc" (children->hiccup content)"paragraph" (into [:p] (children->hiccup content))- "heading" (let [level (min (max (get attrs :level 1) 1) 6)+ "heading" (let [level (min (max (get attrs "level" 1) 1) 6)tag (keyword (str "h" level))](into [tag] (children->hiccup content)))"bulletList" (into [:ul] (children->hiccup content))diff --git a/src/metabase/comments/schema.clj b/src/metabase/comments/schema.cljindex 446453d000b..e56f5bd1e40 100644--- a/src/metabase/comments/schema.clj+++ b/src/metabase/comments/schema.clj@@ -1,13 +1,41 @@(ns metabase.comments.schema"Malli schemas for the comments module."(:require+ [metabase.lib.core :as lib][metabase.lib.schema.id :as lib.schema.id]+ [metabase.util.malli :as mu][metabase.util.malli.registry :as mr][metabase.util.malli.schema :as ms]))+(mr/def ::prose-mirror-node.attrs+ "The `attrs` of a ProseMirror node in a comment: the ones this code reads by name, and whatever else the editor put+ there. Every key, declared or not, is a string, so the map never mixes keyword and string keys."+ (ms/string-keyed-object+ ["model" {:optional true} [:maybe :string]]+ ["entityId" {:optional true} [:maybe [:or :int :string]]]+ ["label" {:optional true} [:maybe :string]]+ ["level" {:optional true} [:maybe :int]]))++(mr/def ::prose-mirror-node+ "One node of the ProseMirror/TipTap document a comment is written in, in the shape ProseMirror's `Node.toJSON`+ emits: a `:type`, the children it contains, the marks applied to it, and `:text` on text nodes. Those five keys are+ the whole of the ProseMirror JSON node format; `:attrs` varies by node type. Marks are nodes too as far as this+ schema is concerned -- a mark carries only `:type` and `:attrs`, which is a subset of a node."+ [:map {:closed true}+ [:type :string]+ [:attrs {:optional true} [:maybe [:ref ::prose-mirror-node.attrs]]]+ [:content {:optional true} [:sequential [:ref ::prose-mirror-node]]]+ [:marks {:optional true} [:sequential [:ref ::prose-mirror-node]]]+ [:text {:optional true} :string]])+(mr/def ::comment.content- "The `:content` column of a Comment, decoded."- :map)+ "The `:content` column of a Comment, decoded: the ProseMirror document the comment was written in."+ ::prose-mirror-node)++(mu/defn normalize-content :- [:maybe ::comment.content]+ "Normalize a comment's content on its way in from the API or out of the application database."+ [content]+ (some->> content (lib/normalize ::comment.content)))(mr/def ::comment.context"The `:context` column of a Comment, decoded."diff --git a/src/metabase/dashboards/models/dashboard.clj b/src/metabase/dashboards/models/dashboard.cljindex 96d10850ae6..3a1b5dbece5 100644--- a/src/metabase/dashboards/models/dashboard.clj+++ b/src/metabase/dashboards/models/dashboard.clj@@ -70,7 +70,7 @@(t2/deftransforms :model/Dashboard{:parameters parameters/transform-parameters:public_uuid (mi/transform-encrypted-text "report_dashboard.public_uuid")- :embedding_params mi/transform-json})+ :embedding_params mi/transform-json-no-keywordization})(t2/define-before-delete :model/Dashboard[dashboard]@@ -255,7 +255,7 @@are performed when finished, for example updating FieldValues for On-Demand DBs.Returns `nil`."[dashboard :- DashboardWithSeriesAndCard- new-dashcards :- [:sequential ms/Map]]+ new-dashcards :- [:sequential :map]](let [old-dashcards (:dashcards dashboard)id->old-dashcard (m/index-by :id old-dashcards)old-dashcard-ids (set (keys id->old-dashcard))diff --git a/src/metabase/dashboards_rest/api.clj b/src/metabase/dashboards_rest/api.cljindex a084f2ca5a6..faa7865c553 100644--- a/src/metabase/dashboards_rest/api.clj+++ b/src/metabase/dashboards_rest/api.clj@@ -27,6 +27,7 @@[metabase.lib-be.core :as lib-be][metabase.lib-be.schema :as lib-be.schema][metabase.lib.schema.id :as lib.schema.id]+ [metabase.lib.schema.parameter :as lib.schema.parameter][metabase.models.interface :as mi][metabase.parameters.chain-filter :as chain-filter][metabase.parameters.core :as parameters]@@ -80,7 +81,7 @@* `archived` - Return Dashboards that have been archived. (By default, these are *excluded*.)"{:deprecated true}[_route-params- {:keys [f]} :- [:map+ {:keys [f]} :- [:map {:closed true}[:f {:optional true} [:maybe [:enum "all" "mine" "archived"]]]]](let [dashboards (dashboards-list f)edit-infos (:dashboard (revisions/fetch-last-edited-info {:dashboard-ids (map :id dashboards)}))]@@ -168,7 +169,7 @@[_route-params_query-params{:keys [name description parameters cache_ttl collection_id collection_position], :as _dashboard}- :- [:map+ :- [:map {:closed true}[:name ms/NonBlankString][:parameters {:optional true} [:maybe ::parameters.schema/parameters]][:description {:optional true} [:maybe :string]]@@ -565,11 +566,11 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :post "/:from-dashboard-id/copy""Copy a Dashboard."- [{:keys [from-dashboard-id]} :- [:map+ [{:keys [from-dashboard-id]} :- [:map {:closed true}[:from-dashboard-id ms/PositiveInt]]_query-params{:keys [name description collection_id collection_position- is_deep_copy], :as _dashboard} :- [:map+ is_deep_copy], :as _dashboard} :- [:map {:closed true}[:name {:optional true} [:maybe ms/NonBlankString]][:description {:optional true} [:maybe :string]][:collection_id {:optional true} [:maybe ms/PositiveInt]]@@ -659,9 +660,9 @@:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id""Get Dashboard with ID."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id [:or ms/PositiveInt ms/NanoIdString]]]- {dashboard-load-id :dashboard_load_id} :- [:map+ {dashboard-load-id :dashboard_load_id} :- [:map {:closed true}[:dashboard_load_id {:optional true} [:maybe ms/NonBlankString]]]](with-dashboard-load-id dashboard-load-id(let [resolved-id (eid-translation/->id-or-404 :dashboard id)@@ -678,10 +679,10 @@action drive the download). Parameters left unspecified fall back to the dashboard's own defaults.`paper_size` is `\"a4\"` (default) or `\"letter\"`."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-params- {:keys [parameters paper_size]} :- [:map+ {:keys [parameters paper_size]} :- [:map {:closed true}[:parameters {:optional true} [:maybe ::parameters.schema/api.parameter-values]][:paper_size {:default "a4"} [:maybe [:enum "a4" "letter"]]]]_request@@ -708,7 +709,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id/items""Get Dashboard with ID."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]];; Output should match the shape of api/collection/<:id|root>/items. There's a test that asserts that this remains;; the case, but if you change one, you'll want to change both.@@ -740,7 +741,7 @@"Hard delete a Dashboard. To soft delete, use `PUT /api/dashboard/:id`This will remove also any questions/models/segments/metrics that use this database."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](let [dashboard (api/write-check :model/Dashboard id)](dashboards-rest.db/delete-dashboard! id)@@ -755,7 +756,11 @@(mu/defn- check-parameter-mapping-permissions"Starting in 0.41.0, you must have *data* permissions in order to add or modify a DashboardCard parameter mapping."{:added "0.41.0"}- [parameter-mappings :- [:sequential ::parameters.schema/parameter-mapping]]+ [parameter-mappings :- [:sequential [:merge+ ::parameters.schema/parameter-mapping+ [:map {:closed true}+ [:dashcard-id {:optional true} [:maybe ms/PositiveInt]]+ [:card-id {:optional true} [:maybe ms/PositiveInt]]]]]](when (seq parameter-mappings)(let [card-ids (into #{} (keep :card-id) parameter-mappings)card-id->query (when (seq card-ids)@@ -851,7 +856,7 @@(create-dashcards! dashboard to-create))}))(def ^:private UpdatedDashboardCard- [:map+ [:map {:closed true};; id can be negative, it indicates a new card and BE should create them[:id int?][:size_x ms/PositiveInt]@@ -862,12 +867,12 @@[:action_id {:optional true} [:maybe ms/PositiveInt]][:dashboard_tab_id {:optional true} [:maybe int?]][:parameter_mappings {:optional true} [:maybe [:ref ::parameters.schema/parameter-mappings]]]- [:visualization_settings {:optional true} [:maybe ms/Map]]+ [:visualization_settings {:optional true} [:maybe ms/VisualizationSettings]][:inline_parameters {:optional true} [:maybe [:sequential ms/NonBlankString]]]- [:series {:optional true} [:maybe [:sequential [:map [:id ms/PositiveInt]]]]]])+ [:series {:optional true} [:maybe [:sequential [:map {:closed true} [:id ms/PositiveInt]]]]]])(def ^:private UpdatedDashboardTab- [:map+ [:map {:closed true};; id can be negative, it indicates a new card and BE should create them[:id ms/Int][:name ms/NonBlankString]@@ -1078,7 +1083,7 @@(def ^:private DashUpdates"Schema for Dashboard Updates."- [:map+ [:map {:closed true}[:name {:optional true} [:maybe ms/NonBlankString]][:description {:optional true} [:maybe :string]][:caveats {:optional true} [:maybe :string]]@@ -1105,7 +1110,7 @@(api.macros/defendpoint :put "/:id""Update a Dashboard, and optionally the `dashcards` and `tabs` of a Dashboard. The request body should be a JSON object with the samestructure as the response from `GET /api/dashboard/:id`."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-paramsdash-updates :- DashUpdates]@@ -1130,10 +1135,10 @@...]:tabs [{:id ... ; DashboardTab ID:name ...}]}"- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-params- {:keys [cards tabs]} :- [:map+ {:keys [cards tabs]} :- [:map {:closed true}[:cards (ms/maps-with-unique-key [:sequential UpdatedDashboardCard] :id)][:tabs {:optional true} [:maybe (ms/maps-with-unique-key [:sequential UpdatedDashboardTab] :id)]]]](log/warn@@ -1152,9 +1157,9 @@:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id/query_metadata""Get all of the required query metadata for the cards on dashboard."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id [:or ms/PositiveInt ms/NanoIdString]]]- {dashboard-load-id :dashboard_load_id} :- [:map+ {dashboard-load-id :dashboard_load_id} :- [:map {:closed true}[:dashboard_load_id {:optional true} [:maybe ms/NonBlankString]]]](with-dashboard-load-id dashboard-load-id(perms/with-relevant-permissions-for-user api/*current-user-id*@@ -1175,7 +1180,7 @@"Generate publicly-accessible links for this Dashboard. Returns UUID to be used in public links. (If thisDashboard has already been shared, it will return the existing public link rather than creating a new one.) Publicsharing must be enabled."- [{:keys [dashboard-id]} :- [:map+ [{:keys [dashboard-id]} :- [:map {:closed true}[:dashboard-id ms/PositiveInt]]](api/check-superuser)(public-sharing.validation/check-public-sharing-enabled)@@ -1200,7 +1205,7 @@:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/:dashboard-id/public_link""Delete the publicly-accessible link to this Dashboard."- [{:keys [dashboard-id]} :- [:map+ [{:keys [dashboard-id]} :- [:map {:closed true}[:dashboard-id ms/PositiveInt]]](perms/check-has-application-permission :setting)(public-sharing.validation/check-public-sharing-enabled)@@ -1219,23 +1224,23 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id/related""Return related entities."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](-> (dashboards-rest.db/dashboard id) api/read-check xrays/related));;; ---------------------------------------------- Transient dashboards ----------------------------------------------(def ^:private TransientCard- [:map+ [:map {:closed true}[:id {:optional true} [:maybe [:or ms/PositiveInt ms/NonBlankString]]][:name {:optional true} [:maybe ms/NonBlankString]][:description {:optional true} [:maybe :string]][:display {:optional true} [:maybe ms/NonBlankString]][:dataset_query {:optional true} [:maybe ::lib-be.schema/maybe-legacy-or-empty-query]]- [:visualization_settings {:optional true} [:maybe ms/Map]]])+ [:visualization_settings {:optional true} [:maybe ms/VisualizationSettings]]])(def ^:private TransientDashboardCard- [:map+ [:map {:closed true}[:card {:optional true} [:maybe TransientCard]][:series {:optional true} [:maybe [:sequential TransientCard]]][:row {:optional true} [:maybe ms/IntGreaterThanOrEqualToZero]]@@ -1244,10 +1249,10 @@[:size_y {:optional true} [:maybe ms/PositiveInt]][:dashboard_tab_id {:optional true} [:maybe ms/Int]][:parameter_mappings {:optional true} [:maybe [:ref ::parameters.schema/parameter-mappings]]]- [:visualization_settings {:optional true} [:maybe ms/Map]]])+ [:visualization_settings {:optional true} [:maybe ms/VisualizationSettings]]])(def ^:private TransientDashboard- [:map+ [:map {:closed true}[:name {:optional true} [:maybe ms/NonBlankString]][:description {:optional true} [:maybe :string]][:parameters {:optional true} [:maybe [:ref ::parameters.schema/parameters]]]@@ -1262,7 +1267,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :post "/save/collection/:parent-collection-id""Save a denormalized description of dashboard into collection with ID `:parent-collection-id`."- [{:keys [parent-collection-id]} :- [:map+ [{:keys [parent-collection-id]} :- [:map {:closed true}[:parent-collection-id ms/PositiveInt]]_query-paramsdashboard :- TransientDashboard]@@ -1301,10 +1306,10 @@;; fetch values for Dashboard 1 parameter 'abc' that are possible when parameter 'def' is set to 100GET /api/dashboard/1/params/abc/values?def=100"- [{:keys [id param-key]} :- [:map+ [{:keys [id param-key]} :- [:map {:closed true}[:id ms/PositiveInt][:param-key ms/NonBlankString]]- constraint-param-key->value :- [:map-of string? any?]]+ constraint-param-key->value :- (ms/string-keyed-map [:ref ::lib.schema.parameter/parameter.value])](let [dashboard (api/read-check :model/Dashboard id)];; If a user can read the dashboard, then they can lookup filters. This also works with sandboxing.(binding [qp.perms/*param-values-query* true]@@ -1323,11 +1328,11 @@GET /api/dashboard/1/params/abc/search/Cam?def=100Currently limited to first 1000 results."- [{:keys [id param-key query]} :- [:map+ [{:keys [id param-key query]} :- [:map {:closed true}[:id ms/PositiveInt][:param-key ms/NonBlankString][:query ms/NonBlankString]]- constraint-param-key->value :- [:map-of string? any?]]+ constraint-param-key->value :- (ms/string-keyed-map [:ref ::lib.schema.parameter/parameter.value])](let [dashboard (api/read-check :model/Dashboard id)];; If a user can read the dashboard, then they can lookup filters. This also works with sandboxing.(binding [qp.perms/*param-values-query* true@@ -1343,10 +1348,10 @@;; fetch the remapped value for Dashboard 1 parameter 'abc' for value 100GET /api/dashboard/1/params/abc/remapping?value=100"- [{:keys [id param-key]} :- [:map+ [{:keys [id param-key]} :- [:map {:closed true}[:id ms/PositiveInt][:param-key ms/NonBlankString]]- {:keys [value]} :- [:map [:value :string]]]+ {:keys [value]} :- [:map {:closed true} [:value :string]]](let [dashboard (api/read-check :model/Dashboard id)](binding [qp.perms/*param-values-query* true](parameters.dashboard/dashboard-param-remapped-value dashboard param-key (codec/url-decode value)))))@@ -1377,7 +1382,7 @@`filtered` Field ID -> subset of `filtering` Field IDs that would be used in chain filter query"[_route-params- {:keys [filtered filtering]} :- [:map+ {:keys [filtered filtering]} :- [:map {:closed true}[:filtered (ms/QueryVectorOf ::lib.schema.id/field)][:filtering {:optional true} [:maybe (ms/QueryVectorOf ::lib.schema.id/field)]]]](let [filtered-field-ids (if (sequential? filtered) (set filtered) #{filtered})@@ -1393,11 +1398,11 @@"Fetches the values for filling in execution parameters. Pass PK parameters and values to select.Parameters are sent in the request body rather than the query string so their values stay out of URLs and logs."- [{:keys [dashboard-id dashcard-id]} :- [:map+ [{:keys [dashboard-id dashcard-id]} :- [:map {:closed true}[:dashboard-id ms/PositiveInt][:dashcard-id ms/PositiveInt]]_query-params- {:keys [parameters]} :- [:map+ {:keys [parameters]} :- [:map {:closed true}[:parameters {:optional true} ::actions.schema/prefetch-parameter-values]]](api/read-check :model/Dashboard dashboard-id)(let [dashcard (api/check-404 (dashboards-rest.db/dashcard-in-dashboard dashcard-id dashboard-id))]@@ -1414,11 +1419,11 @@`parameters` should be the mapped dashboard parameters with values.`extra_parameters` should be the extra, user entered parameter values."- [{:keys [dashboard-id dashcard-id]} :- [:map+ [{:keys [dashboard-id dashcard-id]} :- [:map {:closed true}[:dashboard-id ms/PositiveInt][:dashcard-id ms/PositiveInt]]_query-params- {:keys [parameters]} :- [:map+ {:keys [parameters]} :- [:map {:closed true}[:parameters {:optional true}[:maybe ::actions.schema/execute-parameter-values.string-keys]]]](api/read-check :model/Dashboard dashboard-id)@@ -1432,12 +1437,12 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :post "/:dashboard-id/dashcard/:dashcard-id/card/:card-id/query""Run the query associated with a Saved Question (`Card`) in the context of a `Dashboard` that includes it."- [{:keys [dashboard-id dashcard-id card-id]} :- [:map+ [{:keys [dashboard-id dashcard-id card-id]} :- [:map {:closed true}[:dashboard-id ms/PositiveInt][:dashcard-id ms/PositiveInt][:card-id ms/PositiveInt]]_query-params- {:keys [dashboard_load_id], :as body} :- [:map+ {:keys [dashboard_load_id], :as body} :- [:map {:closed true}[:dashboard_load_id {:optional true} [:maybe ms/NonBlankString]][:parameters {:optional true} [:maybe [:sequential ::parameters.schema/parameter-with-value]]]]](with-dashboard-load-id dashboard_load_id@@ -1458,7 +1463,7 @@`parameters` should be passed as query parameter encoded as a serialized JSON string (this is because this endpointis normally used to power 'Download Results' buttons that use HTML `form` actions)."- [{:keys [dashboard-id dashcard-id card-id export-format]} :- [:map+ [{:keys [dashboard-id dashcard-id card-id export-format]} :- [:map {:closed true}[:dashboard-id ms/PositiveInt][:dashcard-id ms/PositiveInt][:card-id ms/PositiveInt]@@ -1467,7 +1472,7 @@{:keys [parameters]format-rows? :format_rowspivot-results? :pivot_results}- :- [:map+ :- [:map {:closed true}[:parameters {:optional true} [:maybe ::parameters.schema/api.parameter-values]][:format_rows {:default false} ms/BooleanValue][:pivot_results {:default false} ms/BooleanValue]]]@@ -1495,12 +1500,12 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :post "/pivot/:dashboard-id/dashcard/:dashcard-id/card/:card-id/query""Run a pivot table query for a specific DashCard."- [{:keys [dashboard-id dashcard-id card-id]} :- [:map+ [{:keys [dashboard-id dashcard-id card-id]} :- [:map {:closed true}[:dashboard-id ms/PositiveInt][:dashcard-id ms/PositiveInt][:card-id ms/PositiveInt]]_query-params- body :- [:map+ body :- [:map {:closed true}[:parameters {:optional true} [:maybe [:sequential ::parameters.schema/parameter-with-value]]]]](m/mapply qp.dashboard/process-query-for-dashcard(mergediff --git a/src/metabase/data_studio/api/table.clj b/src/metabase/data_studio/api/table.cljindex cc867381035..34429a4e1af 100644--- a/src/metabase/data_studio/api/table.clj+++ b/src/metabase/data_studio/api/table.clj@@ -23,7 +23,7 @@(set! *warn-on-reflection* true)(mr/def ::table-selectors- [:map+ [:map {:closed true};; disjunctive filters (e.g. db_id IN $database_ids OR id IN $table_ids)[:database_ids {:optional true} [:sequential ms/PositiveInt]][:schema_ids {:optional true} [:sequential :string]]diff --git a/src/metabase/documents/api/document.clj b/src/metabase/documents/api/document.cljindex 52ed825a580..a38fe4b9408 100644--- a/src/metabase/documents/api/document.clj+++ b/src/metabase/documents/api/document.clj@@ -16,6 +16,7 @@[metabase.parameters.schema :as parameters.schema][metabase.public-sharing.validation :as public-sharing.validation][metabase.queries.core :as card]+ [metabase.queries.schema :as queries.schema][metabase.query-permissions.core :as query-perms][metabase.query-processor.api :as api.dataset][metabase.query-processor.card :as qp.card]@@ -27,16 +28,16 @@(def ^:private CardCreateSchema"Schema for creating a new card - simplified version to avoid circular dependencies"- [:map+ [:map {:closed true}[:name ms/NonBlankString][:dataset_query ::lib-be.schema/maybe-legacy-query][:entity_id {:optional true} [:maybe ms/NonBlankString]][:parameters {:optional true} [:maybe ::parameters.schema/parameters]]- [:parameter_mappings {:optional true} [:maybe [:sequential ms/Map]]]+ [:parameter_mappings {:optional true} [:maybe ::parameters.schema/parameter-mappings]][:description {:optional true} [:maybe ms/NonBlankString]][:display ms/NonBlankString]- [:visualization_settings ms/Map]- [:result_metadata {:optional true} [:maybe [:sequential ms/Map]]]+ [:visualization_settings ms/VisualizationSettings]+ [:result_metadata {:optional true} [:maybe ::queries.schema/card.result-metadata]][:cache_ttl {:optional true} [:maybe ms/PositiveInt]]])(defn- cards-to-create-schema@@ -57,7 +58,7 @@[:map-of key-schema CardCreateSchema]])(def ^:private DocumentCreateOptions- [:map+ [:map {:closed true}[:name m.document/DocumentName][:document ::prose-mirror/ast][:collection_id {:optional true} [:maybe ms/PositiveInt]]@@ -65,7 +66,7 @@[:cards {:optional true} [:maybe (cards-to-create-schema [:int {:max -1}])]]])(def ^:private DocumentUpdateOptions- [:map+ [:map {:closed true}[:name {:optional true} m.document/DocumentName][:document {:optional true} [:maybe ::prose-mirror/ast]][:collection_id {:optional true} [:maybe ms/PositiveInt]]@@ -112,9 +113,9 @@(map? document)(prose-mirror/update-ast (fn match-card-to-update [{:keys [type attrs]}](and (= type prose-mirror/card-embed-type)- (contains? card-id-map (:id attrs))))+ (contains? card-id-map (get attrs "id"))))(fn update-card-id [embed]- (update-in embed [:attrs :id] card-id-map)))))+ (update-in embed [:attrs "id"] card-id-map)))))(mu/defn- create-cards-for-document! :- [:map-of ms/NegativeInt ms/PositiveInt]"Creates cards for a document from the cards map.@@ -157,8 +158,8 @@- map of old-card-id -> cloned-card-id"[{:keys [id collection_id] :as document}](let [card-ids (prose-mirror/collect-ast document #(when (and (= prose-mirror/card-embed-type (:type %))- (pos-int? (-> % :attrs :id)))- (-> % :attrs :id)))+ (pos-int? (get-in % [:attrs "id"])))+ (get-in % [:attrs "id"])))to-clone (when (seq card-ids)(documents.db/cards-not-in-document card-ids id))](m.document/with-content-gate-cache@@ -200,10 +201,10 @@{:document document :content_type content-type}(fn [{:keys [type attrs]}](when (and (= prose-mirror/card-embed-type type)- (contains? draft-card-id-map (:id attrs))- (:stored_result_id attrs))- [(get draft-card-id-map (:id attrs))- (:stored_result_id attrs)])))+ (contains? draft-card-id-map (get attrs "id"))+ (get attrs "stored_result_id"))+ [(get draft-card-id-map (get attrs "id"))+ (get attrs "stored_result_id")])))distinctvec)))@@ -213,8 +214,8 @@top-level blocks; `nil` appends the embed at the end and out-of-range indexes are clamped.Optional kwargs:- - `:extra-attrs` — map merged onto the `cardEmbed` attrs (e.g. `:stored_result_id`,- `:chart_href`, `:child_target_id`, `:host_data`).+ - `:extra-attrs` — string-keyed map merged onto the `cardEmbed` attrs (e.g. `\"stored_result_id\"`,+ `\"chart_href\"`, `\"child_target_id\"`, `\"host_data\"`).Adding a card clears `:is_placeholder` when it was set. The caller is responsible forwrite-checking the document first. The document is re-read inside the transaction so a@@ -290,7 +291,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:document-id""Returns an existing Document by ID."- [{:keys [document-id]} :- [:map [:document-id ms/PositiveInt]]]+ [{:keys [document-id]} :- [:map {:closed true} [:document-id ms/PositiveInt]]];; `get-document` already does the 404 + read-check internally;(get-document document-id))@@ -300,7 +301,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :put "/:document-id""Updates an existing `Document`."- [{:keys [document-id]} :- [:map+ [{:keys [document-id]} :- [:map {:closed true}[:document-id ms/PositiveInt]]_query-params{:keys [name document collection_id collection_position cards] :as body} :- DocumentUpdateOptions]@@ -364,7 +365,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/:document-id""Permanently deletes an archived Document."- [{:keys [document-id]} :- [:map [:document-id ms/PositiveInt]]]+ [{:keys [document-id]} :- [:map {:closed true} [:document-id ms/PositiveInt]]](let [document (api/check-404 (documents.db/document document-id))](api/write-check document)(when-not (:archived document)@@ -413,10 +414,10 @@(api.macros/defendpoint :post "/:from-document-id/copy" :- [:map [:id ::documents.schema/document.id]]"Copy a Document."- [{:keys [from-document-id]} :- [:map+ [{:keys [from-document-id]} :- [:map {:closed true}[:from-document-id ms/PositiveInt]]_query-params- {:keys [name collection_id collection_position]} :- [:map+ {:keys [name collection_id collection_position]} :- [:map {:closed true}[:name {:optional true} [:maybe ms/NonBlankString]][:collection_id {:optional true} [:maybe ms/PositiveInt]][:collection_position {:optional true} [:maybe ms/PositiveInt]]]]@@ -461,7 +462,7 @@Returns a map containing `:uuid` (the public UUID string).Requires superuser permissions. Public sharing must be enabled via the `enable-public-sharing` setting."- [{:keys [document-id]} :- [:map+ [{:keys [document-id]} :- [:map {:closed true}[:document-id ms/PositiveInt]]](api/check-superuser)(public-sharing.validation/check-public-sharing-enabled)@@ -492,7 +493,7 @@Requires superuser permissions. Public sharing must be enabled via the `enable-public-sharing` setting.Throws a 404 if the Document doesn't exist, is archived, or doesn't have a public link."- [{:keys [document-id]} :- [:map+ [{:keys [document-id]} :- [:map {:closed true}[:document-id ms/PositiveInt]]](api/check-superuser)(public-sharing.validation/check-public-sharing-enabled)@@ -552,7 +553,7 @@- parameters: Optional query parameters (array of maps or JSON string)- format_rows: Whether to apply formatting to results (boolean, default false)- pivot_results: Whether to pivot results (boolean, default false)"- [{:keys [document-id card-id export-format]} :- [:map+ [{:keys [document-id card-id export-format]} :- [:map {:closed true}[:document-id ms/PositiveInt][:card-id ms/PositiveInt][:export-format :keyword]]@@ -561,7 +562,7 @@pivot-results? :pivot_resultsformat-rows? :format_rows:as _body}- :- [:map+ :- [:map {:closed true}[:parameters {:optional true} [:maybe ::parameters.schema/api.parameter-values]][:format_rows {:default false} ms/BooleanValue][:pivot_results {:default false} ms/BooleanValue]]]diff --git a/src/metabase/documents/models/document.clj b/src/metabase/documents/models/document.cljindex eb3926a6f26..e183b10ea85 100644--- a/src/metabase/documents/models/document.clj+++ b/src/metabase/documents/models/document.clj@@ -27,7 +27,9 @@:model/Document)(t2/deftransforms :model/Document- {:document mi/transform-json+ {:document {:in (comp mi/json-in prose-mirror/normalize-document)+ :out (comp (mi/catch-normalization-exceptions prose-mirror/normalize-document)+ mi/json-out-with-keywordization)}:public_uuid (mi/transform-encrypted-text "document.public_uuid")})(doto :model/Document@@ -210,13 +212,15 @@(defn- document->search-text"Extract the plain searchable text from a document's prose-mirror body for the search index.- Receives the raw `:document` value as it comes off the ingestion query (a JSON string).- Returns nil if it can't be parsed, so a malformed/oversized body never blocks the rest of the- document (e.g. its name) from being indexed."+ Receives the raw `:document` value as it comes off the ingestion query (a JSON string). Blindly+ keywordizing that JSON would leave every node's `:attrs` keyword-keyed too, so it is normalized --+ stringifying attrs -- before `ast->text` reads them. Returns nil if it can't be parsed, so a+ malformed/oversized body never blocks the rest of the document (e.g. its name) from being indexed."[document](when document(try(-> (cond-> document (string? document) json/decode+kw)+ prose-mirror/normalize-documentprose-mirror/ast->textnot-empty)(catch Throwable _ nil))))@@ -279,11 +283,11 @@verbatim would, on import, either dangle or silently resolve to an unrelated instance'ssnapshot. Dropping it degrades a static (snapshot-backed) embed to a live embed of the Card,which is portable and renders the same query."- [:stored_result_id])+ ["stored_result_id"])(defn- id->entity-id- [{{:keys [model] :or {model "card"}} :attrs type :type :as node}]- (let [id-key (if (= prose-mirror/smart-link-type type) :entityId :id)+ [{{:strs [model] :or {model "card"}} :attrs type :type :as node}]+ (let [id-key (if (= prose-mirror/smart-link-type type) "entityId" "id")id (prose-mirror/node-entity-id node)node (cond-> node(= prose-mirror/card-embed-type type)@@ -295,12 +299,12 @@(defn- entity-id->id[{:keys [attrs type] :as node}]- (let [id-key (if (= prose-mirror/smart-link-type type) :entityId :id)- id (:id (serdes/load-find-local (id-key attrs)))]+ (let [id-key (if (= prose-mirror/smart-link-type type) "entityId" "id")+ id (:id (serdes/load-find-local (get attrs id-key)))](if id(assoc-in node [:attrs id-key] id)(u/prog1 node- (log/warn "Model not found at path" (id-key attrs))))))+ (log/warn "Model not found at path" (get attrs id-key))))))(defn- serdes-rewritable-node?"The AST nodes whose ids serdes rewrites between database ids and entity ids.@@ -323,11 +327,16 @@document)))(defn- import-document-content- "Transform live cardEmbed / smartLink nodes to use database IDs instead of entity IDs"+ "Transform live cardEmbed / smartLink nodes to use database IDs instead of entity IDs.++ Ingested YAML keywordizes every key, attrs included, so the document is normalized first --+ stringifying attrs keys -- before [[entity-id->id]] reads them; it and the app-DB `:in` transform+ that runs after this must only ever see string-keyed attrs."[document serdes-key _](serdes-key(if (= (:content_type document) prose-mirror/prose-mirror-content-type)- (prose-mirror/update-ast document serdes-rewritable-node? entity-id->id)+ (prose-mirror/update-ast (update document :document prose-mirror/normalize-document)+ serdes-rewritable-node? entity-id->id)document)))(defmethod serdes/make-spec "Document"@@ -359,11 +368,11 @@(set (prose-mirror/collect-ast document (fn document-deps [{:keys [type attrs]}](cond(and (= prose-mirror/smart-link-type type)- (contains? model->serdes-model (:model attrs)))- (:entityId attrs)+ (contains? model->serdes-model (get attrs "model")))+ (get attrs "entityId")(= prose-mirror/card-embed-type type)- (:id attrs)+ (get attrs "id"):elsenil))))))@@ -385,7 +394,7 @@(concat(for [embedded-card-id (prose-mirror/card-ids document)][{:model "Card" :id embedded-card-id}])- (for [{{model :model} :attrs :as node}+ (for [{{model "model"} :attrs :as node}(prose-mirror/collect-ast document#(when (= prose-mirror/smart-link-type (:type %)) %)):let [link-id (prose-mirror/node-entity-id node)]@@ -401,8 +410,8 @@(for [embedded-card-id (prose-mirror/card-ids document)]{["Card" embedded-card-id] {"Document" id}}))(into {}- (for [{{model :model} :attrs :as node} (prose-mirror/collect-ast document- #(when (= prose-mirror/smart-link-type (:type %)) %))+ (for [{{model "model"} :attrs :as node} (prose-mirror/collect-ast document+ #(when (= prose-mirror/smart-link-type (:type %)) %)):let [link-id (prose-mirror/node-entity-id node)]:when (and link-id (contains? model->serdes-model model))]{[(model->serdes-model model) link-id] {"Document" id}}))))))diff --git a/src/metabase/documents/prose_mirror.clj b/src/metabase/documents/prose_mirror.cljindex 68836a35051..346a0983f60 100644--- a/src/metabase/documents/prose_mirror.clj+++ b/src/metabase/documents/prose_mirror.clj@@ -3,16 +3,69 @@(:require[clojure.string :as str][clojure.walk :as walk]- [metabase.util.malli.registry :as mr]))+ [metabase.lib.core :as lib]+ [metabase.lib.schema.parameter :as lib.schema.parameter]+ [metabase.util.malli.registry :as mr]+ [metabase.util.malli.schema :as ms]))++(def ^:private ExploreFilterScalar+ [:maybe [:or :string number? :boolean]])++(mr/def ::card-embed.explore-filter+ "One explore-further filter `metabase.explorations` snapshots onto a static card embed: the filter as the client+ sent it, plus the name of the dimension it is on. Its `:field_ref` is the legacy `field_ref` of the chart column+ that was clicked."+ [:map {:closed true}+ [:operator :string]+ [:field_ref [:ref ::lib.schema.parameter/dimension.target]]+ [:value {:optional true} ExploreFilterScalar]+ [:values {:optional true} [:tuple ExploreFilterScalar ExploreFilterScalar]]+ [:display_value :string]+ [:dimension_name {:optional true} [:maybe :string]]])++(mr/def ::card-embed.host-data+ "What `metabase.explorations` writes under `:host_data` of a static card embed so the frontend can render the+ embed's filter pills and hover highlights without a live lookup."+ [:map {:closed true}+ [:query_ids {:optional true} [:maybe [:sequential :int]]]+ [:explore_filters {:optional true} [:maybe [:sequential [:ref ::card-embed.explore-filter]]]]])++(mr/def ::node.attrs+ "The `attrs` of a ProseMirror node: the ones this code reads by name, the ones `metabase.explorations` writes onto a+ static card embed, and whatever else the editor put there -- every node type has its own attributes and the editor+ owns that set. Every key, declared or not, is a string, so the map never mixes keyword and string keys."+ (ms/string-keyed-object+ ["id" {:optional true} [:maybe [:or :int :string]]]+ ["_id" {:optional true} [:maybe [:or :string :uuid]]]+ ["model" {:optional true} [:maybe :string]]+ ["entityId" {:optional true} [:maybe [:or :int :string]]]+ ["label" {:optional true} [:maybe :string]]+ ["stored_result_id" {:optional true} [:maybe :int]]+ ["chart_href" {:optional true} [:maybe :string]]+ ["child_target_id" {:optional true} [:maybe :string]]+ ["host_data" {:optional true} [:maybe [:ref ::card-embed.host-data]]]))(mr/def ::ast- "Schema for a prose-mirror document AST as it arrives at the API."+ "Schema for a prose-mirror document AST as it arrives at the API or is read back from the application database: a+ node in the shape ProseMirror's `Node.toJSON` emits, whose children and marks are nodes too."[:map- {:decode/normalize (fn [ast]+ {:closed true+ :decode/normalize (fn [ast](cond-> ast- (map? ast) walk/keywordize-keys))- :closed false}- [:type :string]])+ (map? ast) walk/keywordize-keys))}+ [:type :string]+ [:attrs {:optional true} [:maybe [:ref ::node.attrs]]]+ [:content {:optional true} [:maybe [:sequential [:ref ::ast]]]]+ [:marks {:optional true} [:maybe [:sequential [:ref ::ast]]]]+ [:text {:optional true} [:maybe :string]]])++(defn normalize-document+ "Normalize a document AST on its way in from the API or out of the application database. A document in another+ `content_type` is not a ProseMirror node and passes through untouched."+ [document]+ (if (and (map? document) (some #(contains? document %) [:type "type"]))+ (lib/normalize ::ast document)+ document))(def card-embed-type"Type of a card-embed node. Carries either `:id` (live Card reference) or@@ -82,26 +135,26 @@Returns a (possibly empty) string."[ast](->> (tree-seq :content :content ast)- (mapcat (juxt :text (comp :label :attrs)))+ (mapcat (juxt :text #(get (:attrs %) "label")))(remove str/blank?)(str/join " ")))(defn node-entity-id- "The referenced entity id carried by a `smartLink` (`:entityId`) or `cardEmbed` (`:id`) node, or nil.+ "The referenced entity id carried by a `smartLink` (`\"entityId\"`) or `cardEmbed` (`\"id\"`) node, or nil.Returning the id only when it is a positive integer keeps any downstream Toucan lookup parameterized."[{:keys [type attrs]}]- (let [id (if (= smart-link-type type) (:entityId attrs) (:id attrs))]+ (let [id (get attrs (if (= smart-link-type type) "entityId" "id"))](when (pos-int? id)id)))(defn card-ids- "Get the Card ids referenced by live-mode `cardEmbed` nodes (those with a positive `:id`).- Static-mode embeds (with `:stored_result_id`) are skipped — they don't reference a Card."+ "Get the Card ids referenced by live-mode `cardEmbed` nodes (those with a positive `\"id\"`).+ Static-mode embeds (with `\"stored_result_id\"`) are skipped — they don't reference a Card."[document](collect-ast document #(when (and (= card-embed-type (:type %))- (pos-int? (-> % :attrs :id)))- (-> % :attrs :id))))+ (pos-int? (get (:attrs %) "id")))+ (get (:attrs %) "id"))))(defn insert-card-embed"Insert an embed for the card with `card-id` into the document's prose-mirror ast.@@ -110,8 +163,8 @@produces. `index` is a 0-based position among the ast's top-level blocks (0 inserts at thevery top); a `nil` index appends the embed at the end and out-of-range indexes are clamped.An `_id` uuid is stamped on the node for per-node identity. `extra-attrs` (optional) are- merged onto the embed attrs after `:id` / `:_id` (e.g. `:stored_result_id`, `:chart_href`,- `:child_target_id`, `:host_data` for static exploration embeds).+ merged onto the embed attrs after `\"id\"` / `\"_id\"` (e.g. `\"stored_result_id\"`, `\"chart_href\"`,+ `\"child_target_id\"`, `\"host_data\"` for static exploration embeds).Args:- doc - a :model/Document, this will check that the content-type is valid for prose mirror@@ -129,7 +182,7 @@at (if (int? index)(-> index (max 0) (min (count blocks)))(count blocks))- attrs (merge {:id card-id :_id (random-uuid)}+ attrs (merge {"id" card-id "_id" (random-uuid)}extra-attrs)embed {:type "resizeNode":content [{:type card-embed-typediff --git a/src/metabase/eid_translation/api.clj b/src/metabase/eid_translation/api.cljindex be0e968a393..48661d9f4b1 100644--- a/src/metabase/eid_translation/api.clj+++ b/src/metabase/eid_translation/api.clj@@ -2,6 +2,7 @@"`/api/eid-translation` routes."(:require[metabase.api.macros :as api.macros]+ [metabase.eid-translation.schema :as eid-translation.schema][metabase.eid-translation.util :as eid-translation]));; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to@@ -12,6 +13,6 @@"Translate entity IDs to model IDs."[_route-params_query-params- {:keys [entity_ids]} :- [:map- [:entity_ids [:map-of :keyword [:sequential :string]]]]]- {:entity_ids (eid-translation/model->entity-ids->ids entity_ids)})+ {:keys [entity_ids]} :- [:map {:closed true}+ [:entity_ids ::eid-translation.schema/entity-ids-by-model]]]+ {:entity_ids (eid-translation/model->entity-ids->ids (update-keys entity_ids keyword))})diff --git a/src/metabase/eid_translation/schema.clj b/src/metabase/eid_translation/schema.cljnew file mode 100644index 00000000000..a4f3ee9cfae--- /dev/null+++ b/src/metabase/eid_translation/schema.clj@@ -0,0 +1,10 @@+(ns metabase.eid-translation.schema+ "Malli schemas for the entity-ID translation module."+ (:require+ [metabase.util.malli.registry :as mr]+ [metabase.util.malli.schema :as ms]))++(mr/def ::entity-ids-by-model+ "The entity IDs to translate, grouped by the model they belong to. Which models exist is checked by+ [[metabase.eid-translation.util/model->entity-ids->ids]], whose error names them."+ (ms/string-keyed-map [:sequential :string]))diff --git a/src/metabase/embedding_rest/api/common.clj b/src/metabase/embedding_rest/api/common.cljindex 4ce17f311b3..dfff9f956f3 100644--- a/src/metabase/embedding_rest/api/common.clj+++ b/src/metabase/embedding_rest/api/common.clj@@ -38,7 +38,7 @@(def SearchParams"Malli schema for route params of search paths"- [:map+ [:map {:closed true}[:token EncodedToken][:param-key ms/NonBlankString][:prefix ms/NonBlankString]])@@ -46,9 +46,10 @@(def QueryParams"Malli schema for the raw query-string parameter map of the embed query and param-values endpoints: dashboard/cardparameter slugs (or parameter IDs, for the param-values endpoints) mapped to values exactly as they come off the- query string, plus the optional `:parameters` JSON blob (see [[parse-query-params]]). Keys that don't read cleanly- as keywords (e.g. slugs starting with a digit) arrive as strings (see [[normalize-query-params]])."- [:map-of [:or :keyword :string] [:maybe [:or :string [:sequential :string]]]])+ query string, plus the optional `parameters` JSON blob (see [[parse-query-params]]). String-keyed: slugs are not+ ours to name, and some (e.g. ones starting with a digit) never read cleanly as keywords anyway (see+ [[normalize-query-params]])."+ (ms/string-keyed-map [:maybe [:or :string [:sequential :string]]]))(def ParsedQueryParams"Schema for [[QueryParams]] after the `:parameters` JSON blob has been decoded into real JSON scalars."@@ -68,8 +69,12 @@(defn- check-params-are-allowed"Check that the conditions specified by `object-embedding-params` are satisfied."[object-embedding-params token-params user-params]- (let [all-params (merge token-params user-params)- duplicated-params (set/intersection (set (keys token-params)) (set (keys user-params)))]+ (let [param-names (fn [params] (into #{} (map name) (keys params)))+ token-values (update-keys token-params name)+ all-params (param-names (merge token-params user-params))+ token-param-names (param-names token-params)+ user-param-names (param-names user-params)+ duplicated-params (set/intersection token-param-names user-param-names)](doseq [[param status] object-embedding-params](case status;; disabled means a param is not allowed to be specified by either token or user@@ -80,15 +85,15 @@[400 (tru "You can''t specify a value for {0} if it''s already set in the JWT." param)]);; locked means JWT must specify param"locked" (api/check- (some? (get token-params param)) [400 (tru "You must specify a value for {0} in the JWT." param)]- (not (contains? user-params param)) [400 (tru "You can only specify a value for {0} in the JWT." param)])))))+ (some? (get token-values param)) [400 (tru "You must specify a value for {0} in the JWT." (keyword param))]+ (not (contains? user-param-names param)) [400 (tru "You can only specify a value for {0} in the JWT." param)])))))(defn- check-params-exist"Make sure all the params specified are specified in `object-embedding-params`."[object-embedding-params all-params](let [embedding-params (set (keys object-embedding-params))](doseq [[k _] all-params]- (api/check (contains? embedding-params k)+ (api/check (contains? embedding-params (name k))[400 (format "Unknown parameter %s." k)]))))(defn- check-param-sets@@ -96,7 +101,6 @@URL) are valid for the `object-embedding-params`. `token-params` and `user-params` should be sets of all valid paramkeys specified in the JWT or by the user, respectively."[object-embedding-params token-params user-params]- ;; TODO - maybe make this log/debug once embedding is wrapped up(log/debug "Validating params for embedded object:\n""object embedding params:" object-embedding-params"token params:" token-params@@ -162,7 +166,7 @@contains serialized JSON with parameter values. If this object cannot be found or parsed, we fallback to plain querystring parameters."[query-params]- (let [parsed (when-let [parameters (:parameters query-params)]+ (let [parsed (when-let [parameters (some query-params [:parameters "parameters"])](try(json/decode+kw parameters)(catch Throwable _@@ -229,7 +233,7 @@than the client, and are passed to the parameter value lookups as constraints so the values offered for theenabled parameters match the rows the locked values select."[embedding-params token-params]- (into {} (filter (fn [[slug _value]] (= (get embedding-params (keyword slug)) "locked"))) token-params))+ (into {} (filter (fn [[slug _value]] (= (get embedding-params (name slug)) "locked"))) token-params))(defn- enabled-param-slugs"The set of param slugs (as keywords) from `dashboard-or-card-params` that may be exposed to embed viewers: only@@ -237,8 +241,8 @@listed as \"disabled\" or \"locked\" — is not in the set, so it fails closed."[dashboard-or-card-params embedding-params](into #{}- (comp (map (comp keyword :slug))- (filter #(= (get embedding-params %) "enabled")))+ (comp (filter #(= (get embedding-params (:slug %)) "enabled"))+ (map (comp keyword :slug)))dashboard-or-card-params))(mu/defn- enabled-params@@ -489,7 +493,7 @@searched-param-slug (get id->slug param-key)embedding-params (:embedding_params card)](try- (when-not (= (get embedding-params (keyword searched-param-slug)) "enabled")+ (when-not (= (get embedding-params searched-param-slug) "enabled")(throw (ex-info (tru "Cannot search for values: {0} is not an enabled parameter."(pr-str searched-param-slug)){:status-code 400})))@@ -536,7 +540,7 @@searched-param-slug (get id->slug param-key)embedding-params (:embedding_params card)](try- (when-not (= (get embedding-params (keyword searched-param-slug)) "enabled")+ (when-not (= (get embedding-params searched-param-slug) "enabled")(throw (ex-info (tru "Cannot get remapped value for parameter: {0} is not an enabled parameter."(pr-str searched-param-slug)){:status-code 400})))@@ -591,14 +595,14 @@embedding-params (if preview(mergepublished-embedding-params- (get unsigned-token :_embedding_params))+ (update-keys (get unsigned-token :_embedding_params) name))published-embedding-params)id->slug (into {} (map (juxt :id :slug)) parameters)slug->id (set/map-invert id->slug)searched-param-slug (get id->slug searched-param-id)](try;; you can only search for values of a parameter if it is ENABLED and NOT PRESENT in the JWT.- (when-not (= (get embedding-params (keyword searched-param-slug)) "enabled")+ (when-not (= (get embedding-params searched-param-slug) "enabled")(throw (ex-info (tru "Cannot search for values: {0} is not an enabled parameter." (pr-str searched-param-slug)){:status-code 400})))(when (get slug-token-params (keyword searched-param-slug))@@ -647,7 +651,7 @@;; the settings to the Appdb.embedding-params (if preview(merge published-embedding-params- (get unsigned-token :_embedding_params))+ (update-keys (get unsigned-token :_embedding_params) name))published-embedding-params)param-slug (get id->slug param-key)locked-param-ids (into #{}@@ -656,7 +660,7 @@(-> param name slug->id))))embedding-params)];; you can only search for values of a parameter if it is ENABLED and NOT PRESENT in the JWT.- (when (not= (get embedding-params (keyword param-slug)) "enabled")+ (when (not= (get embedding-params param-slug) "enabled")(throw (ex-info (tru "Cannot get remapped value for parameter: {0} is not an enabled parameter." (pr-str param-slug)){:status-code 400})))(when (get slug-token-params (keyword param-slug))diff --git a/src/metabase/embedding_rest/api/embed.clj b/src/metabase/embedding_rest/api/embed.cljindex f90d414eb44..e46c9bba399 100644--- a/src/metabase/embedding_rest/api/embed.clj+++ b/src/metabase/embedding_rest/api/embed.clj@@ -76,7 +76,7 @@Token should have the following format:{:resource {:question <card-id>}}"- [{:keys [token]} :- [:map+ [{:keys [token]} :- [:map {:closed true}[:token api.embed.common/EncodedToken]]](let [unsigned (unsign-and-translate-ids token)card-id (api.embed.common/unsigned-token->card-id unsigned)]@@ -114,7 +114,7 @@{:resource {:question <card-id>}:params <parameters>}"- [{:keys [token]} :- [:map+ [{:keys [token]} :- [:map {:closed true}[:token api.embed.common/EncodedToken]]query-params :- api.embed.common/QueryParams](run-query-for-unsigned-token-async (unsign-and-translate-ids token) :api (api.embed.common/parse-query-params query-params)))@@ -129,7 +129,7 @@:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/card/:token/query/:export-format""Like `GET /api/embed/card/query`, but returns the results as a file in the specified format."- [{:keys [token export-format]} :- [:map+ [{:keys [token export-format]} :- [:map {:closed true}[:token api.embed.common/EncodedToken][:export-format ::qp.schema/export-format]]{format-rows? :format_rows@@ -160,7 +160,7 @@Token should have the following format:{:resource {:dashboard <dashboard-id>}}"- [{:keys [token]} :- [:map+ [{:keys [token]} :- [:map {:closed true}[:token api.embed.common/EncodedToken]]](let [unsigned (unsign-and-translate-ids token)dashboard-id (api.embed.common/unsigned-token->dashboard-id unsigned)]@@ -209,7 +209,7 @@(api.macros/defendpoint :get "/dashboard/:token/dashcard/:dashcard-id/card/:card-id""Fetch the results of running a Card belonging to a Dashboard using a JSON Web Token signed with the`embedding-secret-key`"- [{:keys [token dashcard-id card-id]} :- [:map+ [{:keys [token dashcard-id card-id]} :- [:map {:closed true}[:token api.embed.common/EncodedToken][:dashcard-id ms/PositiveInt][:card-id ms/PositiveInt]]@@ -234,7 +234,7 @@(api.macros/defendpoint :get "/dashboard/:token/dashcard/:dashcard-id/card/:card-id/:export-format""Fetch the results of running a Card belonging to a Dashboard using a JSON Web Token signed with the`embedding-secret-key` return the data in one of the export formats"- [{:keys [token dashcard-id card-id export-format]} :- [:map+ [{:keys [token dashcard-id card-id export-format]} :- [:map {:closed true}[:token api.embed.common/EncodedToken][:dashcard-id ms/PositiveInt][:card-id ms/PositiveInt]@@ -270,7 +270,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/dashboard/:token/params/:param-key/values""Embedded version of chain filter values endpoint."- [{:keys [token param-key]} :- [:map+ [{:keys [token param-key]} :- [:map {:closed true}[:token api.embed.common/EncodedToken][:param-key ms/NonBlankString]]query-params :- api.embed.common/QueryParams]@@ -294,10 +294,10 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/dashboard/:token/params/:param-key/remapping""Embedded version of the remapped dashboard param value endpoint."- [{:keys [token param-key]} :- [:map+ [{:keys [token param-key]} :- [:map {:closed true}[:token api.embed.common/EncodedToken][:param-key ms/NonBlankString]]- {:keys [value]} :- [:map+ {:keys [value]} :- [:map {:closed true}[:value :string]]](api.embed.common/dashboard-param-remapped-value token param-key (codec/url-decode value)))@@ -307,7 +307,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/card/:token/params/:param-key/values""Embedded version of api.card filter values endpoint."- [{:keys [token param-key]} :- [:map+ [{:keys [token param-key]} :- [:map {:closed true}[:token api.embed.common/EncodedToken][:param-key ms/NonBlankString]]](let [unsigned (unsign-and-translate-ids token)@@ -340,10 +340,10 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/card/:token/params/:param-key/remapping""Embedded version of api.card filter values endpoint."- [{:keys [token param-key]} :- [:map+ [{:keys [token param-key]} :- [:map {:closed true}[:token api.embed.common/EncodedToken][:param-key ms/NonBlankString]]- {:keys [value]} :- [:map+ {:keys [value]} :- [:map {:closed true}[:value :string]]](let [unsigned (unsign-and-translate-ids token)card-id (api.embed.common/unsigned-token->card-id unsigned)@@ -365,7 +365,7 @@{:resource {:question <card-id>}:params <parameters>}"- [{:keys [token]} :- [:map+ [{:keys [token]} :- [:map {:closed true}[:token api.embed.common/EncodedToken]]query-params :- api.embed.common/QueryParams](run-query-for-unsigned-token-async (unsign-and-translate-ids token)@@ -379,7 +379,7 @@(api.macros/defendpoint :get "/pivot/dashboard/:token/dashcard/:dashcard-id/card/:card-id""Fetch the results of running a Card belonging to a Dashboard using a JSON Web Token signed with the`embedding-secret-key`"- [{:keys [token dashcard-id card-id]} :- [:map+ [{:keys [token dashcard-id card-id]} :- [:map {:closed true}[:token api.embed.common/EncodedToken][:dashcard-id ms/PositiveInt][:card-id ms/PositiveInt]]@@ -395,13 +395,13 @@(api.macros/defendpoint :get "/tiles/card/:token/:zoom/:x/:y""Generates a single tile image for an embedded Card using the map visualization."[{:keys [token zoom x y]}- :- [:map+ :- [:map {:closed true}[:token api.embed.common/EncodedToken][:zoom ms/Int][:x ms/Int][:y ms/Int]]{:keys [parameters latField lonField]}- :- [:map+ :- [:map {:closed true}[:parameters {:optional true} ::parameters.schema/api.parameter-values][:latField ::api.tiles/legacy-ref][:lonField ::api.tiles/legacy-ref]]]@@ -423,7 +423,7 @@(api.macros/defendpoint :get "/tiles/dashboard/:token/dashcard/:dashcard-id/card/:card-id/:zoom/:x/:y""Generates a single tile image for a Card on an embedded Dashboard using the map visualization."[{:keys [token dashcard-id card-id zoom x y]}- :- [:map+ :- [:map {:closed true}[:token api.embed.common/EncodedToken][:dashcard-id ms/PositiveInt][:card-id ms/PositiveInt]@@ -431,7 +431,7 @@[:x ms/Int][:y ms/Int]]{:keys [parameters latField lonField]}- :- [:map+ :- [:map {:closed true}[:parameters {:optional true} ::parameters.schema/api.parameter-values][:latField ::api.tiles/legacy-ref][:lonField ::api.tiles/legacy-ref]]]diff --git a/src/metabase/embedding_rest/api/preview_embed.clj b/src/metabase/embedding_rest/api/preview_embed.cljindex 5bb6b73bec6..aecb540c27f 100644--- a/src/metabase/embedding_rest/api/preview_embed.clj+++ b/src/metabase/embedding_rest/api/preview_embed.clj@@ -22,6 +22,11 @@[metabase.util.malli.schema :as ms][ring.util.codec :as codec]))+(defn- token-embedding-params+ "The `:_embedding_params` a preview token carries, string-keyed like a stored `embedding_params`."+ [unsigned-token]+ (update-keys (embed/get-in-unsigned-token-or-throw unsigned-token [:_embedding_params]) name))+(defn- check-and-unsign [token](api/check-superuser)(embedding.validation/check-embedding-enabled)@@ -33,11 +38,11 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/card/:token""Fetch a Card you're considering embedding by passing a JWT `token`."- [{:keys [token]} :- [:map+ [{:keys [token]} :- [:map {:closed true}[:token api.embed.common/EncodedToken]]](let [unsigned-token (check-and-unsign token)](api.embed.common/card-for-unsigned-token unsigned-token- :embedding-params (embed/get-in-unsigned-token-or-throw unsigned-token [:_embedding_params]))))+ :embedding-params (token-embedding-params unsigned-token))))(def ^:private max-results"Embedding previews need to be limited in size to avoid performance issues (#20938)."@@ -49,7 +54,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/card/:token/query""Fetch the query results for a Card you're considering embedding by passing a JWT `token`."- [{:keys [token]} :- [:map+ [{:keys [token]} :- [:map {:closed true}[:token api.embed.common/EncodedToken]]query-params :- api.embed.common/QueryParams](let [unsigned-token (check-and-unsign token)@@ -59,7 +64,7 @@:export-format :api:card card:token-params (embed/get-in-unsigned-token-or-throw unsigned-token [:params])- :embedding-params (embed/get-in-unsigned-token-or-throw unsigned-token [:_embedding_params])+ :embedding-params (token-embedding-params unsigned-token):constraints {:max-results max-results}:query-params (api.embed.common/parse-query-params query-params))))@@ -71,11 +76,11 @@[unsigned-token](let [card-id (api.embed.common/unsigned-token->card-id unsigned-token)](-> (api/check-404 (embedding-rest.db/card card-id))- (assoc :embedding_params (embed/get-in-unsigned-token-or-throw unsigned-token [:_embedding_params])))))+ (assoc :embedding_params (token-embedding-params unsigned-token)))))(api.macros/defendpoint :get "/card/:token/params/:param-key/values" :- ms/FieldValuesResult"Embedded version of api.card filter values endpoint."- [{:keys [token param-key]} :- [:map+ [{:keys [token param-key]} :- [:map {:closed true}[:token string?][:param-key string?]]](let [unsigned-token (check-and-unsign token)@@ -90,10 +95,10 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/card/:token/params/:param-key/remapping""Embedded version of api.card filter values endpoint."- [{:keys [token param-key]} :- [:map+ [{:keys [token param-key]} :- [:map {:closed true}[:token api.embed.common/EncodedToken][:param-key ms/NonBlankString]]- {:keys [value]} :- [:map [:value :string]]]+ {:keys [value]} :- [:map {:closed true} [:value :string]]](let [unsigned-token (check-and-unsign token)card (preview-card-for-param-values unsigned-token)](api.embed.common/card-param-remapped-value {:unsigned-token unsigned-token@@ -107,11 +112,11 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/dashboard/:token""Fetch a Dashboard you're considering embedding by passing a JWT `token`. "- [{:keys [token]} :- [:map+ [{:keys [token]} :- [:map {:closed true}[:token api.embed.common/EncodedToken]]](let [unsigned-token (check-and-unsign token)](api.embed.common/dashboard-for-unsigned-token unsigned-token- :embedding-params (embed/get-in-unsigned-token-or-throw unsigned-token [:_embedding_params]))))+ :embedding-params (token-embedding-params unsigned-token))));; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to;; use our API + we will need it when we make auto-TypeScript-signature generation happen@@ -119,7 +124,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/dashboard/:token/params/:param-key/values""Embedded version of chain filter values endpoint."- [{:keys [token param-key]} :- [:map+ [{:keys [token param-key]} :- [:map {:closed true}[:token api.embed.common/EncodedToken][:param-key ms/NonBlankString]]query-params :- api.embed.common/QueryParams]@@ -151,10 +156,10 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/dashboard/:token/params/:param-key/remapping""Embedded version of the remapped dashboard param value endpoint."- [{:keys [token param-key]} :- [:map+ [{:keys [token param-key]} :- [:map {:closed true}[:token api.embed.common/EncodedToken][:param-key ms/NonBlankString]]- {:keys [value]} :- [:map [:value :string]]]+ {:keys [value]} :- [:map {:closed true} [:value :string]]](check-and-unsign token)(api.embed.common/dashboard-param-remapped-value token param-key (codec/url-decode value) {:preview true}))@@ -164,7 +169,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/dashboard/:token/dashcard/:dashcard-id/card/:card-id""Fetch the results of running a Card belonging to a Dashboard you're considering embedding with JWT `token`."- [{:keys [token dashcard-id card-id]} :- [:map+ [{:keys [token dashcard-id card-id]} :- [:map {:closed true}[:token api.embed.common/EncodedToken][:dashcard-id ms/PositiveInt][:card-id ms/PositiveInt]]@@ -174,7 +179,7 @@dashboard (api/check-404 (embedding-rest.db/dashboard dashboard-id))dashcard (api/check-404 (embedding-rest.db/dashcard dashcard-id))card (api/check-404 (embedding-rest.db/card card-id))- embedding-params (embed/get-in-unsigned-token-or-throw unsigned-token [:_embedding_params])+ embedding-params (token-embedding-params unsigned-token)token-params (embed/get-in-unsigned-token-or-throw unsigned-token [:params])](api.embed.common/process-query-for-dashcard:export-format :api@@ -191,7 +196,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/pivot/card/:token/query""Fetch the query results for a Card you're considering embedding by passing a JWT `token`."- [{:keys [token]} :- [:map+ [{:keys [token]} :- [:map {:closed true}[:token api.embed.common/EncodedToken]]query-params :- api.embed.common/QueryParams](let [unsigned-token (check-and-unsign token)@@ -201,7 +206,7 @@:export-format :api:card card:token-params (embed/get-in-unsigned-token-or-throw unsigned-token [:params])- :embedding-params (embed/get-in-unsigned-token-or-throw unsigned-token [:_embedding_params])+ :embedding-params (token-embedding-params unsigned-token):query-params (api.embed.common/parse-query-params query-params):qp qp.pivot/run-pivot-query)))@@ -211,7 +216,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/pivot/dashboard/:token/dashcard/:dashcard-id/card/:card-id""Fetch the results of running a Card belonging to a Dashboard you're considering embedding with JWT `token`."- [{:keys [token dashcard-id card-id]} :- [:map+ [{:keys [token dashcard-id card-id]} :- [:map {:closed true}[:token api.embed.common/EncodedToken][:dashcard-id ms/PositiveInt][:card-id ms/PositiveInt]]@@ -221,7 +226,7 @@dashboard (api/check-404 (embedding-rest.db/dashboard dashboard-id))dashcard (api/check-404 (embedding-rest.db/dashcard dashcard-id))card (api/check-404 (embedding-rest.db/card card-id))- embedding-params (embed/get-in-unsigned-token-or-throw unsigned-token [:_embedding_params])+ embedding-params (token-embedding-params unsigned-token)token-params (embed/get-in-unsigned-token-or-throw unsigned-token [:params])](api.embed.common/process-query-for-dashcard:export-format :api@@ -240,13 +245,13 @@(api.macros/defendpoint :get "/tiles/card/:token/:zoom/:x/:y""Generates a single tile image for an embedded Card using the map visualization."[{:keys [token zoom x y]}- :- [:map+ :- [:map {:closed true}[:token api.embed.common/EncodedToken][:zoom ms/Int][:x ms/Int][:y ms/Int]]{:keys [parameters latField lonField]}- :- [:map+ :- [:map {:closed true}[:parameters {:optional true} ::parameters.schema/api.parameter-values][:latField ::api.tiles/legacy-ref][:lonField ::api.tiles/legacy-ref]]]@@ -267,7 +272,7 @@(api.macros/defendpoint :get "/tiles/dashboard/:token/dashcard/:dashcard-id/card/:card-id/:zoom/:x/:y""Generates a single tile image for a Card on an embedded Dashboard using the map visualization."[{:keys [token dashcard-id card-id zoom x y]}- :- [:map+ :- [:map {:closed true}[:token api.embed.common/EncodedToken][:dashcard-id ms/PositiveInt][:card-id ms/PositiveInt]@@ -275,7 +280,7 @@[:x ms/Int][:y ms/Int]]{:keys [parameters latField lonField]}- :- [:map+ :- [:map {:closed true}[:parameters {:optional true} ::parameters.schema/api.parameter-values][:latField ::api.tiles/legacy-ref][:lonField ::api.tiles/legacy-ref]]]diff --git a/src/metabase/embedding_rest/api/theme.clj b/src/metabase/embedding_rest/api/theme.cljindex f097c6766f6..e6778279e3c 100644--- a/src/metabase/embedding_rest/api/theme.clj+++ b/src/metabase/embedding_rest/api/theme.clj@@ -19,7 +19,7 @@[:id ms/PositiveInt][:entity_id ms/NonBlankString][:name ms/NonBlankString]- [:settings ms/Map]+ [:settings ms/OpaqueJSONObject][:created_at (ms/InstanceOfClass java.time.temporal.Temporal)][:updated_at (ms/InstanceOfClass java.time.temporal.Temporal)]])@@ -32,7 +32,7 @@(api.macros/defendpoint :get "/:id" :- ::EmbeddingTheme"Fetch a single embedding theme by ID."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]](api/check-404 (embedding-rest.db/embedding-theme-exists? id))(embedding-rest.db/embedding-theme id))@@ -40,19 +40,19 @@"Create a new embedding theme."[_route-params_query-params- {:keys [name settings]} :- [:map+ {:keys [name settings]} :- [:map {:closed true}[:name ms/NonBlankString]- [:settings ms/Map]]]+ [:settings ms/OpaqueJSONObject]]](embedding-rest.db/insert-embedding-theme! {:name name:settings settings}))(api.macros/defendpoint :put "/:id" :- ::EmbeddingTheme"Update an embedding theme."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]_query-params- {:keys [name settings]} :- [:map+ {:keys [name settings]} :- [:map {:closed true}[:name {:optional true} [:maybe ms/NonBlankString]]- [:settings {:optional true} [:maybe ms/Map]]]]+ [:settings {:optional true} [:maybe ms/OpaqueJSONObject]]]](api/check-404 (embedding-rest.db/embedding-theme-exists? id))(embedding-rest.db/update-embedding-theme! id(cond-> {}@@ -62,14 +62,14 @@(api.macros/defendpoint :delete "/:id" :- :nil"Delete an embedding theme."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]](api/check-404 (embedding-rest.db/embedding-theme-exists? id))(embedding-rest.db/delete-embedding-theme! id)nil)(api.macros/defendpoint :post "/:id/copy" :- ::EmbeddingTheme"Copy an embedding theme."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]](api/check-404 (embedding-rest.db/embedding-theme-exists? id))(let [source-theme (embedding-rest.db/embedding-theme id)](embedding-rest.db/insert-embedding-theme! {:name (tru "Copy of {0}" (:name source-theme))@@ -83,10 +83,10 @@are no-ops even if the admin has since deleted the seeded themes, so deletions are preserved."[_route-params_query-params- {:keys [themes]} :- [:map- [:themes [:sequential [:map+ {:keys [themes]} :- [:map {:closed true}+ [:themes [:sequential [:map {:closed true}[:name ms/NonBlankString]- [:settings ms/Map]]]]]]+ [:settings ms/OpaqueJSONObject]]]]]](locking seed-defaults-lock(t2/with-transaction [_conn](when-not (embedding.settings/default-embedding-themes-seeded)diff --git a/src/metabase/explorations/api.clj b/src/metabase/explorations/api.cljindex cc0e067e972..e474ad291e9 100644--- a/src/metabase/explorations/api.clj+++ b/src/metabase/explorations/api.clj@@ -19,6 +19,7 @@[metabase.explorations.query-plan.context :as qp.context][metabase.explorations.queues :as explorations.queues][metabase.lib-be.core :as lib-be]+ [metabase.lib.schema.parameter :as lib.schema.parameter][metabase.metrics.core :as metrics][metabase.permissions.core :as perms][metabase.queries.core :as queries]@@ -315,22 +316,27 @@(def ^:private ExploreFilterScalar[:maybe [:or :string number? :boolean]])+(def ^:private ExploreFieldRef+ "The reference an explore filter points at: the legacy `field_ref` of the chart column the client clicked. It is+ persisted and echoed back."+ [:ref ::lib.schema.parameter/dimension.target])+(def ^:private ExploreFilterSpec"One segment filter stamped onto a block metric selection's `:explore_filters` vector.`:display_value` is required — the FE formats it at click time and both the thread nameand filter pills read it as-is."[:multi {:dispatch :operator}["="- [:map+ [:map {:closed true}[:operator [:= "="]]- [:field_ref [:sequential :any]]+ [:field_ref ExploreFieldRef][:value ExploreFilterScalar][:display_value ms/NonBlankString][:dimension_name {:optional true} [:maybe :string]]]]["between"- [:map+ [:map {:closed true}[:operator [:= "between"]]- [:field_ref [:sequential :any]]+ [:field_ref ExploreFieldRef][:values [:tuple ExploreFilterScalar ExploreFilterScalar]][:display_value ms/NonBlankString][:dimension_name {:optional true} [:maybe :string]]]]])@@ -339,7 +345,7 @@;; Mapping objects are decoded from the snake_case wire shape to the internal kebab-case shape;; at the `defendpoint` edge by the wire-annotated schema (see [[metabase.metrics.core]]);;; the envelope `:dimension_mappings` key itself stays snake_case, matching storage.- [:map+ [:map {:closed true}[:card_id ms/PositiveInt][:dimension_mappings {:optional true} [:maybe [:sequential ::metrics/dimension-mapping]]]])@@ -347,7 +353,7 @@;; The FE sends snake_case dimension snapshots; the `:decode/api` rule kebab-cases them at the;; `defendpoint` edge, so entries here are declared in the internal kebab-case shape the;; handler receives and persists. Open map: snapshot keys beyond these pass through kebab-cased.- [:map {:decode/api {:enter #(cond-> % (map? %) (update-keys u/->kebab-case-en))}}+ [:map {:closed true :decode/api {:enter #(cond-> % (map? %) (update-keys u/->kebab-case-en))}}[:dimension-id ms/UUIDString][:display-name {:optional true} [:maybe :string]][:effective-type {:optional true} [:maybe :string]]@@ -358,7 +364,7 @@one `ExplorationBlock` row; the planners cross this block's metrics with this block'sdimensions only. The sidebar heading is computed read-side (the `:name` of an`ExplorationBlockNode`), not supplied here."- [:map+ [:map {:closed true}[:metrics {:optional true} [:maybe [:sequential MetricSelection]]][:dimensions {:optional true} [:maybe [:sequential DimensionSelection]]]])@@ -525,7 +531,7 @@The FE sends one entry per Research-plan block (`:blocks` — each a metric/dimensionarea), each persisted verbatim. `:timeline_ids` is thread-scoped (timelines aren't part ofany metric×dimension cross-product) and lives at the top level, not inside a block."- [:map+ [:map {:closed true}[:name expl.model/ExplorationName][:description {:optional true} [:maybe :string]][:prompt {:optional true} [:maybe :string]]@@ -538,7 +544,7 @@page — its block (metric selection + dimensions) is copied verbatim so the new thread re-runsthe same charts. `explore_filters` is appended to each copied metric selection's existing`:explore_filters`."- [:map+ [:map {:closed true}[:page_id ms/PositiveInt][:explore_filters [:sequential {:min 1} ExploreFilterSpec]]])@@ -547,7 +553,7 @@actually includes are forwarded to the underlying `t2/update!`. `collection_id` may be `nil`to move the exploration to the root collection (\"Our Analytics\"). `collection_position` maybe `nil` to unpin the exploration."- [:map+ [:map {:closed true}[:name {:optional true} expl.model/ExplorationName][:description {:optional true} [:maybe :string]][:archived {:optional true} :boolean]@@ -671,7 +677,7 @@keeps the earlier scope (see`metabase.explorations.query-plan.context/build-row-context`). Returns immediately with the newthread stamped `started_at`; clients poll `GET /:id` for the queries to land, exactly like create."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]_query-params{:keys [page_id explore_filters]} :- ExploreFurther](let [exploration (get-exploration-or-404 id)]@@ -736,7 +742,7 @@Optional `q` filters case-insensitively across metric name and dimension display-name."[_route-params- {:keys [q]} :- [:maybe [:map [:q {:optional true} [:maybe ms/NonBlankString]]]]]+ {:keys [q]} :- [:maybe [:map {:closed true} [:q {:optional true} [:maybe ms/NonBlankString]]]]];; Returned in the internal kebab-case shape; the `::DimensionsResponse` schema encodes;; dimensions and mappings to the snake_case wire shape at the `defendpoint` edge. (The;; `add_research_groups` metabot tool serves the same payload outside `defendpoint` and@@ -764,7 +770,7 @@(api.macros/defendpoint :get "/:id" :- ::HydratedExploration"Fetch an exploration with its thread, selections, and generated queries."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]](let [expl (api/read-check (get-exploration-or-404 id))](hydrate-exploration expl)))@@ -777,7 +783,7 @@Moving an exploration cascades the new `collection_id` onto its Summary document; flipping`archived` cascades to the same document (skipping any that were directly user-archived,mirroring the dashboard / dashboard-question cascade)."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]_query-paramsupdates :- UpdateExploration](let [existing (get-exploration-or-404 id)@@ -803,7 +809,7 @@Cascades to every `exploration_thread`, `exploration_query`, and attached Summary `document`via the on-delete-cascade FKs configured in the explorations migration."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]](let [existing (get-exploration-or-404 id)](api/write-check existing)(explorations.db/delete-exploration! id))@@ -832,7 +838,7 @@No `:event/exploration-update` is published: nothing on the Exploration row changes, so thereis no revision to record (the revision push skips unchanged objects)."- [{:keys [thread-id]} :- [:map [:thread-id ms/PositiveInt]]]+ [{:keys [thread-id]} :- [:map {:closed true} [:thread-id ms/PositiveInt]]](let [thread (get-thread-or-404 thread-id)exploration (api/write-check (get-exploration-or-404 (:exploration_id thread)))](when-not (reset-thread-for-rerun! thread-id)@@ -857,7 +863,7 @@Idempotent: a thread with `completed_at IS NOT NULL` (already terminal — natural completion orprior cancel) returns 200 with its existing state. Authorization is the same write check asother thread-mutating endpoints."- [{:keys [thread-id]} :- [:map [:thread-id ms/PositiveInt]]]+ [{:keys [thread-id]} :- [:map {:closed true} [:thread-id ms/PositiveInt]]](write-check-thread thread-id)(let [now (t/offset-date-time)](t2/with-transaction [_conn]@@ -904,8 +910,8 @@"Stream the result of a single completed exploration query. The optional `format` query paramis one of `api`, `json`, `csv`, `xlsx` (default `api`). When the underlying query is stillpending or has errored, returns a 409 with status info instead of streaming."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]- {:keys [format]} :- [:map+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]+ {:keys [format]} :- [:map {:closed true}[:format {:default :api}[:enum {:decode/api keyword} :api :csv :json :xlsx]]]](let [q (get-exploration-query-or-404 id)]@@ -929,9 +935,9 @@(api.macros/defendpoint :put "/page/:id/starred" :- :nil"Set whether an exploration page is starred."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]_query-params- {:keys [starred]} :- [:map [:starred :boolean]]]+ {:keys [starred]} :- [:map {:closed true} [:starred :boolean]]](let [page (get-exploration-page-or-404 id)](api/write-check page)(explorations.db/update-page! id {:starred starred}))@@ -942,7 +948,7 @@page passes a one-element `page_ids`; hiding a whole group passes all its page ids."[_route-params_query-params- {:keys [page_ids hidden]} :- [:map+ {:keys [page_ids hidden]} :- [:map {:closed true}[:page_ids [:sequential ms/PositiveInt]][:hidden :boolean]]](doseq [id page_ids]@@ -999,13 +1005,13 @@All source EQs must belong to a thread of this exploration. Appending clears`is_placeholder` when it was set."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]_query-params{:keys [exploration_query_ids display visualization_settings]}- :- [:map+ :- [:map {:closed true}[:exploration_query_ids [:sequential {:min 1} ms/PositiveInt]][:display :string]- [:visualization_settings ms/Map]]]+ [:visualization_settings ms/VisualizationSettings]]](api/write-check (get-exploration-or-404 id))(let [doc (summary-document-or-404 id)](api/check-404 (exploration-query-ids-belong-to-exploration? id exploration_query_ids))@@ -1020,13 +1026,13 @@chart-href (explorations.blocks/page-url id page-id);; Snapshot onto host_data so the Summary embed can render pills without a live lookup.explore-filters (page-explore-filters page-id)- extra-attrs {:stored_result_id stored-result-id- :chart_href chart-href+ extra-attrs {"stored_result_id" stored-result-id+ "chart_href" chart-href;; Comment stream key (page id). Distinct from `_id`,;; which must stay unique per node for duplicate embeds.- :child_target_id (str page-id)- :host_data (cond-> {:query_ids exploration_query_ids}- explore-filters (assoc :explore_filters explore-filters))}]+ "child_target_id" (str page-id)+ "host_data" (cond-> {:query_ids exploration_query_ids}+ explore-filters (assoc :explore_filters explore-filters))}](documents/add-card-to-document!(:id doc) card-id nil:extra-attrs extra-attrs)))diff --git a/src/metabase/explorations/models/exploration_block.clj b/src/metabase/explorations/models/exploration_block.cljindex 249700decdd..503fedf73b1 100644--- a/src/metabase/explorations/models/exploration_block.clj+++ b/src/metabase/explorations/models/exploration_block.clj@@ -10,6 +10,8 @@snapshot — so a block is self-contained for both planning and per-row materialization."(:require[metabase.explorations.db :as explorations.db]+ [metabase.lib.core :as lib]+ [metabase.lib.schema.parameter :as lib.schema.parameter][metabase.models.interface :as mi][methodical.core :as methodical][toucan2.core :as t2]))@@ -37,8 +39,32 @@{:in (:in mi/transform-json):out (comp keywordize-dim-types (:out mi/transform-json))})+(defn- normalize-explore-filters+ "The explore filters on a metric selection store the legacy `field_ref` of the chart column that was clicked; read+ it back as the normalized reference the API validates and hands out. A reference that will not normalize is left as+ it is stored."+ [metrics]+ (when metrics+ (mapv (fn [metric]+ (cond-> metric+ (seq (:explore_filters metric))+ (update :explore_filters+ (fn [explore-filters]+ (mapv (fn [{:keys [field_ref] :as explore-filter}]+ (cond-> explore-filter+ field_ref (assoc :field_ref+ (try+ (lib/normalize ::lib.schema.parameter/dimension.target field_ref)+ (catch Exception _ field_ref)))))+ explore-filters)))))+ metrics)))++(def ^:private transform-metrics+ {:in (:in mi/transform-json)+ :out (comp normalize-explore-filters (:out mi/transform-json))})+(t2/deftransforms :model/ExplorationBlock- {:metrics mi/transform-json+ {:metrics transform-metrics:dimensions transform-dimensions})(defmethod mi/can-read? :model/ExplorationBlockdiff --git a/src/metabase/frontend_errors/api.clj b/src/metabase/frontend_errors/api.cljindex 272abdc7d68..5e830b82c74 100644--- a/src/metabase/frontend_errors/api.clj+++ b/src/metabase/frontend_errors/api.clj@@ -46,7 +46,7 @@with the given `type` label."[_route-params_query-params- {:keys [type]} :- [:map [:type ::frontend-error-type]]+ {:keys [type]} :- [:map {:closed true} [:type ::frontend-error-type]]_req](analytics/inc! :metabase-frontend/errors {:type type})api/generic-204-no-content)diff --git a/src/metabase/geojson/api.clj b/src/metabase/geojson/api.cljindex 2fd5c22ef7b..108fc92287d 100644--- a/src/metabase/geojson/api.clj+++ b/src/metabase/geojson/api.clj@@ -119,7 +119,7 @@(api.macros/defendpoint :get "/:key""Fetch a custom GeoJSON file as defined in the [[metabase.geojson.settings/custom-geojson]] setting. (This just actsas a simple proxy for the file specified for `key`)."- [{k :key, :as _route-params} :- [:map+ [{k :key, :as _route-params} :- [:map {:closed true}[:key ms/NonBlankString]]_query-params_body@@ -143,7 +143,7 @@"Load a custom GeoJSON file based on a URL or file path provided as a query parameter.This behaves similarly to /api/geojson/:key but doesn't require the custom map to be saved to the DB first."[_route-params- {:keys [url], :as _query-params} :- [:map+ {:keys [url], :as _query-params} :- [:map {:closed true}[:url ms/NonBlankString]]_body_requestdiff --git a/src/metabase/glossary/api.clj b/src/metabase/glossary/api.cljindex 881f0188390..0d98d413eb8 100644--- a/src/metabase/glossary/api.clj+++ b/src/metabase/glossary/api.clj@@ -15,7 +15,7 @@(api.macros/defendpoint :get "/""Fetch all glossary entries, optionally filtered by search term."[_route-params- {:keys [search]} :- [:maybe [:map [:search {:optional true} [:maybe ms/NonBlankString]]]]]+ {:keys [search]} :- [:maybe [:map {:closed true} [:search {:optional true} [:maybe ms/NonBlankString]]]]]{:data (t2/hydrate (glossary.db/glossary-entries search) :creator)});; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to@@ -26,7 +26,7 @@"Create a new glossary entry."[_route-params_query-params- {:keys [term definition]} :- [:map+ {:keys [term definition]} :- [:map {:closed true}[:term ms/NonBlankString][:definition ms/NonBlankString]]](api/check-data-analyst)@@ -45,9 +45,9 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :put "/:id""Update an existing glossary entry."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]_query-params- {:keys [term definition]} :- [:map+ {:keys [term definition]} :- [:map {:closed true}[:term ms/NonBlankString][:definition ms/NonBlankString]]](api/check-data-analyst)@@ -66,7 +66,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/:id""Delete a glossary entry."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]](api/check-data-analyst)(let [glossary (api/check-404 (glossary.db/glossary-entry id))](glossary.db/delete-glossary-entry! id)diff --git a/src/metabase/health_inspector/api.clj b/src/metabase/health_inspector/api.cljindex 4895309ebcd..d6b5145242f 100644--- a/src/metabase/health_inspector/api.clj+++ b/src/metabase/health_inspector/api.clj@@ -15,7 +15,7 @@(api.macros/defendpoint :get "/" :- [:sequential ::result]"Get a list of recent health check runs."[_route-params- {:keys [limit]} :- [:map+ {:keys [limit]} :- [:map {:closed true}[:limit {:optional true} ms/PositiveInt]]](api/check-superuser)(health/list-runs (min (or limit 32) 512)))diff --git a/src/metabase/indexed_entities/api.clj b/src/metabase/indexed_entities/api.cljindex a90627ff91f..2848a25257b 100644--- a/src/metabase/indexed_entities/api.clj+++ b/src/metabase/indexed_entities/api.clj@@ -5,6 +5,7 @@[metabase.api.macros :as api.macros][metabase.indexed-entities.db :as indexed-entities.db][metabase.indexed-entities.models.model-index :as model-index]+ [metabase.indexed-entities.schema :as indexed-entities.schema][metabase.indexed-entities.task.index-values :as task.index-values];; legacy usage, do not use this in new code^{:clj-kondo/ignore [:discouraged-namespace]} [metabase.legacy-mbql.normalize :as mbql.normalize]@@ -42,10 +43,10 @@"Create ModelIndex."[_route-params_query-params- {:keys [model_id pk_ref value_ref] :as _model-index} :- [:map+ {:keys [model_id pk_ref value_ref] :as _model-index} :- [:map {:closed true}[:model_id ms/PositiveInt]- [:pk_ref any?]- [:value_ref any?]]]+ [:pk_ref ::indexed-entities.schema/model-index.pk-ref]+ [:value_ref ::indexed-entities.schema/model-index.value-ref]]](let [model (api/write-check :model/Card model_id)metadata (:result_metadata model)](when-not (seq metadata)@@ -77,7 +78,7 @@(api.macros/defendpoint :get "/""Retrieve list of ModelIndex."[_route-params- {:keys [model_id]} :- [:map+ {:keys [model_id]} :- [:map {:closed true}[:model_id ms/PositiveInt]]](let [model (api/read-check :model/Card model_id)](when-not (= (:type model) :model)@@ -92,7 +93,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id""Retrieve ModelIndex."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](let [model-index (api/check-404 (indexed-entities.db/model-index id))model (api/read-check :model/Card (:model_id model-index))]@@ -108,7 +109,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/:id""Delete ModelIndex."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](api/let-404 [model-index (indexed-entities.db/model-index id)](api/write-check :model/Card (:model_id model-index))diff --git a/src/metabase/indexes/schema.clj b/src/metabase/indexes/schema.cljindex 017b40c10f1..f9c7adfa3bf 100644--- a/src/metabase/indexes/schema.clj+++ b/src/metabase/indexes/schema.clj@@ -22,13 +22,13 @@[:string {:min 1 :max 255}])(mr/def ::column- [:map+ [:map {:closed true}[:name ::column-name][:direction {:optional true} [:enum :asc :desc]]])(mr/def ::classical-index"Postgres / MySQL / SQL Server secondary index."- [:map+ [:map {:closed true}[:kind [:enum :btree :hash :gin :gist :brin :spgist :fulltext :spatial:clustered :nonclustered :columnstore]][:name ::index-name]@@ -38,7 +38,7 @@(mr/def ::sortkey"Redshift sort key, inline."- [:map+ [:map {:closed true}[:kind [:= :sortkey]][:style [:enum :compound :interleaved]][:columns [:vector {:min 1} ::column]]])@@ -46,7 +46,7 @@(mr/def ::distkey"Redshift distribution, inline. Only `:key` uses a column (the one DISTKEY column); `:all`/`:even` take none."[:and- [:map+ [:map {:closed true}[:kind [:= :distkey]][:style [:enum :key :all :even]][:columns {:optional true} [:vector {:min 1 :max 1} ::column]]]@@ -55,21 +55,21 @@(mr/def ::clustering"Snowflake (standalone) / BigQuery (inline) clustering. `:name` is required for the standalone form."- [:map+ [:map {:closed true}[:kind [:= :clustering]][:name {:optional true} ::index-name][:columns [:vector {:min 1} ::column]]])(mr/def ::order-by"ClickHouse ORDER BY, inline."- [:map+ [:map {:closed true}[:kind [:= :order-by]][:columns [:vector {:min 1} ::column]]])(mr/def ::skip-index"ClickHouse data-skipping index, standalone. Only arg-free types; the parameterized ones need type-args the formcan't supply yet."- [:map+ [:map {:closed true}[:kind [:= :skip-index]][:name ::index-name][:columns [:vector {:min 1} ::column]]diff --git a/src/metabase/indexes_rest/api.clj b/src/metabase/indexes_rest/api.cljindex 7041ef81a6d..248160bae88 100644--- a/src/metabase/indexes_rest/api.clj+++ b/src/metabase/indexes_rest/api.clj@@ -66,7 +66,7 @@"A transform's indexes: those physically in the warehouse, merged with its managed requests. Each entry is flagged`:metabase_managed`; managed ones also carry `:request` (status + definition)."[_route-params- {:keys [transform-id]} :- [:map [:transform-id ms/PositiveInt]]]+ {:keys [transform-id]} :- [:map {:closed true} [:transform-id ms/PositiveInt]]](let [transform (api/read-check :model/Transform transform-id)database-id (transforms-base.i/target-db-id transform){:keys [schema] table-name :name} (:target transform)@@ -78,7 +78,7 @@(api.macros/defendpoint :get "/request/:id" :- RequestIndex"Fetch a single index request (e.g. to poll its status)."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]](doto (api/check-404 (indexes-rest.db/table-index id))(read-check-owner!)))@@ -87,7 +87,7 @@not under `/request`."[_route-params_query-params- {:keys [transform_id structured]} :- [:map+ {:keys [transform_id structured]} :- [:map {:closed true}[:transform_id ms/PositiveInt][:structured ::schema/index-structured]]](api/write-check :model/Transform transform_id)@@ -118,9 +118,9 @@(api.macros/defendpoint :put "/request/:id" :- RequestIndex"Replace the structured definition of an index request, marking it update-pending."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]_query-params- {:keys [structured]} :- [:map [:structured ::schema/index-structured]]]+ {:keys [structured]} :- [:map {:closed true} [:structured ::schema/index-structured]]](let [existing (api/check-404 (table-index/select-applicable-by-id id))](write-check-owner! existing)(assert-stable-key! existing structured)@@ -133,7 +133,7 @@(api.macros/defendpoint :delete "/request/:id""Mark an index request `delete-pending`. The physical index is only dropped when the target table is next rebuilt(pending changes force a full run), so the row stays visible in this state until that rebuild removes it."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]](let [existing (api/check-404 (table-index/select-applicable-by-id id))](write-check-owner! existing)(indexes-rest.db/set-table-index-status! id :delete-pending))diff --git a/src/metabase/legacy_mbql/schema.cljc b/src/metabase/legacy_mbql/schema.cljcindex 63a73605300..c6b95a3bb40 100644--- a/src/metabase/legacy_mbql/schema.cljc+++ b/src/metabase/legacy_mbql/schema.cljc@@ -442,14 +442,17 @@;;;; As of 0.42.0 `:aggregation` references can have an optional options map.(mr/def ::AggregationRefOptions- [:map- {:decode/normalize (fn [m]- (when-let [m (lib.schema.ref/normalize-aggregation-ref-options m)]- (not-empty (dissoc m :lib/uuid))))}- [:name {:optional true} ::lib.schema.common/non-blank-string]- [:display-name {:optional true} ::lib.schema.common/non-blank-string]- [:base-type {:optional true} [:maybe ::lib.schema.common/base-type]]- [:effective-type {:optional true} [:maybe ::lib.schema.common/base-type]]])+ "Options for a legacy `:aggregation` ref in MBQL 4 are the same as in MBQL 5, except that `:lib/uuid` is optional and+ the map cannot be empty."+ [:and+ [:merge+ {:decode/normalize (fn [m]+ (when-let [m (lib.schema.ref/normalize-aggregation-ref-options m)]+ (not-empty (dissoc m :lib/uuid))))}+ ::lib.schema.ref/aggregation-options+ [:map+ [:lib/uuid {:optional true} ::lib.schema.common/uuid]]]+ (lib.schema.common/disallowed-keys {:lib/uuid "MBQL 4 refs should not have :lib/uuid"})])(defclause* aggregation[:and@@ -1587,12 +1590,15 @@;; :dimension [:field 4 nil];; :widget-type :date/all-options}(mr/def ::TemplateTag.FieldFilter.Options- [:map-of+ "Options appended to the filter clause a Field Filter template tag generates. Mirrors its MBQL 5 twin,+ `:metabase.lib.schema.template-tag/field-filter.options`; the map stays open there and here because these options+ are merged into the parameter value the QP builds for the tag."+ [:map{:decode/normalize (fn [m](when (map? m)(update-keys m lib.schema.common/normalize-keyword)))}- :keyword- :any])+ [:case-sensitive {:optional true} :boolean]+ [:include-current {:optional true} :boolean]])(mr/def ::TemplateTag.FieldFilter"Schema for a field filter template tag."@@ -1777,6 +1783,7 @@(when (map? m)(-> mlib.schema.common/normalize-map-no-kebab-case+ lib.schema.common/remove-internal-keys;; remove deprecated `:ident` key.(dissoc :ident);; set `display_name` to `name` if it's unset.@@ -1794,11 +1801,14 @@(cond-> m(and (:binning_strategy m)(not (:strategy m)))- (assoc :strategy (:binning_strategy m))))))}+ (assoc :strategy (:binning_strategy m))))))+ :closed true}[:strategy [:ref ::lib.schema.binning/strategy]][:binning_strategy {:optional true} [:ref ::lib.schema.binning/strategy]][:bin_width {:optional true} [:ref ::lib.schema.binning/bin-width]]- [:num_bins {:optional true} [:ref ::lib.schema.binning/num-bins]]]+ [:num_bins {:optional true} [:ref ::lib.schema.binning/num-bins]]+ [:min_value {:optional true} number?]+ [:max_value {:optional true} number?]][:fn{:error/message "bin_width is a required key when strategy is bin-width"}(fn [m]@@ -1850,7 +1860,9 @@[:merge[:map;; this schema is allowed for Card `result_metadata` in Lib so `:decode/normalize` is used for those Lib use cases.- {:decode/normalize #'normalize-legacy-column}+ {:closed true+ :decode/normalize #'normalize-legacy-column+ :decode/api lib.schema.common/remove-internal-keys}[:base_type {:default :type/*} ::lib.schema.common/base-type][:display_name :string][:name :string]@@ -1875,12 +1887,31 @@[:inherited_temporal_unit {:optional true} [:maybe [:ref ::lib.schema.temporal-bucketing/unit]]][:nfc_path {:optional true} [:maybe [:sequential :string]]][:position {:optional true} [:maybe :int]]+ [:custom_position {:optional true} [:maybe :int]]+ [:database_position {:optional true} [:maybe :int]]+ [:database_is_auto_increment {:optional true} [:maybe :boolean]]+ [:database_partitioned {:optional true} [:maybe :boolean]]+ [:database_required {:optional true} [:maybe :boolean]]+ [:data_sensitivity {:optional true} [:maybe [:or :string :keyword]]]+ [:fingerprint_version {:optional true} [:maybe :int]]+ [:parent_id {:optional true} [:maybe ::lib.schema.id/field]]+ [:points_of_interest {:optional true} [:maybe :string]]+ [:preview_display {:optional true} [:maybe :boolean]]+ [:caveats {:optional true} [:maybe :string]]+ [:target {:optional true} [:maybe [:or ::lib.schema.id/field [:ref ::legacy-column-metadata]]]]+ [:options {:optional true} [:maybe [:ref ::lib.schema.metadata/column.options]]][:remapped_from {:optional true} [:maybe :string]][:remapped_to {:optional true} [:maybe :string]]+ [:remapped_from_index {:optional true} [:maybe :int]]+ [:source_alias {:optional true} [:maybe :string]]+ [:aggregation_index {:optional true} [:maybe :int]]+ [:expression_name {:optional true} [:maybe :string]]+ [:special_type {:optional true} [:maybe [:or :string :keyword]]]+ [:remapping {:optional true} [:maybe [:map-of [:ref ::lib.schema.literal/literal] [:ref ::lib.schema.literal/literal]]]][:selected? {:optional true} :boolean];; name is allowed to be empty in some databases like SQL Server.[:semantic_type {:optional true} [:maybe ::lib.schema.common/semantic-or-relation-type]]- [:settings {:optional true} [:maybe [:map {:closed false}]]]+ [:settings {:optional true} [:maybe [:ref ::lib.schema.common/visualization-settings]]][:source {:optional true} [:maybe [:ref ::lib.schema.metadata/column.legacy-source]]][:table_id {:optional true} [:maybe [:ref ::SourceTable]]][:unit {:optional true} [:maybe [:ref ::lib.schema.temporal-bucketing/unit]]]@@ -2107,10 +2138,9 @@;; {:aggregation "ROWS"} => {:aggregation nil};;;; but not actually remove that key; so we need this second pass to remove it.- ;; open: this only exists to run a second normalization pass, so it must not constrain (or strip) any keys[:schema{:decode/normalize #'remove-empty-keys-from-mbql-inner-query}- [:map {:closed false}]]+ :any];;;; CONSTRAINTS;;diff --git a/src/metabase/lib/binning.cljc b/src/metabase/lib/binning.cljcindex adc372d7bcf..dcb84cf7590 100644--- a/src/metabase/lib/binning.cljc+++ b/src/metabase/lib/binning.cljc@@ -18,6 +18,13 @@[metabase.util.malli :as mu][metabase.util.performance :refer [mapv select-keys get-in]]))+(mu/defn ->binning-options :- [:maybe ::lib.schema.binning/binning]+ "The plain `:binning` options behind the value [[binning]] returns: the same map without the `:lib/type` tag and the+ `:metadata-fn` closure that `display-info` needs. Use this whenever those options go back into a query or into+ column metadata -- the closure cannot be serialized."+ [resolved :- [:maybe ::lib.schema.binning/binning.resolved]]+ (some-> resolved (dissoc :lib/type :metadata-fn)))+(defmulti with-binning-method"Implementation for [[with-binning]]. Implement this to tell [[with-binning]] how to add binning to a particular MBQLclause."@@ -38,10 +45,10 @@Pass `nil` `binning` to remove any binning."{:style/indent [:form]}- [x binning :- [:maybe [:or ::lib.schema.binning/binning ::lib.schema.binning/binning-option]]]- (with-binning-method x (if (contains? binning :mbql)- (:mbql binning)- binning)))+ [x binning :- [:maybe [:or ::lib.schema.binning/binning.resolved ::lib.schema.binning/binning-option]]]+ (with-binning-method x (->binning-options (if (contains? binning :mbql)+ (:mbql binning)+ binning))))(defmulti binning-method"Implementation of [[binning]]. Return the current binning options associated with `x`."@@ -53,8 +60,10 @@[_x]nil)-(mu/defn binning :- [:maybe ::lib.schema.binning/binning]- "Get the current binning options associated with `x`, if any."+(mu/defn binning :- [:maybe ::lib.schema.binning/binning.resolved]+ "Get the current binning options associated with `x`, if any. The options come back tagged with `:lib/type` and a+ `:metadata-fn` closure for [[metabase.lib.metadata.calculation/display-info]]; strip those before putting them back+ into a query."[x](binning-method x))@@ -127,7 +136,7 @@(mu/defn binning-display-name :- ::lib.schema.common/non-blank-string"This is implemented outside of [[lib.metadata.calculation/display-name]] because it needs access to the field type.It's called directly by `:field` or `:metadata/column`'s [[lib.metadata.calculation/display-name]]."- [{:keys [bin-width num-bins strategy] :as binning-options} :- ::lib.schema.binning/binning+ [{:keys [bin-width num-bins strategy] :as binning-options} :- ::lib.schema.binning/binning.resolvedx :- [:maybe[:or::lib.schema.metadata/column@@ -155,8 +164,8 @@(mu/defn binning= :- boolean?"Given binning values (as returned by [[binning]]), check if they match."- [x :- [:maybe ::lib.schema.binning/binning]- y :- [:maybe ::lib.schema.binning/binning]]+ [x :- [:maybe ::lib.schema.binning/binning.resolved]+ y :- [:maybe ::lib.schema.binning/binning.resolved]](let [binning-keys (case (:strategy x):num-bins [:strategy :num-bins]:bin-width [:strategy :bin-width]@@ -167,7 +176,7 @@"Given a binning option (as returned by [[available-binning-strategies]]) and the binning value (possibly nil) froma column, check if they match."[binning-option :- ::lib.schema.binning/binning-option- column-binning :- [:maybe ::lib.schema.binning/binning]]+ column-binning :- [:maybe ::lib.schema.binning/binning.resolved]](binning= (:mbql binning-option) column-binning))(mu/defn default-bin-width :- [:maybe ::lib.schema.binning/bin-width]diff --git a/src/metabase/lib/drill_thru/quick_filter.cljc b/src/metabase/lib/drill_thru/quick_filter.cljcindex 9faca526fbf..b125c198c7e 100644--- a/src/metabase/lib/drill_thru/quick_filter.cljc+++ b/src/metabase/lib/drill_thru/quick_filter.cljc@@ -72,9 +72,7 @@(mu/defn- operators-for :- [:sequential ::lib.schema.drill-thru/drill-thru.quick-filter.operator][column :- ::lib.schema.metadata/columnvalue]- (let [field-ref (cond-> (lib.ref/ref column)- (:temporal-unit column)- (lib.temporal-bucket/with-temporal-bucket (:temporal-unit column)))]+ (let [field-ref (lib.ref/ref column)](cond(lib.types.isa/structured? column)[]@@ -141,8 +139,8 @@(let [temporal-unit (lib.temporal-bucket/temporal-bucket column-ref)binning (lib.binning/binning column-ref)column (cond-> (:column drill-details)- temporal-unit (assoc :temporal-unit temporal-unit)- binning (assoc :lib/binning binning))]+ temporal-unit (lib.temporal-bucket/with-temporal-bucket temporal-unit)+ binning (lib.binning/with-binning binning))](merge drill-details{:lib/type :metabase.lib.drill-thru/drill-thru:type :drill-thru/quick-filterdiff --git a/src/metabase/lib/drill_thru/zoom_in_bins.cljc b/src/metabase/lib/drill_thru/zoom_in_bins.cljcindex 0e3ec3b6dc3..209ab32abf7 100644--- a/src/metabase/lib/drill_thru/zoom_in_bins.cljc+++ b/src/metabase/lib/drill_thru/zoom_in_bins.cljc@@ -135,7 +135,8 @@:column column:min-value min-value:max-value max-value- :new-binning (update binning :bin-width #(double (/ % 10.0)))}))))))+ :new-binning (-> (lib.binning/->binning-options binning)+ (update :bin-width #(double (/ % 10.0))))}))))));;;;;; applicationdiff --git a/src/metabase/lib/schema.cljc b/src/metabase/lib/schema.cljcindex 9b984e0ef15..38f2c4e572c 100644--- a/src/metabase/lib/schema.cljc+++ b/src/metabase/lib/schema.cljc@@ -8,7 +8,6 @@future we can deprecate that namespace and eventually do away with it entirely."(:refer-clojure :exclude [ref every? some select-keys empty? get-in])(:require- [malli.util :as mut][medley.core :as m][metabase.lib.options :as lib.options][metabase.lib.schema.actions :as actions]@@ -61,13 +60,48 @@[:parameters:lib/stage-metadata])))+(mr/def ::external-remapping+ "One external (Dimension) column remapping, as recorded on a query or stage+ by [[metabase.query-processor.middleware.add-remaps]]. Mirrors `:metabase.query-processor.middleware.add-remaps/external-remapping`;+ it is duplicated here because Lib may not depend on the query processor."+ [:map+ {:closed true}+ [:id [:ref ::id/dimension]]+ [:name ::common/non-blank-string]+ [:field-id [:ref ::id/field]]+ [:field-name ::common/non-blank-string]+ [:human-readable-field-id [:ref ::id/field]]+ [:human-readable-field-name ::common/non-blank-string]])++(mr/def ::external-remappings+ [:sequential [:ref ::external-remapping]])+(mr/def ::stage.common[:map- {:decode/normalize normalize-stage-common+ {:closed true+ :decode/normalize normalize-stage-common:decode/api common/remove-internal-keys:encode/serialize common/remove-internal-keys}[:parameters {:optional true} [:ref ::lib.schema.parameter/parameters]]- [:lib/stage-metadata {:optional true} [:ref ::lib.schema.metadata/stage]]])+ [:lib/stage-metadata {:optional true} [:ref ::lib.schema.metadata/stage]]+ [:qp/stage-is-from-source-card {:optional true} [:ref ::id/card]]+ [:qp/stage-had-source-card {:optional true} [:ref ::id/card]]+ [:qp/added-implicit-fields? {:optional true} :boolean]+ [:qp/skip-persisted-cache {:optional true} :boolean]+ [:persisted-info/native {:optional true} ::common/non-blank-string]+ [:source-query/model? {:optional true} :boolean]+ [:source-query/native-model? {:optional true} [:maybe :boolean]]+ [:query-permissions/sandboxed-table {:optional true} [:ref ::id/table]]+ [:metabase-enterprise.sandbox.query-processor.middleware.sandboxing/sandbox? {:optional true} :boolean]+ [:metabase.query-processor.middleware.add-remaps/remaps {:optional true} [:ref ::external-remappings]]+ [:metabase.query-processor.middleware.cumulative-aggregations/replaced-indexes {:optional true} [:set [:int {:min 0}]]]+ [:metabase.query-processor.middleware.add-implicit-joins/reused-join-aliases {:optional true} [:set [:ref ::join/alias]]]+ [:metabase.query-processor.util.add-alias-info/desired-alias->escaped+ {:optional true}+ [:map-of [:ref ::lib.schema.metadata/desired-column-alias] [:ref ::lib.schema.metadata/desired-column-alias]]]+ [:metabase.query-processor.util.add-alias-info/join-alias->escaped+ {:optional true}+ [:map-of [:ref ::join/alias] :string]]])(mr/def ::stage.native[:and@@ -89,7 +123,11 @@;; the actual native query, depends on the underlying database. Could be a raw SQL string or something like that.;; Only restriction is that, if present, it is non-nil.;; It is valid to have a blank query like `{:type :native}` in legacy.- [:native {:optional true} some?]+ [:native {:optional true} [:or+ :string+ [:schema {::mr/deliberately-open true+ :description "a driver's native query when it is not a string, e.g. a MongoDB pipeline or a query with its parameters; its shape is the driver's"}+ :some]]];; any parameters that should be passed in along with the query to the underlying query engine, e.g. for JDBC these;; are the parameters we pass in for a `PreparedStatement` for `?` placeholders. These can be anything, including;; nil.@@ -97,10 +135,14 @@;; This schema is `[:or ::literal/literal :any]` so Malli encoding [[metabase.lib.serialize]] will use it if;; applicable... e.g. a Java time type will get serialized to a;; string (see [[metabase.lib.serialize-test/encode-java-time-types-in-native-query-args-test]])- [:params {:optional true} [:maybe [:sequential [:or [:ref ::literal/literal] :any]]]]+ [:params {:optional true} [:maybe [:sequential [:ref ::literal/param-value]]]];; the Table/Collection/etc. that this query should be executed against; currently only used for MongoDB, where it;; is required.[:collection {:optional true} ::common/non-blank-string]+ [:projections {:optional true} [:maybe [:sequential :string]]]+ [:mbql? {:optional true} [:maybe :boolean]]+ ;; the table the query was compiled from; BigQuery's compiled native form carries it+ [:table-name {:optional true} [:maybe :string]];; optional template tag declarations. Template tags are things like `{{x}}` in the query (the value of the;; `:native` key), but their definition lives under this key.;;@@ -262,7 +304,7 @@[:map{:decode/normalize common/normalize-map:decode/api common/remove-internal-keys- :encode/serialize common/remove-internal-keys}+ :encode/serialize common/remove-internal-keys :closed true}[:page pos-int?][:items pos-int?]])@@ -270,7 +312,7 @@"Pivot intent. `:rows` and `:columns` are sequences of UUIDs that reference `:lib/uuid` values on breakouts of thestage that carries this clause. `:show-row-totals` and `:show-column-totals` default to `true` when absent."[:map- {:decode/normalize common/normalize-map}+ {:decode/normalize common/normalize-map :closed true}[:rows [:sequential ::common/uuid]][:columns [:sequential ::common/uuid]][:show-row-totals {:optional true} :boolean]@@ -391,7 +433,7 @@(mr/def ::stage.initial[:multi {:dispatch lib-type:error/message "Invalid stage :lib/type: expected :mbql.stage/native or :mbql.stage/mbql"}- [:mbql.stage/native :map]+ [:mbql.stage/native [:fn {:error/message "Initial native stage"} map?]][:mbql.stage/mbql [:fn{:error/message "Initial MBQL stage must have either :source-table or :source-card (but not both)"}(some-fn :source-table :source-card)]]])@@ -527,6 +569,87 @@(common/unfussy-sorted-map)query)))+(mr/def ::sandboxing.original-metadata+ "The columns a query was expected to return *before* sandboxes replaced its source tables, stashed on the query by+ the enterprise sandboxing middleware (see `expected-cols` in+ `metabase-enterprise.sandbox.query-processor.middleware.sandboxing`) and compared against the sandboxed results+ afterwards.++ In production these are legacy, `snake_cased` column metadata maps (i.e.+ `:metabase.legacy-mbql.schema/legacy-column-metadata`), but this key is a verbatim snapshot that must survive+ normalization untouched -- pointing at that schema here would rewrite its keys and drop deprecated ones, which+ breaks round-tripping (see `metabase.lib.convert-test/round-trip-preserve-metadata-test`). So the elements are+ declared as plain maps, which carry no decoders."+ [:sequential :map])++(mr/def ::query.snapshot+ "A whole copy of a query stashed on the query itself under one of the internal keys below.++ Deliberately NOT `[:ref ::query]`: [[malli.util/merge]] recurses into the entries that the two schemas being merged+ share, so a self-referential `::query` entry makes `[:merge ::query [:map [<same key> ::query]]]` -- which+ [[metabase.query-processor.util.add-alias-info]] uses -- recur until the stack blows. This shallow shape says what+ the value is without reintroducing the cycle."+ [:map+ [:lib/type [:= {:decode/normalize common/normalize-keyword} :mbql/query]]+ [:stages [:ref ::stages]]])++(mr/def ::cache-strategy.nocache+ [:map {:closed true, :decode/normalize common/normalize-map-no-kebab-case}+ [:type [:= {:decode/normalize common/normalize-keyword} :nocache]]+ [:name {:optional true} [:maybe :string]]])++(mr/def ::cache-strategy.ttl+ "Cache for a multiple of the query's average execution time. Typed as plain numbers here: a strategy reaches a query+ from several places (the Card, a Dashboard, the Database), and `metabase.cache.api` is the one that asks for integers."+ [:map {:closed true, :decode/normalize common/normalize-map-no-kebab-case}+ [:type [:= {:decode/normalize common/normalize-keyword} :ttl]]+ [:multiplier number?]+ [:min_duration_ms number?]])++(mr/def ::cache-strategy.duration+ "Cache for a fixed duration (EE)."+ [:map {:closed true, :decode/normalize common/normalize-map-no-kebab-case}+ [:type [:= {:decode/normalize common/normalize-keyword} :duration]]+ [:duration number?]+ [:unit [:enum "hours" "minutes" "seconds" "days"]]+ [:refresh_automatically {:optional true} [:maybe :boolean]]])++(mr/def ::cache-strategy.schedule+ "Cache until the next run of a cron schedule (EE)."+ [:map {:closed true, :decode/normalize common/normalize-map-no-kebab-case}+ [:type [:= {:decode/normalize common/normalize-keyword} :schedule]]+ [:schedule :string]+ [:refresh_automatically {:optional true} [:maybe :boolean]]])++(mr/def ::cache-strategy.on-query+ "What is added to a strategy once it is attached to a query."+ [:map {:closed true}+ [:invalidated-at {:optional true} [:maybe [:or :string #?@(:clj [(common/instance-of-class java.time.temporal.Temporal)])]]]+ [:avg-execution-ms {:optional true} [:int {:min 0}]]])++(mr/def ::cache-strategy+ "The caching strategy the results-cache middleware should apply to this query, attached+ by [[metabase.query-processor.card]]. Any of the strategy types: which ones an instance may configure is+ `metabase.cache.api`'s business, not the query's."+ [:multi {:dispatch (fn [strategy] (some-> (:type strategy) keyword))+ :decode/normalize common/normalize-map-no-kebab-case}+ [:nocache [:merge ::cache-strategy.nocache ::cache-strategy.on-query]]+ [:ttl [:merge ::cache-strategy.ttl ::cache-strategy.on-query]]+ [:duration [:merge ::cache-strategy.duration ::cache-strategy.on-query]]+ [:schedule [:merge ::cache-strategy.schedule ::cache-strategy.on-query]]])++(mr/def ::compiled-native-query+ "A native query compiled from this query by [[metabase.query-processor.compile]], ready to hand to the driver.+ `:query` is whatever native form the driver uses -- a string for SQL drivers, a map for Mongo -- so it is only+ constrained to be non-`nil`.++ Deliberately NOT closed: drivers add their own keys, e.g. Mongo adds `:collection`, `:projections` and `:mbql?`+ (see `:metabase.driver.mongo.query-processor/compiled-pipeline`), and for a query that was already native the+ compiled form is the native stage itself, carrying every key a `::stage.native` has."+ [:map+ [:query :some]+ [:params {:optional true} [:maybe [:sequential [:ref ::literal/param-value]]]]])+(mr/def ::query[:and[:map@@ -534,7 +657,8 @@:decode/normalize #'normalize-query:decode/api #'common/remove-internal-keys:encode/serialize #'serialize-query- :encode/for-hashing #'encode-query-for-hashing}+ :encode/for-hashing #'encode-query-for-hashing+ :closed true}[:lib/type [:={:decode/normalize common/normalize-keyword, :default :mbql/query}:mbql/query]]@@ -555,6 +679,8 @@[:settings {:optional true} [:ref ::lib.schema.settings/settings]][:constraints {:optional true} [:ref ::lib.schema.constraints/constraints]][:middleware {:optional true} [:ref ::lib.schema.middleware-options/middleware-options]]+ [:async? {:optional true} :boolean]+ [:cache-strategy {:optional true} [:maybe [:ref ::cache-strategy]]][:was-pivot{:optional true:description@@ -567,7 +693,34 @@[:pivot-measures {:optional true} [:maybe [:sequential [:int {:min 0}]]]][:show-row-totals {:optional true} [:maybe :boolean]][:show-column-totals {:optional true} [:maybe :boolean]]- ;; TODO -- `:viz-settings` ?+ [:pivot_rows {:optional true} [:maybe [:sequential [:int {:min 0}]]]]+ [:pivot_cols {:optional true} [:maybe [:sequential [:int {:min 0}]]]]+ [:pivot_measures {:optional true} [:maybe [:sequential [:int {:min 0}]]]]+ [:show_row_totals {:optional true} [:maybe :boolean]]+ [:show_column_totals {:optional true} [:maybe :boolean]]+ [:viz-settings {:optional true} [:maybe [:ref ::common/visualization-settings]]]+ [:user-parameters {:optional true} [:ref ::lib.schema.parameter/parameters]]+ [:lib.convert/converted? {:optional true} :boolean]+ [:qp/compiled {:optional true} [:ref ::compiled-native-query]]+ [:qp/compiled-inline {:optional true} [:ref ::compiled-native-query]]+ [:qp/source-card-id {:optional true} [:ref ::id/card]]+ [:qp/skip-result-metadata-persistence {:optional true} :boolean]+ [:qp.pivot/unremapped-breakout-combination {:optional true} [:sequential [:int {:min 0}]]]+ [:qp.pivot/remapped-breakout-combination {:optional true} [:maybe [:sequential [:int {:min 0}]]]]+ [:qp.pivot/num-remapped-cols {:optional true} [:int {:min 0}]]+ [:qp.pivot/num-unremapped-breakouts {:optional true} [:int {:min 0}]]+ [:qp.pivot/num-remapped-breakouts {:optional true} [:int {:min 0}]]+ [:qp.pivot/remapped-indexes {:optional true} [:map-of [:int {:min 0}] [:int {:min 0}]]]+ [:query-permissions/referenced-card-ids {:optional true} [:maybe [:set [:ref ::id/card]]]]+ [:destination-database/id {:optional true} [:ref ::id/database]]+ [:impersonation/role {:optional true} ::common/non-blank-string]+ [:impersonation/admin? {:optional true} :boolean]+ [:impersonation/allow-write? {:optional true} :boolean]+ [:metabase.query-processor.util.add-alias-info/original {:optional true} [:ref ::query.snapshot]]+ [:metabase.query-processor.middleware.add-remaps/external-remaps {:optional true} [:ref ::external-remappings]]+ [:metabase-enterprise.sandbox.query-processor.middleware.sandboxing/original-metadata+ {:optional true}+ [:ref ::sandboxing.original-metadata]];;;; INFO;;@@ -613,9 +766,11 @@:mbql.clause/field (assoc-in (mr/schema :mbql.clause/field)[3 2 0] :dispatch-type/sequential);; similarly we need to get rid of the :lib/uuid key of- ;; a map that's nested in position 2 of an :and schema:::common/options (update (mr/schema ::common/options) 2- mut/dissoc :lib/uuid)}}+ (fn [map-form]+ (into []+ (remove #(and (vector? %) (= :lib/uuid (first %))))+ map-form)))}}[:ref ::query]])(defn native-only-query?diff --git a/src/metabase/lib/schema/actions.cljc b/src/metabase/lib/schema/actions.cljcindex 8e2bc76d191..643c38b5909 100644--- a/src/metabase/lib/schema/actions.cljc+++ b/src/metabase/lib/schema/actions.cljc@@ -1,10 +1,11 @@(ns metabase.lib.schema.actions(:require[metabase.lib.schema.common :as lib.schema.common]+ [metabase.lib.schema.literal :as lib.schema.literal][metabase.util.malli.registry :as mr]));;; only for Actions. Column name => value. A column name is technically allowed to be blank.(mr/def ::row[:map-of[:string {:decode/normalize lib.schema.common/normalize-string-key}]- :any])+ [:ref ::lib.schema.literal/literal]])diff --git a/src/metabase/lib/schema/binning.cljc b/src/metabase/lib/schema/binning.cljcindex c54fa4ab2bb..98d1e2f29d7 100644--- a/src/metabase/lib/schema/binning.cljc+++ b/src/metabase/lib/schema/binning.cljc@@ -39,14 +39,39 @@(keyword (some #(get x %) [:strategy "strategy"]))):error/fn (fn [{:keys [value]} _](str "Invalid binning strategy" (pr-str value)))}- [:default [:map- [:strategy [:= :default]]]]- [:bin-width [:map+ [:default [:map {:closed true}+ [:strategy [:= :default]]+ [:bin-width {:optional true} [:ref ::bin-width]]+ [:num-bins {:optional true} [:ref ::num-bins]]+ [:min-value {:optional true} number?]+ [:max-value {:optional true} number?]]]+ [:bin-width [:map {:closed true}[:strategy [:= :bin-width]]- [:bin-width [:ref ::bin-width]]]]- [:num-bins [:map- [:strategy [:= :num-bins]]- [:num-bins [:ref ::num-bins]]]]]])+ [:bin-width [:ref ::bin-width]]+ [:num-bins {:optional true} [:ref ::num-bins]]+ [:min-value {:optional true} number?]+ [:max-value {:optional true} number?]]]+ [:num-bins [:map {:closed true}+ [:strategy [:= :num-bins]]+ [:num-bins [:ref ::num-bins]]+ [:bin-width {:optional true} [:ref ::bin-width]]+ [:min-value {:optional true} number?]+ [:max-value {:optional true} number?]]]]])++(mr/def ::binning.resolved+ "What [[metabase.lib.binning/binning]] returns: the `:binning` options of a `:field` ref or of column metadata, plus+ the `:lib/type` tag and the `:metadata-fn` closure that [[metabase.lib.metadata.calculation/display-info]] uses to+ fetch the column those options apply to.++ This is a Lib return value, never part of a query -- the two extra keys are attached on the way out+ by [[metabase.lib.binning/binning-method]] and are `dissoc`ed again before the options go back into a query. They+ are optional because the equality helpers ([[metabase.lib.binning/binning=]] and friends) compare a resolved+ binning against a plain [[binning]] taken straight from a ref."+ [:merge+ ::binning+ [:map+ [:lib/type {:optional true} [:= :metabase.lib.binning/binning]]+ [:metadata-fn {:optional true} ifn?]]])(mr/def ::binning-option[:mapdiff --git a/src/metabase/lib/schema/common.cljc b/src/metabase/lib/schema/common.cljcindex 2c905367b68..23007890cea 100644--- a/src/metabase/lib/schema/common.cljc+++ b/src/metabase/lib/schema/common.cljc@@ -126,6 +126,13 @@{:error/message "positive number"}(every-pred number? pos?)])+(mr/def ::visualization-settings+ "Chart-rendering settings authored by the frontend. The backend stores and echoes them and reads no fixed key set, so+ the keys are whatever the visualization the user picked needs. This is the `.cljc` equivalent+ of [[metabase.util.malli.schema/VisualizationSettings]], which we cannot use here because that namespace is `.clj`+ only."+ [:map {:closed false, ::mr/deliberately-open true, :description "visualization settings", :decode/normalize normalize-map-no-kebab-case}])+(mr/def ::uuid[:string{:decode/normalize (fn [x]@@ -302,13 +309,26 @@(first fn-schemas)(into [:and] fn-schemas))))+(mr/def ::add-alias-info.source-table+ "Value of the `:metabase.query-processor.util.add-alias-info/source-table` option+ that [[metabase.query-processor.util.add-alias-info]] adds to a `:field` ref: the ID of the Table the field comes+ from, the (escaped) alias of the join or source query it comes from, or one of the two sentinel keywords that+ namespace uses for 'the source query' and 'nowhere in particular'."+ [:or+ :string+ [:ref :metabase.lib.schema.id/table]+ [:enum+ :metabase.query-processor.util.add-alias-info/source+ :metabase.query-processor.util.add-alias-info/none]])+(mr/def ::options[:and{:default {}}[:map{:decode/normalize #'normalize-options-map:decode/api #'remove-internal-keys- :encode/for-hashing #'encode-map-for-hashing}+ :encode/for-hashing #'encode-map-for-hashing+ :closed true}[:lib/uuid ::uuid];; these options aren't required for any clause in particular, but if they're present they must follow these schemas.[:base-type {:optional true} [:maybe ::base-type]]@@ -329,7 +349,26 @@;; `:time-interval`[:include-current {:optional true} :boolean];; the name an aggregation is referenced by- [:lib/source-name {:optional true} ::non-blank-string]]+ [:lib/source-name {:optional true} ::non-blank-string]+ [:default {:optional true} [:ref :metabase.lib.schema.expression/expression]]+ [:join-alias {:optional true} [:ref :metabase.lib.schema.join/alias]]+ [:qp/ignore-coercion {:optional true} :boolean]+ [:qp/allow-coercion-for-columns-without-integer-qp.add.source-table {:optional true} :boolean]+ [:qp/native-sandbox-column.force-coercion-strategy {:optional true} [:ref ::coercion-strategy]]+ [:metabase.query-processor.util.add-alias-info/source-table {:optional true} [:ref ::add-alias-info.source-table]]+ [:metabase.query-processor.util.add-alias-info/source-alias {:optional true} [:maybe :string]]+ [:metabase.query-processor.util.add-alias-info/desired-alias {:optional true} [:maybe :string]]+ [:metabase.query-processor.util.add-alias-info/nfc-path {:optional true} [:sequential :string]]+ [:metabase.query-processor.util.add-alias-info/resolved {:optional true} [:ref :metabase.lib.schema.metadata/column]]+ [:metabase.query-processor.util.transformations.nest-breakouts/externally-remapped-field {:optional true} :boolean]+ [:metabase.query-processor.middleware.add-remaps/new-field-dimension-id {:optional true} [:ref :metabase.lib.schema.id/dimension]]+ [:metabase.query-processor.middleware.add-remaps/original-field-dimension-id {:optional true} [:ref :metabase.lib.schema.id/dimension]]+ [:metabase.driver.sql.query-processor/forced-alias {:optional true} :boolean]+ [:metabase.driver.sql.query-processor/add-cast {:optional true} :keyword]+ [:metabase.driver.sql.query-processor/wrap-in-case {:optional true} :boolean]+ [:metabase.driver.sql.parameters.substitution/compiling-field-filter? {:optional true} :boolean]+ [:metabase.driver.sqlserver/optimized-bucketing? {:optional true} :boolean]+ [:metabase.driver.mongo.query-processor/join-local {:optional true} [:ref :metabase.lib.schema.join/alias]]](disallowed-keys{:ident ":ident is deprecated and should not be included in options maps"})])diff --git a/src/metabase/lib/schema/constraints.cljc b/src/metabase/lib/schema/constraints.cljcindex f1a4b30c5e5..7f6b6c2aa9d 100644--- a/src/metabase/lib/schema/constraints.cljc+++ b/src/metabase/lib/schema/constraints.cljc@@ -11,7 +11,8 @@[:map{:decode/normalize lib.schema.common/normalize-map:decode/api lib.schema.common/remove-internal-keys- :encode/serialize lib.schema.common/remove-internal-keys}+ :encode/serialize lib.schema.common/remove-internal-keys+ :closed true}[:max-results{:optional true:descriptiondiff --git a/src/metabase/lib/schema/info.cljc b/src/metabase/lib/schema/info.cljcindex 26ee516c6be..42a6df5a450 100644--- a/src/metabase/lib/schema/info.cljc+++ b/src/metabase/lib/schema/info.cljc@@ -56,7 +56,7 @@like [[metabase.query-processor/userland-query]] some of these keys (e.g. `:context`) are in fact required"[:map;; do not decode, since this should not get written to the app DB or come in from the REST API.- {:decode/normalize identity}+ {:closed true, :decode/normalize identity};; TODO -- not 100% sure info should be getting normalized, because we're not supposed to be saving this map;; anyway, right?;; These keys are nice to pass in if you're running queries on the backend and you know these values. They aren't@@ -69,8 +69,10 @@[:dashboard-id {:optional true} [:maybe ::lib.schema.id/dashboard]][:transform-id {:optional true} [:maybe ::lib.schema.id/transform]][:lens-id {:optional true} [:maybe ::lib.schema.common/non-blank-string]]- [:lens-params {:optional true} [:maybe [:map-of :keyword :any]]]+ [:lens-params {:optional true} [:maybe [:map {:closed true}+ [:join_step {:optional true} [:maybe :int]]]]][:pulse-id {:optional true} [:maybe ::lib.schema.id/pulse]]+ [:visualization-settings {:optional true} [:maybe [:ref ::lib.schema.common/visualization-settings]]];; Metadata for datasets when querying the dataset. This ensures that user edits to dataset metadata are blended in;; with runtime computed metadata so that edits are saved.;;@@ -79,9 +81,10 @@;; TODO (Cam 6/13/25) -- weird to put this at the top-level of the query as opposed to in the stage to which this;; applies... I guess it's mostly only used to in [[metabase.lib.metadata.result-metadata]] tho[:metadata/model-metadata {:optional true} [:maybe [:sequential ::lib.schema.metadata/lib-or-legacy-column]]]+ [:metadata/own-model-query? {:optional true} :boolean]+ [:pivot/original-query {:optional true} [:maybe [:ref :metabase.lib.schema/query]]];; Pivot QP runs multiple queries, and in the dataset api, we need to have access to the original query;; so that we can pass it to the pivot.qp for downloads on unsaved questions- [:pivot/original-query {:optional true} [:maybe [:map-of :any :any]]];; this gets added by [[metabase.query-processor.pivot]] for pivot queries; it's merged in to other metadata;; by [[metabase.query-processor.middleware.results-metadata]] before recording it.[:pivot/result-metadata {:optional true} [:maybe [:multidiff --git a/src/metabase/lib/schema/join.cljc b/src/metabase/lib/schema/join.cljcindex 6f25c19a973..13c2e96025d 100644--- a/src/metabase/lib/schema/join.cljc+++ b/src/metabase/lib/schema/join.cljc@@ -122,13 +122,23 @@{:default {}:decode/normalize normalize-join:decode/api common/remove-internal-keys- :encode/serialize common/remove-internal-keys}+ :encode/serialize common/remove-internal-keys+ :closed true}[:lib/type [:= {:default :mbql/join, :decode/normalize common/normalize-keyword} :mbql/join]][:stages [:ref :metabase.lib.schema/stages]][:conditions ::conditions][:alias ::alias][:fields {:optional true} ::fields]- [:strategy {:optional true} ::strategy]]+ [:strategy {:optional true} ::strategy]+ [:fk-field-id {:optional true} [:maybe [:ref :metabase.lib.schema.id/field]]]+ [:fk-field-name {:optional true} [:maybe :string]]+ [:fk-join-alias {:optional true} [:maybe ::alias]]+ [:qp/is-implicit-join {:optional true} :boolean]+ [:qp/keep-default-join-alias {:optional true} :boolean]+ [:metabase.query-processor.middleware.add-implicit-joins/original-position {:optional true} [:int {:min 0}]]+ [:metabase.query-processor.util.add-alias-info/alias {:optional true} ::alias]+ [:metabase.query-processor.util.add-alias-info/original-alias {:optional true} ::alias]+ [:metabase.lib.join/replace-alias {:optional true} :boolean]](common/disallowed-keys{:lib/stage-metadata "joins should not have metadata attached directly to them; attach metadata to their last stage instead":source-metadata "joins should not have metadata attached directly to them; attach metadata to their last stage instead"diff --git a/src/metabase/lib/schema/literal.cljc b/src/metabase/lib/schema/literal.cljcindex 0c155a81937..f97b9976676 100644--- a/src/metabase/lib/schema/literal.cljc+++ b/src/metabase/lib/schema/literal.cljc@@ -150,7 +150,8 @@(not (:effective-type m)))(assoc :effective-type (:base-type m))))))}[:effective-type ::common/base-type]- [:unit {:optional true} [:maybe ::temporal-bucketing/unit]]]])+ [:unit {:optional true} [:maybe ::temporal-bucketing/unit]]+ [:coercion-strategy {:optional true} [:maybe ::common/coercion-strategy]]]])(mr/def ::value.value"The value slot of a `:value` clause: a single literal that is not a Clojure collection."@@ -174,6 +175,14 @@#_opts [:ref ::value.options]#_value [:ref ::value.value]])+(mr/def ::param-value+ "A value bound to a native query parameter: a literal or, once the query processor has substituted parameters, a+ UUID or a `java.time` object."+ [:or+ [:ref ::literal]+ :uuid+ #?@(:clj [(common/instance-of-class java.time.temporal.Temporal)])])+(mr/def ::literal[:or:nildiff --git a/src/metabase/lib/schema/metadata.cljc b/src/metabase/lib/schema/metadata.cljcindex 0b76470740b..7287ecbdc01 100644--- a/src/metabase/lib/schema/metadata.cljc+++ b/src/metabase/lib/schema/metadata.cljc@@ -9,6 +9,7 @@[metabase.lib.schema.common :as lib.schema.common][metabase.lib.schema.id :as lib.schema.id][metabase.lib.schema.join :as lib.schema.join]+ [metabase.lib.schema.literal :as lib.schema.literal][metabase.lib.schema.metadata.fingerprint :as lib.schema.metadata.fingerprint][metabase.lib.schema.template-tag :as lib.schema.template-tag][metabase.lib.schema.temporal-bucketing :as lib.schema.temporal-bucketing]@@ -127,7 +128,7 @@"External remapping (Dimension) for a column. From the [[metabase.warehouse-schema.models.dimension]] with `type =external` associated with a `Field` in the application database.See [[metabase.query-processor.middleware.add-remaps]] for what this means."- [:map+ [:map {:closed true}[:lib/type [:= {:decode/normalize lib.schema.common/normalize-keyword} :metadata.column.remapping/external]][:id ::lib.schema.id/dimension];; from `dimension.name`@@ -140,16 +141,16 @@"Internal remapping (FieldValues) for a column. From [[metabase.warehouse-schema.models.dimension]] with `type =internal` and the [[metabase.warehouse-schema.models.field-values]] associated with a `Field` in the applicationdatabase. See [[metabase.query-processor.middleware.add-remaps]] for what this means."- [:map+ [:map {:closed true}[:lib/type [:= {:decode/normalize lib.schema.common/normalize-keyword} :metadata.column.remapping/internal]][:id ::lib.schema.id/dimension];; from `dimension.name`[:name ::lib.schema.common/non-blank-string];; From `metabase_fieldvalues.values`. Original values- [:values [:sequential :any]]+ [:values [:sequential [:ref ::lib.schema.literal/literal]]];; From `metabase_fieldvalues.human_readable_values`. Human readable remaps for the values at the same indexes in;; `:values`- [:human-readable-values [:sequential :any]]])+ [:human-readable-values [:sequential [:ref ::lib.schema.literal/literal]]]]);; these can both be empty strings like `""` because SQL Server (and possibly some other DBs) allow empty strings as;; column identifiers@@ -333,6 +334,61 @@instead."[:enum {:decode/normalize keyword} :aggregation :fields :breakout :native])+(mr/def ::column.snapshot+ "A whole column metadata map stashed on *another* column under one of the internal keys below.++ Deliberately NOT `[:ref ::column]`: [[malli.util/merge]] recurses into the entries that the two schemas being merged+ share, so a self-referential `::column` entry makes any `[:merge ...]` of two column-bearing maps -- for instance+ `:metabase.lib.schema.drill-thru/drill-thru.column-filter`, which merges two maps that both have a `:column` --+ recur until the stack blows. This shallow shape says what the value is without reintroducing the cycle."+ [:map+ [:lib/type [:= {:decode/normalize lib.schema.common/normalize-keyword} :metadata/column]]+ [:name :string]+ [:base-type {:optional true} ::lib.schema.common/base-type]])++(mr/def ::column.timestamp+ "A timestamp column of a `metabase_field` row: a `java.time` value on the JVM, the string it was encoded as elsewhere."+ #?(:clj [:or :string (lib.schema.common/instance-of-class java.time.temporal.Temporal)]+ :cljs :string))++(mr/def ::column.options+ "What the query processor stashes under a column's `:options` while it runs: never sent by a client, and never+ handed back to one."+ [:map {:closed true, :decode/api lib.schema.common/remove-internal-keys, :encode/serialize lib.schema.common/remove-internal-keys}+ [:qp/ignore-coercion {:optional true} :boolean]+ [:qp/native-sandbox-column.force-coercion-strategy {:optional true} [:maybe ::lib.schema.common/coercion-strategy]]+ [:qp/native-sandbox-column.propagate-coercion? {:optional true} [:maybe :boolean]]+ [:metabase.query-processor.util.add-alias-info/source-table {:optional true} [:maybe [:or :int :string :keyword]]]+ [:metabase.query-processor.util.add-alias-info/source-alias {:optional true} [:maybe :string]]+ [:metabase.query-processor.util.add-alias-info/desired-alias {:optional true} [:maybe :string]]+ [:metabase.query-processor.middleware.add-remaps/original-field-dimension-id {:optional true} [:maybe ::lib.schema.id/dimension]]+ [:metabase.query-processor.middleware.add-remaps/new-field-dimension-id {:optional true} [:maybe ::lib.schema.id/dimension]]+ [:metabase.query-processor.util.transformations.nest-breakouts/externally-remapped-field {:optional true} :boolean]])++(mr/def ::column.lib-options+ "What [[metabase.lib.options/with-options]] puts under `:lib/options` when it is handed a column rather than a+ clause: the expression name [[metabase.lib.fe-util/expression-parts]] pins on an expression column, and a `:lib/uuid`+ if something asked for one."+ [:map {:closed true}+ [:lib/uuid {:optional true} ::lib.schema.common/uuid]+ [:lib/expression-name {:optional true} ::lib.schema.common/non-blank-string]])++(mr/def ::column.binning-info+ "The legacy description of how a column was binned, as [[metabase.lib.metadata.result-metadata]] spells it out for+ the frontend."+ [:map {:closed true}+ [:strategy {:optional true} [:maybe [:ref ::lib.schema.binning/strategy]]]+ [:binning-strategy {:optional true} [:maybe [:ref ::lib.schema.binning/strategy]]]+ [:binning_strategy {:optional true} [:maybe [:ref ::lib.schema.binning/strategy]]]+ [:num-bins {:optional true} [:maybe :int]]+ [:num_bins {:optional true} [:maybe :int]]+ [:bin-width {:optional true} [:maybe number?]]+ [:bin_width {:optional true} [:maybe number?]]+ [:min-value {:optional true} [:maybe number?]]+ [:min_value {:optional true} [:maybe number?]]+ [:max-value {:optional true} [:maybe number?]]+ [:max_value {:optional true} [:maybe number?]]])+(mr/def ::column"Malli schema for a valid map of column metadata, which can mean one of two things:@@ -348,8 +404,11 @@to differentiate between the two versions."[:and[:map- {:error/message "Valid column metadata"- :decode/normalize normalize-column}+ {:closed true+ :error/message "Valid column metadata"+ :decode/normalize normalize-column+ :decode/api lib.schema.common/remove-internal-keys+ :encode/serialize lib.schema.common/remove-internal-keys}[:lib/type [:= {:decode/normalize lib.schema.common/normalize-keyword, :default :metadata/column} :metadata/column]];;;; TODO (Cam 6/19/25) -- change all these comments to proper `:description`s like we have@@ -511,10 +570,73 @@;; including BigQuery `RECORD` columns and MongoDB nested columns. See;; https://metaboat.slack.com/archives/C0645JP1W81/p1754949404592539 for code archeology[:nfc-path {:optional true} [:maybe [:sequential :string]]]+ ;; the rest of the `metabase_field` row a metadata provider hands back+ [:table-id {:optional true} [:maybe ::lib.schema.id/table]]+ [:parent-id {:optional true} [:maybe ::lib.schema.id/field]]+ [:description {:optional true} [:maybe :string]]+ [:caveats {:optional true} [:maybe :string]]+ [:points-of-interest {:optional true} [:maybe :string]]+ [:coercion-strategy {:optional true} [:maybe ::lib.schema.common/coercion-strategy]]+ [:position {:optional true} [:maybe :int]]+ [:custom-position {:optional true} [:maybe :int]]+ [:database-position {:optional true} [:maybe :int]]+ [:database-default {:optional true} [:maybe :string]]+ [:database-indexed {:optional true} [:maybe :boolean]]+ [:database-is-auto-increment {:optional true} [:maybe :boolean]]+ [:database-is-generated {:optional true} [:maybe :boolean]]+ [:database-is-nullable {:optional true} [:maybe :boolean]]+ [:database-is-pk {:optional true} [:maybe :boolean]]+ [:database-partitioned {:optional true} [:maybe :boolean]]+ [:database-required {:optional true} [:maybe :boolean]]+ [:json-unfolding {:optional true} [:maybe :boolean]]+ [:preview-display {:optional true} [:maybe :boolean]]+ [:fingerprint-version {:optional true} [:maybe :int]]+ [:created-at {:optional true} [:maybe [:ref ::column.timestamp]]]+ [:updated-at {:optional true} [:maybe [:ref ::column.timestamp]]]+ [:last-analyzed {:optional true} [:maybe [:ref ::column.timestamp]]]+ ;; the Field a foreign key points at, and the Field that names this table's rows: hydrated onto a Field by the+ ;; application database metadata provider, but only an id reference in the metadata the frontend hands over+ [:target {:optional true} [:maybe [:or ::lib.schema.id/field [:ref ::column]]]]+ [:name-field {:optional true} [:maybe [:or ::lib.schema.id/field [:ref ::column]]]]+ ;; the Dimension and FieldValues joined onto a Field by the application database metadata provider+ [:dimension/id {:optional true} [:maybe ::lib.schema.id/dimension]]+ [:dimension/name {:optional true} [:maybe :string]]+ [:dimension/type {:optional true} [:maybe [:enum {:decode/normalize lib.schema.common/normalize-keyword} :internal :external]]]+ [:dimension/human-readable-field-id {:optional true} [:maybe ::lib.schema.id/field]]+ [:values/values {:optional true} [:maybe [:sequential [:ref ::lib.schema.literal/literal]]]]+ [:values/human-readable-values {:optional true} [:maybe [:sequential [:ref ::lib.schema.literal/literal]]]]+ ;; what Lib annotates a column with when it returns it from a query+ [:breakout-positions {:optional true} [:maybe [:sequential :int]]]+ [:filter-positions {:optional true} [:maybe [:sequential :int]]]+ [:order-by-position {:optional true} [:maybe :int]]+ [:converted-timezone {:optional true} [:maybe :string]]+ [:remapped-from {:optional true} [:maybe :string]]+ [:remapped-to {:optional true} [:maybe :string]]+ [:remapped-from-index {:optional true} [:maybe :int]]+ [:remapping {:optional true} [:maybe [:map-of [:ref ::lib.schema.literal/literal] [:ref ::lib.schema.literal/literal]]]]+ [:dimension-interestingness {:optional true} [:maybe number?]]+ [:options {:optional true} [:maybe [:ref ::column.options]]]+ [:lib/options {:optional true} [:maybe [:ref ::column.lib-options]]]+ [:lib/original-fk-field-id {:optional true} [:maybe ::lib.schema.id/field]]+ [:lib/original-fk-field-name {:optional true} [:maybe :string]]+ [:lib/original-fk-join-alias {:optional true} [:maybe ::lib.schema.join/alias]]+ [:lib/original-join-name {:optional true} [:maybe :string]]+ [:lib/source-display-name {:optional true} [:maybe :string]]+ [:metabase.lib.join/HACK-from-incomplete-join? {:optional true} [:maybe :boolean]]+ ;; where the Mongo driver keeps the aliases of a `:field` ref while it compiles the ref as a column+ [:metabase.driver.mongo.query-processor/source-alias {:optional true} [:maybe :string]]+ [:metabase.driver.mongo.query-processor/join-field {:optional true} [:maybe :string]]+ [:metabase.driver.mongo.query-processor/inherited? {:optional true} [:maybe :boolean]]+ ;;+ ;; `:unit` and `:binning-info` are legacy keys and should not be set on a Lib column; `:lib/temporal-unit` and+ ;; `:lib/binning` are the keys for that. [[metabase.lib.metadata.result-metadata]] pins these two on a column on its+ ;; way to becoming legacy result metadata, which is the only reason they are declared.+ [:unit {:optional true} [:maybe [:ref ::lib.schema.temporal-bucketing/unit]]]+ [:binning-info {:optional true} [:maybe [:ref ::column.binning-info]]];;;; populated by the `metabase_field.settings` column in the application database; I'm not really sure what goes in;; here and if it's actually used for anything important in Lib or the QP (I suspect it's not).- [:settings {:optional true} [:maybe [:map-of {:decode/normalize lib.schema.common/normalize-map-no-kebab-case} :keyword :any]]]+ [:settings {:optional true} [:maybe [:ref ::lib.schema.common/visualization-settings]]];;;; Added by [[metabase.lib.metadata.result-metadata]] primarily for legacy/backward-compatibility purposes with;; legacy viz settings. This should not be used for anything other than that.@@ -558,7 +680,17 @@[:qp/native-sandbox-column.force-coercion-strategy {:optional true} [:ref ::lib.schema.common/coercion-strategy]];;;; See above about `:qp/native-sandbox-column.force-coercion-strategy`.- [:qp/native-sandbox-column.propagate-coercion? {:optional true} :boolean]]+ [:qp/native-sandbox-column.propagate-coercion? {:optional true} :boolean]+ [:metabase.lib.metadata.result-metadata/remove-join-alias? {:optional true} :boolean]+ [:lib/original-ref-style-for-result-metadata-purposes+ {:optional true}+ [:enum :original-ref-style/id :original-ref-style/name]]+ [:metabase.lib.field.resolution/fallback-metadata? {:optional true} :boolean]+ [:metabase.lib.join/target {:optional true} [:ref ::column.snapshot]]+ [:metabase.lib.underlying/original {:optional true} [:ref ::column.snapshot]]+ [:metabase.lib.underlying/temporal-unit {:optional true} [:maybe [:ref ::lib.schema.temporal-bucketing/unit]]]+ [:metabase.lib.underlying/binning {:optional true} [:maybe [:ref ::lib.schema.binning/binning]]]+ [:metabase.query-processor.pivot/idx {:optional true} [:int {:min 0}]]];;;; Additional constraints;;@@ -831,7 +963,7 @@[:features {:optional true} [:set [:keyword {:decode/normalize lib.schema.common/normalize-keyword}]]][:is-audit {:optional true} :boolean][:is-attached-dwh {:optional true} :boolean]- [:settings {:optional true} [:maybe :map]]])+ [:settings {:optional true} [:maybe [:ref ::lib.schema.common/visualization-settings]]]])(mr/def ::metadata-provider"Schema for something that satisfies the [[metabase.lib.metadata.protocols/MetadataProvider]] protocol."@@ -871,7 +1003,7 @@`frontend/src/metabase/query_builder/selectors.js` -- but this is ridiculous. Let's try to merge anything missing in`results_metadata` into `cols` going forward so things don't need to be manually merged in the future."[:map- {:decode/normalize lib.schema.common/normalize-map}+ {:decode/normalize lib.schema.common/normalize-map :closed true}[:lib/type [:= {:default :metadata/results} :metadata/results]][:columns [:sequential ::column]]])diff --git a/src/metabase/lib/schema/metadata/fingerprint.cljc b/src/metabase/lib/schema/metadata/fingerprint.cljcindex 5c0a4d091b0..9788f568fc1 100644--- a/src/metabase/lib/schema/metadata/fingerprint.cljc+++ b/src/metabase/lib/schema/metadata/fingerprint.cljc@@ -1,4 +1,13 @@(ns metabase.lib.schema.metadata.fingerprint+ "Schemas for the `fingerprint` a Field carries: the summary statistics the analysis stage computes from a sample of+ its values.++ Every map in here is deliberately open. A fingerprint is not something anybody sends us -- it is written by sync,+ stored in the app DB, and read back by whatever version happens to be running later, so a row can easily hold stats+ an older (or newer) version of this schema does not name, and rejecting one would make the whole column metadata map+ it hangs off of invalid. It is provider content in the same sense `:metabase.lib.schema.metadata/column` is, and is+ covered by the same `:lib/metadata` exception. Rather than a `:map-of`, the statistics we do know about are named+ and typed, so a fingerprint with a nonsense *value* is still rejected."(:require[metabase.lib.schema.common :as lib.schema.common][metabase.util.malli.registry :as mr]@@ -15,14 +24,14 @@(mr/def ::fingerprint.global"Fingerprint values that Fields of all types should have."[:map- {:decode/normalize lib.schema.common/normalize-map-no-kebab-case}+ {:closed true, :decode/normalize lib.schema.common/normalize-map-no-kebab-case}[:distinct-count {:optional true} :int][:nil% {:optional true} [:maybe [:ref ::percent]]]])(mr/def ::fingerprint.number"Schema for fingerprint information for Fields deriving from `:type/Number`."[:map- {:decode/normalize lib.schema.common/normalize-map-no-kebab-case}+ {:closed true, :decode/normalize lib.schema.common/normalize-map-no-kebab-case}[:min {:optional true} [:maybe number?]][:max {:optional true} [:maybe number?]][:avg {:optional true} [:maybe number?]]@@ -38,7 +47,7 @@(mr/def ::fingerprint.text"Schema for fingerprint information for Fields deriving from `:type/Text`."[:map- {:decode/normalize lib.schema.common/normalize-map-no-kebab-case}+ {:closed true, :decode/normalize lib.schema.common/normalize-map-no-kebab-case}[:percent-json {:optional true} [:maybe [:ref ::percent]]][:percent-url {:optional true} [:maybe [:ref ::percent]]][:percent-email {:optional true} [:maybe [:ref ::percent]]]@@ -51,7 +60,7 @@(mr/def ::fingerprint.temporal"Schema for fingerprint information for Fields deriving from `:type/Temporal`."[:map- {:decode/normalize lib.schema.common/normalize-map-no-kebab-case}+ {:closed true, :decode/normalize lib.schema.common/normalize-map-no-kebab-case}[:earliest {:optional true} [:maybe :string]][:latest {:optional true} [:maybe :string]][:mode-fraction {:optional true} [:maybe [:ref ::percent]]]@@ -66,12 +75,14 @@{:decode/normalize (fn [m](some-> (lib.schema.common/normalize-map-no-kebab-case m)(perf/update-keys lib.schema.common/normalize-base-type)))}- [:map+ [:map {:closed true}[:type/Number {:optional true} [:ref ::fingerprint.number]][:type/Text {:optional true} [:ref ::fingerprint.text]];; temporal fingerprints are keyed by `:type/DateTime` for historical reasons. `DateTime` used to be the parent of;; all temporal MB types.- [:type/DateTime {:optional true} [:ref ::fingerprint.temporal]]]+ [:type/DateTime {:optional true} [:ref ::fingerprint.temporal]]+ [:type/Date {:optional true} [:ref ::fingerprint.temporal]]+ [:type/Time {:optional true} [:ref ::fingerprint.temporal]]][:fn{:error/message "Type-specific fingerprint with exactly one key"}(fn [m]@@ -81,7 +92,7 @@"Schema for a Field 'fingerprint' generated as part of the analysis stage. Used to power the 'classification'sub-stage of analysis. Stored as the `fingerprint` column of Field."[:map- {:decode/normalize lib.schema.common/normalize-map-no-kebab-case}+ {:closed true, :decode/normalize lib.schema.common/normalize-map-no-kebab-case}[:global {:optional true} [:ref ::fingerprint.global]][:type {:optional true} [:ref ::fingerprint.type-specific]]- [:experimental {:optional true} [:map-of :keyword :any]]])+ [:experimental {:optional true} [:map {:closed true}]]])diff --git a/src/metabase/lib/schema/middleware_options.cljc b/src/metabase/lib/schema/middleware_options.cljcindex c51cfae3fc2..3f1d5fc7fc4 100644--- a/src/metabase/lib/schema/middleware_options.cljc+++ b/src/metabase/lib/schema/middleware_options.cljc@@ -8,7 +8,7 @@[:map{:decode/normalize lib.schema.common/normalize-map:decode/api lib.schema.common/remove-internal-keys- :encode/serialize lib.schema.common/remove-internal-keys}+ :encode/serialize lib.schema.common/remove-internal-keys :closed true}[:skip-results-metadata?{:optional true:description@@ -74,4 +74,43 @@:description"Whether to ignore any cached results and re-run the query. Used by the query results cache middleware; default`false`."}- [:maybe :boolean]]])+ [:maybe :boolean]]+ [:disable-remaps?+ {:optional true+ :description+ "Whether to skip the remapped (human-readable) columns that `metabase.query-processor.middleware.add-remaps`+ normally splices in. Set by callers that want the query's own columns and nothing else -- calculating a Card's+ result metadata, or fetching field values for a filter widget; default `false`."}+ [:maybe :boolean]]+ [:csv-include-bom?+ {:optional true+ :description+ "Whether a CSV download should start with a UTF-8 byte-order mark, which Excel needs to read the file as UTF-8.+ Set by `metabase.query-processor.api` from the download's options and read by+ `metabase.query-processor.middleware.format-rows` and the CSV writer; default `true`."}+ [:maybe :boolean]]+ [:pivot?+ {:optional true+ :description+ "Whether the results should be laid out as a pivot table. Set by `metabase.query-processor.api` from the+ `format_rows`/pivot download options and read by `metabase.query-processor.middleware.pivot-export` and the+ streaming writers; default `false`."}+ [:maybe :boolean]]+ [:pivot-options+ {:optional true+ :description+ "Which of the query's breakouts and aggregations are the pivot table's rows, columns and measures, and whether it+ shows totals. Attached by `metabase.query-processor.pivot` from the question's visualization settings (or from the+ matching top-level query keys) so the export middleware and streaming writers can lay the results out; not something+ a client sets itself."}+ [:maybe+ [:map+ {:closed true}+ [:pivot-rows {:optional true} [:maybe [:sequential [:int {:min 0}]]]]+ [:pivot-cols {:optional true} [:maybe [:sequential [:int {:min 0}]]]]+ [:pivot-measures {:optional true} [:maybe [:sequential [:int {:min 0}]]]]+ [:show-row-totals {:optional true} [:maybe :boolean]]+ [:show-column-totals {:optional true} [:maybe :boolean]]+ [:column-sort-order {:optional true} [:maybe [:multi {:dispatch map?}+ [true [:map-of [:maybe [:int {:min 0}]] [:maybe :keyword]]]+ [false [:fn {:error/message "map"} map?]]]]]]]]])diff --git a/src/metabase/lib/schema/parameter.cljc b/src/metabase/lib/schema/parameter.cljcindex 3a51fed2af0..9a9a5f371a4 100644--- a/src/metabase/lib/schema/parameter.cljc+++ b/src/metabase/lib/schema/parameter.cljc@@ -27,6 +27,8 @@([flatland.ordered.map :as ordered-map]))[malli.core :as mc][metabase.lib.schema.common :as lib.schema.common]+ [metabase.lib.schema.id :as lib.schema.id]+ [metabase.lib.schema.temporal-bucketing :as lib.schema.temporal-bucketing][metabase.util :as u][metabase.util.malli :as mu][metabase.util.malli.registry :as mr]@@ -238,7 +240,7 @@(mr/def ::dimension.options[:map{:error/message "dimension options"- :decode/normalize lib.schema.common/normalize-map}+ :decode/normalize lib.schema.common/normalize-map :closed true}[:stage-number {:optional true} :int]]);;; TODO (Cam 8/8/25) -- seems really WACK to have dimension use MBQL 4 clause order even in Lib... I guess it's not a@@ -269,7 +271,7 @@(mr/def ::template-tag.tag-name[:multi {:dispatch map?}- [true [:map+ [true [:map {:closed true}[:id ::lib.schema.common/non-blank-string]]][false [:schema{:decode/normalize (fn [x]@@ -379,10 +381,33 @@(mr/def ::parameter.options"Options the frontend attaches to a parameter value."[:map- {:decode/normalize lib.schema.common/normalize-map}+ {:closed true, :decode/normalize lib.schema.common/normalize-map}[:case-sensitive {:optional true} :boolean][:include-current {:optional true} :boolean]])+(mr/def ::values-query-type+ "How a filter widget asks for its values."+ [:enum {:decode/normalize lib.schema.common/normalize-keyword} :none :list :search])++(mr/def ::values-source-type+ "Where a filter widget's values come from, when not from the field it is connected to."+ [:enum {:decode/normalize lib.schema.common/normalize-keyword} :static-list :card])++(mr/def ::values-source-config.value+ "One value of a static-list source: a bare value, a one-tuple of it, or a `[value label]` pair."+ [:or+ [:ref ::parameter.value.scalar]+ [:tuple [:ref ::parameter.value.scalar]]+ [:tuple [:ref ::parameter.value.scalar] :string]])++(mr/def ::values-source-config+ "The configuration of a filter widget's value source. Its keys are the frontend's snake_case names."+ [:map {:closed true}+ [:values {:optional true} [:maybe [:sequential [:ref ::values-source-config.value]]]]+ [:card_id {:optional true} [:maybe ::lib.schema.id/card]]+ [:value_field {:optional true} [:maybe [:or [:ref ::target.legacy-field-ref] [:ref ::target.legacy-expression-ref]]]]+ [:label_field {:optional true} [:maybe [:or [:ref ::target.legacy-field-ref] [:ref ::target.legacy-expression-ref]]]]])+(mr/def ::parameter"Schema for the *value* of a parameter (e.g. a Dashboard parameter or a native query template tag) as passed in aspart of the `:parameters` list in a query.@@ -394,7 +419,8 @@[:map{:decode/normalize #'normalize-parameter:decode/api #'lib.schema.common/remove-internal-keys- :encode/serialize #'lib.schema.common/remove-internal-keys}+ :encode/serialize #'lib.schema.common/remove-internal-keys+ :closed true}[:type [:ref ::type]];; TODO -- these definitely SHOULD NOT be optional but a ton of tests aren't passing them in like they should be.;; At some point we need to go fix those tests and then make these keys required@@ -411,7 +437,20 @@[:slug {:optional true} ::lib.schema.common/non-blank-string][:default {:optional true} [:ref ::parameter.value]][:required {:optional true} [:maybe :boolean]]- [:options {:optional true} [:maybe [:ref ::parameter.options]]]]+ [:options {:optional true} [:maybe [:ref ::parameter.options]]]+ [:temporal-units {:optional true} [:maybe [:sequential [:ref ::lib.schema.temporal-bucketing/unit]]]]+ ;; The rest of a stored filter declaration. Dashboards, subscriptions and actions hand whole declarations to the+ ;; query processor as its `:parameters`; the keys are the frontend's camelCase and snake_case names as+ ;; [[normalize-parameter]] leaves them.+ [:display-name {:optional true} [:maybe :string]]+ [:sectionid {:optional true} [:maybe :string]]+ [:filteringparameters {:optional true} [:maybe [:sequential [:ref ::id]]]]+ [:ismultiselect {:optional true} [:maybe :boolean]]+ [:hasvariabletemplatetagtarget {:optional true} [:maybe :boolean]]+ [:position {:optional true} [:maybe :int]]+ [:values-query-type {:optional true} [:maybe [:ref ::values-query-type]]]+ [:values-source-type {:optional true} [:maybe [:ref ::values-source-type]]]+ [:values-source-config {:optional true} [:maybe [:ref ::values-source-config]]]]::lib.schema.common/kebab-cased-map(lib.schema.common/disallowed-keys{:dimension ":dimension is not allowed in a parameter, you probably meant to use :target [:dimension ...] instead."})])diff --git a/src/metabase/lib/schema/ref.cljc b/src/metabase/lib/schema/ref.cljcindex 7b5ffe57803..7eeb1069f2e 100644--- a/src/metabase/lib/schema/ref.cljc+++ b/src/metabase/lib/schema/ref.cljc@@ -230,7 +230,8 @@{:decode/normalize normalize-expression-options}::common/options[:map- [:temporal-unit {:optional true} [:ref ::temporal-bucketing/unit]]]])+ [:temporal-unit {:optional true} [:ref ::temporal-bucketing/unit]]+ [:lib/original-effective-type {:optional true} [:ref ::common/base-type]]]])(mbql-clause/define-mbql-clause :expression[:anddiff --git a/src/metabase/lib/schema/settings.cljc b/src/metabase/lib/schema/settings.cljcindex 5407a06f178..59b96248283 100644--- a/src/metabase/lib/schema/settings.cljc+++ b/src/metabase/lib/schema/settings.cljc@@ -7,7 +7,7 @@(mr/def ::settings"Options that tweak the behavior of the query processor."[:map- {:decode/normalize lib.schema.common/normalize-map}+ {:decode/normalize lib.schema.common/normalize-map :closed true}[:report-timezone{:optional true:description "The timezone the query should be ran in, overriding the default report timezone for the instance."}diff --git a/src/metabase/lib/schema/template_tag.cljc b/src/metabase/lib/schema/template_tag.cljcindex dfb0dca2fc6..adbf2fe2cb9 100644--- a/src/metabase/lib/schema/template_tag.cljc+++ b/src/metabase/lib/schema/template_tag.cljc@@ -31,12 +31,14 @@;;; Things required by all template tag types.(mr/def ::common- [:map+ [:map {:closed true}[:name ::name][:display-name ::common/non-blank-string];; TODO -- `:id` is actually 100% required but we have a lot of tests that don't specify it because this constraint;; wasn't previously enforced; we need to go in and fix those tests and make this non-optional- [:id {:optional true} [:ref ::id]]])+ [:id {:optional true} [:ref ::id]]+ [:lib.walk/template-tag-name {:optional true} ::name]+ [:sectionid {:optional true} ::common/non-blank-string]]);;; Stuff shared between the Field filter and raw value template tag schemas.(mr/def ::value.common@@ -67,7 +69,7 @@"Options appended to the filter clause a Field Filter template tag generates. These get merged into the parametervalue the QP builds for the tag, so they are the same options as `:metabase.lib.schema.parameter/parameter.options`."[:map- {:decode/normalize common/normalize-map-no-kebab-case}+ {:decode/normalize common/normalize-map-no-kebab-case :closed true}[:case-sensitive {:optional true} :boolean][:include-current {:optional true} :boolean]])@@ -129,7 +131,7 @@(mr/def ::source-query[:and[:merge- [:ref ::common]+ [:ref ::value.common][:map[:type [:= :card]][:card-id ::id/card]]]@@ -141,7 +143,7 @@(mr/def ::source-filter"Schema for a single source-filter applied to a table template tag."- [:map+ [:map {:closed true}[:field-id ::id/field][:op (into [:enum] allowed-source-filter-ops)][:value [:ref ::lib.schema.parameter/parameter.value]]])@@ -157,7 +159,7 @@(mr/def ::source-table[:and[:merge- [:ref ::common]+ [:ref ::value.common][:map[:type [:= :table]][:table-id ::id/table]@@ -188,7 +190,8 @@;; `:type` is used be the FE to determine which type of widget to display for the template tag, and to determine;; which types of parameters are allowed to be passed in for this template tag.[:map- [:type [:ref ::raw-value.type]]]]+ [:type [:ref ::raw-value.type]]+ [:widget-type {:optional true} [:maybe [:ref ::widget-type]]]]][:ref ::disallow-dimension]])(mr/def ::template-tagdiff --git a/src/metabase/lib_be/schema.clj b/src/metabase/lib_be/schema.cljindex e8a9ea49da4..41526556a00 100644--- a/src/metabase/lib_be/schema.clj+++ b/src/metabase/lib_be/schema.clj@@ -4,6 +4,7 @@[metabase.lib-be.models.transforms :as lib-be.transforms][metabase.lib.core :as lib][metabase.lib.schema :as lib.schema]+ [metabase.lib.schema.middleware-options :as lib.schema.middleware-options][metabase.lib.util :as lib.util][metabase.util.i18n :refer [deferred-tru tru]][metabase.util.malli.registry :as mr]@@ -32,12 +33,13 @@[:ref ::lib.schema/query]])(mr/def ::internal-query- [:map+ [:map {:closed true}[:type [:= {:decode/normalize keyword} :internal]][:fn :string]- [:args {:optional true} [:maybe [:sequential :any]]]+ [:args {:optional true} [:maybe [:sequential [:maybe [:or :string number? :boolean]]]]][:limit {:optional true} [:maybe :int]]- [:offset {:optional true} [:maybe :int]]])+ [:offset {:optional true} [:maybe :int]]+ [:middleware {:optional true} [:ref ::lib.schema.middleware-options/middleware-options]]])(mr/def ::maybe-legacy-or-internal-query[:multi {:dispatch (fn [query] (and (map? query) (= (lib.util/normalized-query-type query) :internal)))diff --git a/src/metabase/lib_metric/schema.cljc b/src/metabase/lib_metric/schema.cljcindex 63ff0db42fa..a79f5543ba6 100644--- a/src/metabase/lib_metric/schema.cljc+++ b/src/metabase/lib_metric/schema.cljc@@ -5,6 +5,8 @@[metabase.lib-metric.operators :as operators][metabase.lib.schema.common :as lib.schema.common][metabase.lib.schema.id :as lib.schema.id]+ [metabase.lib.schema.literal :as lib.schema.literal]+ [metabase.lib.schema.metadata :as lib.schema.metadata][metabase.lib.schema.ref :as lib.schema.ref][metabase.lib.schema.temporal-bucketing :as lib.schema.temporal-bucketing][metabase.util.malli.registry :as mr]@@ -31,12 +33,12 @@(keyword (some #(get x %) [:strategy "strategy"]))):error/fn (fn [{:keys [value]} _](str "Invalid binning strategy" (pr-str value)))}- [:default [:map+ [:default [:map {:closed true}[:strategy [:= :default]]]]- [:bin-width [:map+ [:bin-width [:map {:closed true}[:strategy [:= :bin-width]][:bin-width [:ref ::lib.schema.common/positive-number]]]]- [:num-bins [:map+ [:num-bins [:map {:closed true}[:strategy [:= :num-bins]][:num-bins pos-int?]]]]])@@ -57,7 +59,7 @@(mr/def ::dimension-group"Group descriptor for a dimension, indicating which table it belongs to."- [:map+ [:map {:closed true}[:id :string][:type [:enum "main" "connection"]][:display-name :string]])@@ -66,19 +68,30 @@[:enum :field])(mr/def ::dimension-source- [:map+ [:map {:closed true}[:type ::dimension-source.type][:field-id {:optional true} [:maybe ::lib.schema.id/field]][:binning {:optional true} [:maybe :boolean]]])(mr/def ::dimension- "Schema for a dimension definition."- [:map- [:id ::dimension-id]- [:display-name {:optional true} [:maybe ::lib.schema.common/non-blank-string]]- [:effective-type {:optional true} [:maybe ::lib.schema.common/base-type]]- [:semantic-type {:optional true} [:maybe ::lib.schema.common/semantic-or-relation-type]]- [:sources {:optional true} [:maybe [:sequential ::dimension-source]]]])+ "Schema for a dimension definition, plus what the metrics module annotates a dimension with before handing it to a+ client: the column it came from, its group, its field values status and how interesting it looks."+ [:map {:closed true}+ [:id ::dimension-id]+ [:display-name {:optional true} [:maybe ::lib.schema.common/non-blank-string]]+ [:effective-type {:optional true} [:maybe ::lib.schema.common/base-type]]+ [:semantic-type {:optional true} [:maybe ::lib.schema.common/semantic-or-relation-type]]+ [:sources {:optional true} [:maybe [:sequential ::dimension-source]]]+ [:name {:optional true} [:maybe :string]]+ [:group {:optional true} [:maybe ::dimension-group]]+ [:lib/source {:optional true} [:maybe [:or ::lib.schema.metadata/column.source :string]]]+ [:has-field-values {:optional true} [:maybe ::lib.schema.metadata/column.has-field-values]]+ [:status {:optional true} [:maybe [:or :keyword :string]]]+ [:status-message {:optional true} [:maybe :string]]+ [:default-temporal-unit {:optional true} [:maybe ::lib.schema.temporal-bucketing/unit]]+ [:dimension-interestingness {:optional true} [:maybe number?]]+ [:default {:optional true} [:maybe :boolean]]+ [:description {:optional true} [:maybe :string]]])(mr/def ::dimension-mapping.type"Type of dimension mapping."@@ -90,7 +103,7 @@(mr/def ::dimension-mapping"Schema for a dimension mapping."- [:map+ [:map {:closed true}[:type ::dimension-mapping.type][:table-id {:optional true} [:maybe ::lib.schema.id/table]][:dimension-id ::dimension-id]@@ -99,7 +112,8 @@(mr/def ::dimension-reference.options"Options map for dimension references."[:map- {:decode/normalize lib.schema.common/normalize-options-map}+ {:decode/normalize lib.schema.common/normalize-options-map :closed true}+ [:lib/uuid {:optional true} [:ref ::lib.schema.common/uuid]][:display-name {:optional true} [:maybe ::lib.schema.common/non-blank-string]][:effective-type {:optional true} [:maybe ::lib.schema.common/base-type]][:semantic-type {:optional true} [:maybe ::lib.schema.common/semantic-or-relation-type]]@@ -182,10 +196,27 @@arg))args))))))+(mr/def ::filter-clause.options+ "The options of a metric filter clause: MBQL options plus the offset [[metabase.lib-metric.filter]] puts on a+ relative date filter (`previous N units, starting M units ago`)."+ [:merge+ ::lib.schema.common/options+ [:map+ [:offset-unit {:optional true} [:ref ::lib.schema.temporal-bucketing/unit]]+ [:offset-value {:optional true} :int]]])+(mr/def ::filter-clause"MBQL filter clause with normalization for API input.- Handles string operators and dimension references."- [:any {:decode/normalize normalize-filter-clause}])+ Handles string operators and dimension references. After normalization every clause is a tag, an options map and+ arguments that are dimension references, literals or clauses themselves."+ [:schema {:decode/normalize normalize-filter-clause}+ [:cat+ :keyword+ [:schema [:ref ::filter-clause.options]]+ [:* [:or+ [:schema [:ref ::dimension-reference]]+ [:schema [:ref ::lib.schema.literal/literal]]+ [:schema [:ref ::filter-clause]]]]]]);;; ------------------------------------------------- Metric Math Expressions -------------------------------------------------;;; Expression schemas for metric math: combining multiple metrics/measures with arithmetic.@@ -210,7 +241,7 @@[:tuple{:decode/normalize normalize-metric-ref}[:= {:decode/normalize lib.schema.common/normalize-keyword} :metric]- [:map {:decode/normalize lib.schema.common/normalize-options-map}+ [:map {:decode/normalize lib.schema.common/normalize-options-map :closed true}[:lib/uuid ::lib.schema.common/non-blank-string]]pos-int?])@@ -219,7 +250,7 @@[:tuple{:decode/normalize normalize-measure-ref}[:= {:decode/normalize lib.schema.common/normalize-keyword} :measure]- [:map {:decode/normalize lib.schema.common/normalize-options-map}+ [:map {:decode/normalize lib.schema.common/normalize-options-map :closed true}[:lib/uuid ::lib.schema.common/non-blank-string]]pos-int?])@@ -277,7 +308,7 @@(mr/def ::instance-filter"A filter associated with a specific expression instance via lib/uuid."[:map- {:decode/normalize lib.schema.common/normalize-map}+ {:decode/normalize lib.schema.common/normalize-map :closed true}[:lib/uuid ::lib.schema.common/non-blank-string][:filter ::filter-clause]])@@ -293,7 +324,7 @@The :type and :id identify the source metric/measure for metadata resolution.The :lib/uuid disambiguates multiple references to the same metric/measure in an expression."[:map- {:decode/normalize lib.schema.common/normalize-map}+ {:decode/normalize lib.schema.common/normalize-map :closed true}[:type [:enum {:decode/normalize lib.schema.common/normalize-keyword} :metric :measure]][:id pos-int?][:lib/uuid ::lib.schema.common/non-blank-string]diff --git a/src/metabase/llm/api.clj b/src/metabase/llm/api.cljindex b15c4995b86..892d5e8fb7c 100644--- a/src/metabase/llm/api.clj+++ b/src/metabase/llm/api.clj@@ -107,7 +107,7 @@(def ^:private template-tags-schema[:map-of :string- [:map+ [:map {:closed true}[:type :string][:card-id {:optional true} pos-int?]]])@@ -125,7 +125,7 @@or field value fetching."[_route-params_query-params- body :- [:map+ body :- [:map {:closed true}[:database_id pos-int?][:sql :string][:template_tags {:optional true} template-tags-schema]]]@@ -168,12 +168,12 @@Returns generated SQL and the list of tables used for context."[_route-params_query-params- body :- [:map+ body :- [:map {:closed true}[:prompt :string][:database_id pos-int?][:source_sql {:optional true} :string][:referenced_entities {:optional true}- [:sequential [:map+ [:sequential [:map {:closed true}[:model :string][:id pos-int?]]]]]request]diff --git a/src/metabase/llm/api/provider.clj b/src/metabase/llm/api/provider.cljindex 17832641177..f6012416ca4 100644--- a/src/metabase/llm/api/provider.clj+++ b/src/metabase/llm/api/provider.clj@@ -17,7 +17,8 @@[metabase.premium-features.core :refer [defenterprise]][metabase.settings.core :as setting][metabase.util.i18n :refer [tru]]- [metabase.util.log :as log]))+ [metabase.util.log :as log]+ [metabase.util.malli.schema :as ms]))(set! *warn-on-reflection* true)@@ -82,9 +83,6 @@[:models [:sequential llm-model-response-schema]][:error {:optional true} [:maybe :string]]]])-(def ^:private config-schema- [:map-of :keyword [:maybe :string]])-(def ^:private connection-key-schema[:string {:api/regex #"[a-z0-9][a-z0-9-]*"}])@@ -404,11 +402,11 @@"Create a provider connection. The credentials are verified before the connection is saved."[_route-params_query-params- {:keys [type name key config model]} :- [:map+ {:keys [type name key config model]} :- [:map {:closed true}[:type :string][:name {:optional true} [:maybe :string]][:key {:optional true} [:maybe :string]]- [:config {:optional true} [:maybe config-schema]]+ [:config {:optional true} [:maybe (ms/string-keyed-map [:maybe :string])]][:model {:optional true} [:maybe :string]]]](perms/check-has-application-permission :setting)(refresh-settings!)@@ -434,7 +432,7 @@(not= llm.provider/managed-connection-key conn-key))(tru "The {0} connection key is reserved for the Metabase AI service."(pr-str llm.provider/managed-connection-key)))- config (without-blank-values config)+ config (without-blank-values (update-keys config keyword))conn {:key conn-key:type type:name (or (not-empty name) (str (:label provider-type)))@@ -454,16 +452,17 @@(api.macros/defendpoint :put "/providers/:key":- connection-response-schema"Update a provider connection. Secret fields the client echoes back masked keep their stored value."- [{conn-key :key} :- [:map [:key connection-key-schema]]+ [{conn-key :key} :- [:map {:closed true} [:key connection-key-schema]]_query-params- {:keys [name config model]} :- [:map+ {:keys [name config model]} :- [:map {:closed true}[:name {:optional true} [:maybe :string]]- [:config {:optional true} [:maybe config-schema]]+ [:config {:optional true} [:maybe (ms/string-keyed-map [:maybe :string])]][:model {:optional true} [:maybe :string]]]](perms/check-has-application-permission :setting)(refresh-settings!)(check-connections-not-env-managed!)- (let [stored (llm.provider/stored-connections)+ (let [config (some-> config (update-keys keyword))+ stored (llm.provider/stored-connections)idx (first (keep-indexed (fn [i c] (when (= (:key c) conn-key) i)) stored))_ (api/check-404 idx)existing (nth stored idx)@@ -498,7 +497,7 @@(api.macros/defendpoint :delete "/providers/:key" :- :nil"Delete a provider connection."- [{conn-key :key} :- [:map [:key connection-key-schema]]]+ [{conn-key :key} :- [:map {:closed true} [:key connection-key-schema]]](perms/check-has-application-permission :setting)(refresh-settings!)(check-connections-not-env-managed!)diff --git a/src/metabase/llm/provider.clj b/src/metabase/llm/provider.cljindex 635beba0097..b146f20d073 100644--- a/src/metabase/llm/provider.clj+++ b/src/metabase/llm/provider.clj@@ -368,6 +368,12 @@(or (premium-features/is-hosted?)(nil? (premium-features/canonically-has-feature? :hosting))))+(defn config-field-keys+ "Every key a connection's `:config` may carry: the `:fields` of every registered provider type, taken together. Which+ of them a given connection may use depends on its type; [[validate-config!]] checks that."+ []+ (into (sorted-set) (comp (mapcat :fields) (map :key)) provider-type-registry))+(defn provider-type"The registry entry for `type-name`, or nil when it is not a known provider type."[type-name]diff --git a/src/metabase/logger/api.clj b/src/metabase/logger/api.cljindex cb556f7ecb7..748ff43ae1a 100644--- a/src/metabase/logger/api.clj+++ b/src/metabase/logger/api.clj@@ -11,7 +11,8 @@[metabase.util.i18n :refer [tru]][metabase.util.log :as log][metabase.util.malli :as mu]- [metabase.util.malli.registry :as mr])+ [metabase.util.malli.registry :as mr]+ [metabase.util.malli.schema :as ms])(:import(java.util.concurrent ScheduledFuture ScheduledThreadPoolExecutor ThreadFactory TimeUnit)(java.util.concurrent.atomic AtomicInteger)))@@ -176,7 +177,7 @@(into [:enum {:decode/json keyword}] (keys keyword->TimeUnit)))(mr/def ::log-levels- [:map-of :string (into [:enum] (map name) (reverse logger/levels))])+ (ms/string-keyed-map (into [:enum] (map name) (reverse logger/levels))))(defn- ->seconds-str[unit value]@@ -197,22 +198,12 @@"Temporarily adjust the log levels."[_route-params_query-params- {:keys [duration duration_unit log_levels]} :- [:map+ {:keys [duration duration_unit log_levels]} :- [:map {:closed true}[:duration :int][:duration_unit ::time-unit]- [:log_levels :any]]]+ [:log_levels (ms/string-keyed-map :string)]]](api/check-superuser)- (when-not (map? log_levels)- (let [json-type (condp #(%1 %2) log_levels- nil? "null"- boolean? "boolean"- number? "number"- string? "string"- sequential? "array"- "something strange")]- (api/check-400 false {:specific-errors {:log_levels [(str "invalid type, received: " json-type)]}- :errors {:_error (tru "Log levels should be an object, {0} received" json-type)}})))- (let [log-levels (update-keys log_levels #(cond-> % (instance? clojure.lang.Named %) name))]+ (let [log-levels log_levels](when-let [error (mu/explain ::log-levels log-levels)](api/check-400 false {:specific-errors {:log_levels error}:errors {:_error (tru (str "The format of the provided logging configuration is incorrect."diff --git a/src/metabase/mcp/callback_api.clj b/src/metabase/mcp/callback_api.cljindex c8ee2f5625f..e196234a02b 100644--- a/src/metabase/mcp/callback_api.clj+++ b/src/metabase/mcp/callback_api.clj@@ -58,7 +58,7 @@`render_drill_through` tool can fetch it."[_route-params_query-params- {:keys [encodedQuery]} :- [:map [:encodedQuery ms/NonBlankString]]+ {:keys [encodedQuery]} :- [:map {:closed true} [:encodedQuery ms/NonBlankString]]request](let [session-id (mcp-session-id-from-headers request)](check-session-header! session-id api/*current-user-id* request)@@ -70,12 +70,12 @@"Persist MCP Apps visualization feedback."[_route-params_query-params- body :- [:map- [:feedback [:map+ body :- [:map {:closed true}+ [:feedback [:map {:closed true}[:positive :boolean][:issue_type {:optional true} [:maybe [:string {:max 64}]]][:freeform_feedback {:optional true} OptionalFeedbackText]]]- [:conversation_data [:map+ [:conversation_data [:map {:closed true}[:source [:= "mcp"]][:prompt {:optional true} OptionalFeedbackText][:query {:optional true} OptionalFeedbackText]]]]diff --git a/src/metabase/measures/api.clj b/src/metabase/measures/api.cljindex 00550d242ed..1b40889c62d 100644--- a/src/metabase/measures/api.clj+++ b/src/metabase/measures/api.clj@@ -23,7 +23,7 @@[:id ms/PositiveInt][:name ms/NonBlankString][:table_id ms/PositiveInt]- [:definition ms/Map]+ [:definition ::measures.schema/definition][:description {:optional true} [:maybe :string]][:archived :boolean][:creator_id ms/PositiveInt]@@ -46,7 +46,7 @@"Create a new `Measure`. The Measure's table is derived from its `definition`."[_route-params_query-params- {:keys [name description definition], :as body} :- [:map+ {:keys [name description definition], :as body} :- [:map {:closed true}[:name ms/NonBlankString][:definition ::measures.schema/definition][:description {:optional true} [:maybe :string]]]]@@ -76,9 +76,9 @@(api.macros/defendpoint :get "/:id" :- ::measure"Fetch `Measure` with ID."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]- {:keys [include-orphaned]} :- [:map+ {:keys [include-orphaned]} :- [:map {:closed true}[:include-orphaned {:optional true} [:maybe ms/BooleanValue]]]](let [measure (hydrated-measure id (boolean include-orphaned))](-> measure@@ -122,10 +122,10 @@(api.macros/defendpoint :put "/:id" :- ::measure"Update a `Measure` with ID."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-params- body :- [:map+ body :- [:map {:closed true}[:name {:optional true} [:maybe ms/NonBlankString]][:definition {:optional true} [:maybe ::measures.schema/definition]][:revision_message ms/NonBlankString]@@ -152,7 +152,7 @@- values: list of [value] or [value, display-name] tuples- field_id: the underlying field ID- has_more_values: boolean indicating if there are more values"- [{:keys [id dimension-key]} :- [:map+ [{:keys [id dimension-key]} :- [:map {:closed true}[:id ms/PositiveInt][:dimension-key ms/UUIDString]]](let [measure (hydrated-measure id false)]@@ -166,10 +166,10 @@"Search for values of a dimension that contain the query string.Returns field values matching the search query in the same format as the field values API."- [{:keys [id dimension-key]} :- [:map+ [{:keys [id dimension-key]} :- [:map {:closed true}[:id ms/PositiveInt][:dimension-key ms/UUIDString]]- {:keys [query]} :- [:map [:query ms/NonBlankString]]]+ {:keys [query]} :- [:map {:closed true} [:query ms/NonBlankString]]](let [measure (hydrated-measure id false)](metrics/dimension-search-values(:dimensions measure)@@ -182,10 +182,10 @@"Fetch remapped value for a specific dimension value.Returns a pair [value, display-name] if remapping exists, or [value] otherwise."- [{:keys [id dimension-key]} :- [:map+ [{:keys [id dimension-key]} :- [:map {:closed true}[:id ms/PositiveInt][:dimension-key ms/UUIDString]]- {:keys [value]} :- [:map [:value :string]]]+ {:keys [value]} :- [:map {:closed true} [:value :string]]](let [measure (hydrated-measure id false)](metrics/dimension-remapped-value(:dimensions measure)diff --git a/src/metabase/metabot/api.clj b/src/metabase/metabot/api.cljindex 2ae81d1d630..763d39d0335 100644--- a/src/metabase/metabot/api.clj+++ b/src/metabase/metabot/api.clj@@ -371,7 +371,7 @@(mu/defn- upgrade-viewing-queries"Update queries of items in viewing context vector. Handles following item types: adhoc, question, model, metric"- [viewing :- [:vector metabot.context/ViewingItemSchema]]+ [viewing :- [:vector :map]](letfn [(update-items-query [item] (m/update-existing item :query legacy->modern-query))(maybe-update-item [item] (cond-> item(contains? upgradable-item-types (:type item))@@ -387,7 +387,7 @@"Send a chat message to the LLM via the AI Proxy."[_route-params_query-params- body :- [:map+ body :- [:map {:closed true}[:profile_id {:optional true} :string][:metabot_id {:optional true} :string][:message ms/NonBlankString]@@ -420,7 +420,7 @@"Persist Metabot feedback."[_route-params_query-params- body :- [:map+ body :- [:map {:closed true}[:metabot_id ms/PositiveInt][:message_id ms/NonBlankString][:positive :boolean]@@ -436,7 +436,7 @@"Persist Metabot source feedback."[_route-params_query-params- body :- [:map+ body :- [:map {:closed true}[:metabot_id ms/PositiveInt][:message_id ms/NonBlankString][:source_id ms/PositiveInt]diff --git a/src/metabase/metabot/api/conversations.clj b/src/metabase/metabot/api/conversations.cljindex 0e9167896b9..a1d8fac3baa 100644--- a/src/metabase/metabot/api/conversations.clj+++ b/src/metabase/metabot/api/conversations.clj@@ -71,31 +71,31 @@[:title [:maybe :string]]])(def ^:private ConversationIdParams- [:map [:id ms/UUIDString]])+ [:map {:closed true} [:id ms/UUIDString]])(def ^:private ListConversationsQueryParams[:maybe- [:map+ [:map {:closed true}[:profile_id {:optional true} [:maybe ms/NonBlankString]]]])(def ^:private ForkConversationBody- [:map+ [:map {:closed true};; the `external_id` of the assistant message to fork at (the FE's message id)[:message_id ms/UUIDString]])(def ^:private SaveEntityCard- [:map+ [:map {:closed true}[:name ms/NonBlankString][:description {:optional true} [:maybe :string]][:dataset_query ::lib-be.schema/maybe-legacy-query][:display ms/NonBlankString]- [:visualization_settings {:optional true} [:maybe ms/Map]]+ [:visualization_settings {:optional true} [:maybe ms/VisualizationSettings]][:collection_id {:optional true} [:maybe ms/PositiveInt]][:dashboard_id {:optional true} [:maybe ms/PositiveInt]][:dashboard_tab_id {:optional true} [:maybe ms/PositiveInt]]])(def ^:private SaveEntityBody- [:map+ [:map {:closed true};; stamped onto report_card.metabot_chart_id, a varchar(36) — clamp to fit[:chart_id [:and ms/NonBlankString [:string {:max 36}]]][:card SaveEntityCard]])@@ -105,9 +105,9 @@[:id ms/PositiveInt][:name ms/NonBlankString][:description {:optional true} [:maybe :string]]- [:dataset_query ms/Map]+ [:dataset_query ::lib-be.schema/maybe-legacy-query][:display :keyword]- [:visualization_settings {:optional true} [:maybe ms/Map]]+ [:visualization_settings {:optional true} [:maybe ms/VisualizationSettings]][:collection_id {:optional true} [:maybe ms/PositiveInt]][:dashboard_id {:optional true} [:maybe ms/PositiveInt]][:dashboard_tab_id {:optional true} [:maybe ms/PositiveInt]]diff --git a/src/metabase/metabot/api/document.clj b/src/metabase/metabot/api/document.cljindex 34fee999feb..59e43f4378e 100644--- a/src/metabase/metabot/api/document.clj+++ b/src/metabase/metabot/api/document.clj@@ -4,27 +4,30 @@[clojure.string :as str][metabase.api.macros :as api.macros][metabase.api.routes.common :refer [+auth]]+ [metabase.lib-be.core :as lib-be]+ [metabase.lib-be.schema :as lib-be.schema][metabase.metabot.agent.core :as metabot.agent][metabase.metabot.config :as metabot.config][metabase.metabot.context :as metabot.context][metabase.metabot.usage :as metabot.usage]+ [metabase.parameters.schema :as parameters.schema][metabase.util.malli.schema :as ms]))(set! *warn-on-reflection* true)(def ^:private generate-content-body-schema- [:map+ [:map {:closed true}[:instructions ms/NonBlankString]- [:references {:optional true} ms/Map]])+ [:references {:optional true} ms/OpaqueJSONObject]])(def ^:private generate-content-response-schema[:map[:draft_card [:maybe [:map[:name ms/NonBlankString]- [:dataset_query ms/Map]+ [:dataset_query ::lib-be.schema/maybe-legacy-query][:database_id ms/PositiveInt]- [:parameters [:maybe [:sequential ms/Map]]]- [:visualization_settings ms/Map]]]]+ [:parameters [:maybe ::parameters.schema/parameters]]+ [:visualization_settings ms/VisualizationSettings]]]][:error [:maybe ms/NonBlankString]][:description [:maybe ms/NonBlankString]]])@@ -53,7 +56,7 @@(when (and chart-name (map? query) chart-type){:name chart-name:display (name chart-type)- :dataset_query query+ :dataset_query (lib-be/normalize-query nil query):database_id (:database query):parameters []:visualization_settings {}})))diff --git a/src/metabase/metabot/api/metabot.clj b/src/metabase/metabot/api/metabot.cljindex bc6ab44aeff..64552d465b5 100644--- a/src/metabase/metabot/api/metabot.clj+++ b/src/metabase/metabot/api/metabot.clj@@ -32,7 +32,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id""Retrieve one metabot instance"- [{:keys [id]} :- [:map [:id pos-int?]]]+ [{:keys [id]} :- [:map {:closed true} [:id pos-int?]]](api/check-superuser)(api/check-404 (metabot.db/metabot id)))@@ -42,7 +42,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :put "/:id""Update a metabot instance"- [{:keys [id]} :- [:map [:id pos-int?]]+ [{:keys [id]} :- [:map {:closed true} [:id pos-int?]]_query-paramsmetabot-updates :- [:map {:closed true}[:use_verified_content {:optional true} :boolean]@@ -75,7 +75,7 @@`:no-library-content` when the Metabot has no models or metrics to summarize, or`:ai-produced-no-prompts` when generation produced nothing.Returns a 402 if the instance has reached its managed-AI usage limit."- [{:keys [id]} :- [:map [:id pos-int?]]]+ [{:keys [id]} :- [:map {:closed true} [:id pos-int?]]](api/check-superuser)(t2/with-transaction [_conn](api/check-404 (metabot.db/metabot-exists? id))@@ -93,8 +93,8 @@:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id/prompt-suggestions""Return the prompt suggestions for the metabot instance with `id`."- [{:keys [id]} :- [:map [:id pos-int?]]- {:keys [sample model model_id]} :- [:map+ [{:keys [id]} :- [:map {:closed true} [:id pos-int?]]+ {:keys [sample model model_id]} :- [:map {:closed true}[:sample {:optional true} :boolean][:model {:optional true} [:enum "metric" "model"]][:model_id {:optional true} pos-int?]]]@@ -112,7 +112,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/:id/prompt-suggestions""Delete all prompt suggestions for the metabot instance with `id`."- [{:keys [id]} :- [:map [:id pos-int?]]]+ [{:keys [id]} :- [:map {:closed true} [:id pos-int?]]](api/check-superuser)(metabot.suggested-prompts/delete-all-metabot-prompts id)api/generic-204-no-content)@@ -123,7 +123,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/:id/prompt-suggestions/:prompt-id""Delete the prompt suggestion with ID `prompt-id` for the metabot instance with `id`."- [{:keys [id prompt-id]} :- [:map+ [{:keys [id prompt-id]} :- [:map {:closed true}[:id pos-int?][:prompt-id pos-int?]]](api/check-superuser)diff --git a/src/metabase/metabot/context.clj b/src/metabase/metabot/context.cljindex 80f6dacfc76..016ebcf6cdf 100644--- a/src/metabase/metabot/context.clj+++ b/src/metabase/metabot/context.clj@@ -1,25 +1,32 @@(ns metabase.metabot.context(:require[clojure.java.io :as io]- [malli.core :as mc][medley.core :as m][metabase.activity-feed.core :as activity-feed][metabase.api.common :as api]+ [metabase.collections.schema :as collections.schema][metabase.config.core :as config]+ [metabase.driver :as driver][metabase.lib-be.core :as lib-be]+ [metabase.lib-be.schema :as lib-be.schema][metabase.lib.core :as lib]+ [metabase.lib.schema :as lib.schema]+ [metabase.lib.schema.template-tag :as lib.schema.template-tag][metabase.metabot.config :as metabot.config][metabase.metabot.curation :as curation][metabase.metabot.db :as metabot.db][metabase.metabot.metadata-perms :as metabot.perms][metabase.metabot.settings :as metabot.settings][metabase.metabot.table-utils :as table-utils]+ [metabase.parameters.schema :as parameters.schema][metabase.transforms-base.util :as transforms-base.u]+ [metabase.transforms.schema :as transforms.schema][metabase.util.json :as json][metabase.util.log :as log][metabase.util.malli :as mu][metabase.util.malli.registry :as mr]- [metabase.util.malli.schema :as ms])+ [metabase.util.malli.schema :as ms]+ [metabase.warehouse-schema.schema :as warehouse-schema.schema])(:import(java.time OffsetDateTime)(java.time.format DateTimeFormatter)))@@ -70,49 +77,326 @@"Schema for the `:type` key of `:user_is_viewing` item."(into [:enum] item-types))+(def ^:private DraftLegacyInnerQuery+ "The `:query` (inner MBQL 4 query) of a legacy dataset-query whose outer map has no `:database` yet -- a brand-new+ structured query, e.g. `STRUCTURED_QUERY_TEMPLATE` on the frontend."+ [:map {:closed true}+ [:source-table {:optional true} [:maybe [:or :int :string]]]])++(def ^:private DraftNativeQuery+ "The `:native` map of a legacy dataset-query whose outer map has no `:database` yet -- a brand-new native query,+ e.g. `NATIVE_QUERY_TEMPLATE` on the frontend."+ [:map {:closed true}+ [:query {:optional true} [:maybe :string]]+ [:template-tags {:optional true} [:maybe [:ref ::lib.schema.template-tag/template-tag-map]]]+ [:collection {:optional true} [:maybe :string]]])++(def ^:private DraftQuerySchema+ "A viewing-context/transform-source query with no `:database` yet: a brand-new adhoc question or transform+ before the user picked a data source. `::lib-be.schema/maybe-legacy-query` requires `:database`, so this covers+ the gap (`STRUCTURED_QUERY_TEMPLATE`/`NATIVE_QUERY_TEMPLATE` on the frontend, or an in-progress MBQL 5 draft)."+ [:map {:closed true}+ [:database {:optional true} nil?]+ [:type {:optional true} [:maybe [:or :string :keyword]]]+ [:native {:optional true} [:maybe DraftNativeQuery]]+ [:query {:optional true} [:maybe DraftLegacyInnerQuery]]+ [:lib/type {:optional true} [:maybe [:or :string :keyword]]]+ [:stages {:optional true} [:maybe [:sequential [:schema [:ref ::lib.schema/stage]]]]]+ [:parameters {:optional true} [:maybe [:sequential ::parameters.schema/parameter]]]])+(def ^:private ItemQuerySchema"Schema for the `:query` of a viewing context item: whatever query the client currently has open, in any MBQL- version.-- Open ([[ms/Map]]) rather than `[:or ::lib.schema/query ::mbql.s/Query]`. Request decoding strips keys a map schema- doesn't declare, and both of those schemas would have gutted the query on its way in — a legacy query arrived as- `{:database 1}`, which then failed validation and 400'd the request. The real shape is checked downstream anyway:- every consumer routes the query through `lib-be/normalize-query` / `lib/query`, which normalize and validate it."- ms/Map)+ version, or a databaseless draft (see [[DraftQuerySchema]]).++ Decoding converts a legacy query to MBQL 5 and validates it, so every consumer gets the shape `lib/query` expects."+ [:multi {:dispatch (fn [q] (boolean (and (map? q) (some? (:database q)))))}+ [true ::lib-be.schema/maybe-legacy-query]+ [false DraftQuerySchema]])++(def ^:private MetabotColumnTypeSchema+ "Schema for `MetabotColumnInfo`'s `:type`."+ (into [:enum] #{"number" "string" "date" "datetime" "time" "boolean" "null"}))++(def ^:private ColumnInfoSchema+ "A chart column's name and inferred type, as sent for chart analysis."+ [:map {:closed true}+ [:name :string]+ [:type {:optional true} [:maybe MetabotColumnTypeSchema]]])++(def ^:private RowValueSchema+ "One cell value in a chart series, matching the frontend's `RowValue`. The `object` arm is never read by this+ code -- it's forwarded to the interestingness stats/repr code as-is -- so it's opaque rather than typed."+ [:maybe [:or :string number? :boolean ms/OpaqueJSONObject]])++(def ^:private SeriesConfigSchema+ "One series of a chart, pre-materialized by the frontend for `analyze_chart`."+ [:map {:closed true}+ [:x ColumnInfoSchema]+ [:y {:optional true} [:maybe ColumnInfoSchema]]+ [:x_values {:optional true} [:maybe [:sequential RowValueSchema]]]+ [:y_values {:optional true} [:maybe [:sequential RowValueSchema]]]+ [:display_name :string]+ [:chart_type [:or :string :keyword]]+ [:stacked {:optional true} [:maybe :boolean]]])++(def ^:private ChartTimelineEventSchema+ "One timeline event overlaid on a chart, pre-materialized by the frontend."+ [:map {:closed true}+ [:name :string]+ [:description {:optional true} [:maybe :string]]+ [:timestamp :string]])++(def ^:private ChartDataSchema+ "One pre-materialized table of raw chart data (columns + rows)."+ [:map {:closed true}+ [:columns [:sequential ColumnInfoSchema]]+ [:rows [:sequential [:sequential [:or :string number?]]]]])++(def ^:private ChartConfigSchema+ "A `chart_configs` entry: a chart's title, pre-materialized series data, and the query that produced it."+ [:map {:closed true}+ [:title {:optional true} [:maybe :string]]+ [:description {:optional true} [:maybe :string]]+ [:data {:optional true} [:maybe [:sequential ChartDataSchema]]]+ [:series {:optional true} [:maybe (ms/string-keyed-map SeriesConfigSchema)]]+ [:timeline_events {:optional true} [:maybe [:sequential ChartTimelineEventSchema]]]+ [:query {:optional true} ItemQuerySchema]+ [:display_type {:optional true} [:maybe [:or :string :keyword]]]])++(def ^:private CodeEditorBufferSourceSchema+ "The `:source` of a code-editor buffer: the editor's language and the database it targets."+ [:map {:closed true}+ [:language [:= "sql"]]+ [:database_id [:maybe :int]]])++(def ^:private CodeEditorCursorSchema+ [:map {:closed true}+ [:line :int]+ [:column :int]])++(def ^:private CodeEditorBufferSelectionSchema+ [:map {:closed true}+ [:text :string]+ [:start CodeEditorCursorSchema]+ [:end CodeEditorCursorSchema]])++(def ^:private CodeEditorBufferSchema+ "One open buffer in the code editor viewing context."+ [:map {:closed true}+ [:id :string]+ [:source CodeEditorBufferSourceSchema]+ [:cursor CodeEditorCursorSchema]+ [:selection {:optional true} [:maybe CodeEditorBufferSelectionSchema]]])++(def ^:private CodeEditorContextSchema+ "The top-level `:code_editor` key of [[::context]] (as distinct from a `type: code_editor` viewing-context item)."+ [:map {:closed true}+ [:type [:= "code_editor"]]+ [:buffers [:sequential CodeEditorBufferSchema]]])++(def ^:private TransformSourceTableSchema+ "One entry of a Python transform's `source-tables`."+ [:map {:closed true}+ [:alias :string]+ [:table_id {:optional true} [:maybe :int]]+ [:schema {:optional true} [:maybe :string]]+ [:database_id {:optional true} [:maybe :int]]])++(def ^:private TransformSourceSchema+ "A transform's `:source`. Everything but `:type` is optional so a draft transform -- no database chosen, no+ source tables picked -- validates just like a saved one."+ [:multi {:dispatch (comp keyword :type)}+ [:query+ [:map {:closed true}+ [:type [:or [:= :query] [:= "query"]]]+ [:query {:optional true} [:maybe [:or :string ItemQuerySchema]]]+ [:source-incremental-strategy {:optional true} [:maybe ::transforms.schema/source-incremental-strategy]]]]+ [:python+ [:map {:closed true}+ [:type [:or [:= :python] [:= "python"]]]+ [:body {:optional true} [:maybe :string]]+ [:source-database {:optional true} [:maybe :int]]+ [:source-tables {:optional true} [:maybe [:sequential TransformSourceTableSchema]]]+ [:source-incremental-strategy {:optional true} [:maybe ::transforms.schema/source-incremental-strategy]]]]])++(def ^:private TransformTargetSchema+ "A transform's `:target`. Everything but `:type` is optional so an unsaved/suggested transform -- which may omit+ `:database` or the incremental strategy -- validates just like a saved one."+ [:multi {:dispatch (comp keyword :type)}+ [:table+ [:map {:closed true}+ [:type [:or [:= :table] [:= "table"]]]+ [:name {:optional true} [:maybe :string]]+ [:schema {:optional true} [:maybe :string]]+ [:database {:optional true} [:maybe :int]]]]+ [:table-incremental+ [:map {:closed true}+ [:type [:or [:= :table-incremental] [:= "table-incremental"]]]+ [:name {:optional true} [:maybe :string]]+ [:schema {:optional true} [:maybe :string]]+ [:database {:optional true} [:maybe :int]]+ [:target-incremental-strategy {:optional true} [:maybe ::transforms.schema/target-incremental-strategy]]]]])++(def ^:private TransformCreatorSchema+ "The `:creator` hydrated onto a transform, mirroring the transforms REST API's own response shape."+ [:map {:closed true}+ [:id :int]+ [:email :string]+ [:first_name {:optional true} [:maybe :string]]+ [:last_name {:optional true} [:maybe :string]]+ [:common_name {:optional true} [:maybe :string]]+ [:last_login {:optional true} [:maybe :string]]+ [:is_qbnewb {:optional true} [:maybe :boolean]]+ [:is_superuser {:optional true} [:maybe :boolean]]+ [:is_data_analyst {:optional true} [:maybe :boolean]]+ [:tenant_id {:optional true} [:maybe :int]]+ [:date_joined {:optional true} [:maybe :string]]])++(def ^:private TransformOwnerSchema+ "The `:owner` hydrated onto a transform, mirroring the transforms REST API's own response shape."+ [:map {:closed true}+ [:id {:optional true} [:maybe :int]]+ [:email {:optional true} [:maybe :string]]+ [:first_name {:optional true} [:maybe :string]]+ [:last_name {:optional true} [:maybe :string]]+ [:common_name {:optional true} [:maybe :string]]])++(def ^:private TransformLastRunSchema+ "The `:last_run` hydrated onto a transform, mirroring the transforms REST API's own response shape."+ [:map {:closed true}+ [:id {:optional true} [:maybe :int]]+ [:transform_id {:optional true} [:maybe :int]]+ [:run_method {:optional true} [:maybe [:or :string :keyword]]]+ [:status {:optional true} [:maybe [:or :string :keyword]]]+ [:is_active {:optional true} [:maybe :boolean]]+ [:start_time {:optional true} [:maybe :string]]+ [:end_time {:optional true} [:maybe :string]]+ [:message {:optional true} [:maybe :string]]+ [:user_id {:optional true} [:maybe :int]]+ [:transform_name {:optional true} [:maybe :string]]+ [:transform_entity_id {:optional true} [:maybe :string]]+ [:job_run_id {:optional true} [:maybe :int]]+ [:dag_run_id {:optional true} [:maybe :int]]+ [:checkpoint_filter_field_id {:optional true} [:maybe :int]]+ [:checkpoint_lo_value {:optional true} [:maybe :string]]+ [:checkpoint_hi_value {:optional true} [:maybe :string]]+ [:metered_as {:optional true} [:maybe :string]]])++(def ^:private TransformTableDependencySchema+ "One entry of a transform's `:table_dependencies`."+ [:or ::driver/native-query-deps.table-dep ::driver/native-query-deps.transform-dep])++(def ^:private item-entries+ "The keys of a viewing context item this code reads. The rest of the item is the shape of one of+ `MetabotEntityInfo`'s variants (card/dashboard/adhoc/document/transform) or `MetabotCodeEditorContext`, so+ everything the frontend can send is named here rather than forwarded opaquely."+ [[:id {:optional true} [:maybe [:or :int :string]]]+ [:name {:optional true} [:maybe :string]]+ [:description {:optional true} [:maybe :string]]+ [:database_schema {:optional true} [:maybe :string]]+ [:sql_engine {:optional true} [:maybe :string]]+ [:error {:optional true} [:maybe :string]]+ [:source_type {:optional true} [:maybe [:or :string :keyword]]]+ [:source {:optional true} [:maybe TransformSourceSchema]]+ [:target {:optional true} [:maybe TransformTargetSchema]]+ [:used_tables {:optional true} [:maybe [:sequential [:map {:closed true}+ [:id {:optional true} [:maybe :int]]+ [:type {:optional true} [:maybe [:or :keyword :string]]]+ [:name {:optional true} [:maybe :string]]+ [:database_schema {:optional true} [:maybe :string]]+ [:description {:optional true} [:maybe :string]]]]]]+ [:buffers {:optional true} [:maybe [:sequential CodeEditorBufferSchema]]]+ [:query {:optional true} ItemQuerySchema]+ [:chart_configs {:optional true} [:maybe [:vector ChartConfigSchema]]]+ ;; Transform fields (`MetabotTransformInfo` = `Transform | SuggestedTransform | DraftTransform`), mirroring the+ ;; transforms REST API's own response shape. All optional: a draft/suggested/unsaved transform may carry only a+ ;; handful of these.+ [:collection_id {:optional true} [:maybe :int]]+ [:created_at {:optional true} [:maybe :string]]+ [:updated_at {:optional true} [:maybe :string]]+ [:source_readable {:optional true} [:maybe :boolean]]+ [:can_read {:optional true} [:maybe :boolean]]+ [:can_write {:optional true} [:maybe :boolean]]+ [:can_execute {:optional true} [:maybe :boolean]]+ [:source_database_id {:optional true} [:maybe :int]]+ [:deleted {:optional true} [:maybe :boolean]]+ [:creator_id {:optional true} [:maybe :int]]+ [:owner_user_id {:optional true} [:maybe :int]]+ [:owner_email {:optional true} [:maybe :string]]+ [:owner {:optional true} [:maybe TransformOwnerSchema]]+ [:last_checkpoint_value {:optional true} [:maybe :string]]+ [:dependency {:optional true} [:maybe :boolean]]+ [:scheduled {:optional true} [:maybe :boolean]]+ [:collection {:optional true} [:maybe ::collections.schema/collection]]+ [:tag_ids {:optional true} [:maybe [:sequential :int]]]+ [:table {:optional true} [:maybe ::warehouse-schema.schema/table]]+ [:last_run {:optional true} [:maybe TransformLastRunSchema]]+ [:creator {:optional true} [:maybe TransformCreatorSchema]]+ ;; Driver index-method metadata, keyed by index-kind. Never read by this code -- forwarded as the frontend+ ;; sent it -- and the driver's own schema for it isn't closed-schema-clean, so it's opaque rather than typed.+ [:requestable_indexes {:optional true} [:maybe ms/OpaqueJSONObject]]+ [:target_db_id {:optional true} [:maybe :int]]+ [:target_table_id {:optional true} [:maybe :int]]+ [:run_trigger {:optional true} [:maybe [:or :string :keyword]]]+ [:entity_id {:optional true} [:maybe :string]]+ [:table_dependencies {:optional true} [:maybe [:sequential TransformTableDependencySchema]]]])(def DefaultItemSchema"Default schema of viewing context item."- [:map- ;; `::mc/default` because the rest of the item is forwarded to the model as the client sent it -- the FE grows- ;; these fields (`:id`, `:name`, `:source`, `:sql_engine`, ...) faster than this schema could name them, and- ;; dropping one degrades Metabot silently rather than erroring.- [::mc/default :any]- [:type item-type-schema]- [:query {:optional true} ItemQuerySchema]])+ (into [:map {:closed true} [:type item-type-schema]] item-entries))(def QcItemSchema"Schema viewing context item with query and charts."- [:map- [::mc/default :any]- [:type (into [:enum] item-types-qc)]- [:query {:optional true} ItemQuerySchema]- [:chart_configs- {:optional true}- [:vector- [:map- [::mc/default :any]- [:query {:optional true} ItemQuerySchema]]]]])+ (into [:map {:closed true}+ [:type (into [:enum] item-types-qc)]]+ item-entries))(def ViewingItemSchema"Schema of user is viewing item."[:or QcItemSchema DefaultItemSchema])+(mr/def ::recently-viewed-item+ "One of the user's recent views, trimmed to what the model gets told about it."+ [:map {:closed true}+ [:id {:optional true} [:maybe [:or :int :string]]]+ [:name {:optional true} [:maybe :string]]+ [:description {:optional true} [:maybe :string]]+ [:type {:optional true} [:maybe :string]]])++(mr/def ::research-plan-ref+ "A named reference to a research-plan metric/dimension/timeline: what the frontend echoes back in+ `ResearchPlanContext`."+ [:map {:closed true}+ [:id [:or :int :string]]+ [:name :string]])++(mr/def ::research-plan-group+ [:map {:closed true}+ [:block_id :string]+ [:metric ::research-plan-ref]+ [:dimensions [:sequential ::research-plan-ref]]])++(mr/def ::research-plan+ "The in-progress Research plan the frontend serializes into `:research_plan` each turn (`ResearchPlanContext`)."+ [:map {:closed true}+ [:name :string]+ [:groups [:sequential ::research-plan-group]]+ [:timelines [:sequential ::research-plan-ref]]])+(mr/def ::context- [:and- [:map-of :keyword :any]- [:map- [::mc/default :any]- [:user_is_viewing {:optional true} [:vector ViewingItemSchema]]]])+ "The context a Metabot request carries. Besides what the client sends, [[create-context]] adds the user's recent+ views, the current time and the caller's capabilities before the agent reads it."+ [:map {:closed true}+ [:user_is_viewing {:optional true} [:vector ViewingItemSchema]]+ [:user_recently_viewed {:optional true} [:maybe [:sequential ::recently-viewed-item]]]+ [:current_time_with_timezone {:optional true} [:maybe :string]]+ [:current_user_time {:optional true} [:maybe :string]]+ [:first_day_of_week {:optional true} [:maybe :string]]+ [:capabilities {:optional true} [:maybe [:or [:set :string] [:sequential :string]]]]+ [:slack_channel_id {:optional true} [:maybe :string]]+ [:default_database_id {:optional true} [:maybe :int]]+ [:code_editor {:optional true} [:maybe CodeEditorContextSchema]]+ [:research_plan {:optional true} [:maybe ::research-plan]]])(defn- query-for-sql-parsing"Given an item in context, return the query if it is a native query or SQL transform that can have table usage parseddiff --git a/src/metabase/metabot/tools/resources.clj b/src/metabase/metabot/tools/resources.cljindex 3389875c295..85b8a39cf54 100644--- a/src/metabase/metabot/tools/resources.clj+++ b/src/metabase/metabot/tools/resources.clj@@ -696,7 +696,7 @@[index block](let [card-ids (->> (tree-seq :content :content block)(keep #(when (= (:type %) prose-mirror/card-embed-type)- (-> % :attrs :id))))+ (get-in % [:attrs "id"]))))text (prose-mirror/ast->text block)](str "[" index "] " (:type block)(when (seq card-ids)diff --git a/src/metabase/metrics/api.clj b/src/metabase/metrics/api.cljindex ffe18200adb..05ad5030c25 100644--- a/src/metabase/metrics/api.clj+++ b/src/metabase/metrics/api.clj@@ -5,6 +5,7 @@[metabase.api.macros :as api.macros][metabase.app-db.core :as mdb][metabase.events.core :as events]+ [metabase.lib-be.schema :as lib-be.schema][metabase.lib-metric.core :as lib-metric][metabase.lib-metric.schema :as lib-metric.schema][metabase.metrics.core :as metrics]@@ -46,7 +47,7 @@[:map[:dimensions [:sequential ::metrics.dimension/dimension]][:dimension_mappings [:sequential ::metrics.dimension/dimension-mapping]]- [:dataset_query {:optional true} [:maybe ms/Map]]+ [:dataset_query {:optional true} [:maybe ::lib-be.schema/maybe-legacy-or-empty-query]][:database_id {:optional true} [:maybe ms/PositiveInt]][:result_column_name {:optional true} [:maybe :string]]]])@@ -93,8 +94,8 @@Returns the metric with hydrated dimensions and dimension mappings; the `::MetricWithDimensions`schema encodes them to the snake_case wire shape at the `defendpoint` edge."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]- {:keys [include-orphaned]} :- [:map+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]+ {:keys [include-orphaned]} :- [:map {:closed true}[:include-orphaned {:optional true} [:maybe ms/BooleanValue]]]](let [metric (hydrated-metric id (boolean include-orphaned))](assoc metric :result_column_name (metrics/aggregation-column-name (:database_id metric) (:dataset_query metric)))))@@ -120,7 +121,7 @@"Schema for the definition object within a dataset request.Uses expression-based contract for metric math support."[:and- [:map+ [:map {:closed true}[:expression ::lib-metric.schema/metric-math-expression][:filters {:optional true} [:maybe ::lib-metric.schema/instance-filters]][:projections {:optional true} [:maybe ::lib-metric.schema/typed-projections]]]@@ -142,7 +143,7 @@(mr/def ::DatasetRequest"Schema for POST /dataset request body."- [:map+ [:map {:closed true}[:definition ::Definition]])(mr/def ::RemappedValueResponse@@ -295,7 +296,7 @@- values: list of [value] or [value, display-name] tuples- field_id: the underlying field ID- has_more_values: boolean indicating if there are more values"- [{:keys [id dimension-key]} :- [:map+ [{:keys [id dimension-key]} :- [:map {:closed true}[:id ms/PositiveInt][:dimension-key ms/UUIDString]]](let [metric (hydrated-metric id false)]@@ -309,10 +310,10 @@"Search for values of a dimension that contain the query string.Returns field values matching the search query in the same format as the field values API."- [{:keys [id dimension-key]} :- [:map+ [{:keys [id dimension-key]} :- [:map {:closed true}[:id ms/PositiveInt][:dimension-key ms/UUIDString]]- {:keys [query]} :- [:map [:query ms/NonBlankString]]]+ {:keys [query]} :- [:map {:closed true} [:query ms/NonBlankString]]](let [metric (hydrated-metric id false)](metrics/dimension-search-values(:dimensions metric)@@ -325,10 +326,10 @@"Fetch remapped value for a specific dimension value.Returns a pair [value, display-name] if remapping exists, or [value] otherwise."- [{:keys [id dimension-key]} :- [:map+ [{:keys [id dimension-key]} :- [:map {:closed true}[:id ms/PositiveInt][:dimension-key ms/UUIDString]]- {:keys [value]} :- [:map [:value :string]]]+ {:keys [value]} :- [:map {:closed true} [:value :string]]](let [metric (hydrated-metric id false)](metrics/dimension-remapped-value(:dimensions metric)@@ -362,8 +363,8 @@[:addable [:sequential :map]]]"List a metric's curated dimensions, and (when `with-addable=true`) the columns still available toadd, grouped by source table. Both can be filtered with a `query` name substring."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]- {:keys [query with-addable include-orphaned]} :- [:map+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]+ {:keys [query with-addable include-orphaned]} :- [:map {:closed true}[:query {:optional true} [:maybe :string]][:with-addable {:optional true} [:maybe ms/BooleanValue]][:include-orphaned {:optional true} [:maybe ms/BooleanValue]]]]@@ -379,10 +380,10 @@are recomputed server-side.Returns the updated list of dimensions."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]_query-params- {:keys [dimensions]} :- [:map- [:dimensions [:sequential [:map+ {:keys [dimensions]} :- [:map {:closed true}+ [:dimensions [:sequential [:map {:closed true}[:id ms/NonBlankString][:display_name {:optional true} ms/NonBlankString][:description {:optional true} [:maybe :string]]@@ -394,9 +395,9 @@(api.macros/defendpoint :post "/:id/dimension/remove":- [:sequential :map]"Remove dimensions (by UUID) from a metric. Returns the updated list of added dimensions."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]_query-params- {:keys [dimension_ids]} :- [:map [:dimension_ids [:sequential ms/NonBlankString]]]]+ {:keys [dimension_ids]} :- [:map {:closed true} [:dimension_ids [:sequential ms/NonBlankString]]]](write-check-metric! id)(u/prog1 (metrics/remove-dimensions! :metadata/metric id dimension_ids)(notify-dimensions-changed! id)))@@ -406,9 +407,9 @@"Mark exactly one dimension as the metric's default, clearing any previous default. A null`dimension_id` clears the default without setting a new one, so the metric renders as a scalar.Returns the updated list of added dimensions."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]_query-params- {:keys [dimension_id]} :- [:map [:dimension_id [:maybe ms/NonBlankString]]]]+ {:keys [dimension_id]} :- [:map {:closed true} [:dimension_id [:maybe ms/NonBlankString]]]](write-check-metric! id)(metrics/set-default-dimension! :metadata/metric id dimension_id))@@ -417,9 +418,9 @@"Persist a new ordering for a metric's dimensions. `dimension_ids` is the desired order; dimensionsnot listed keep their relative order after the listed ones. Returns the updated list of addeddimensions."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]_query-params- {:keys [dimension_ids]} :- [:map [:dimension_ids [:sequential ms/NonBlankString]]]]+ {:keys [dimension_ids]} :- [:map {:closed true} [:dimension_ids [:sequential ms/NonBlankString]]]](write-check-metric! id)(metrics/reorder-dimensions! :metadata/metric id dimension_ids))@@ -429,15 +430,15 @@column.`source` is a `{type, field-id}`; the new column must have the same effective type."- [{:keys [id dimension-key]} :- [:map+ [{:keys [id dimension-key]} :- [:map {:closed true}[:id ms/PositiveInt][:dimension-key ms/UUIDString]]_query-params- body :- [:map+ body :- [:map {:closed true}[:display_name {:optional true} ms/NonBlankString][:description {:optional true} [:maybe :string]][:default_temporal_unit {:optional true} ms/NonBlankString]- [:source {:optional true} [:maybe [:map [:field-id ms/PositiveInt]]]]]]+ [:source {:optional true} [:maybe [:map {:closed true} [:field-id ms/PositiveInt]]]]]](write-check-metric! id)(u/prog1 (metrics/update-dimension! :metadata/metric id dimension-key body);; Only a source-column change alters the mapping (and thus the deps graph).diff --git a/src/metabase/metrics/dimension.clj b/src/metabase/metrics/dimension.cljindex 8ca84e00708..0e33fe9242f 100644--- a/src/metabase/metrics/dimension.clj+++ b/src/metabase/metrics/dimension.clj@@ -87,6 +87,7 @@ks (into #{} (map first) (mc/entries schema))](mut/update-propertiesschema assoc+ :closed false:encode/api {:enter (fn [m] (if (map? m) (enter (select-keys m ks)) m)):leave snake-case-keys}:decode/api {:enter kebab-case-keys}))))@@ -95,7 +96,7 @@"A dimension source annotated with its wire-encoding rules. Quirks preserved from the previoushand-rolled shape: entries keep their kebab-case `:field-id` key on the wire (no key renaming),`:field-id` is always present (nil when missing), and other keys (e.g. `:binning`) are dropped."- [:map {:encode/api {:enter #(merge {:field-id nil} (select-keys % [:type :field-id]))}}+ [:map {:closed false, :encode/api {:enter #(merge {:field-id nil} (select-keys % [:type :field-id]))}}[:type ::lm.schema/dimension-source.type][:field-id {:optional true} [:maybe :int]]])@@ -120,16 +121,15 @@encode-dimension-map))(mr/def ::dimension-mapping- "The internal (kebab-case) dimension-mapping shape annotated with its wire-conversion rules.- `:target` is re-typed as `:any` so the transformer never walks into the MBQL ref and renames- its option-map keys — it passes through untouched in both directions. `:type` is optional on+ "The internal (kebab-case) dimension-mapping shape annotated with its wire-conversion rules. `:type` is optional onthe wire (FE payloads may omit it); `:dimension-id` keeps the strict uuid schema."- (wire-map- ::lm.schema/dimension-mapping- [:map- [:type {:optional true} ::lm.schema/dimension-mapping.type]- [:target :any]]- encode-mapping-map))+ (mut/update-properties+ (wire-map+ ::lm.schema/dimension-mapping+ [:map+ [:type {:optional true} ::lm.schema/dimension-mapping.type]]+ encode-mapping-map)+ assoc :closed true))(def ^:private api-transformer"The `:api`-named step of the transformers `defendpoint` applies, on its own.diff --git a/src/metabase/model_persistence/api.clj b/src/metabase/model_persistence/api.cljindex 1f88b4d94c3..ca6b8ded625 100644--- a/src/metabase/model_persistence/api.clj+++ b/src/metabase/model_persistence/api.clj@@ -68,7 +68,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:persisted-info-id""Fetch a particular [[PersistedInfo]] by id."- [{:keys [persisted-info-id]} :- [:map+ [{:keys [persisted-info-id]} :- [:map {:closed true}[:persisted-info-id ms/PositiveInt]]](api/let-404 [persisted-info (first (fetch-persisted-info {:persisted-info-id persisted-info-id} nil nil))](api/read-check :model/Card (:card_id persisted-info))@@ -81,7 +81,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/card/:card-id""Fetch a particular [[PersistedInfo]] by card-id."- [{:keys [card-id]} :- [:map+ [{:keys [card-id]} :- [:map {:closed true}[:card-id ms/PositiveInt]]](api/let-404 [persisted-info (first (fetch-persisted-info {:card-id card-id} nil nil))](api/read-check :model/Card card-id)@@ -105,7 +105,7 @@Shape should be JSON like {cron: \"0 30 1/8 * * ? *\"}."[_route-params_query-params- {:keys [cron], :as _body} :- [:map+ {:keys [cron], :as _body} :- [:map {:closed true}[:cron CronSchedule]]](perms/check-has-application-permission :setting)(when cron@@ -174,7 +174,7 @@(api.macros/defendpoint :post "/card/:card-id/persist""Mark the model (card) as persisted. Runs the query and saves it to the database backing the card and hot swaps thisquery in place of the model's query."- [{:keys [card-id]} :- [:map+ [{:keys [card-id]} :- [:map {:closed true}[:card-id ms/PositiveInt]]](premium-features/assert-has-feature :cache-granular-controls (tru "Granular cache controls"))(api/let-404 [{:keys [database_id] :as card} (model-persistence.db/card card-id)]@@ -201,7 +201,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :post "/card/:card-id/refresh""Refresh the persisted model caching `card-id`."- [{:keys [card-id]} :- [:map+ [{:keys [card-id]} :- [:map {:closed true}[:card-id ms/PositiveInt]]](api/let-404 [card (model-persistence.db/card card-id)persisted-info (model-persistence.db/persisted-info-for-card card-id)]@@ -221,7 +221,7 @@(api.macros/defendpoint :post "/card/:card-id/unpersist""Unpersist this model. Deletes the persisted table backing the model and all queries after this will use the card'squery rather than the saved version of the query."- [{:keys [card-id]} :- [:map+ [{:keys [card-id]} :- [:map {:closed true}[:card-id ms/PositiveInt]]](premium-features/assert-has-feature :cache-granular-controls (tru "Granular cache controls"))(api/let-404 [card (model-persistence.db/card card-id)]@@ -241,7 +241,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :post "/database/:id/persist""Attempt to enable model persistence for a database. If already enabled returns a generic 204."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](api/check (model-persistence.settings/persisted-models-enabled)400@@ -271,7 +271,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :post "/database/:id/unpersist""Attempt to disable model persistence for a database. If already not enabled, just returns a generic 204."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](api/let-404 [database (model-persistence.db/database id)](api/write-check database)diff --git a/src/metabase/native_query_snippets/api.clj b/src/metabase/native_query_snippets/api.cljindex 3be6d0bbb2e..cdce29f9eb0 100644--- a/src/metabase/native_query_snippets/api.clj+++ b/src/metabase/native_query_snippets/api.clj@@ -31,7 +31,7 @@(api.macros/defendpoint :get "/""Fetch all snippets"[_route-params- {:keys [archived]} :- [:map+ {:keys [archived]} :- [:map {:closed true}[:archived {:default false} [:maybe ms/BooleanValue]]]](list-native-query-snippets (boolean archived)))@@ -47,7 +47,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id""Fetch native query snippet with ID."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](get-native-query-snippet id))@@ -64,7 +64,7 @@"Create a new `NativeQuerySnippet`."[_route-params_query-params- {:keys [content description name collection_id]} :- [:map+ {:keys [content description name collection_id]} :- [:map {:closed true}[:content :string][:description {:optional true} [:maybe :string]][:name native-query-snippet/NativeQuerySnippetName]@@ -102,10 +102,10 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :put "/:id""Update an existing `NativeQuerySnippet`."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-params- body :- [:map+ body :- [:map {:closed true}[:archived {:optional true} [:maybe :boolean]][:content {:optional true} [:maybe :string]][:description {:optional true} [:maybe :string]]diff --git a/src/metabase/notification/api/admin.clj b/src/metabase/notification/api/admin.cljindex 93de3ea1fb2..af5d4cbe170 100644--- a/src/metabase/notification/api/admin.clj+++ b/src/metabase/notification/api/admin.clj@@ -235,6 +235,10 @@(cond-> creator (assoc :creator (assoc creator :is_active creator_is_active)))(dissoc :creator_is_active)))+(def ^:private admin-list-keys+ "What the admin list adds to a notification row on top of the notification itself."+ [:last_check :last_send :creator_is_active :creator_name :card_name])+(defn- list-notifications"Single SQL query for the page; one extra query for failed-run error messages on that page."[{:keys [limit offset recipient_email] :as filters}]@@ -243,10 +247,12 @@(assoc :recipient_notification_ids (notification-ids-with-recipient-email recipient_email)))page-rows (notification.db/admin-notifications-page base-filters limit offset)total (or (notification.db/admin-notifications-count base-filters) 0)- decorated (-> page-rows- decorate-runs- models.notification/hydrate-notification)]- {:data (mapv splice-creator-active decorated)+ decorated (decorate-runs page-rows)+ hydrated (models.notification/hydrate-notification (mapv #(apply dissoc % admin-list-keys) decorated))]+ {:data (mapv (fn [notification row]+ (splice-creator-active (merge notification (select-keys row admin-list-keys))))+ hydrated+ decorated):total total:limit limit:offset offset}))@@ -275,7 +281,7 @@[_route{:keys [active creator_id creator_active creatorless card_id recipient_email channel last_send_statuslast_check_status query sort_column sort_direction]} :-- [:map+ [:map {:closed true}[:active {:optional true} [:maybe ms/BooleanValue]][:creator_id {:optional true} ms/PositiveInt][:creator_active {:optional true} [:maybe ms/BooleanValue]]@@ -370,8 +376,9 @@for a missing or non-card notification."[id](when-let [row (notification.db/admin-notification-detail-row id)]- (let [decorated (-> (models.notification/hydrate-notification [row])+ (let [decorated (-> (models.notification/hydrate-notification [(apply dissoc row admin-list-keys)])first+ (merge (select-keys row admin-list-keys))splice-creator-active)check-history (check-history-for-notification id)send-history (send-history-for-notification id)]@@ -385,7 +392,7 @@"Get a single card-type notification with last_check, last_send, check_history (up to 10most-recent terminal alert-type TaskRuns) and send_history (up to 10 most-recent channel-senddelivery attempts). 404 if the notification doesn't exist or isn't a card-type notification."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](api/check-superuser)(api/check-404 (get-notification-detail id)))@@ -424,7 +431,7 @@endpoint's side-effect contract can't drift from `PUT /api/notification/:id`."[_route _query{:keys [notification_ids action creator_id]} :-- [:map+ [:map {:closed true}[:notification_ids [:sequential {:min 1} ms/PositiveInt]][:action [:enum "archive" "change-creator"]][:creator_id {:optional true} ms/PositiveInt]]]diff --git a/src/metabase/notification/api/notification.clj b/src/metabase/notification/api/notification.cljindex f240d4ac197..7473624fe2b 100644--- a/src/metabase/notification/api/notification.clj+++ b/src/metabase/notification/api/notification.clj@@ -27,7 +27,7 @@[handler-schema recipient-schema][:mergehandler-schema- [:map+ [:map {:closed true}[:template {:optional true} [:multi {:dispatch map?}[true ::models.channel/ChannelTemplateUserProvided][false :nil]]]@@ -128,7 +128,7 @@- `card_id`: if provided returns only notification that has card_id as payload"[_route-params{:keys [creator_id creator_or_recipient_id recipient_id card_id include_inactive payload_type]} :-- [:map+ [:map {:closed true}[:creator_id {:optional true} ms/PositiveInt][:recipient_id {:optional true} ms/PositiveInt][:creator_or_recipient_id {:optional true} ms/PositiveInt]@@ -148,7 +148,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id""Get a notification by id."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]](-> (get-notification id)api/read-check))@@ -257,7 +257,7 @@`creator_id` (owner) can be reassigned here only by superusers (e.g. the admin 'Edit alert'modal's owner picker). `mi/can-update?` rejects a non-superuser reassignment attempt with 403;the model's `before-update` hook is the backstop. Echoing back the unchanged value is fine."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]_querybody :- ::NotificationApiUpdateInput](let [existing-notification (get-notification id)]@@ -274,9 +274,9 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :post "/:id/send""Send a notification by id."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]_query- {:keys [handler_ids]} :- [:map [:handler_ids {:optional true} [:sequential ms/PositiveInt]]]]+ {:keys [handler_ids]} :- [:map {:closed true} [:handler_ids {:optional true} [:sequential ms/PositiveInt]]]](let [notification (cond-> (get-notification id)(seq handler_ids)(update :handlers (fn [handlers] (filter (comp (set handler_ids) :id) handlers))))]@@ -334,6 +334,6 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :post "/:id/unsubscribe""Unsubscribe current user from a notification."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]](unsubscribe-user! id api/*current-user-id*)api/generic-204-no-content)diff --git a/src/metabase/notification/api/unsubscribe.clj b/src/metabase/notification/api/unsubscribe.cljindex 57ce94b5f67..b643006d462 100644--- a/src/metabase/notification/api/unsubscribe.clj+++ b/src/metabase/notification/api/unsubscribe.clj@@ -43,7 +43,7 @@"Allow non-users to unsubscribe from notifications, with the hash given through email."[_route-params_query-params- {:keys [email hash notification-handler-id]} :- [:map+ {:keys [email hash notification-handler-id]} :- [:map {:closed true}[:notification-handler-id ms/PositiveInt][:email :string][:hash :string]]@@ -67,7 +67,7 @@"Allow non-users to undo an unsubscribe from notifications, with the hash given through email."[_route-params_query-params- {:keys [email hash notification-handler-id]} :- [:map+ {:keys [email hash notification-handler-id]} :- [:map {:closed true}[:notification-handler-id ms/PositiveInt][:email :string][:hash :string]]diff --git a/src/metabase/notification/models.clj b/src/metabase/notification/models.cljindex 6bdf26df5f8..f314fe90c52 100644--- a/src/metabase/notification/models.clj+++ b/src/metabase/notification/models.clj@@ -12,7 +12,10 @@[metabase.models.util.spec-update :as models.u.spec-update][metabase.notification.db :as notification.db][metabase.permissions.core :as perms]+ [metabase.permissions.schema :as permissions.schema][metabase.premium-features.core :as premium-features :refer [defenterprise]]+ [metabase.queries.schema :as queries.schema]+ [metabase.users.schema :as users.schema][metabase.util :as u][metabase.util.malli :as mu][metabase.util.malli.registry :as mr]@@ -43,6 +46,20 @@;; :model/Notification ;;;; ------------------------------------------------------------------------------------------------;;+(def ^:private RowTimestamp+ "A `created_at`/`updated_at` column: a `java.time` value on the way out, and -- because clients echo the+ notification they were handed back at us on update -- the ISO string it was encoded as on the way back in."+ [:maybe [:or ms/TemporalInstant ms/TemporalString]])++(mr/def ::EchoedUser+ "A hydrated User as a client hands it back on update: a `::users.schema/user` whose timestamps may be the ISO strings+ they were encoded as on the way out."+ [:merge+ ::users.schema/user+ [:map {:closed true}+ [:date_joined RowTimestamp]+ [:last_login RowTimestamp]]])+(def notification-types"Set of valid notification types."#{:notification/system-event@@ -101,12 +118,16 @@"Entries every notification map has, whatever its `:payload_type`."[{:keys [with-id?]}](cond->> [[:payload_type (ms/enum-decode-keyword notification-types)]- [:active {:optional true} [:maybe :boolean]]]+ [:active {:optional true} [:maybe :boolean]]+ [:internal_id {:optional true} [:maybe :string]]+ [:creator_id {:optional true} [:maybe ms/PositiveInt]]+ [:created_at {:optional true} RowTimestamp]+ [:updated_at {:optional true} RowTimestamp]]with-id? (into [[:id {:optional true} ms/PositiveInt]])))(mr/def ::Notification[:merge- (into [:map] (notification-entries {:with-id? true}))+ (into [:map {:closed true}] (notification-entries {:with-id? true}))[:multi {:decode/normalize lib.schema.common/normalize-map-no-kebab-case:dispatch (comp keyword :payload_type)}[:notification/system-event@@ -188,9 +209,12 @@(defn- notification-subscription-schema[{:keys [with-id?]}][:merge- (into [:map] (cond->> [[:type (ms/enum-decode-keyword subscription-types)]- [:notification_id {:optional true} ms/PositiveInt]]- with-id? (into [[:id {:optional true} :int]])))+ (into [:map {:closed true}]+ (cond->> [[:type (ms/enum-decode-keyword subscription-types)]+ [:notification_id {:optional true} ms/PositiveInt]+ [:ui_display_type {:optional true} [:maybe [:or :keyword :string]]]+ [:created_at {:optional true} RowTimestamp]]+ with-id? (into [[:id {:optional true} :int]])))[:multi {:decode/normalize lib.schema.common/normalize-map-no-kebab-case:dispatch (comp keyword :type)}[:notification-subscription/system-event@@ -306,13 +330,15 @@(defn- notification-handler-schema[{:keys [with-id?]}]- (into [:map]+ (into [:map {:closed true}](cond->> [;; optional during insertion[:notification_id {:optional true} ms/PositiveInt][:channel_type {:decode/json keyword} [:fn #(= "channel" (-> % keyword namespace))]][:channel_id {:optional true} [:maybe ms/PositiveInt]][:template_id {:optional true} [:maybe ms/PositiveInt]]- [:active {:optional true} [:maybe :boolean]]]+ [:active {:optional true} [:maybe :boolean]]+ [:created_at {:optional true} RowTimestamp]+ [:updated_at {:optional true} RowTimestamp]]with-id? (into [[:id {:optional true} ms/PositiveInt]]))))(mr/def ::NotificationHandler@@ -356,25 +382,33 @@(defn- notification-recipient-schema[{:keys [with-id?]}][:merge- (into [:map] (cond->> [[:type (ms/enum-decode-keyword notification-recipient-types)]- [:notification_handler_id {:optional true} ms/PositiveInt]]- with-id? (into [[:id {:optional true} ms/PositiveInt]])))+ (into [:map {:closed true}]+ (cond->> [[:type (ms/enum-decode-keyword notification-recipient-types)]+ [:notification_handler_id {:optional true} ms/PositiveInt]+ [:created_at {:optional true} RowTimestamp]+ [:updated_at {:optional true} RowTimestamp]]+ with-id? (into [[:id {:optional true} ms/PositiveInt]])))[:multi {:decode/normalize lib.schema.common/normalize-map-no-kebab-case:dispatch (comp keyword :type)}[:notification-recipient/user[:map[:user_id ms/PositiveInt][:permissions_group_id {:optional true} [:fn nil?]]- [:details {:optional true} [:fn empty?]]]]+ [:details {:optional true} [:fn empty?]]+ [:user {:optional true} [:maybe ::EchoedUser]]]][:notification-recipient/group[:map[:permissions_group_id ms/PositiveInt][:user_id {:optional true} [:fn nil?]]- [:details {:optional true} [:fn empty?]]]]+ [:details {:optional true} [:fn empty?]]+ [:permissions_group {:optional true} [:maybe [:merge+ ::permissions.schema/permissions-group+ [:map {:closed true}+ [:members {:optional true} [:sequential ::permissions.schema/permissions-group.member]]]]]]]][:notification-recipient/raw-value[:map[:details [:map {:closed true}- [:value :any]+ [:value :string][:channel_id {:optional true} [:maybe :string]]]][:user_id {:optional true} [:fn nil?]][:permissions_group_id {:optional true} [:fn nil?]]]]@@ -442,13 +476,24 @@[[:card_id ms/PositiveInt][:notification_id {:optional true} [:maybe ms/PositiveInt]];; the hydrated Card, echoed back by clients on update; nothing here reads it- [:card {:optional true} [:maybe ms/Map]]+ [:card {:optional true} [:maybe [:merge+ ::queries.schema/card.update+ [:map {:closed true}+ [:id ms/PositiveInt]+ ;; a metric's Card row describes its query on the way out of the database+ [:query_description {:optional true} [:maybe :string]]+ [:created_at {:optional true} RowTimestamp]+ [:updated_at {:optional true} RowTimestamp]+ [:last_used_at {:optional true} RowTimestamp]]]]][:send_condition {:optional true} (ms/enum-decode-keyword card-subscription-send-conditions)]- [:send_once {:optional true} :boolean]])+ [:send_once {:optional true} :boolean]+ [:disable_links {:optional true} [:maybe :boolean]]+ [:created_at {:optional true} RowTimestamp]+ [:updated_at {:optional true} RowTimestamp]])(defn- notification-card-schema[{:keys [with-id?]}]- (into [:map]+ (into [:map {:closed true}](cond->> notification-card-entries;; nil on an unsaved notification, e.g. the one POST /api/pulse/test builds to send a test alertwith-id? (into [[:id {:optional true} [:maybe ms/PositiveInt]]]))))@@ -507,8 +552,9 @@(mr/def ::NotificationCardUpdate"::NotificationCard restricted to what the update spec writes - `:id` comes from the URL's notification."- (into [:map] (update-input-entries notification-card-entries- (get-in notification-update-spec [:nested-specs :payload]))))+ (into [:map {:closed true}]+ (update-input-entries notification-card-entries+ (get-in notification-update-spec [:nested-specs :payload]))));; ------------------------------------------------------------------------------------------------;;;; Helpers ;;@@ -610,6 +656,22 @@;; Public APIs ;;;; ------------------------------------------------------------------------------------------------;;+(mr/def ::SystemEventPayload.request+ "The `:payload` of a system event notification as a client may send it: the event topic, plus the `:disable_links`+ `POST /api/notification` stamps on. The event map itself is the server's to supply, so a request carries none."+ [:map {:closed true}+ [:event_topic {:optional true} [:fn #(= "event" (-> % keyword namespace))]]+ [:disable_links {:optional true} [:maybe :boolean]]])++(mr/def ::SystemEventPayload+ "The `:payload` of a system event notification on its way to being sent: a [[::SystemEventPayload.request]] plus+ the event map published under the topic, keyed the way [[metabase.events.core/publish-event!]] was handed it. A+ `:notification/testing` notification's payload is empty."+ [:merge+ ::SystemEventPayload.request+ [:map {:closed true}+ [:event_info {:optional true} [:maybe [:map-of :keyword :any]]]]])+(defn hydrated-notification-schema"Schema for a notification hydrated with its creator, subscriptions and handlers, where each handler matches`handler-schema`. Callers supply the handler schema because API input accepts a narrower set of templates than what@@ -618,25 +680,29 @@(hydrated-notification-schema handler-schema {:with-id? true}))([handler-schema {:keys [with-id? update-input?] :as opts}](let [entries (into (notification-entries opts)- (cond->> [;; the hydrated User, echoed back by clients on update; `:creator_id` is what gets read- [:creator {:optional true} [:maybe ms/Map]]- [:creator_id {:optional true} [:maybe int?]]+ (cond->> [;; the hydrated User, echoed back by clients on update; `:creator_id`, declared by+ [:creator {:optional true} [:maybe ::EchoedUser]][:subscriptions {:optional true} [:sequential [:ref (if with-id?::NotificationSubscription::CreateNotificationSubscriptionParams)]]][:handlers {:optional true} [:sequential handler-schema]]]- with-id? (into [[:payload_id {:optional true} [:maybe int?]]])))+ with-id? (into [[:payload_id {:optional true} [:maybe int?]]+ [:triggering_subscription {:optional true} [:maybe ::NotificationSubscription]]])))entries (cond-> entriesupdate-input? (update-input-entries notification-update-spec))][:merge- (into [:map] entries)+ (into [:map {:closed true}] entries)[:multi {:decode/normalize lib.schema.common/normalize-map-no-kebab-case:dispatch (comp keyword :payload_type)}- [:notification/card [:map [:payload [:ref (cond- update-input? ::NotificationCardUpdate- with-id? ::NotificationCard- :else ::CreateNotificationCardParams)]]]]- [::mc/default [:map]]]])))+ [:notification/card [:map {:closed true}+ [:payload [:ref (cond+ update-input? ::NotificationCardUpdate+ with-id? ::NotificationCard+ :else ::CreateNotificationCardParams)]]]]+ [::mc/default [:map {:closed true}+ [:payload {:optional true} [:maybe (if (or update-input? (not with-id?))+ ::SystemEventPayload.request+ ::SystemEventPayload)]]]]]])))(mr/def ::FullyHydratedNotification"Fully hydrated notification."diff --git a/src/metabase/oauth_server/api/admin.clj b/src/metabase/oauth_server/api/admin.cljindex 1dc06509643..751457c3b9c 100644--- a/src/metabase/oauth_server/api/admin.clj+++ b/src/metabase/oauth_server/api/admin.clj@@ -29,7 +29,7 @@"List OAuth dynamic client registration events (registered, approved, or denied), newest first.Joins client info and, for decision events, the deciding user. Superuser only."[_route-params- {:keys [client-id event-type]} :- [:map+ {:keys [client-id event-type]} :- [:map {:closed true}[:client-id {:optional true} [:maybe ms/NonBlankString]][:event-type {:optional true} [:maybe [:enum "registered" "approved" "denied"]]]]](api/check-superuser)diff --git a/src/metabase/oauth_server/api/oauth.clj b/src/metabase/oauth_server/api/oauth.cljindex a8b7808c47e..763ac02ffe8 100644--- a/src/metabase/oauth_server/api/oauth.clj+++ b/src/metabase/oauth_server/api/oauth.clj@@ -5,7 +5,6 @@[buddy.core.mac :as mac][buddy.core.nonce :as nonce][clojure.string :as str]- [malli.core :as mc][metabase.api-scope.core :as api-scope][metabase.api.macros :as api.macros][metabase.oauth-server.consent-page :as consent-page]@@ -194,7 +193,7 @@_query-paramsbody :- [:maybe {:decode/api {:enter (fn [body] (when (map? body) body))}};; the RFC 7591 client metadata we keep -- see the column list in `metabase.oauth-server.store`- [:map+ [:map {:closed true}[:application_type {:optional true} [:maybe :string]][:client_name {:optional true} [:maybe :string]][:client_uri {:optional true} [:maybe :string]]@@ -252,7 +251,7 @@(api.macros/defendpoint :get "/register/:client-id":- [:map [:status [:enum 200 401 404]] [:body :map]]"Handles client configuration read (RFC 7592)."- [{:keys [client-id]} :- [:map+ [{:keys [client-id]} :- [:map {:closed true}[:client-id ms/NonBlankString]]_query-params_body@@ -274,7 +273,7 @@:- [:map [:status [:enum 200 302 400 404]] [:body [:or :string :map]]]"Handles the authorization endpoint (GET /oauth/authorize)."[_route-params- query-params :- [:map+ query-params :- [:map {:closed true}[:client_id {:optional true} [:maybe :string]][:response_type {:optional true} [:maybe :string]][:redirect_uri {:optional true} [:maybe :string]]@@ -283,8 +282,7 @@[:code_challenge {:optional true} [:maybe :string]][:code_challenge_method {:optional true} [:maybe :string]][:nonce {:optional true} [:maybe :string]]- [:resource {:optional true} [:maybe [:or :string [:sequential :string]]]]- [::mc/default [:map-of :keyword :string]]]+ [:resource {:optional true} [:maybe [:or :string [:sequential :string]]]]]_bodyrequest](if-not (:metabase-user-id request)@@ -321,7 +319,7 @@"Handles the authorization decision (POST /oauth/authorize/decision)."[_route-params_query-params- body :- [:map {:decode/api {:enter (fn [body] (if (map? body) body {}))}}+ body :- [:map {:closed true, :decode/api {:enter (fn [body] (if (map? body) body {}))}}[:csrf_token {:optional true} [:maybe :string]][:params_sig {:optional true} [:maybe :string]][:approved {:optional true} [:maybe :string]]@@ -333,8 +331,7 @@[:code_challenge {:optional true} [:maybe :string]][:code_challenge_method {:optional true} [:maybe :string]][:nonce {:optional true} [:maybe :string]]- [:resource {:optional true} [:maybe [:or :string [:sequential :string]]]]- [::mc/default [:map-of :keyword :string]]]+ [:resource {:optional true} [:maybe [:or :string [:sequential :string]]]]]request](if-not (:metabase-user-id request){:status 401@@ -379,7 +376,7 @@"Handles the token endpoint (POST /oauth/token)."[_route-params_query-params- body :- [:map {:decode/api {:enter (fn [body] (if (map? body) body {}))}}+ body :- [:map {:closed true, :decode/api {:enter (fn [body] (if (map? body) body {}))}}[:grant_type {:optional true} [:maybe :string]][:code {:optional true} [:maybe :string]][:redirect_uri {:optional true} [:maybe :string]]@@ -388,8 +385,7 @@[:client_secret {:optional true} [:maybe :string]][:scope {:optional true} [:maybe :string]][:code_verifier {:optional true} [:maybe :string]]- [:resource {:optional true} [:maybe [:or :string [:sequential :string]]]]- [::mc/default [:map-of :keyword :string]]]+ [:resource {:optional true} [:maybe [:or :string [:sequential :string]]]]]request](let [ip-address (request/ip-address request);; Fall back to IP when client_id isn't in the body (e.g. confidential clients using@@ -423,7 +419,7 @@"Handles the token revocation endpoint (POST /oauth/revoke) per RFC 7009."[_route-params_query-params- _body :- [:map {:decode/api {:enter (fn [body] (if (map? body) body {}))}}+ _body :- [:map {:closed true :decode/api {:enter (fn [body] (if (map? body) body {}))}}[:token {:optional true} [:maybe :string]][:token_type_hint {:optional true} [:maybe :string]][:client_id {:optional true} [:maybe :string]]diff --git a/src/metabase/osi/ai_context/api.clj b/src/metabase/osi/ai_context/api.cljindex e700e71ab48..53043e79993 100644--- a/src/metabase/osi/ai_context/api.clj+++ b/src/metabase/osi/ai_context/api.clj@@ -30,7 +30,7 @@"OSI ai_context blob. All fields optional; extra keys tolerated for forward-compat with the OSI spec.String and list lengths are capped so a single curated entity can't bloat the index, its embeddings, orthe agent prompt."- [:map {:closed false}+ [:map {:closed true}[:instructions {:optional true} [:maybe [:string {:max entity-retrieval/max-instructions-len}]]][:synonyms {:optional true} [:sequential {:max max-list-len} [:string {:max max-item-len}]]][:examples {:optional true} [:sequential {:max max-list-len} [:string {:max max-item-len}]]]])@@ -66,7 +66,7 @@;; entity-type is any non-blank string at the route level — a write to a non-writable type gets a clear;; 400 in the handler (an enum here would 404 the route instead), and reads/deletes of an unknown type;; simply find no row and 404.- [:map+ [:map {:closed true}[:entity-type ms/NonBlankString][:entity-local-id ms/PositiveInt]])@@ -102,7 +102,7 @@upsert keep two concurrent writers from racing in a duplicate row."[{:keys [entity-type entity-local-id]} :- logical-key-route-schema_query-params- {:keys [ai_context]} :- [:map [:ai_context AiContextInput]]]+ {:keys [ai_context]} :- [:map {:closed true} [:ai_context AiContextInput]]](api/check-superuser)(api/check-400 (contains? writable-entity-types entity-type)"entity_type must be one of: measure, metric, model, segment, table")diff --git a/src/metabase/parameters/custom_values.clj b/src/metabase/parameters/custom_values.cljindex d5285bd5bc5..9c981af6ec9 100644--- a/src/metabase/parameters/custom_values.clj+++ b/src/metabase/parameters/custom_values.clj@@ -196,7 +196,7 @@`default-case-thunk` is a 0-arity function that returns values list when:- :values_source_type = card but the card is archived or the card no longer contains the value-field.- :values_source_type = nil."- [parameter :- ::parameters.schema/parameter+ [parameter :- ::parameters.schema/resolved-parameterquery-string :- [:maybe ms/NonBlankString]default-case-thunk :- [:=> [:cat :any] ms/FieldValuesResult]](case (:values_source_type parameter)@@ -266,7 +266,7 @@the function `default-case-thunk`.`default-case-thunk` is a 0-arity function that returns values list when :values_source_type = nil."- [param :- ::parameters.schema/parameter+ [param :- ::parameters.schema/resolved-parametervaluedefault-case-thunk :- [:=> [:cat] :any]](case (:values_source_type param)diff --git a/src/metabase/parameters/dashboard.clj b/src/metabase/parameters/dashboard.cljindex 5076df4ed52..1ac85731541 100644--- a/src/metabase/parameters/dashboard.clj+++ b/src/metabase/parameters/dashboard.clj@@ -19,7 +19,7 @@1000)(mu/defn- param->fields- [param :- ::parameters.schema/parameter & {:keys [op-override]}]+ [param :- ::parameters.schema/resolved-parameter & {:keys [op-override]}](let [op (or op-override (params/param-type->op (:type param)))options (or (:options param) (params/param-type->default-options (:type param)))](for [field-id (params/dashboard-param->field-ids param)]@@ -78,7 +78,7 @@([dashboard param-key constraint-param-key->value](chain-filter dashboard param-key constraint-param-key->value nil))- ([dashboard :- ms/Map+ ([dashboard :- :mapparam-key :- ms/NonBlankStringconstraint-param-key->value :- [:map-of string? any?]query :- [:maybe ms/NonBlankString]]diff --git a/src/metabase/parameters/params.clj b/src/metabase/parameters/params.cljindex 219757213af..fc06ede5bed 100644--- a/src/metabase/parameters/params.clj+++ b/src/metabase/parameters/params.clj@@ -225,7 +225,7 @@columns)."[:map[:dashcard :map]- [:param-mapping ::parameters.schema/parameter-mapping]+ [:param-mapping ::parameters.schema/parameter-mapping-with-dashcard][:param-target-field-id [:maybe ::lib.schema.id/field]]])(mu/defn- card->filterable-columns-query :- [:maybe ::lib.schema/query]@@ -365,7 +365,7 @@"Build the `param-dashcard-info` for a parameter `mapping` on `dashcard`, resolving `:param-target-field-id` when thetarget is already field-id-based."[dashcard :- :map- mapping :- ::parameters.schema/parameter-mapping]+ mapping :- ::parameters.schema/parameter-mapping-with-dashcard](let [card (find-card-for-mapping dashcard mapping)]{:dashcard dashcard:param-mapping mapping@@ -424,7 +424,7 @@(mu/defn dashboard-param->field-ids :- [:set ::lib.schema.id/field]"Return field ids mapped to the parameter. `dashcard` and `card` must be present for each mapping."- [{:keys [mappings]} :- ::parameters.schema/parameter]+ [{:keys [mappings]} :- ::parameters.schema/resolved-parameter](let [param-dashcard-infos (mapv (fn [mapping](mapping->param-dashcard-info (:dashcard mapping) mapping))mappings)]diff --git a/src/metabase/parameters/schema.cljc b/src/metabase/parameters/schema.cljcindex 7b695712b37..470f34c8855 100644--- a/src/metabase/parameters/schema.cljc+++ b/src/metabase/parameters/schema.cljc@@ -41,8 +41,8 @@"Schema for valid source_options within a Parameter";; TODO: This should be tighter[:map- {:decode/normalize normalize-values-source-config}- [:values {:optional true} [:* :any]]+ {:closed true :decode/normalize normalize-values-source-config}+ [:values {:optional true} [:* [:schema [:ref ::lib.schema.parameter/values-source-config.value]]]][:card_id {:optional true} ::lib.schema.id/card][:value_field {:optional true} [:ref ::legacy-ref]][:label_field {:optional true} [:ref ::legacy-ref]]])@@ -61,7 +61,7 @@[:values_source_type :string][:values_source_config[:map {:closed true}- [:values {:optional true} [:* :any]]]]]]]))+ [:values {:optional true} [:* [:schema [:ref ::lib.schema.parameter/values-source-config.value]]]]]]]]]))(mr/def ::values-source-type[:enum {:decode/normalize lib.schema.common/normalize-keyword} :static-list :card])@@ -75,12 +75,14 @@queries.";; TODO we could use :multi to dispatch values_source_type to the correct values_source_config[:map- {:description "parameter must be a map with :id and :type keys"+ {:closed true+ :description "parameter must be a map with :id and :type keys":decode/normalize lib.schema.common/normalize-map-no-kebab-case}[:default {:optional true} [:ref ::lib.schema.parameter/parameter.value]][:display-name {:optional true} [:maybe :string]];; TODO (Cam 9/18/25) -- why are we mixing `camelCase` and `snake_case` here? Is this to make me sad?[:filteringParameters {:optional true} [:maybe [:sequential ::lib.schema.parameter/id]]]+ [:hasVariableTemplateTagTarget {:optional true} [:maybe :boolean]][:id ::lib.schema.parameter/id];; whether the widget lets you pick more than one value. Saved on the parameter by the "A single value"/"Multiple;; values" picker, and read back by the frontend to choose the widget, so it has to survive a round trip.@@ -90,6 +92,7 @@[:set [:ref ::parameter-mapping]]]]][:name {:optional true} :string][:options {:optional true} [:maybe [:ref ::lib.schema.parameter/parameter.options]]]+ [:position {:optional true} [:maybe :int]][:required {:optional true} [:maybe :boolean]];; ok now I know you're trying to mess with me with this camelCase key[:sectionId {:optional true} ::lib.schema.common/non-blank-string]@@ -155,7 +158,8 @@the frontend's `normalizeParameters` sends. Distinct from `::lib.schema.parameter/parameter`, which requires `:type`and normalizes the value."[:map- {:description "parameter must be a map with an :id key"+ {:closed true+ :description "parameter must be a map with an :id key":decode/normalize lib.schema.common/normalize-map-no-kebab-case}[:id ::lib.schema.common/non-blank-string];; the name of the template tag this value is for, when it can't be inferred from `:target`@@ -187,7 +191,8 @@(mr/def ::parameter-mapping"Schema for a valid Parameter Mapping"[:map- {:decode/normalize (fn [mapping]+ {:closed true+ :decode/normalize (fn [mapping](when (map? mapping)(let [mapping (lib.schema.common/normalize-map-no-kebab-case mapping)](cond-> mapping@@ -224,4 +229,12 @@[:merge[:ref ::parameter-mapping][:map- [:dashcard :map]]])+ [:dashcard {:optional true} :map]]])++(mr/def ::resolved-parameter+ "A dashboard parameter with its `:mappings` resolved against the DashboardCards that carry them, as the+ `:resolved-params` hydration builds it."+ [:merge+ [:ref ::parameter]+ [:map {:closed true}+ [:mappings {:optional true} [:maybe [:set [:ref ::parameter-mapping-with-dashcard]]]]]])diff --git a/src/metabase/permissions/schema.clj b/src/metabase/permissions/schema.cljindex a70bd78f047..1ed6e256be4 100644--- a/src/metabase/permissions/schema.clj+++ b/src/metabase/permissions/schema.clj@@ -130,6 +130,15 @@[:perm_type {:optional true} [:maybe [:or :keyword :string]]][:collection_id {:optional true} [:maybe ::lib.schema.id/collection]]])+(mr/def ::data-access-token+ "A persisted [[metabase.permissions.data-access-token/data-access-token]]: the lens a piece of content was produced+ under, as digests of the sandbox, impersonation and routing tokens that applied, keyed by table or database id. A+ lens with nothing applied is `{}`."+ [:map {:closed true}+ [:sandbox {:optional true} [:map-of ms/PositiveInt :string]]+ [:impersonation {:optional true} [:map-of ms/PositiveInt :string]]+ [:routing {:optional true} [:map-of ms/PositiveInt :string]]])+(mr/def ::permissions-group"A PermissionsGroup as selected from the app DB: every column of `:permissions_group`."[:map {:closed true}@@ -139,6 +148,22 @@[:magic_group_type [:maybe [:or :keyword :string]]][:is_tenant_group :boolean]])+(mr/def ::permissions-group.member+ "A member of a PermissionsGroup as `metabase.permissions.db/group-members` selects it: the User columns the group+ member list shows, the membership it comes from, and `:is_group_manager` when advanced permissions are enabled."+ [:map {:closed true}+ [:id ms/PositiveInt]+ [:user_id ms/PositiveInt]+ [:first_name [:maybe :string]]+ [:last_name [:maybe :string]]+ [:email :string]+ [:is_superuser :boolean]+ [:type [:or :keyword :string]]+ [:group_id ms/PositiveInt]+ [:membership_id ms/PositiveInt]+ [:is_group_manager {:optional true} [:maybe :boolean]]+ [:common_name {:optional true} [:maybe :string]]])+(mr/def ::permissions-group.update"What an update (or insert) of a PermissionsGroup accepts: every column of `:permissions_group` except `id`, all optional."[:map {:closed true}diff --git a/src/metabase/permissions_rest/api.clj b/src/metabase/permissions_rest/api.cljindex 9f312f839aa..9d489dbe8c7 100644--- a/src/metabase/permissions_rest/api.clj+++ b/src/metabase/permissions_rest/api.clj@@ -33,7 +33,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/graph/db/:db-id""Fetch a graph of all Permissions for db-id `db-id`."- [{:keys [db-id]} :- [:map+ [{:keys [db-id]} :- [:map {:closed true}[:db-id ms/PositiveInt]]](api/check-superuser)(data-perms.graph/api-graph {:db-id db-id}))@@ -44,7 +44,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/graph/group/:group-id""Fetch a graph of all Permissions for group-id `group-id`."- [{:keys [group-id]} :- [:map+ [{:keys [group-id]} :- [:map {:closed true}[:group-id ms/PositiveInt]]](api/check-superuser)(api/check-404 (empty? (perms/hidden-tenant-group-ids [group-id])))@@ -83,7 +83,7 @@If the skip-graph query param is truthy, then the graph will not be returned."[_route-params- {:keys [skip-graph force]} :- [:map+ {:keys [skip-graph force]} :- [:map {:closed true}[:skip-graph {:default false} [:maybe ms/BooleanValue]][:force {:default false} [:maybe ms/BooleanValue]]]new-graph :- ::permissions-rest.schema/graph-update-request]@@ -156,7 +156,7 @@- `tenancy=internal`: Returns only non-tenant groups (where `is_tenant_group = false`)- No `tenancy` parameter: Returns all groups (default behavior)"[_route_params- {:keys [tenancy]} :- [:map+ {:keys [tenancy]} :- [:map {:closed true}[:tenancy {:optional true} [:enum "external" "internal"]]]](try(perms/check-group-manager)@@ -180,7 +180,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/group/:id""Fetch the details for a certain permissions group."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](perms/check-manager-of-group id)(api/check-404 (empty? (perms/hidden-tenant-group-ids [id])))@@ -197,7 +197,7 @@never included. The ids are otherwise unfiltered; system-managed groups like Data Analysts appear when they hold agrant, and clients intersect the ids with the groups they display. Superuser-only, like the invite action itself."[_route-params- {:keys [id] item-type :type} :- [:map+ {:keys [id] item-type :type} :- [:map {:closed true}[:type [:enum "dashboard" "question"]][:id ms/PositiveInt]]](api/check-superuser)@@ -215,7 +215,7 @@"Create a new `PermissionsGroup`."[_route-params_query-params- {:keys [name is_tenant_group]} :- [:map+ {:keys [name is_tenant_group]} :- [:map {:closed true}[:name ms/NonBlankString][:is_tenant_group {:optional true} [:maybe :boolean]]]](api/check-superuser)@@ -235,10 +235,10 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :put "/group/:group-id""Update the name of a `PermissionsGroup`."- [{:keys [group-id]} :- [:map+ [{:keys [group-id]} :- [:map {:closed true}[:group-id ms/PositiveInt]]_query-params- {:keys [name]} :- [:map+ {:keys [name]} :- [:map {:closed true}[:name ms/NonBlankString]]](perms/check-manager-of-group group-id)(api/check-404 (empty? (perms/hidden-tenant-group-ids [group-id])))@@ -258,7 +258,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/group/:group-id""Delete a specific `PermissionsGroup`."- [{:keys [group-id]} :- [:map+ [{:keys [group-id]} :- [:map {:closed true}[:group-id ms/PositiveInt]]](perms/check-manager-of-group group-id)(api/check-404 (empty? (perms/hidden-tenant-group-ids [group-id])))@@ -299,7 +299,7 @@"Add a `User` to a `PermissionsGroup`. Returns updated list of members belonging to the group."[_route-params_query-params- {:keys [group_id user_id is_group_manager]} :- [:map+ {:keys [group_id user_id is_group_manager]} :- [:map {:closed true}[:group_id ms/PositiveInt][:user_id ms/PositiveInt][:is_group_manager {:default false} [:maybe :boolean]]]]@@ -323,10 +323,10 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :put "/membership/:id""Update a Permission Group membership. Returns the updated record."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-params- {:keys [is_group_manager]} :- [:map+ {:keys [is_group_manager]} :- [:map {:closed true}[:is_group_manager :boolean]]];; currently this API is only used to update the `is_group_manager` flag and it requires advanced-permissions(perms/check-advanced-permissions-enabled :group-manager)@@ -348,7 +348,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :put "/membership/:group-id/clear""Remove all members from a `PermissionsGroup`. Returns a 400 (Bad Request) if the group ID is for the admin group."- [{:keys [group-id]} :- [:map+ [{:keys [group-id]} :- [:map {:closed true}[:group-id ms/PositiveInt]]](perms/check-manager-of-group group-id)(api/check-404 (permissions-rest.db/permissions-group-exists? group-id))@@ -363,7 +363,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/membership/:id""Remove a User from a PermissionsGroup (delete their membership)."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](let [membership (permissions-rest.db/group-membership id)](api/check-404 membership)diff --git a/src/metabase/permissions_rest/schema.clj b/src/metabase/permissions_rest/schema.cljindex 333afdc2d6a..87fc636b91b 100644--- a/src/metabase/permissions_rest/schema.clj+++ b/src/metabase/permissions_rest/schema.clj@@ -49,7 +49,7 @@(mr/def ::table-perms(named-or-granular- [:map+ [:map {:closed true}[:read {:optional true} [:enum :all :none]][:query {:optional true} [:enum :all :none :segmented]]]))@@ -92,7 +92,7 @@:no]]])(mr/def ::data-perms- [:map+ [:map {:closed true}[:native {:optional true} [:ref ::native]][:schemas {:optional true} [:ref ::schemas]]])@@ -160,7 +160,7 @@(mr/def ::sandbox-update"a sandbox to write alongside a permissions graph update"[:and- [:map+ [:map {:closed true}[:id {:optional true} ms/PositiveInt][:group_id {:optional true} ms/PositiveInt][:table_id {:optional true} ms/PositiveInt]@@ -173,14 +173,14 @@(mr/def ::impersonation-update"a connection impersonation policy to write alongside a permissions graph update"- [:map+ [:map {:closed true}[:group_id ms/PositiveInt][:db_id ms/PositiveInt][:attribute ms/NonBlankString]])(mr/def ::graph-update-request"the permissions graph, plus the sandboxes and connection impersonations to write with it"- [:map+ [:map {:closed true}[:groups [:and[:multi {:dispatch map?}[true [:map-ofdiff --git a/src/metabase/product_feedback/api.clj b/src/metabase/product_feedback/api.cljindex 787f014eade..907d44c75b5 100644--- a/src/metabase/product_feedback/api.clj+++ b/src/metabase/product_feedback/api.clj@@ -35,7 +35,7 @@"Endpoint to provide feedback from the product"[_route-params_query-params- {:keys [comments source email]} :- [:map+ {:keys [comments source email]} :- [:map {:closed true}[:comments {:optional true} [:maybe ms/NonBlankString]][:source ms/NonBlankString][:email {:optional true} [:maybe ms/NonBlankString]]]]diff --git a/src/metabase/public_sharing_rest/api.clj b/src/metabase/public_sharing_rest/api.cljindex 97d22d72804..1a9b20fc436 100644--- a/src/metabase/public_sharing_rest/api.clj+++ b/src/metabase/public_sharing_rest/api.clj@@ -15,6 +15,7 @@[metabase.lib.core :as lib][metabase.lib.metadata :as lib.metadata][metabase.lib.schema.info :as lib.schema.info]+ [metabase.lib.schema.parameter :as lib.schema.parameter][metabase.models.interface :as mi][metabase.parameters.dashboard :as parameters.dashboard][metabase.parameters.params :as params]@@ -130,7 +131,7 @@(api.macros/defendpoint :get "/card/:uuid""Fetch a publicly-accessible Card an return query results as well as `:card` information. Does not require authcredentials. Public sharing must be enabled."- [{:keys [uuid]} :- [:map+ [{:keys [uuid]} :- [:map {:closed true}[:uuid ms/UUIDString]]](public-sharing.validation/check-public-sharing-enabled)(card-with-uuid uuid))@@ -217,9 +218,9 @@(api.macros/defendpoint :get "/card/:uuid/query""Fetch a publicly-accessible Card an return query results as well as `:card` information. Does not require authcredentials. Public sharing must be enabled."- [{:keys [uuid]} :- [:map+ [{:keys [uuid]} :- [:map {:closed true}[:uuid ms/UUIDString]]- {:keys [parameters]} :- [:map+ {:keys [parameters]} :- [:map {:closed true}[:parameters {:optional true} [:maybe ::parameters.schema/api.parameter-values]][:ignore_cache {:optional true} [:maybe ms/BooleanValue]]]](process-query-for-card-with-public-uuid uuid :api parameters))@@ -235,10 +236,10 @@(api.macros/defendpoint :get "/card/:uuid/query/:export-format""Fetch a publicly-accessible Card and return query results in the specified format. Does not require authcredentials. Public sharing must be enabled."- [{:keys [uuid export-format]} :- [:map+ [{:keys [uuid export-format]} :- [:map {:closed true}[:uuid ms/UUIDString][:export-format ::qp.schema/export-format]]- {:keys [parameters format_rows pivot_results]} :- [:map+ {:keys [parameters format_rows pivot_results]} :- [:map {:closed true}[:format_rows {:default false} :boolean][:pivot_results {:default false} :boolean][:parameters {:optional true} [:maybe ::parameters.schema/api.parameter-values]]@@ -318,9 +319,9 @@:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/dashboard/:uuid""Fetch a publicly-accessible Dashboard. Does not require auth credentials. Public sharing must be enabled."- [{:keys [uuid]} :- [:map+ [{:keys [uuid]} :- [:map {:closed true}[:uuid ms/UUIDString]]- _query-params :- [:map+ _query-params :- [:map {:closed true}[:dashboard_load_id {:optional true} [:maybe ms/NonBlankString]]]](public-sharing.validation/check-public-sharing-enabled)(u/prog1 (dashboard-with-uuid uuid)@@ -383,11 +384,11 @@(api.macros/defendpoint :get "/dashboard/:uuid/dashcard/:dashcard-id/card/:card-id""Fetch the results for a Card in a publicly-accessible Dashboard. Does not require auth credentials. Publicsharing must be enabled."- [{:keys [uuid dashcard-id card-id]} :- [:map+ [{:keys [uuid dashcard-id card-id]} :- [:map {:closed true}[:uuid ms/UUIDString][:dashcard-id ms/PositiveInt][:card-id ms/PositiveInt]]- {:keys [parameters]} :- [:map+ {:keys [parameters]} :- [:map {:closed true}[:parameters {:optional true} [:maybe ::parameters.schema/api.parameter-values]][:ignore_cache {:optional true} [:maybe ms/BooleanValue]]]](public-sharing.validation/check-public-sharing-enabled)@@ -409,13 +410,13 @@:export-format qp.schema/export-formats-regex]"Fetch the results of running a publicly-accessible Card belonging to a Dashboard and return the data in one of theexport formats. Does not require auth credentials. Public sharing must be enabled."- [{:keys [uuid dashcard-id card-id export-format]} :- [:map+ [{:keys [uuid dashcard-id card-id export-format]} :- [:map {:closed true}[:uuid ms/UUIDString][:dashcard-id ms/PositiveInt][:card-id ms/PositiveInt][:export-format ::qp.schema/export-format]]_query-parameters- {:keys [format_rows pivot_results parameters]} :- [:map+ {:keys [format_rows pivot_results parameters]} :- [:map {:closed true}[:parameters {:optional true} [:maybe ::parameters.schema/api.parameter-values]][:format_rows {:default false} ms/BooleanValue][:pivot_results {:default false} ms/BooleanValue]@@ -439,11 +440,11 @@"Fetches the values for filling in execution parameters. Pass PK parameters and values to select.Parameters are sent in the request body rather than the query string so their values stay out of URLs and logs."- [{:keys [uuid dashcard-id]} :- [:map+ [{:keys [uuid dashcard-id]} :- [:map {:closed true}[:uuid ms/UUIDString][:dashcard-id ms/PositiveInt]]_query-params- {:keys [parameters]} :- [:map+ {:keys [parameters]} :- [:map {:closed true}[:parameters ::actions.schema/prefetch-parameter-values]]](public-sharing.validation/check-public-sharing-enabled)(let [dashboard-id (api/check-404 (public-sharing/public-uuid->id :model/Dashboard uuid))]@@ -462,11 +463,11 @@"Execute the associated Action in the context of a `Dashboard` and `DashboardCard` that includes it.`parameters` should be the mapped dashboard parameters with values."- [{:keys [uuid dashcard-id]} :- [:map+ [{:keys [uuid dashcard-id]} :- [:map {:closed true}[:uuid ms/UUIDString][:dashcard-id ms/PositiveInt]]_query-params- {:keys [parameters], :as _body} :- [:map+ {:keys [parameters], :as _body} :- [:map {:closed true}[:parameters {:optional true} [:maybe ::actions.schema/execute-parameter-values]][:modelId {:optional true} [:maybe ms/PositiveInt]]]](let [throttle-message (try@@ -507,7 +508,7 @@"oEmbed endpoint used to retrieve embed code and metadata for a (public) Metabase URL."[_route-params{:keys [url maxheight maxwidth]}- :- [:map+ :- [:map {:closed true}[:url ms/NonBlankString][:format {:optional true} [:maybe{:description (str "The format param is not used by the API, but is required as"@@ -531,7 +532,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/action/:uuid""Fetch a publicly-accessible Action. Does not require auth credentials. Public sharing must be enabled."- [{:keys [uuid]} :- [:map+ [{:keys [uuid]} :- [:map {:closed true}[:uuid ms/UUIDString]]](public-sharing.validation/check-public-sharing-enabled)(let [action (api/check-404 (actions/select-action :id (public-sharing/public-uuid->id :model/Action uuid)))]@@ -550,7 +551,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/card/:uuid/params/:param-key/values""Fetch values for a parameter on a public card."- [{:keys [uuid param-key]} :- [:map+ [{:keys [uuid param-key]} :- [:map {:closed true}[:uuid ms/UUIDString][:param-key ms/NonBlankString]]](public-sharing.validation/check-public-sharing-enabled)@@ -564,7 +565,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/card/:uuid/params/:param-key/search/:query""Fetch values for a parameter on a public card containing `query`."- [{:keys [uuid param-key query]} :- [:map+ [{:keys [uuid param-key query]} :- [:map {:closed true}[:uuid ms/UUIDString][:param-key ms/NonBlankString][:query ms/NonBlankString]]]@@ -579,10 +580,10 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/card/:uuid/params/:param-key/remapping""Fetch the remapped value for the given `value` of parameter with ID `:param-key` of card with UUID `uuid`."- [{:keys [uuid param-key]} :- [:map+ [{:keys [uuid param-key]} :- [:map {:closed true}[:uuid ms/UUIDString][:param-key ms/NonBlankString]]- {:keys [value]} :- [:map [:value :string]]]+ {:keys [value]} :- [:map {:closed true} [:value :string]]](public-sharing.validation/check-public-sharing-enabled)(let [card (public-sharing/public-uuid->model :model/Card uuid)](request/as-admin@@ -594,10 +595,10 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/dashboard/:uuid/params/:param-key/values""Fetch filter values for dashboard parameter `param-key`."- [{:keys [uuid param-key]} :- [:map+ [{:keys [uuid param-key]} :- [:map {:closed true}[:uuid ms/UUIDString][:param-key ms/NonBlankString]]- constraint-param-key->value :- [:map-of string? any?]]+ constraint-param-key->value :- (ms/string-keyed-map [:ref ::lib.schema.parameter/parameter.value])](public-sharing.validation/check-public-sharing-enabled)(let [dashboard (dashboard-with-uuid-for-param-values uuid)](request/as-admin@@ -610,11 +611,11 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/dashboard/:uuid/params/:param-key/search/:query""Fetch filter values for dashboard parameter `param-key`, containing specified `query`."- [{:keys [uuid param-key query]} :- [:map+ [{:keys [uuid param-key query]} :- [:map {:closed true}[:uuid ms/UUIDString][:param-key ms/NonBlankString][:query ms/NonBlankString]]- constraint-param-key->value :- [:map-of string? any?]]+ constraint-param-key->value :- (ms/string-keyed-map [:ref ::lib.schema.parameter/parameter.value])](public-sharing.validation/check-public-sharing-enabled)(let [dashboard (dashboard-with-uuid-for-param-values uuid)](request/as-admin@@ -627,10 +628,10 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/dashboard/:uuid/params/:param-key/remapping""Fetch the remapped value for the given `value` of parameter with ID `:param-key` of dashboard with UUID `uuid`."- [{:keys [uuid param-key]} :- [:map+ [{:keys [uuid param-key]} :- [:map {:closed true}[:uuid ms/UUIDString][:param-key ms/NonBlankString]]- {:keys [value]} :- [:map [:value :string]]]+ {:keys [value]} :- [:map {:closed true} [:value :string]]](public-sharing.validation/check-public-sharing-enabled)(let [dashboard (dashboard-with-uuid-for-param-values uuid)](request/as-admin@@ -649,9 +650,9 @@(api.macros/defendpoint :get "/pivot/card/:uuid/query""Fetch a publicly-accessible Card an return query results as well as `:card` information. Does not require authcredentials. Public sharing must be enabled."- [{:keys [uuid]} :- [:map+ [{:keys [uuid]} :- [:map {:closed true}[:uuid ms/UUIDString]]- {:keys [parameters]} :- [:map+ {:keys [parameters]} :- [:map {:closed true}[:parameters {:optional true} [:maybe ::parameters.schema/api.parameter-values]][:ignore_cache {:optional true} [:maybe ms/BooleanValue]]]](process-query-for-card-with-public-uuid uuid :api parameters@@ -665,11 +666,11 @@(api.macros/defendpoint :get "/pivot/dashboard/:uuid/dashcard/:dashcard-id/card/:card-id""Fetch the results for a Card in a publicly-accessible Dashboard. Does not require auth credentials. Publicsharing must be enabled."- [{:keys [uuid dashcard-id card-id]} :- [:map+ [{:keys [uuid dashcard-id card-id]} :- [:map {:closed true}[:uuid ms/UUIDString][:card-id ms/PositiveInt][:dashcard-id ms/PositiveInt]]- {:keys [parameters]} :- [:map+ {:keys [parameters]} :- [:map {:closed true}[:parameters {:optional true} [:maybe ::parameters.schema/api.parameter-values]][:ignore_cache {:optional true} [:maybe ms/BooleanValue]]]](public-sharing.validation/check-public-sharing-enabled)@@ -702,10 +703,10 @@"Execute the Action.`parameters` should be the mapped dashboard parameters with values."- [{:keys [uuid]} :- [:map+ [{:keys [uuid]} :- [:map {:closed true}[:uuid ms/UUIDString]]_query-params- {:keys [parameters], :as _body} :- [:map+ {:keys [parameters], :as _body} :- [:map {:closed true}[:parameters {:optional true} [:maybe ::actions.schema/execute-parameter-values]]]](let [throttle-message (try(throttle/check action-execution-throttle uuid)@@ -745,13 +746,13 @@"Generates a single tile image for a publicly-accessible Card using the map visualization. Does not require authcredentials. Public sharing must be enabled."[{:keys [uuid zoom x y]}- :- [:map+ :- [:map {:closed true}[:uuid ms/UUIDString][:zoom ms/Int][:x ms/Int][:y ms/Int]]{:keys [parameters latField lonField]}- :- [:map+ :- [:map {:closed true}[:parameters {:optional true} ::parameters.schema/api.parameter-values][:latField ::api.tiles/legacy-ref][:lonField ::api.tiles/legacy-ref]]]@@ -768,7 +769,7 @@"Generates a single tile image for a Card using the map visualization in a publicly-accessible Dashboard. Does notrequire auth credentials. Public sharing must be enabled."[{:keys [uuid dashcard-id card-id zoom x y]}- :- [:map+ :- [:map {:closed true}[:uuid ms/UUIDString][:dashcard-id ms/PositiveInt][:card-id ms/PositiveInt]@@ -776,7 +777,7 @@[:x ms/Int][:y ms/Int]]{:keys [parameters latField lonField]}- :- [:map+ :- [:map {:closed true}[:parameters {:optional true} ::parameters.schema/api.parameter-values][:latField ::api.tiles/legacy-ref][:lonField ::api.tiles/legacy-ref]]]@@ -840,7 +841,7 @@Returns a Document with sensitive fields removed (excludes collection_id, permissions, creator details, etc.).Includes all embedded Cards with their metadata hydrated so the frontend doesn't need to make separaterequests for each card — just like public Dashboards do."- [{:keys [uuid]} :- [:map+ [{:keys [uuid]} :- [:map {:closed true}[:uuid ms/UUIDString]]](public-sharing.validation/check-public-sharing-enabled)(let [document (public-document (public-sharing/public-uuid->id :model/Document uuid))]@@ -854,10 +855,10 @@(api.macros/defendpoint :get "/document/:uuid/card/:card-id""Run a query for a Card that's embedded in a public Document. Doesn't require auth credentials. Public sharing mustbe enabled."- [{:keys [uuid card-id]} :- [:map+ [{:keys [uuid card-id]} :- [:map {:closed true}[:uuid ms/UUIDString][:card-id ms/PositiveInt]]- {:keys [parameters]} :- [:map+ {:keys [parameters]} :- [:map {:closed true}[:parameters {:optional true} [:maybe ::parameters.schema/api.parameter-values]]]](public-sharing.validation/check-public-sharing-enabled)(let [card (validate-card-in-public-document uuid card-id)]@@ -876,12 +877,12 @@(api.macros/defendpoint :post "/document/:uuid/card/:card-id/:export-format""Fetch a Card embedded in a public Document and return query results in the specified format.Does not require auth credentials. Public sharing must be enabled."- [{:keys [uuid card-id export-format]} :- [:map+ [{:keys [uuid card-id export-format]} :- [:map {:closed true}[:uuid ms/UUIDString][:card-id ms/PositiveInt][:export-format ::qp.schema/export-format]]_query-params- {:keys [parameters format_rows pivot_results]} :- [:map+ {:keys [parameters format_rows pivot_results]} :- [:map {:closed true}[:parameters {:optional true} [:maybe ::parameters.schema/api.parameter-values]][:format_rows {:default false} ms/BooleanValue][:pivot_results {:default false} ms/BooleanValue]diff --git a/src/metabase/pulse/api/alert.clj b/src/metabase/pulse/api/alert.cljindex a56ed499a97..fa7ff68983a 100644--- a/src/metabase/pulse/api/alert.clj+++ b/src/metabase/pulse/api/alert.clj@@ -87,7 +87,7 @@"Fetch alerts which the current user has created or will receive, or all alerts if the user is an admin.The optional `user_id` will return alerts created by the corresponding user, but is ignored for non-admin users."[_route-params- {:keys [archived user_id]} :- [:map+ {:keys [archived user_id]} :- [:map {:closed true}[:archived {:default false} [:maybe ms/BooleanValue]][:user_id {:optional true} [:maybe ms/PositiveInt]]]](let [user-id (if api/*is-superuser?*@@ -106,7 +106,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id""Fetch an alert by ID"- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](-> (notification.api/get-notification id)api/read-check@@ -118,7 +118,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/:id/subscription""For users to unsubscribe themselves from the given alert."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](notification.api/unsubscribe-user! id api/*current-user-id*)api/generic-204-no-content)diff --git a/src/metabase/pulse/api/pulse.clj b/src/metabase/pulse/api/pulse.cljindex 77863530db1..eddd6248eb1 100644--- a/src/metabase/pulse/api/pulse.clj+++ b/src/metabase/pulse/api/pulse.clj@@ -64,7 +64,7 @@{:keys [archived]dashboard-id :dashboard_idcreator-or-recipient :creator_or_recipient}- :- [:map+ :- [:map {:closed true}[:archived {:default false} [:maybe ms/BooleanValue]][:dashboard_id {:optional true} [:maybe ms/PositiveInt]][:creator_or_recipient {:default false} [:maybe ms/BooleanValue]]]]@@ -122,12 +122,12 @@[:int {:min 0 :max 23}])(def ^:private PulseChannelRecipient- [:map+ [:map {:closed true}[:id {:optional true} [:maybe ms/PositiveInt]][:email {:optional true} [:maybe ms/Email]]])(def ^:private PulseChannelDetails- [:map+ [:map {:closed true}[:attachment_only {:optional true} [:maybe :boolean]][:include_pdf {:optional true} [:maybe :boolean]][:channel {:optional true} [:maybe :string]]@@ -137,7 +137,7 @@(def ^:private PulseChannel"The fields [[metabase.pulse.models.pulse-channel/create-pulse-channel!]] reads off a channel."- [:map+ [:map {:closed true}[:id {:optional true} [:maybe ms/PositiveInt]][:channel_type PulseChannelType][:enabled {:optional true} [:maybe :boolean]]@@ -163,7 +163,7 @@collection-id :collection_idcollection-position :collection_positiondashboard-id :dashboard_id}- :- [:map+ :- [:map {:closed true}[:name ms/NonBlankString][:cards [:+ models.pulse/CoercibleToCardRef]][:channels [:+ PulseChannel]]@@ -192,7 +192,7 @@(api.macros/defendpoint :get "/:id""Fetch `Pulse` with ID. If the user is a recipient of the Pulse but does not have read permissions for its collection,we still return it but with some sensitive metadata removed."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](api/let-404 [pulse (models.pulse/retrieve-pulse id)](api/check-403 (mi/can-read? pulse))@@ -300,10 +300,10 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :put "/:id""Update a Pulse with `id`."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-params- pulse-updates :- [:map+ pulse-updates :- [:map {:closed true}[:name {:optional true} [:maybe ms/NonBlankString]][:cards {:optional true} [:maybe [:+ models.pulse/CoercibleToCardRef]]][:channels {:optional true} [:maybe [:+ PulseChannel]]]@@ -361,7 +361,7 @@"Test send an unsaved pulse."[_route-params_query-params- {:keys [cards channels] :as body} :- [:map+ {:keys [cards channels] :as body} :- [:map {:closed true};; the saved subscription this is a test send of, when there is one.;; `send-pulse!` builds the non-user unsubscribe link out of it, and the;; email template drops the whole "Unsubscribe" footer without a link@@ -403,7 +403,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/:id/subscription""For users to unsubscribe themselves from a pulse subscription."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](api/let-404 [pulse-id (pulse.db/pulse-id id)pc-id (pulse.db/email-pulse-channel-id pulse-id)diff --git a/src/metabase/pulse/api/unsubscribe.clj b/src/metabase/pulse/api/unsubscribe.cljindex 656c372221e..8e0fb67bf2c 100644--- a/src/metabase/pulse/api/unsubscribe.clj+++ b/src/metabase/pulse/api/unsubscribe.clj@@ -35,7 +35,7 @@"Allow non-users to unsubscribe from pulses/subscriptions, with the hash given through email."[_route-params_query-params- {:keys [email hash pulse-id]} :- [:map+ {:keys [email hash pulse-id]} :- [:map {:closed true}[:pulse-id ms/PositiveInt][:email :string][:hash :string]]@@ -60,7 +60,7 @@"Allow non-users to undo an unsubscribe from pulses/subscriptions, with the hash given through email."[_route-params_query-params- {:keys [email hash pulse-id]} :- [:map+ {:keys [email hash pulse-id]} :- [:map {:closed true}[:pulse-id ms/PositiveInt][:email :string][:hash :string]]diff --git a/src/metabase/pulse/models/pulse.clj b/src/metabase/pulse/models/pulse.cljindex fde28ff1e01..22b10120a64 100644--- a/src/metabase/pulse/models/pulse.clj+++ b/src/metabase/pulse/models/pulse.clj@@ -24,6 +24,7 @@[metabase.collections.models.collection :as collection][metabase.events.core :as events][metabase.models.interface :as mi]+ [metabase.parameters.schema :as parameters.schema][metabase.permissions.core :as perms][metabase.pulse.db :as pulse.db][metabase.pulse.models.pulse-channel :as pulse-channel]@@ -200,7 +201,7 @@"Schema for the map we use to internally represent the base elements of a Card used for Notifications. id is notrequired since the card may be a placeholder."(mu/with-api-error-message- [:map+ [:map {:closed true}[:include_csv ms/BooleanValue][:include_xls ms/BooleanValue][:format_rows {:optional true} [:maybe ms/BooleanValue]]@@ -229,7 +230,8 @@[:display [:maybe ms/KeywordOrString]][:collection_id [:maybe ms/PositiveInt]][:dashboard_id [:maybe ms/PositiveInt]]- [:parameter_mappings [:maybe [:sequential ms/Map]]]]]+ [:parameter_mappings [:maybe ::parameters.schema/parameter-mappings]]+ [:pulse_id {:optional true} [:maybe ms/PositiveInt]]]](deferred-tru "value must be a map with the following keys `({0})`"(str/join ", " ["collection_id" "description" "display" "id" "include_csv" "include_xls" "name""dashboard_id" "parameter_mappings"]))))diff --git a/src/metabase/pulse/send.clj b/src/metabase/pulse/send.cljindex e569525bc86..50ee7155e3f 100644--- a/src/metabase/pulse/send.clj+++ b/src/metabase/pulse/send.clj@@ -92,7 +92,7 @@:else :goal_below)}:subscriptions [{:type :notification-subscription/cron- :cron_schedule (u.cron/schedule-map->cron-string (-> pulse-channel+ :cron_schedule (u.cron/schedule-map->cron-string (-> (select-keys pulse-channel u.cron/schedule-keys)(update :schedule_type maybe-name)(update :schedule_day maybe-name)(update :schedule_frame maybe-name)))}]diff --git a/src/metabase/pulse/task/send_pulses.clj b/src/metabase/pulse/task/send_pulses.cljindex 95892700ebd..2f7e017ec04 100644--- a/src/metabase/pulse/task/send_pulses.clj+++ b/src/metabase/pulse/task/send_pulses.clj@@ -35,7 +35,7 @@(defn- send-pulse-trigger-key^TriggerKey [pulse-id schedule-map](triggers/key (format "metabase.task.send-pulse.trigger.%d.%s"- pulse-id (-> schedule-map+ pulse-id (-> (select-keys schedule-map u.cron/schedule-keys)u.cron/schedule-map->cron-string(str/replace " " "_")))))@@ -94,7 +94,7 @@"channel-ids" pc-ids})(triggers/with-schedule(cron/schedule- (cron/cron-schedule (u.cron/schedule-map->cron-string schedule-map))+ (cron/cron-schedule (u.cron/schedule-map->cron-string (select-keys schedule-map u.cron/schedule-keys)))(cron/in-time-zone (TimeZone/getTimeZone ^String timezone));; If the trigger is misfired, fire it immediately and proceed with the next scheduled time.;; TODO: upon testing, look like re-firing on startup is not working as expected@@ -204,7 +204,7 @@* To remove 2 pulse channels from a trigger(update-send-pulse-trigger-if-needed! pulse-id schedule-map :remove-pc-ids #{1 2}))"[pulse-id schedule-map & {:keys [add-pc-ids remove-pc-ids]}]- (let [schedule-map (update-vals schedule-map+ (let [schedule-map (update-vals (select-keys schedule-map u.cron/schedule-keys)#(if (keyword? %)(name %)%))diff --git a/src/metabase/queries/card.clj b/src/metabase/queries/card.cljindex 120b2e97718..a09567112e7 100644--- a/src/metabase/queries/card.clj+++ b/src/metabase/queries/card.clj@@ -90,7 +90,7 @@([card param-key query-string](card-param-values card param-key query-string nil))- ([card :- ms/Map+ ([card :- ::queries.schema/cardparam-key :- ::lib.schema.parameter/idquery-string :- [:maybe ms/NonBlankString]constraints :- [:maybe ::chain-filter/constraints]]diff --git a/src/metabase/queries/models/card.clj b/src/metabase/queries/models/card.cljindex 954dacf118a..72be90e2062 100644--- a/src/metabase/queries/models/card.clj+++ b/src/metabase/queries/models/card.clj@@ -117,7 +117,7 @@{:dataset_query lib-be/transform-query:public_uuid (mi/transform-encrypted-text "report_card.public_uuid"):display mi/transform-keyword- :embedding_params mi/transform-json+ :embedding_params mi/transform-json-no-keywordization:query_type mi/transform-keyword:result_metadata mi/transform-result-metadata:visualization_settings mi/transform-visualization-settings@@ -1258,7 +1258,9 @@(cache/invalidate-config! {:questions [(:id card-before-update)]:with-overrides? true});; ok, now save the Card- (queries.db/update-card! (:id card-before-update) updated-fields))+ (queries.db/update-card! (:id card-before-update)+ (m/update-existing updated-fields :dataset_query+ #(lib/normalize ::queries.schema/card.dataset-query %))));; Update all transitively dependent cards if the database was changed (#74561)(cascade-database-change-to-dependents! card-before-update card-updates);; ok, now update dependent dashcard parametersdiff --git a/src/metabase/queries/schema.clj b/src/metabase/queries/schema.cljindex a7b7ed2c2e8..6f3ee9e336e 100644--- a/src/metabase/queries/schema.clj+++ b/src/metabase/queries/schema.clj@@ -2,6 +2,7 @@(:require[metabase.documents.schema :as documents.schema][metabase.lib-be.schema :as lib-be.schema]+ [metabase.lib-metric.schema :as lib-metric.schema][metabase.lib.core :as lib][metabase.lib.schema.id :as lib.schema.id][metabase.lib.schema.metadata :as lib.schema.metadata]@@ -58,27 +59,27 @@(mr/def ::card.dataset-query"The `:dataset_query` column of a Card, decoded."- :map)+ ::lib-be.schema/maybe-legacy-or-empty-query)(mr/def ::card.visualization-settings"The `:visualization_settings` column of a Card, decoded."- :map)+ ms/VisualizationSettings)(mr/def ::card.parameter"One entry of the `:parameters` column of a Card, decoded."- :map)+ ::parameters.schema/parameter)(mr/def ::card.parameter-mapping"One entry of the `:parameter_mappings` column of a Card, decoded."- :map)+ ::parameters.schema/parameter-mapping)(mr/def ::card.dimension"One entry of the `:dimensions` column of a Card, decoded."- :map)+ ::lib-metric.schema/dimension)(mr/def ::card.dimension-mapping"One entry of the `:dimension_mappings` column of a Card, decoded."- :map)+ ::lib-metric.schema/dimension-mapping)(mr/def ::card.update"What an update (or insert) of a Card accepts: every column of `:report_card` except `id`, all optional, plus `:verified-result-metadata?` consumed by the model's hooks."diff --git a/src/metabase/queries_rest/api/card.clj b/src/metabase/queries_rest/api/card.cljindex de5b6a0f431..c91c8ce904a 100644--- a/src/metabase/queries_rest/api/card.clj+++ b/src/metabase/queries_rest/api/card.clj@@ -157,7 +157,7 @@`archived`. See corresponding implementation functions above for the specific behavior of each filteroption. :card_index:"[_route-params- {:keys [f], model-id :model_id} :- [:map+ {:keys [f], model-id :model_id} :- [:map {:closed true}[:f {:default :all} (into [:enum] card-filter-options)][:model_id {:optional true} [:maybe ms/PositiveInt]]]](when (contains? #{:database :table :using_model :using_segment} f)@@ -226,10 +226,10 @@As of v57, returns the MBQL query (`dataset_query`) as MBQL 5; to return the query as MBQL 4 (aka legacy MBQL)instead, you can specify `?legacy-mbql=true`."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id [:or ms/PositiveInt ms/NanoIdString]]]{legacy-mbql? :legacy-mbql- :keys []} :- [:map [:legacy-mbql {:optional true, :default false} [:maybe :boolean]]]]+ :keys []} :- [:map {:closed true} [:legacy-mbql {:optional true, :default false} [:maybe :boolean]]]](let [resolved-id (eid-translation/->id-or-404 :card id)card (get-card resolved-id)](cond-> card@@ -252,7 +252,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id/dashboards""Get a list of `{:name ... :id ...}` pairs for all the dashboards this card appears in."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](let [card (get-card id)dashboards (:in_dashboards (t2/hydrate card :in_dashboards))]@@ -416,10 +416,10 @@- `last_cursor` with value is the id of the last card from the previous page to fetch the next page.- `query` to search card by name.- `exclude_ids` to filter out a list of card ids"- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id int?]]{:keys [last_cursor query exclude_ids]}- :- [:map+ :- [:map {:closed true}[:last_cursor {:optional true} [:maybe ms/PositiveInt]][:query {:optional true} [:maybe ms/NonBlankString]][:exclude_ids {:optional true} [:maybe [:fn@@ -481,7 +481,7 @@(def ^:private CardCreateSchema"Schema for creating a new card"- [:map+ [:map {:closed true}[:name ms/NonBlankString][:type {:optional true} [:maybe ::queries.schema/card.type]][:dataset_query ::lib-be.schema/maybe-legacy-query]@@ -491,14 +491,14 @@[:parameter_mappings {:optional true} [:maybe ::parameters.schema/parameter-mappings]][:description {:optional true} [:maybe ms/NonBlankString]][:display ms/NonBlankString]- [:visualization_settings ms/Map]+ [:visualization_settings ms/VisualizationSettings][:collection_id {:optional true} [:maybe [:or ms/PositiveInt ms/NanoIdString]]][:collection_position {:optional true} [:maybe ms/PositiveInt]][:result_metadata {:optional true} [:maybe [:ref ::lib.schema.metadata/card.result-metadata]]][:cache_ttl {:optional true} [:maybe ms/PositiveInt]][:dashboard_id {:optional true} [:maybe ms/PositiveInt]][:dashboard_tab_id {:optional true} [:maybe ms/PositiveInt]]- [:size {:optional true} [:maybe [:map+ [:size {:optional true} [:maybe [:map {:closed true}[:size_x ms/PositiveInt][:size_y ms/PositiveInt]]]]])@@ -554,7 +554,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :post "/:id/copy""Copy a `Card`, with the new name 'Copy of _name_'"- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](let [orig-card (api/read-check :model/Card id)new-name (trs "Copy of {0}" (:name orig-card))@@ -600,7 +600,7 @@;;; TODO -- merge this into `:metabase.queries.schema/card`(def ^:private CardUpdateSchema- [:map+ [:map {:closed true}[:name {:optional true} [:maybe ms/NonBlankString]][:parameters {:optional true} [:maybe ::parameters.schema/parameters]][:parameter_mappings {:optional true} [:maybe ::parameters.schema/parameter-mappings]]@@ -608,7 +608,7 @@[:type {:optional true} [:maybe ::queries.schema/card.type]][:display {:optional true} [:maybe ms/NonBlankString]][:description {:optional true} [:maybe :string]]- [:visualization_settings {:optional true} [:maybe ms/Map]]+ [:visualization_settings {:optional true} [:maybe ms/VisualizationSettings]][:archived {:optional true} [:maybe :boolean]][:enable_embedding {:optional true} [:maybe :boolean]][:embedding_type {:optional true} [:maybe :string]]@@ -719,9 +719,9 @@:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :put "/:id""Update a `Card`."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]- {delete-old-dashcards? :delete_old_dashcards} :- [:map+ {delete-old-dashcards? :delete_old_dashcards} :- [:map {:closed true}[:delete_old_dashcards {:optional true} [:maybe :boolean]]]body :- CardUpdateSchema](update-card! id body (boolean delete-old-dashcards?)))@@ -735,7 +735,7 @@:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id/query_metadata""Get all of the required query metadata for a card."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id [:or ms/PositiveInt ms/NanoIdString]]]](let [resolved-id (eid-translation/->id-or-404 :card id)](queries/batch-fetch-card-metadata [(get-card resolved-id)])))@@ -748,7 +748,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/:id""Hard delete a Card. To soft delete, use `PUT /api/queries/:id`"- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](let [card (api/write-check :model/Card id)](queries-rest.db/delete-card! id)@@ -828,7 +828,7 @@`collection_id`, or remove them from any Collections by passing a `null` `collection_id`."[_route-params_query-params- {:keys [card_ids collection_id]} :- [:map+ {:keys [card_ids collection_id]} :- [:map {:closed true}[:card_ids [:sequential ms/PositiveInt]][:collection_id {:optional true} [:maybe ms/PositiveInt]]]](move-cards-to-collection! collection_id card_ids)@@ -870,11 +870,11 @@(api.macros/defendpoint :post "/:card-id/query""Run the query associated with a Card. When `stored_result_id` is supplied, serve the cached snapshot instead of re-running the queryand optionally re-sorts the rows via the `sort` body param."- [{:keys [card-id]} :- [:map+ [{:keys [card-id]} :- [:map {:closed true}[:card-id [:or ms/PositiveInt ms/NanoIdString]]]_query-params{:keys [parameters ignore_cache dashboard_id collection_preview stored_result_id sort]}- :- [:map+ :- [:map {:closed true}[:ignore_cache {:default false} :boolean][:collection_preview {:optional true} [:maybe :boolean]][:dashboard_id {:optional true} [:maybe ms/PositiveInt]]@@ -917,7 +917,7 @@`csv_include_bom`, `parameters`, `pivot-results?` and `format-rows?` should be passed as application/x-www-form-urlencoded form contentor json in the body. This is because this endpoint is normally used to power 'Download Results' buttons that useHTML `form` actions)."- [{:keys [card-id export-format]} :- [:map+ [{:keys [card-id export-format]} :- [:map {:closed true}[:card-id ms/PositiveInt][:export-format ::qp.schema/export-format]]_query-params@@ -926,7 +926,7 @@format-rows? :format_rowscsv-include-bom? :csv_include_bom:as _body}- :- [:map+ :- [:map {:closed true};; JSON-encoded string form supported for backwards compatibility with `<form>` submission... see;; https://metaboat.slack.com/archives/C010L1Z4F9S/p1738003606875659[:parameters {:optional true} [:maybe ::parameters.schema/api.parameter-values]]@@ -959,7 +959,7 @@"Generate publicly-accessible links for this Card. Returns UUID to be used in public links. (If this Card hasalready been shared, it will return the existing public link rather than creating a new one.) Public sharing mustbe enabled."- [{:keys [card-id]} :- [:map+ [{:keys [card-id]} :- [:map {:closed true}[:card-id ms/PositiveInt]]](api/check-superuser)(public-sharing.validation/check-public-sharing-enabled)@@ -984,7 +984,7 @@:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/:card-id/public_link""Delete the publicly-accessible link to this Card."- [{:keys [card-id]} :- [:map+ [{:keys [card-id]} :- [:map {:closed true}[:card-id ms/PositiveInt]]](perms/check-has-application-permission :setting)(public-sharing.validation/check-public-sharing-enabled)@@ -1003,11 +1003,11 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :post "/pivot/:card-id/query""Run the query associated with a Card."- [{:keys [card-id]} :- [:map+ [{:keys [card-id]} :- [:map {:closed true}[:card-id ms/PositiveInt]]_query-params{:keys [parameters ignore_cache dashboard_id]- :or {ignore_cache false}} :- [:map+ :or {ignore_cache false}} :- [:map {:closed true}[:ignore_cache {:optional true} [:maybe :boolean]][:dashboard_id {:optional true} [:maybe ms/PositiveInt]][:parameters {:optional true} [:maybe [:sequential ::parameters.schema/parameter-with-value]]]]]@@ -1031,7 +1031,7 @@;; fetch values for Card 1 parameter 'abc' that are possibleGET /api/queries/1/params/abc/values"- [{:keys [card-id param-key]} :- [:map+ [{:keys [card-id param-key]} :- [:map {:closed true}[:card-id ms/PositiveInt][:param-key ::lib.schema.parameter/id]]](binding [qp.perms/*param-values-query* true]@@ -1048,7 +1048,7 @@GET /api/queries/1/params/abc/search/OrangeCurrently limited to first 1000 results."- [{:keys [card-id param-key query]} :- [:map+ [{:keys [card-id param-key query]} :- [:map {:closed true}[:card-id ms/PositiveInt][:param-key ::lib.schema.parameter/id][:query ms/NonBlankString]]]@@ -1064,10 +1064,10 @@;; fetch the remapped value for Card 1 parameter 'abc' for value 100GET /api/queries/1/params/abc/remapping?value=100"- [{:keys [id param-key]} :- [:map+ [{:keys [id param-key]} :- [:map {:closed true}[:id ::lib.schema.id/card][:param-key ::lib.schema.parameter/id]]- {:keys [value]} :- [:map [:value :string]]]+ {:keys [value]} :- [:map {:closed true} [:value :string]]](binding [qp.perms/*param-values-query* true](-> (api/read-check :model/Card id)(queries/card-param-remapped-value param-key (codec/url-decode value)))))diff --git a/src/metabase/queries_rest/api/cards.clj b/src/metabase/queries_rest/api/cards.cljindex 6aae8b33151..e97b5f122db 100644--- a/src/metabase/queries_rest/api/cards.clj+++ b/src/metabase/queries_rest/api/cards.clj@@ -26,7 +26,7 @@present."[_route-params_query-params- {:keys [card_ids]} :- [:map+ {:keys [card_ids]} :- [:map {:closed true}[:card_ids [:sequential ms/PositiveInt]]]](let [id->card (queries-rest.db/cards-by-id card_ids)](as-> card_ids $@@ -46,7 +46,7 @@For now, just either succeed or fail as a batch - we can think more about error handling later down the road."[_route-params_query-params- {:keys [card_ids], :as body} :- [:map+ {:keys [card_ids], :as body} :- [:map {:closed true}[:card_ids [:sequential ms/PositiveInt]][:collection_id {:optional true} [:maybe ms/PositiveInt]][:dashboard_id {:optional true} [:maybe ms/PositiveInt]]]]diff --git a/src/metabase/query_processor/api.clj b/src/metabase/query_processor/api.cljindex 33ae379b635..7254e10b80d 100644--- a/src/metabase/query_processor/api.clj+++ b/src/metabase/query_processor/api.clj@@ -2,6 +2,7 @@"/api/dataset endpoints."(:refer-clojure :exclude [get-in select-keys])(:require+ [malli.core :as mc][metabase.api.common :as api][metabase.api.macros :as api.macros][metabase.driver :as driver]@@ -13,6 +14,7 @@[metabase.lib.schema :as lib.schema][metabase.lib.schema.id :as lib.schema.id][metabase.lib.schema.info :as lib.schema.info]+ [metabase.lib.schema.parameter :as lib.schema.parameter][metabase.model-persistence.core :as model-persistence][metabase.models.interface :as mi][metabase.models.visualization-settings :as mb.viz]@@ -101,6 +103,7 @@query :- ::lib-be.schema/maybe-legacy-or-internal-query](run-streaming-query(-> query+ (dissoc :cache-strategy)(update-in [:middleware :js-int-to-string?] (fnil identity true))qp/userland-query-with-default-constraints)))@@ -127,7 +130,7 @@(api.macros/defendpoint :post ["/:export-format", :export-format qp.schema/export-formats-regex]:- (server/streaming-response-schema ::qp.schema/query-result)"Execute a query and download the result data as a file in the specified format."- [{:keys [export-format]} :- [:map+ [{:keys [export-format]} :- [:map {:closed true}[:export-format ::qp.schema/export-format]]_query-params{{:keys [was-pivot] :as query} :query@@ -137,17 +140,16 @@visualization-settings :visualization_settings};; Support JSON-encoded query and viz settings for backwards compatibility for when downloads used to be triggered by;; `<form>` submissions... see https://metaboat.slack.com/archives/C010L1Z4F9S/p1738003606875659- :- [:map+ :- [:map {:closed true}[:query [:schema{:decode/api (fn [x](cond-> x(string? x) json/decode))}::lib-be.schema/maybe-legacy-or-internal-query]]- [:visualization_settings {:default {}} [:map- {:closed false- :decode/api (fn [x]- (cond-> x- (string? x) (json/decode viz-setting-key-fn)))}]]+ [:visualization_settings {:default {}} (mu/with ms/VisualizationSettings+ {:decode/api (fn [x]+ (cond-> x+ (string? x) (json/decode viz-setting-key-fn)))})][:format_rows {:default false} ms/BooleanValue][:pivot_results {:default false} ms/BooleanValue][:csv_include_bom {:default false} ms/BooleanValue]]]@@ -155,7 +157,7 @@mi/normalize-visualization-settingsmb.viz/norm->db)query (-> query- (dissoc :constraints)+ (dissoc :constraints :cache-strategy)(assoc :viz-settings viz-settings)(update :middleware #(-> %(select-keys [:ignore-cached-results?])@@ -200,9 +202,9 @@"Fetch a native version of an MBQL query."[_route-params_query-params- {:keys [database pretty] :as query} :- [:map {:closed false}- [:database ms/PositiveInt]- [:pretty {:default true} [:maybe :boolean]]]]+ {:keys [database pretty] :as query} :- [:map {:closed true}+ [:pretty {:default true} [:maybe :boolean]]+ [::mc/default ::lib-be.schema/maybe-legacy-query]]](model-persistence/with-persisted-substituion-disabled(let [query (-> (lib-be/normalize-query (dissoc query :pretty))(dissoc :constraints :middleware)@@ -239,7 +241,9 @@(let [info {:executed-by api/*current-user-id*:context :ad-hoc}](qp.streaming/streaming-response [rff :api]- (qp.pivot/run-pivot-query (assoc (update query :middleware select-keys [:js-int-to-string? :ignore-cached-results?])+ (qp.pivot/run-pivot-query (assoc (-> query+ (dissoc :cache-strategy)+ (update :middleware select-keys [:js-int-to-string? :ignore-cached-results?])):constraints (qp.constraints/default-query-constraints):info info)rff)@@ -278,7 +282,7 @@[_route-params_query-params{:keys [parameter]- field-ids :field_ids} :- [:map+ field-ids :field_ids} :- [:map {:closed true}[:parameter ::parameters.schema/parameter][:field_ids {:optional true} [:maybe [:sequential ::lib.schema.id/field]]]]](parameter-values parameter field-ids nil))@@ -289,11 +293,11 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :post "/parameter/search/:query""Return parameter values for cards or dashboards that are being edited. Expects a query string at `?query=foo`."- [{:keys [query]} :- [:map+ [{:keys [query]} :- [:map {:closed true}[:query ms/NonBlankString]]_query-params{:keys [parameter]- field-ids :field_ids} :- [:map+ field-ids :field_ids} :- [:map {:closed true}[:parameter ::parameters.schema/parameter][:field_ids {:optional true} [:maybe [:sequential ::lib.schema.id/field]]]]](parameter-values parameter field-ids query))@@ -320,8 +324,8 @@"Return the remapped parameter values for cards or dashboards that are being edited."[_route-params_query-params- {:keys [parameter value field_ids]} :- [:map+ {:keys [parameter value field_ids]} :- [:map {:closed true}[:parameter ::parameters.schema/parameter]- [:value :any]+ [:value [:ref ::lib.schema.parameter/parameter.value]][:field_ids {:optional true} [:maybe [:sequential ::lib.schema.id/field]]]]](param-remapped-value field_ids parameter value))diff --git a/src/metabase/revisions/api.clj b/src/metabase/revisions/api.cljindex e68bfff4575..a20087ac96c 100644--- a/src/metabase/revisions/api.clj+++ b/src/metabase/revisions/api.clj@@ -44,7 +44,7 @@(api.macros/defendpoint :get "/""Get revisions of an object."[_route-params- {:keys [entity id]} :- [:map+ {:keys [entity id]} :- [:map {:closed true}[:id ms/PositiveInt][:entity Entity]]](let [[model instance] (model-and-instance entity id)]@@ -112,7 +112,7 @@"Revert an object to a prior revision."[_route-params_query-params- {:keys [entity id], revision-id :revision_id} :- [:map+ {:keys [entity id], revision-id :revision_id} :- [:map {:closed true}[:id ms/PositiveInt][:entity Entity][:revision_id ms/PositiveInt]]]@@ -155,7 +155,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:entity/:id""Fetch `Revisions` for an object with ID."- [{:keys [id entity]} :- [:map+ [{:keys [id entity]} :- [:map {:closed true}[:entity Entity][:id ms/PositiveInt]]](let [model (entity->model entity)]diff --git a/src/metabase/search/api.clj b/src/metabase/search/api.cljindex 23013e9ed44..47e387a9cf9 100644--- a/src/metabase/search/api.clj+++ b/src/metabase/search/api.clj@@ -2,7 +2,6 @@(:require[clojure.string :as str][java-time.api :as t]- [malli.core :as mc][metabase.analytics-interface.core :as analytics][metabase.api.common :as api][metabase.api.macros :as api.macros]@@ -173,7 +172,7 @@(api.macros/defendpoint :get "/weights""Return the current weights being used to rank the search results"[_route-params- {:keys [context]} :- [:map [:context {:default :default} :keyword]]]+ {:keys [context]} :- [:map {:closed true} [:context {:default :default} :keyword]]];; normalize so the reported weights match what search actually applies for this context(search.config/weights {:context (search.config/normalized-context context)}))@@ -188,14 +187,13 @@(api.macros/defendpoint :put "/weights""Update the current weights being used to rank the search results"[_route-params- {:keys [context], :as overrides} :- [:map- [:context {:default :default} :keyword]- [:search_engine {:optional true} :any]- [::mc/default [:map-of :keyword :string]]]]+ overrides :- (ms/string-keyed-object+ ["context" {:default :default} :keyword]+ ["search_engine" {:optional true} [:maybe :string]])];; remove cookie;; normalize so overrides are stored under the same key search reads them from- (let [context (search.config/normalized-context context)- overrides (-> overrides (dissoc :search_engine :context) (update-vals parse-double))]+ (let [context (search.config/normalized-context (get overrides "context"))+ overrides (-> overrides (dissoc "search_engine" "context") (update-keys keyword) (update-vals parse-double))](when (seq overrides)(set-weights! context overrides))(search.config/weights {:context context})))@@ -208,7 +206,7 @@;;(def ^:private search-request-schema"Query-parameter schema shared by `GET /api/search` and `GET /api/search/debug`."- [:map+ [:map {:closed true}[:q {:optional true} [:maybe :string]];; no `:optional true`: default-value-transformer skips defaults for absent optional keys, so it's;; what makes `:default :api` actually apply when the param is omitteddiff --git a/src/metabase/search/in_place/legacy.clj b/src/metabase/search/in_place/legacy.cljindex 448d1043a57..37bfaff577e 100644--- a/src/metabase/search/in_place/legacy.clj+++ b/src/metabase/search/in_place/legacy.clj@@ -158,7 +158,7 @@(mu/defn- add-table-db-id-clause"Add a WHERE clause to only return tables with the given DB id.Used in data picker for joins because we can't join across DB's."- [query :- ms/Map id :- [:maybe ms/PositiveInt]]+ [query :- :map id :- [:maybe ms/PositiveInt]](if (some? id)(sql.helpers/where query [:= id :db_id])query))@@ -166,7 +166,7 @@(mu/defn- add-card-db-id-clause"Add a WHERE clause to only return cards with the given DB id.Used in data picker for joins because we can't join across DB's."- [query :- ms/Map id :- [:maybe ms/PositiveInt]]+ [query :- :map id :- [:maybe ms/PositiveInt]](if (some? id)(sql.helpers/where query [:= id :database_id])query))diff --git a/src/metabase/security_center/schema.clj b/src/metabase/security_center/schema.cljindex 3fd4fe4a67e..b010196388c 100644--- a/src/metabase/security_center/schema.clj+++ b/src/metabase/security_center/schema.clj@@ -34,10 +34,15 @@(mr/def ::download-jar-urls[:sequential ::download-jar-url])+(mr/def ::driver+ "The app DB an advisory's `:matching_query` is written for. `:default` is the fallback used when there is no query+ for the app DB in use."+ [:enum :default :h2 :mysql :postgres])+(mr/def ::matching-query"HoneySQL query keyed by dialect. nil means affects all instances.Stored as EDN to preserve keywords that HoneySQL requires for identifiers/operators."- [:maybe [:map-of :keyword :map]])+ [:maybe [:map-of ::driver ms/OpaqueJSONObject]])(mr/def ::security-advisory.matching-query"The `:matching_query` column of a SecurityAdvisory, decoded."diff --git a/src/metabase/segments/api.clj b/src/metabase/segments/api.cljindex c3d0f0f3f38..deb7b83adf8 100644--- a/src/metabase/segments/api.clj+++ b/src/metabase/segments/api.clj@@ -40,7 +40,7 @@"Create a new `Segment`. The Segment's table is derived from its `definition`."[_route-params_query-params- {:keys [name description definition], :as body} :- [:map+ {:keys [name description definition], :as body} :- [:map {:closed true}[:name ms/NonBlankString][:definition ::segments.schema/definition][:description {:optional true} [:maybe :string]]]]@@ -62,7 +62,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id""Fetch `Segment` with ID."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](hydrated-segment id))@@ -111,10 +111,10 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :put "/:id""Update a `Segment` with ID."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-params- body :- [:map+ body :- [:map {:closed true}[:name {:optional true} [:maybe ms/NonBlankString]][:definition {:optional true} [:maybe ::segments.schema/definition]][:revision_message ms/NonBlankString]@@ -135,9 +135,9 @@:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/:id""Archive a Segment. (DEPRECATED -- Just pass updated value of `:archived` to the `PUT` endpoint instead.)"- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]- {:keys [revision_message]} :- [:map+ {:keys [revision_message]} :- [:map {:closed true}[:revision_message ms/NonBlankString]]](log/warn "DELETE /api/segment/:id is deprecated. Instead, change its `archived` value via PUT /api/segment/:id.")(write-check-and-update-segment! id {:archived true, :revision_message revision_message})@@ -149,6 +149,6 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id/related""Return related entities."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](-> (segments.db/segment id) api/read-check xrays/related))diff --git a/src/metabase/segments/models/segment.clj b/src/metabase/segments/models/segment.cljindex 1df0a5b9faf..ee9d1aa5261 100644--- a/src/metabase/segments/models/segment.clj+++ b/src/metabase/segments/models/segment.clj@@ -28,11 +28,11 @@(methodical/defmethod t2/model-for-automagic-hydration [:default :segment] [_original-model _k] :model/Segment)(defn- validate-mbql5-definition- "Validate that an MBQL 5 segment definition has the correct structure."+ "Validate that an MBQL 5 segment definition has the correct structure. Normalizing a definition that cannot be made+ into a query yields an empty map, which is as invalid as any other broken definition."[definition]- (when (seq definition)- (mu/validate-throw ::segments.schema/definition definition)- definition))+ (mu/validate-throw ::segments.schema/definition definition)+ definition)(defn- normalize-segment-definition"Normalize segment definition.diff --git a/src/metabase/session/api.clj b/src/metabase/session/api.cljindex b97c893ab6e..c5c19adad7d 100644--- a/src/metabase/session/api.clj+++ b/src/metabase/session/api.clj@@ -185,7 +185,7 @@"Login."[_route-params_query-params- {:keys [username password]} :- [:map+ {:keys [username password]} :- [:map {:closed true}[:username ms/NonBlankString][:password ms/NonBlankString]]request]@@ -301,7 +301,7 @@"Send a reset email when user has forgotten their password."[_route-params_query-params- {:keys [email]} :- [:map+ {:keys [email]} :- [:map {:closed true}[:email ms/Email]]request];; Don't leak whether the account doesn't exist, just pretend everything is ok@@ -376,7 +376,7 @@(api.macros/defendpoint :get "/password_reset_token_valid""Check if a password reset token is valid and isn't expired."[_route-params- {:keys [token]} :- [:map+ {:keys [token]} :- [:map {:closed true}[:token ms/NonBlankString]]](let [auth-result (auth-identity/with-fallback auth-identity/authenticate[:provider/support-access-grant@@ -405,7 +405,7 @@"Login with Google Auth."[_route-params_query-params- {:keys [token]} :- [:map+ {:keys [token]} :- [:map {:closed true}[:token ms/NonBlankString]]request](when-not (sso/google-auth-client-id)@@ -444,7 +444,7 @@"Endpoint that checks if the supplied password meets the currently configured password complexity rules."[_route-params_query-params- _body :- [:map+ _body :- [:map {:closed true}[:password ms/ValidPassword]]];; if we pass the [[ms/ValidPassword]] test we're g2g{:valid true})@@ -462,7 +462,7 @@;; `:remember` is not bound here but is part of the contract: `request/set-session-cookies`;; reads it from the raw body to decide session-vs-permanent cookie, exactly as on;; `POST /api/session` — for MFA users THIS request is the one that creates the session.- {challenge-token :challenge_token, code :code} :- [:map+ {challenge-token :challenge_token, code :code} :- [:map {:closed true}[:challenge_token ms/NonBlankString][:code ms/NonBlankString][:remember {:optional true} :boolean]]@@ -502,7 +502,7 @@`POST /mfa/verify` like any other code."[_route-params_query-params- {challenge-token :challenge_token} :- [:map [:challenge_token ms/NonBlankString]]+ {challenge-token :challenge_token} :- [:map {:closed true} [:challenge_token ms/NonBlankString]]request](let [claims (or (session.challenge/verify-challenge-token challenge-token)(throw (ex-info (tru "Authentication session expired. Please log in again.")diff --git a/src/metabase/settings_rest/api.clj b/src/metabase/settings_rest/api.cljindex 17726b03c03..4718669b907 100644--- a/src/metabase/settings_rest/api.clj+++ b/src/metabase/settings_rest/api.clj@@ -5,7 +5,8 @@[metabase.api.macros :as api.macros][metabase.permissions.core :as perms][metabase.settings.core :as setting]- [metabase.util :as u]))+ [metabase.util :as u]+ [metabase.util.malli.schema :as ms]))(defn- do-with-setting-access-control[thunk]@@ -17,6 +18,14 @@(api/check-superuser)(throw e))))+(def ^:private kebab-cased-keyword+ "Keyword that can be transformed from \"a_b\" -> :a-b"+ [:keyword {:decode/json #(keyword (u/->kebab-case-en %))}])++(def ^:private SettingValue+ "What a client may set a Setting to: the JSON encoding of any setting type -- a scalar, a list, or an object."+ [:maybe [:or :string number? :boolean [:sequential [:or :string number? :boolean ms/OpaqueJSONObject]] ms/OpaqueJSONObject]])+(defmacro ^:private with-setting-access-control"Executes the given body with setting access enforcement enabled, and adds some exception handling to make sure wereturn generic 403s to non-admins who try to read or write settings they don't have access to."@@ -41,10 +50,6 @@(perms/check-has-application-permission :setting)(setting/writable-settings))-(def ^:private kebab-cased-keyword- "Keyword that can be transformed from \"a_b\" -> :a-b"- [:keyword {:decode/json #(keyword (u/->kebab-case-en %))}])-;; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to;; use our API + we will need it when we make auto-TypeScript-signature generation happen;;@@ -53,9 +58,11 @@"Update multiple `Settings` values. If called by a non-superuser, only user-local settings can be updated."[_route-params_query-params- settings :- [:map-of kebab-cased-keyword :any]]+ settings :- (ms/string-keyed-map SettingValue)+ request]+ (api/check-no-dropped-entries (:body request) settings)(with-setting-access-control- (setting/set-many! settings))+ (setting/set-many! (update-keys settings #(keyword (u/->kebab-case-en %)))))(add-settings-last-updated-cookie api/generic-204-no-content));; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to@@ -64,7 +71,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:key""Fetch a single `Setting`."- [{:keys [key]} :- [:map+ [{:keys [key]} :- [:map {:closed true}[:key kebab-cased-keyword]]](with-setting-access-control(setting/user-facing-value key)))@@ -76,10 +83,10 @@(api.macros/defendpoint :put "/:key""Create/update a `Setting`. If called by a non-admin, only user-local settings can be updated.This endpoint can also be used to delete Settings by passing `nil` for `:value`."- [{:keys [key]} :- [:map+ [{:keys [key]} :- [:map {:closed true}[:key kebab-cased-keyword]]_query-params- {:keys [value]} :- [:map [:value :any]]]+ {:keys [value]} :- [:map {:closed true} [:value SettingValue]]](with-setting-access-control(setting/set! key value))(add-settings-last-updated-cookie api/generic-204-no-content))diff --git a/src/metabase/setup_rest/api.clj b/src/metabase/setup_rest/api.cljindex 3be51c908f0..1cb1838a493 100644--- a/src/metabase/setup_rest/api.clj+++ b/src/metabase/setup_rest/api.clj@@ -69,14 +69,14 @@{{first-name :first_name, last-name :last_name, :keys [email password]} :user{site-name :site_namesite-locale :site_locale} :prefs}- :- [:map+ :- [:map {:closed true}[:token SetupToken]- [:user [:map+ [:user [:map {:closed true}[:email ms/Email][:password ms/ValidPassword][:first_name {:optional true} [:maybe ms/NonBlankString]][:last_name {:optional true} [:maybe ms/NonBlankString]]]]- [:prefs [:map+ [:prefs [:map {:closed true}[:site_name ms/NonBlankString][:site_locale {:optional true} [:maybe ms/ValidLocale]]]]]request]diff --git a/src/metabase/slackbot/api.clj b/src/metabase/slackbot/api.cljindex 464af325d89..40b0078ec08 100644--- a/src/metabase/slackbot/api.clj+++ b/src/metabase/slackbot/api.clj@@ -431,7 +431,7 @@:dispatch :type}["url_verification" slackbot.events/SlackUrlVerificationEvent]["event_callback" slackbot.events/SlackEventCallbackEvent]- [::mc/default [:map [:type :string]]]]+ [::mc/default [:map {:closed true} [:type :string]]]]request](log/debugf "[slackbot] Incoming Slack request type=%s slack_event_type=%s request_ts=%s"(:type body)@@ -448,7 +448,7 @@(def SlackBotSettingsRequest"Malli schema for the request body of PUT /api/metabot/slack/settings.All credential fields must be provided together (either all set or all nil)."- [:map+ [:map {:closed true}[:slack-connect-client-id [:maybe ms/NonBlankString]][:slack-connect-client-secret [:maybe ms/NonBlankString]][:metabot-slack-signing-secret [:maybe ms/NonBlankString]]])@@ -621,7 +621,7 @@"Handle interactive payloads from Slack (button clicks, modal submissions)."[_route-params_query-params- {:keys [payload]} :- [:map+ {:keys [payload]} :- [:map {:closed true}[:payload ms/NonBlankString]]request](assert-valid-slack-req request)diff --git a/src/metabase/slackbot/events.clj b/src/metabase/slackbot/events.cljindex c48460f6196..cb773d5d095 100644--- a/src/metabase/slackbot/events.clj+++ b/src/metabase/slackbot/events.clj@@ -5,22 +5,22 @@(def SlackEventsResponse"Malli schema for Slack events API response"- [:map+ [:map {:closed true};; Response status is expected to be 2xx to indicate the event was received;; https://docs.slack.dev/apis/events-api/#error-handling[:status [:= 200]]- [:headers [:map ["Content-Type" [:= "text/plain"]]]]+ [:headers [:map {:closed true} ["Content-Type" [:= "text/plain"]]]][:body :string]])(def SlackUrlVerificationEvent"Malli schema for Slack url_verification event"- [:map+ [:map {:closed true}[:type [:= "url_verification"]][:challenge :string]])(def SlackFile"Malli schema for a file attached to a Slack message"- [:map+ [:map {:closed true}[:id :string][:name :string][:mimetype {:optional true} [:maybe :string]]@@ -30,7 +30,7 @@(def SlackMessageEvent"Base schema for Slack message events"- [:map+ [:map {:closed true}[:type [:= "message"]][:channel :string][:user :string]@@ -41,7 +41,7 @@(def SlackMessageFileShareEvent"Schema for file_share message events"[:merge SlackMessageEvent- [:map+ [:map {:closed true}[:subtype [:= "file_share"]][:channel_type :string][:files [:sequential SlackFile]]@@ -50,11 +50,11 @@(def SlackEventCallbackEvent"Malli schema for Slack event_callback event"- [:map+ [:map {:closed true}[:type [:= "event_callback"]][:event_id {:optional true} :string][:team_id {:optional true} :string]- [:event [:map+ [:event [:map {:closed true}[:type :string][:event_ts :string][:user {:optional true} :string]@@ -66,11 +66,11 @@[:text {:optional true} [:maybe :string]][:bot_id {:optional true} [:maybe :string]][:reaction {:optional true} :string]- [:edited {:optional true} [:map+ [:edited {:optional true} [:map {:closed true}[:user {:optional true} :string][:ts {:optional true} :string]]][:files {:optional true} [:sequential SlackFile]]- [:item {:optional true} [:map+ [:item {:optional true} [:map {:closed true}[:type {:optional true} :string][:channel {:optional true} :string][:ts {:optional true} :string]]]]]])diff --git a/src/metabase/sso/api/google.clj b/src/metabase/sso/api/google.cljindex 42e186ce7db..0d1fca3f313 100644--- a/src/metabase/sso/api/google.clj+++ b/src/metabase/sso/api/google.clj@@ -16,7 +16,7 @@[_route-params_query-params{:keys [google-auth-client-id google-auth-enabled google-auth-auto-create-accounts-domain]}- :- [:map+ :- [:map {:closed true}[:google-auth-client-id {:optional true} [:maybe :string]][:google-auth-enabled {:optional true} [:maybe :boolean]][:google-auth-auto-create-accounts-domain {:optional true} [:maybe :string]]]]diff --git a/src/metabase/sso/api/ldap.clj b/src/metabase/sso/api/ldap.cljindex fc7210bc129..655a1597550 100644--- a/src/metabase/sso/api/ldap.clj+++ b/src/metabase/sso/api/ldap.clj@@ -6,8 +6,8 @@[metabase.api.macros :as api.macros][metabase.settings.core :as setting][metabase.sso.ldap :as ldap]+ [metabase.sso.schema :as sso.schema][metabase.sso.settings :as sso.settings]- [metabase.util.malli.schema :as ms][toucan2.core :as t2]))(set! *warn-on-reflection* true)@@ -28,7 +28,7 @@"Update LDAP related settings. You must be a superuser to do this."[_route-params_query-params- settings :- [:map+ settings :- [:map {:closed true}[:ldap-port {:optional true} [:maybe;; treat empty string as nil{:decode/api (fn [x]@@ -48,7 +48,7 @@[:ldap-group-sync {:optional true} [:maybe :boolean]][:ldap-group-base {:optional true} [:maybe :string]][:ldap-group-membership-filter {:optional true} [:maybe :string]]- [:ldap-group-mappings {:optional true} [:maybe [:map-of :keyword [:sequential ms/PositiveInt]]]]]]+ [:ldap-group-mappings {:optional true} [:maybe ::sso.schema/group-mappings]]]](api/check-superuser)(let [ldap-settings (-> settings(update :ldap-password update-password-if-needed)diff --git a/src/metabase/sso/schema.clj b/src/metabase/sso/schema.cljnew file mode 100644index 00000000000..6a52358931f--- /dev/null+++ b/src/metabase/sso/schema.clj@@ -0,0 +1,11 @@+(ns metabase.sso.schema+ "Malli schemas for the SSO module."+ (:require+ [metabase.util.malli.registry :as mr]+ [metabase.util.malli.schema :as ms]))++(mr/def ::group-mappings+ "An identity provider's groups mapped to the Metabase group IDs that membership in them grants. The keys are the+ provider's -- LDAP group DNs, SAML and JWT group names -- so the map is string-keyed on its way in; it is stored as a+ JSON setting and read back through that setting's own decoder."+ (ms/string-keyed-map [:sequential ms/PositiveInt]))diff --git a/src/metabase/sync/api/notify.clj b/src/metabase/sync/api/notify.cljindex 968d0747136..fe1bd257fb8 100644--- a/src/metabase/sync/api/notify.clj+++ b/src/metabase/sync/api/notify.clj@@ -27,10 +27,10 @@regardless if a `:table_id` or `:table_name` is passed.This endpoint is secured by an API key that needs to be passed as a `X-METABASE-APIKEY` header which needs to be defined inthe `MB_API_KEY` [environment variable](https://www.metabase.com/docs/latest/configuring-metabase/environment-variables.html#mb_api_key)"- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-params- {:keys [table_id table_name scan synchronous?]} :- [:map+ {:keys [table_id table_name scan synchronous?]} :- [:map {:closed true}[:table_id {:optional true} [:maybe ms/PositiveInt]][:table_name {:optional true} [:maybe ms/NonBlankString]][:scan {:optional true} [:maybe [:enum "full" "schema"]]]@@ -84,7 +84,7 @@- synchronous?: is a boolean value to indicate if this should block on the result."[_route-params_query-params- {:keys [table_name schema_name synchronous?]} :- [:map+ {:keys [table_name schema_name synchronous?]} :- [:map {:closed true}[:table_name {:optional true} [:maybe ms/NonBlankString]][:schema_name {:optional true} [:maybe string?]][:synchronous? {:default false} [:maybe ms/BooleanValue]]]]@@ -107,10 +107,10 @@(api.macros/defendpoint :post "/db/:id/new-table""Sync a new table without running a full database sync. Requires `schema_name` and `table_name`. Will throw an errorif the table already exists in Metabase or cannot be found."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-params- {:keys [schema_name table_name]} :- [:map+ {:keys [schema_name table_name]} :- [:map {:closed true}[:schema_name ms/NonBlankString][:table_name ms/NonBlankString]]](api/let-404 [database (sync.db/database id)]diff --git a/src/metabase/sync/schedules.clj b/src/metabase/sync/schedules.cljindex 2f4622bbfdc..6b066aad2a4 100644--- a/src/metabase/sync/schedules.clj+++ b/src/metabase/sync/schedules.clj@@ -17,7 +17,7 @@(mr/def ::ExpandedSchedulesMap(mu/with-api-error-message[:map- {:error/message "Map of expanded schedule maps"}+ {:closed true :error/message "Map of expanded schedule maps"}[:cache_field_values {:optional true} [:maybe u.cron/ScheduleMap]][:metadata_sync {:optional true} u.cron/ScheduleMap]](deferred-tru "value must be a valid map of schedule maps for a DB.")))diff --git a/src/metabase/task_history/api.clj b/src/metabase/task_history/api.cljindex 6f712e2d956..74c0f0780af 100644--- a/src/metabase/task_history/api.clj+++ b/src/metabase/task_history/api.clj@@ -22,7 +22,7 @@(api.macros/defendpoint :get "/""Fetch a list of recent tasks stored as Task History"[_- params :- [:maybe [:merge task-history/FilterParams task-history/SortParams]]]+ params :- [:maybe task-history/FilterAndSortParams]](perms/check-has-application-permission :monitoring){:total (task-history/total params):limit (request/limit)@@ -35,7 +35,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id""Get `TaskHistory` entry with ID."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](api/check-404 (api/read-check :model/TaskHistory id)))@@ -69,7 +69,7 @@;;; +----------------------------------------------------------------------------------------------------------------+(mr/def ::RunFilterParams- [:map+ [:map {:closed true}[:run-type {:optional true} (into [:enum] (map name task-run/run-types))][:entity-type {:optional true} (into [:enum] (map name task-run/entity-types))][:entity-id {:optional true} ms/PositiveInt]@@ -81,7 +81,7 @@#{:started_at :ended_at :run_type :status :entity_name :task_count})(mr/def ::RunSortParams- [:map+ [:map {:closed true}[:sort-column {:default :started_at} (into [:enum] run-sort-columns)][:sort-direction {:default :desc} [:enum :asc :desc]]])@@ -204,7 +204,7 @@(api.macros/defendpoint :get "/runs/:id" :- ::TaskRunWithTasks"Get a single task run with all its child tasks."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]](perms/check-has-application-permission :monitoring)(let [run (api/check-404 (task-history.db/task-run id))tasks (task-history.db/tasks-for-run id)]@@ -217,7 +217,7 @@(api.macros/defendpoint :get "/runs/entities" :- [:sequential ::RunEntity]"Get distinct entities that have task runs for a given run type. Used for populating entity filter picker."[_- params :- [:map+ params :- [:map {:closed true}[:run-type (into [:enum] (map name task-run/run-types))][:started-at ms/NonBlankString]]](perms/check-has-application-permission :monitoring)diff --git a/src/metabase/task_history/models/task_history.clj b/src/metabase/task_history/models/task_history.cljindex 7681c16311a..a2098f04fc6 100644--- a/src/metabase/task_history/models/task_history.clj+++ b/src/metabase/task_history/models/task_history.clj@@ -75,7 +75,7 @@(def FilterParams"Schema for filter for task history."- [:map+ [:map {:closed true}[:status {:optional true} (into [:enum] task-history-status)][:task {:optional true} [:string {:min 1}]]])@@ -84,20 +84,25 @@(def SortParams"Sorting map schema."- [:map+ [:map {:closed true}[:sort_column {:default :started_at} (into [:enum] available-sort-columns)][:sort_direction {:default :desc} [:enum :asc :desc]]])+(def FilterAndSortParams+ "The query params of `GET /api/task`: [[FilterParams]] and [[SortParams]] together. `:merge` merges the two maps'+ properties, so the result is closed like both of its halves."+ [:merge FilterParams SortParams])+(mu/defn all"Return all TaskHistory entries, filtered if `filter` is provided, applying `limit` and `offset` if not nil."[limit :- [:maybe ms/PositiveInt]offset :- [:maybe ms/IntGreaterThanOrEqualToZero]- {:keys [status task sort_column sort_direction]} :- [:maybe [:merge FilterParams SortParams]]]+ {:keys [status task sort_column sort_direction]} :- [:maybe FilterAndSortParams]](task-history.db/task-histories status task (or sort_column :started_at) (or sort_direction :desc) limit offset))(mu/defn total"Return count of all, or filtered if `filter` is provided, task history entries."- [{:keys [status task]} :- FilterParams]+ [{:keys [status task]} :- [:maybe FilterAndSortParams]](task-history.db/task-history-count status task))(defn unique-tasksdiff --git a/src/metabase/testing_api/api.clj b/src/metabase/testing_api/api.cljindex 66723b2f63e..dd1dbf80932 100644--- a/src/metabase/testing_api/api.clj+++ b/src/metabase/testing_api/api.clj@@ -3,8 +3,10 @@(:require[clojure.java.jdbc :as jdbc][clojure.string :as str]+ [clojure.walk :as walk][java-time.api :as t][java-time.clock]+ [medley.core :as m][metabase.analytics.core :as analytics][metabase.api.common :as api][metabase.api.macros :as api.macros]@@ -22,6 +24,7 @@[metabase.search.core :as search][metabase.search.ingestion :as search.ingestion][metabase.search.task.search-index :as task.search-index]+ [metabase.security-center.schema :as security-center.schema][metabase.session.api :as session.api][metabase.testing-api.db :as testing-api.db][metabase.util.date-2 :as u.date]@@ -44,7 +47,7 @@[:key ms/NonBlankString][:type ms/NonBlankString][:name ms/NonBlankString]- [:config [:map-of :keyword [:maybe :string]]]])+ [:config (ms/string-keyed-map [:maybe :string])]])(defn- validate-llm-provider-fixture![{:keys [type config]}]@@ -80,7 +83,7 @@;;(api.macros/defendpoint :post "/snapshot/:name""Snapshot the database for testing purposes."- [{snapshot-name :name} :- [:map+ [{snapshot-name :name} :- [:map {:closed true}[:name ms/NonBlankString]]](task.search-index/wait-for-init!)(search.ingestion/wait-for-idle!)@@ -155,7 +158,7 @@;;(api.macros/defendpoint :post "/restore/:name""Restore a database snapshot for testing purposes."- [{snapshot-name :name} :- [:map+ [{snapshot-name :name} :- [:map {:closed true}[:name ms/NonBlankString]]];; reset the system clock, in case `/set-time` was called without cleanup(alter-var-root #'java-time.clock/*clock* (constantly nil))@@ -170,9 +173,9 @@(api.macros/defendpoint :post "/echo""Simple echo handler. Fails when you POST with `?fail=true`."[_route-params- {:keys [fail]} :- [:map+ {:keys [fail]} :- [:map {:closed true}[:fail {:default false} ms/BooleanValue]]- body :- ms/Map]+ body :- ms/OpaqueJSONObject](if fail{:status 400:body {:error-code "oops"}}@@ -186,7 +189,7 @@"Make java-time see world at exact time."[_route-params_query-params- {:keys [time add-ms]} :- [:map+ {:keys [time add-ms]} :- [:map {:closed true}[:time {:optional true} [:maybe ms/TemporalString]][:add-ms {:optional true} [:maybe ms/Int]]]](let [clock (when-let [time' (cond@@ -205,9 +208,9 @@(api.macros/defendpoint :get "/echo""Simple echo handler. Fails when you GET with `?fail=true`."[_route-params- {:keys [fail body]} :- [:map+ {:keys [fail body]} :- [:map {:closed true}[:fail {:default false} ms/BooleanValue]- [:body ms/JSONString]]]+ [:body :string]]](if fail{:status 400:body {:error-code "oops"}}@@ -221,7 +224,7 @@"Mark the card or dashboard as stale"[_route-params_query-params- {:keys [id model date-str]} :- [:map+ {:keys [id model date-str]} :- [:map {:closed true}[:id ms/PositiveInt][:model :string][:date-str {:optional true} [:maybe :string]]]]@@ -279,8 +282,9 @@[_route-params_query-params{:keys [value]} :- [:map {:closed true} [:value [:sequential llm-provider-fixture-schema]]]]- (run! validate-llm-provider-fixture! value)- (llm.settings/set-llm-providers! (vec value))+ (let [value (mapv #(update % :config update-keys keyword) value)]+ (run! validate-llm-provider-fixture! value)+ (llm.settings/set-llm-providers! value))nil);; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to@@ -295,54 +299,42 @@"Creates a query from a test query spec."[_route-params_query-params- {:keys [database], :as query-spec} :- [:map- ;; open: clients send the spec in camelCase and `lib/test-query` re-parses- ;; it with its own coercer, which kebab-cases the keys and validates the- ;; result. Declaring `::lib.schema.test-spec/test-query-spec` here would- ;; strip every camelCase key before that coercer ever saw it.- {:closed false}- [:database ::lib.schema.id/database]]]- (-> (lib-be/application-database-metadata-provider database)- (lib/test-query query-spec)))+ query-spec :- (ms/string-keyed-object ["database" ::lib.schema.id/database])]+ (-> (lib-be/application-database-metadata-provider (get query-spec "database"))+ (lib/test-query (walk/keywordize-keys query-spec))))(def ^:private TestAdvisory"Schema for a single advisory in the testing seed endpoint."- [:map+ [:map {:closed true}[:advisory_id ms/NonBlankString][:title ms/NonBlankString][:severity [:enum "critical" "high" "medium" "low"]][:description ms/NonBlankString][:advisory_url {:optional true} [:maybe ms/NonBlankString]][:remediation ms/NonBlankString]- [:affected_versions [:sequential [:map [:min :string] [:fixed :string]]]]- [:download_jar_urls {:optional true} [:maybe [:sequential [:map [:version :string] [:url :string]]]]]- [:matching_query {:optional true} [:maybe [:map-of :keyword :string]]]+ [:affected_versions [:sequential [:map {:closed true} [:min :string] [:fixed :string]]]]+ [:download_jar_urls {:optional true} [:maybe [:sequential [:map {:closed true} [:version :string] [:url :string]]]]]+ [:matching_query {:optional true} [:maybe ::security-center.schema/matching-query]][:match_status [:enum "unknown" "active" "resolved" "not_affected" "error"]]- [:published_at :any]- [:updated_at :any]])+ [:published_at [:maybe :string]]+ [:updated_at [:maybe :string]]])(api.macros/defendpoint :post "/security-advisories""Nuke all existing security advisories and insert the provided ones."[_route-params_query-params- {:keys [advisories]} :- [:map+ {:keys [advisories]} :- [:map {:closed true}[:advisories [:sequential TestAdvisory]]]](testing-api.db/delete-all-security-advisories!)- (testing-api.db/insert-security-advisories! advisories))+ (testing-api.db/insert-security-advisories! (mapv #(m/update-existing % :matching_query walk/keywordize-keys) advisories)))(api.macros/defendpoint :post "/native-query" :- ::lib.schema/query"Creates a native query from a test query spec."[_route-params_query-params- {:keys [database], :as native-query-spec} :- [:map- ;; open, for the same reason as `POST /query` above:- ;; `lib/test-native-query` re-parses and validates the spec itself,- ;; and it is the only thing that understands the camelCase keys- ;; (`templateTags`, ...) clients send.- {:closed false}- [:database ::lib.schema.id/database]]]- (-> (lib-be/application-database-metadata-provider database)- (lib/test-native-query native-query-spec)))+ native-query-spec :- (ms/string-keyed-object ["database" ::lib.schema.id/database])]+ (-> (lib-be/application-database-metadata-provider (get native-query-spec "database"))+ (lib/test-native-query (walk/keywordize-keys native-query-spec))));;;; Metabot AI usage seeding@@ -563,7 +555,7 @@cache so limit checks re-evaluate immediately. Intended only for E2E tests."[_route-params_query-params- {:keys [user_id count]} :- [:map+ {:keys [user_id count]} :- [:map {:closed true}[:user_id ms/PositiveInt][:count ms/PositiveInt]]](dotimes [_ count]@@ -583,7 +575,7 @@clear the metabot limit cache. Intended only for E2E tests."[_route-params_query-params- {:keys [user_id]} :- [:map+ {:keys [user_id]} :- [:map {:closed true}[:user_id ms/PositiveInt]]](let [deleted (testing-api.db/delete-ai-usage-logs-for-user-and-source! user_id e2e-usage-source)](clear-metabot-limit-cache!)@@ -596,7 +588,7 @@"Seed deterministic Metabot conversation, message, and token usage rows for the usage auditing E2E charts."[_route-params_query-params- {:keys [user_id second_user_id tenant_id second_tenant_id]} :- [:map+ {:keys [user_id second_user_id tenant_id second_tenant_id]} :- [:map {:closed true}[:user_id ms/PositiveInt][:second_user_id ms/PositiveInt][:tenant_id {:optional true} [:maybe ms/PositiveInt]]@@ -614,7 +606,7 @@[_route-params_query-params{:keys [user_id tool_name client_name client_version status error_code error_message duration_ms]}- :- [:map+ :- [:map {:closed true}[:user_id ms/PositiveInt][:tool_name {:optional true} [:maybe ms/NonBlankString]][:client_name {:optional true} [:maybe ms/NonBlankString]]diff --git a/src/metabase/tiles/api.clj b/src/metabase/tiles/api.cljindex 7d6bc72f19c..397a22705b5 100644--- a/src/metabase/tiles/api.clj+++ b/src/metabase/tiles/api.clj@@ -222,13 +222,13 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:zoom/:x/:y""Generates a single tile image for an ad-hoc query."- [{:keys [zoom x y]} :- [:map+ [{:keys [zoom x y]} :- [:map {:closed true}[:zoom ms/Int][:x ms/Int][:y ms/Int]]{:keys [query]lat-field :latField- lon-field :lonField} :- [:map+ lon-field :lonField} :- [:map {:closed true}[:query ::query][:latField ::legacy-ref][:lonField ::legacy-ref]]]@@ -292,13 +292,13 @@(api.macros/defendpoint :get "/:card-id/:zoom/:x/:y""Generates a single tile image for a saved Card."[{:keys [card-id zoom x y]}- :- [:map+ :- [:map {:closed true}[:card-id ::lib.schema.id/card][:zoom ms/Int][:x ms/Int][:y ms/Int]]{:keys [parameters], lat-field :latField lon-field :lonField}- :- [:map+ :- [:map {:closed true}[:parameters {:optional true} ::parameters.schema/api.parameter-values][:latField ::legacy-ref][:lonField ::legacy-ref]]]@@ -312,7 +312,7 @@(api.macros/defendpoint :get "/:dashboard-id/dashcard/:dashcard-id/card/:card-id/:zoom/:x/:y""Generates a single tile image for a dashcard."[{:keys [dashboard-id dashcard-id card-id zoom x y], :as _route-params}- :- [:map+ :- [:map {:closed true}[:dashboard-id ::lib.schema.id/dashboard][:dashcard-id ::lib.schema.id/dashcard][:card-id ::lib.schema.id/card]@@ -320,7 +320,7 @@[:x ms/Int][:y ms/Int]]{:keys [parameters] lat-field :latField, lon-field :lonField, :as _query-params}- :- [:map+ :- [:map {:closed true}[:parameters {:optional true} ::parameters.schema/api.parameter-values][:latField ::legacy-ref][:lonField ::legacy-ref]]]diff --git a/src/metabase/timeline/api/timeline.clj b/src/metabase/timeline/api/timeline.cljindex fa89cf7f7d3..0bcef4a3a0e 100644--- a/src/metabase/timeline/api/timeline.clj+++ b/src/metabase/timeline/api/timeline.clj@@ -29,7 +29,7 @@"Create a new [[Timeline]]."[_route-params_query-params- {:keys [icon], collection-id :collection_id, :as body} :- [:map+ {:keys [icon], collection-id :collection_id, :as body} :- [:map {:closed true}[:name ms/NonBlankString][:default {:optional true} [:maybe :boolean]][:description {:optional true} [:maybe :string]]@@ -60,7 +60,7 @@(api.macros/defendpoint :get "/" :- [:sequential ::Timeline]"Fetch a list of `Timeline`s. Can include `archived=true` to return archived timelines."[_route-params- {:keys [include], archived? :archived} :- [:map+ {:keys [include], archived? :archived} :- [:map {:closed true}[:include {:optional true} ::include][:archived {:default false} ms/BooleanValue]]](let [timelines (->> (list-timelines archived?)@@ -72,9 +72,9 @@(api.macros/defendpoint :get "/:id" :- ::Timeline"Fetch the `Timeline` with `id`. Include `include=events` to unarchived events included on the timeline. Add`archived=true` to return all events on the timeline, both archived and unarchived."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]- {:keys [include archived start end]} :- [:map+ {:keys [include archived start end]} :- [:map {:closed true}[:include {:optional true} ::include][:archived {:default :false} ms/BooleanValue][:start {:optional true} ms/TemporalString]@@ -99,10 +99,10 @@(api.macros/defendpoint :put "/:id""Update the [[Timeline]] with `id`. Returns the timeline without events. Archiving a timeline will archive all of theevents in that timeline."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-params- {:keys [archived] :as timeline-updates} :- [:map+ {:keys [archived] :as timeline-updates} :- [:map {:closed true}[:name {:optional true} [:maybe ms/NonBlankString]][:default {:optional true} [:maybe :boolean]][:description {:optional true} [:maybe :string]]@@ -127,7 +127,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/:id""Delete a [[Timeline]]. Will cascade delete its events as well."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](let [timeline (api/write-check :model/Timeline id)](timeline.db/delete-timeline! id)@@ -141,7 +141,7 @@(api.macros/defendpoint :get "/collection/root""Fetch the root Collection's timelines."[_route-params- {:keys [include archived]} :- [:map+ {:keys [include archived]} :- [:map {:closed true}[:include {:optional true} [:maybe [:= "events"]]][:archived {:default false} [:maybe :boolean]]]](api/read-check collection/root-collection)@@ -154,9 +154,9 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/collection/:id""Fetch a specific Collection's timelines."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]- {:keys [include archived]} :- [:map+ {:keys [include archived]} :- [:map {:closed true}[:include {:optional true} [:maybe [:= "events"]]][:archived {:default false} [:maybe :boolean]]]](api/read-check (timeline.db/collection id))diff --git a/src/metabase/timeline/api/timeline_event.clj b/src/metabase/timeline/api/timeline_event.cljindex 0acb769c6de..c903c4027ed 100644--- a/src/metabase/timeline/api/timeline_event.clj+++ b/src/metabase/timeline/api/timeline_event.clj@@ -22,7 +22,7 @@[_route-params_query-params{:keys [timestamp time_matters icon timeline_id source question_id] :as body}- :- [:map+ :- [:map {:closed true}[:name ms/NonBlankString][:description {:optional true} [:maybe :string]][:timestamp ms/TemporalString]@@ -63,7 +63,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id""Fetch the [[TimelineEvent]] with `id`."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](api/read-check :model/TimelineEvent id))@@ -73,11 +73,11 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :put "/:id""Update a [[TimelineEvent]]."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-params{:keys [timestamp]- :as timeline-event-updates} :- [:map+ :as timeline-event-updates} :- [:map {:closed true}[:name {:optional true} [:maybe ms/NonBlankString]][:description {:optional true} [:maybe :string]][:timestamp {:optional true} [:maybe ms/TemporalString]]@@ -106,7 +106,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/:id""Delete a [[TimelineEvent]]."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](api/write-check :model/TimelineEvent id)(let [timeline-event (api/write-check :model/TimelineEvent id)]diff --git a/src/metabase/transforms/schema.clj b/src/metabase/transforms/schema.cljindex 24b3d52950e..2051ccb79c9 100644--- a/src/metabase/transforms/schema.clj+++ b/src/metabase/transforms/schema.clj@@ -13,12 +13,12 @@"A lookback window: each run re-reads source rows up to `value` `unit`s behind the checkpoint,so late-arriving rows older than the watermark still get picked up. Only supported fortemporal checkpoint columns."- [:map+ [:map {:closed true}[:value pos-int?][:unit (into [:enum] (map name) (sort u.date/add-units))]])(mr/def ::checkpoint-strategy- [:map+ [:map {:closed true}[:type [:= "checkpoint"]][:checkpoint-filter-field-id {:optional true} ::lib.schema.id/field][:lookback {:optional true} [:maybe ::lookback]]])@@ -32,12 +32,12 @@[:multi {:decode/normalize lib.schema.common/normalize-map-no-kebab-case:dispatch (comp keyword :type)}[:query- [:map+ [:map {:closed true}[:type {:decode/normalize lib.schema.common/normalize-keyword} [:= :query]][:query ::lib-be.schema/maybe-legacy-query][:source-incremental-strategy {:optional true} ::source-incremental-strategy]]][:python- [:map+ [:map {:closed true}[:source-database {:optional true} :int];; NB: if source is checkpoint, only one table allowed[:source-tables [:sequential ::transforms-base.u/source-table-entry]]@@ -46,17 +46,17 @@[:source-incremental-strategy {:optional true} ::source-incremental-strategy]]]])(mr/def ::append-config- [:map [:type [:= "append"]]])+ [:map {:closed true} [:type [:= "append"]]])(mr/def ::merge-key-column"One column of a merge unique key. Carries a resolved `:field-id` when the target column is known,degrading to a `:name` ref when the target table doesn't exist yet (mirrors `::source-table-entry`)."- [:map+ [:map {:closed true}[:name {:optional true} ms/NonBlankString][:field-id {:optional true} [:maybe ::lib.schema.id/field]]])(mr/def ::merge-config- [:map+ [:map {:closed true}[:type [:= "merge"]][:unique-key [:sequential ::merge-key-column]]])@@ -67,14 +67,14 @@["merge" ::merge-config]])(mr/def ::table-target- [:map+ [:map {:closed true}[:database {:optional true} :int][:type [:= "table"]][:schema {:optional true} [:maybe ms/NonBlankString]][:name :string]])(mr/def ::table-incremental-target- [:map+ [:map {:closed true}[:database {:optional true} :int][:type [:= "table-incremental"]][:schema {:optional true} [:maybe ms/NonBlankString]]diff --git a/src/metabase/transforms_base/util.clj b/src/metabase/transforms_base/util.cljindex cc8904e4486..db6bf00fa42 100644--- a/src/metabase/transforms_base/util.clj+++ b/src/metabase/transforms_base/util.clj@@ -798,7 +798,7 @@(mr/def ::source-table-entry"A source table entry in the array format. Combines alias with table reference."- [:map+ [:map {:closed true}[:alias :string][:database_id :int][:schema [:maybe :string]]diff --git a/src/metabase/transforms_rest/api/transform.clj b/src/metabase/transforms_rest/api/transform.cljindex 84a67d3dd13..c70de0c7c9a 100644--- a/src/metabase/transforms_rest/api/transform.clj+++ b/src/metabase/transforms_rest/api/transform.clj@@ -155,7 +155,7 @@"Get a list of transforms."[_route-paramsquery-params :-- [:map+ [:map {:closed true}[:last-run-start-time {:optional true} [:maybe ms/NonBlankString]][:last-run-statuses {:optional true} [:maybe (ms/QueryVectorOf [:enum "started" "succeeded" "failed" "timeout"])]][:tag-ids {:optional true} [:maybe (ms/QueryVectorOf ms/IntGreaterThanOrEqualToZero)]]@@ -169,7 +169,7 @@"Create a new transform."[_route-params_query-params- body :- [:map+ body :- [:map {:closed true}[:name :string][:description {:optional true} [:maybe :string]][:source ::transforms.schema/transform-source]@@ -191,13 +191,13 @@(api.macros/defendpoint :get "/:id" :- TransformResponse"Get a specific transform."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](transforms.core/get-transform id))(api.macros/defendpoint :get "/:id/dependencies" :- [:sequential TransformResponse]"Get the dependencies of a specific transform."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](api/read-check :model/Transform id)(let [id->transform (transforms-rest.db/transforms-by-id)@@ -215,7 +215,7 @@"Get transform runs based on a set of filter params."[_route-paramsquery-params :-- [:map+ [:map {:closed true}[:sort-column {:optional true} [:enum "transform-name" "start-time" "end-time" "status" "run-method" "transform-tags" "duration"]][:sort-direction {:optional true} [:enum "asc" "desc"]][:transform-ids {:optional true} [:maybe (ms/QueryVectorOf ms/PositiveInt)]]@@ -265,7 +265,7 @@any of the given transforms. The remaining filters work as in `GET /run`."[_route-paramsquery-params :-- [:map+ [:map {:closed true}[:types {:optional true} [:maybe (ms/QueryVectorOf [:enum "job" "dag" "transform"])]][:statuses {:optional true} [:maybe (ms/QueryVectorOf [:enum "started" "succeeded" "failed" "timeout" "canceled" "canceling"])]][:run-methods {:optional true} [:maybe (ms/QueryVectorOf [:enum "manual" "cron"])]]@@ -283,7 +283,7 @@(api.macros/defendpoint :get "/run/:run-id" :- TransformRunResponse"Get a transform run by ID."- [{:keys [run-id]} :- [:map+ [{:keys [run-id]} :- [:map {:closed true}[:run-id ms/PositiveInt]]](api/check-data-analyst)(-> (api/read-check :model/TransformRun run-id)@@ -292,10 +292,10 @@(api.macros/defendpoint :put "/:id" :- TransformResponse"Update a transform."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-params- body :- [:map+ body :- [:map {:closed true}[:name {:optional true} :string][:description {:optional true} [:maybe :string]][:source {:optional true} ::transforms.schema/transform-source]@@ -310,13 +310,13 @@(api.macros/defendpoint :delete "/:id" :- :nil"Delete a transform."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](transforms.core/delete-transform! (api/write-check :model/Transform id)))(api.macros/defendpoint :delete "/:id/table" :- :nil"Delete a transform's output table."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](api/write-check :model/Transform id)(transforms-base.u/delete-target-table-by-id! id)@@ -324,7 +324,7 @@(api.macros/defendpoint :post "/:id/cancel" :- :nil"Cancel the current run for a given transform."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](let [transform (api/write-check :model/Transform id)run (api/check-404 (transforms.core/running-run-for-transform-id id))]@@ -338,7 +338,7 @@(api.macros/defendpoint :post "/:id/reset-checkpoint" :- :nil"Reset the stored checkpoint for an incremental transform."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]](api/write-check :model/Transform id)(transforms-rest.db/reset-checkpoint! id)nil)@@ -371,7 +371,7 @@[:message :any][:run_id [:maybe pos-int?]]]]]"Run a transform."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](run-transform! (api/read-check :model/Transform id)))@@ -388,9 +388,9 @@`direction` selects which transforms are included:- `upstream` — the seed transform plus all transforms it depends on- `downstream` — the seed transform plus all transforms that depend on it"- [{:keys [id]} :- [:map [:id ms/PositiveInt]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]_query-params- {:keys [direction]} :- [:map+ {:keys [direction]} :- [:map {:closed true}[:direction (ms/enum-decode-keyword transforms.dag-run/dag-directions)]]](check-feature-and-lock! (api/write-check :model/Transform id))(transforms-rest.api.u/async-run-response@@ -406,8 +406,8 @@[:name :string]]]"Preview the transforms a DAG reprocess from this transform would run (see `POST /:id/run-dag`),in execution order."- [{:keys [id]} :- [:map [:id ms/PositiveInt]]- {:keys [direction]} :- [:map [:direction (ms/enum-decode-keyword transforms.dag-run/dag-directions)]]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]+ {:keys [direction]} :- [:map {:closed true} [:direction (ms/enum-decode-keyword transforms.dag-run/dag-directions)]]](api/read-check :model/Transform id)(mapv (fn [{xform-id :id, xform-name :name}]{:id xform-id, :name xform-name})diff --git a/src/metabase/transforms_rest/api/transform_dag_run.clj b/src/metabase/transforms_rest/api/transform_dag_run.cljindex 97f66080b3c..42051207f2f 100644--- a/src/metabase/transforms_rest/api/transform_dag_run.clj+++ b/src/metabase/transforms_rest/api/transform_dag_run.clj@@ -30,7 +30,7 @@(api.macros/defendpoint :get "/:run-id/transform-runs" :- [:sequential transforms-rest.api.u/MemberTransformRunResponse]"Get the transform runs that made up a specific DAG run."- [{:keys [run-id]} :- [:map [:run-id ms/PositiveInt]]]+ [{:keys [run-id]} :- [:map {:closed true} [:run-id ms/PositiveInt]]](let [dag-run (api/check-404 (transforms-rest.db/dag-run run-id))](check-seed-transform api/read-check dag-run)(->> (t2/hydrate (transforms.core/transform-runs-for-dag-run run-id)@@ -39,7 +39,7 @@(api.macros/defendpoint :post "/:run-id/cancel" :- :nil"Cancel an in-progress manual DAG run and request cancellation of its still-running transforms."- [{:keys [run-id]} :- [:map [:run-id ms/PositiveInt]]]+ [{:keys [run-id]} :- [:map {:closed true} [:run-id ms/PositiveInt]]](let [dag-run (api/check-404 (transforms-rest.db/dag-run run-id))](check-seed-transform api/write-check dag-run)(api/check-400 (transforms.core/cancel-dag-run! run-id))diff --git a/src/metabase/transforms_rest/api/transform_job.clj b/src/metabase/transforms_rest/api/transform_job.cljindex f80f53fc6d1..b2e997718fc 100644--- a/src/metabase/transforms_rest/api/transform_job.clj+++ b/src/metabase/transforms_rest/api/transform_job.clj@@ -92,7 +92,7 @@"Create a new transform job."[_route-params_query-params- {:keys [name description schedule ui_display_type tag_ids]} :- [:map+ {:keys [name description schedule ui_display_type tag_ids]} :- [:map {:closed true}[:name ms/NonBlankString][:description {:optional true} [:maybe ms/NonBlankString]][:schedule ms/NonBlankString]@@ -137,7 +137,7 @@error during the flip — the row update or Quartz write failed and was logged)."[_route-params_query-params- {:keys [active]} :- [:map [:active :boolean]]]+ {:keys [active]} :- [:map {:closed true} [:active :boolean]]](api/check-superuser)(log/info "Setting active =" active "on all transform jobs")(let [op (if active transforms.core/activate-job! transforms.core/deactivate-job!)@@ -156,11 +156,11 @@(api.macros/defendpoint :put "/:job-id" :- TransformJobResponse"Update a transform job."- [{:keys [job-id]} :- [:map+ [{:keys [job-id]} :- [:map {:closed true}[:job-id ms/PositiveInt]]_query-params{tag-ids :tag_ids- :keys [name description schedule ui_display_type active]} :- [:map+ :keys [name description schedule ui_display_type active]} :- [:map {:closed true}[:name {:optional true} ms/NonBlankString][:description {:optional true} [:maybe ms/NonBlankString]][:schedule {:optional true} ms/NonBlankString]@@ -211,7 +211,7 @@(api.macros/defendpoint :delete "/:job-id" :- nil"Delete a transform job."- [{:keys [job-id]} :- [:map [:job-id ms/PositiveInt]]]+ [{:keys [job-id]} :- [:map {:closed true} [:job-id ms/PositiveInt]]](log/info "Deleting transform job" job-id)(api/write-check (t2/hydrate (transforms-rest.db/job job-id) :tag_ids))(transforms-rest.db/delete-job! job-id)@@ -226,9 +226,9 @@"Run a transform job manually. Returns a 202 with the created `job_run_id`, or a nil `job_run_id`when nothing was run (the job is already running, or has no transforms). By default, freshpulled-in dependencies are skipped; pass `run_all` to force-refresh the whole plan."- [{:keys [job-id]} :- [:map [:job-id ms/PositiveInt]]+ [{:keys [job-id]} :- [:map {:closed true} [:job-id ms/PositiveInt]]_query-params- {:keys [run_all]} :- [:map+ {:keys [run_all]} :- [:map {:closed true}[:run_all {:default false} :boolean]]](log/info "Manual run of transform job" job-id)(api/write-check (transforms-rest.db/job job-id))@@ -243,7 +243,7 @@(api.macros/defendpoint :get "/:job-id" :- TransformJobResponse"Get a transform job by ID."- [{:keys [job-id]} :- [:map+ [{:keys [job-id]} :- [:map {:closed true}[:job-id ms/PositiveInt]]](log/info "Getting transform job" job-id)(-> (api/read-check (transforms-rest.db/job job-id))@@ -258,7 +258,7 @@(api.macros/defendpoint :get "/:job-id/transforms" :- [:sequential TransformResponse]"Get the transforms of job specified by the job's ID."- [{:keys [job-id]} :- [:map+ [{:keys [job-id]} :- [:map {:closed true}[:job-id ms/PositiveInt]]](log/info "Getting the transforms of transform job" job-id)(api/check-404 (transforms-rest.db/job-pk job-id))@@ -271,7 +271,7 @@"Get all transform jobs."[_route-params{:keys [last-run-start-time next-run-start-time last-run-statuses tag-ids]} :-- [:map+ [:map {:closed true}[:last-run-start-time {:optional true} [:maybe ms/NonBlankString]][:next-run-start-time {:optional true} [:maybe ms/NonBlankString]][:last-run-statuses {:optional true} [:maybe (ms/QueryVectorOf [:enum "started" "succeeded" "failed" "timeout"])]]@@ -310,8 +310,8 @@[:offset :int][:total :int]]"Get paginated run history for a transform job."- [{:keys [job-id]} :- [:map [:job-id ms/PositiveInt]]- query-params :- [:map+ [{:keys [job-id]} :- [:map {:closed true} [:job-id ms/PositiveInt]]+ query-params :- [:map {:closed true}[:status {:optional true} [:maybe [:enum "started" "succeeded" "failed" "timeout" "canceled"]]][:run-method {:optional true} [:maybe [:enum "manual" "cron"]]][:start-time {:optional true} [:maybe ms/NonBlankString]]@@ -326,7 +326,7 @@(api.macros/defendpoint :get "/:job-id/runs/:run-id/transform-runs" :- [:sequential transforms-rest.api.u/MemberTransformRunResponse]"Get the transform runs that made up a specific job run."- [{:keys [job-id run-id]} :- [:map+ [{:keys [job-id run-id]} :- [:map {:closed true}[:job-id ms/PositiveInt][:run-id ms/PositiveInt]]_query-params]@@ -338,7 +338,7 @@(api.macros/defendpoint :post "/:job-id/runs/:run-id/cancel" :- :nil"Cancel an in-progress job run and request cancellation of its still-running transforms."- [{:keys [job-id run-id]} :- [:map+ [{:keys [job-id run-id]} :- [:map {:closed true}[:job-id ms/PositiveInt][:run-id ms/PositiveInt]]](api/write-check :model/TransformJob job-id)diff --git a/src/metabase/transforms_rest/api/transform_tag.clj b/src/metabase/transforms_rest/api/transform_tag.cljindex 129432a5fc3..a8bc992d851 100644--- a/src/metabase/transforms_rest/api/transform_tag.clj+++ b/src/metabase/transforms_rest/api/transform_tag.clj@@ -27,7 +27,7 @@"Create a new transform tag."[_route-params_query-params- {:keys [name]} :- [:map+ {:keys [name]} :- [:map {:closed true}[:name ms/NonBlankString]]](log/info "Creating transform tag")(api/check-403 (mi/can-create? :model/TransformTag {:name name}))@@ -37,10 +37,10 @@(api.macros/defendpoint :put "/:tag-id" :- TransformTagResponse"Update a transform tag."- [{:keys [tag-id]} :- [:map+ [{:keys [tag-id]} :- [:map {:closed true}[:tag-id ms/PositiveInt]]_query-params- {:keys [name]} :- [:map+ {:keys [name]} :- [:map {:closed true}[:name ms/NonBlankString]]](log/info "Updating transform tag" tag-id)(api/write-check (transforms-rest.db/tag tag-id))@@ -51,7 +51,7 @@(api.macros/defendpoint :delete "/:tag-id" :- :nil"Delete a transform tag. Removes it from all transforms and jobs."- [{:keys [tag-id]} :- [:map+ [{:keys [tag-id]} :- [:map {:closed true}[:tag-id ms/PositiveInt]]](log/info "Deleting transform tag" tag-id)(api/write-check (transforms-rest.db/tag tag-id))diff --git a/src/metabase/typed_schemas_rest/api.clj b/src/metabase/typed_schemas_rest/api.cljindex 4561464612a..5757293a4fe 100644--- a/src/metabase/typed_schemas_rest/api.clj+++ b/src/metabase/typed_schemas_rest/api.clj@@ -20,7 +20,7 @@"Cache-Control" "no-store"})(def ^:private TypedSchemaQueryParams- [:map+ [:map {:closed true}[:database {:optional true}[:maybe {:description "Scopes the schema to a database by numeric id or name."}ms/NonBlankString]]diff --git a/src/metabase/upload/api.clj b/src/metabase/upload/api.cljindex 8d7a63d6d8e..b6358d98143 100644--- a/src/metabase/upload/api.clj+++ b/src/metabase/upload/api.clj@@ -50,7 +50,7 @@(when-not (= collection-id "root")collection-id))}pos-int?]]- [:file [:map+ [:file [:map {:closed true}[:filename :string][:tempfile (ms/InstanceOfClass java.io.File)]]]]];; parse-long returns nil with "root" as the collection ID, which is what we want anywaydiff --git a/src/metabase/upload/impl.clj b/src/metabase/upload/impl.cljindex 37a1f545f78..28e4da03e5c 100644--- a/src/metabase/upload/impl.clj+++ b/src/metabase/upload/impl.clj@@ -17,6 +17,7 @@[metabase.driver.sync :as driver.s][metabase.driver.util :as driver.u][metabase.events.core :as events]+ [metabase.lib-be.schema :as lib-be.schema][metabase.lib.core :as lib][metabase.model-persistence.core :as model-persistence][metabase.models.humanization :as humanization]@@ -989,7 +990,7 @@[models :- [:sequential [:map;; query_type and dataset_query can be null in tests, so we make them nullable here.;; they should never be null in production- [:dataset_query [:maybe ms/Map]]+ [:dataset_query [:maybe ::lib-be.schema/maybe-legacy-or-empty-query]][:query_type [:maybe [:or :string :keyword]]][:table_id [:maybe ms/PositiveInt]];; is_upload can be provided for an optional optimizationdiff --git a/src/metabase/user_key_value/api.clj b/src/metabase/user_key_value/api.cljindex ed55465d9a2..275aa8da497 100644--- a/src/metabase/user_key_value/api.clj+++ b/src/metabase/user_key_value/api.clj@@ -16,12 +16,12 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :put "/namespace/:namespace/key/:key""Upsert a KV-pair for the user"- [{nmspace :namespace, k :key} :- [:map+ [{nmspace :namespace, k :key} :- [:map {:closed true}[:key ms/NonBlankString][:namespace ms/NonBlankString]]_query-params- {v :value, expires-at :expires_at} :- [:map- [:value {:optional true} :any]+ {v :value, expires-at :expires_at} :- [:map {:closed true}+ [:value {:optional true} [:maybe [:or :string number? :boolean ms/OpaqueJSONObject [:sequential [:or :string number? :boolean ms/OpaqueJSONObject]]]]][:expires_at {:optional true} [:maybe :metabase.lib.schema.literal/string.datetime]]]](try(user-key-value/put! api/*current-user-id* (mc/coerce ::types/user-key-value@@ -46,7 +46,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/namespace/:namespace/key/:key""Get a value for the user"- [{nmspace :namespace, k :key} :- [:map+ [{nmspace :namespace, k :key} :- [:map {:closed true}[:key ms/NonBlankString][:namespace ms/NonBlankString]]](user-key-value/retrieve api/*current-user-id* nmspace k))@@ -57,7 +57,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/namespace/:namespace""Returns all KV pairs in a given namespace for the current user"- [{nmspace :namespace} :- [:map+ [{nmspace :namespace} :- [:map {:closed true}[:namespace ms/NonBlankString]]](user-key-value/retrieve-all api/*current-user-id* nmspace))@@ -67,7 +67,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/namespace/:namespace/key/:key""Deletes a KV-pair for the user"- [{nmspace :namespace, k :key} :- [:map+ [{nmspace :namespace, k :key} :- [:map {:closed true}[:key ms/NonBlankString][:namespace ms/NonBlankString]]](user-key-value/delete! api/*current-user-id* nmspace k))diff --git a/src/metabase/users/schema.clj b/src/metabase/users/schema.cljindex b3380a7a38c..a2a3dd15976 100644--- a/src/metabase/users/schema.clj+++ b/src/metabase/users/schema.clj@@ -2,6 +2,7 @@(:require[clojure.string :as str][metabase.lib.schema.id :as lib.schema.id]+ [metabase.lib.schema.parameter :as lib.schema.parameter][metabase.util.i18n :refer [deferred-tru]][metabase.util.malli :as mu][metabase.util.malli.registry :as mr]@@ -10,11 +11,7 @@(def LoginAttributes"Login attributes, currently not collected for LDAP or Google Auth. Will ultimately be stored as JSON."[:and- [:map-of- (mu/with-api-error-message- ms/KeywordOrString- (deferred-tru "login attribute keys must be a keyword or string"))- :any]+ (ms/string-keyed-map [:ref ::lib.schema.parameter/parameter.value]);; checked over the whole map rather than as part of the key schema: a key that fails the key schema is stripped;; from the request, which would drop the attribute silently instead of telling the caller.(mu/with-api-error-message@@ -39,7 +36,7 @@(mr/def ::user-group-membership"Group Membership info of a User.In which :is_group_manager is only included if `advanced-permissions` is enabled."- [:map+ [:map {:closed true}[:id ms/PositiveInt][:is_group_manager{:optional true, :description "Only relevant if `advanced-permissions` is enabled. If it is, you should always include this key."}@@ -48,7 +45,7 @@(def InviteTarget"The dashboard or question an invite points at, as `{:type :id :name}`. Drives the post-signuplanding redirect and the scoped invite email. Not an access grant; collection permissions still apply."- [:map+ [:map {:closed true}[:type [:enum "dashboard" "question"]][:id ms/PositiveInt][:name ms/NonBlankString]])diff --git a/src/metabase/users_rest/api.clj b/src/metabase/users_rest/api.cljindex 13d04bd3885..33d6c30e966 100644--- a/src/metabase/users_rest/api.clj+++ b/src/metabase/users_rest/api.clj@@ -174,7 +174,7 @@If the user is a sandboxed user, only return themselves regardless of the query parameters."[_route-params{:keys [status query group_id include_deactivated tenant_id tenancy is_data_analyst can_access_data_studio] :as params}- :- [:map+ :- [:map {:closed true}[:status {:optional true} [:maybe :string]][:query {:optional true} [:maybe :string]][:group_id {:optional true} [:maybe ms/PositiveInt]]@@ -412,7 +412,7 @@(api.macros/defendpoint :get "/:id""Fetch a `User`. You must be fetching yourself *or* be a superuser *or* a Group Manager.Only personal users can be fetched this way; API-key users and the internal user 404."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](try(users/check-self-or-superuser id)@@ -434,7 +434,7 @@"Create a new `User`, return a 400 if the email address is already taken"[_route-params_query-params- body :- [:map+ body :- [:map {:closed true}[:first_name {:optional true} [:maybe ms/NonBlankString]][:last_name {:optional true} [:maybe ms/NonBlankString]][:email ms/Email]@@ -498,11 +498,11 @@Self or superusers can update user info and groups.Group Managers can only add/remove users from groups they are manager of.Only personal users can be updated this way; API-key users 404 (manage them via `/api/api-key` instead)."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-params{:keys [email first_name last_name user_group_memberships is_superuser is_data_analyst] :as body}- :- [:map+ :- [:map {:closed true}[:email {:optional true} [:maybe ms/Email]][:first_name {:optional true} [:maybe ms/NonBlankString]][:last_name {:optional true} [:maybe ms/NonBlankString]]@@ -587,7 +587,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :put "/:id/reactivate""Reactivate user at `:id`"- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](api/check-superuser)(check-not-internal-user id)@@ -614,10 +614,10 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :put "/:id/password""Update a user's password."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-params- {:keys [password old_password]} :- [:map+ {:keys [password old_password]} :- [:map {:closed true}[:password ms/ValidPassword][:old_password {:optional true} [:maybe :string]]]request]@@ -648,7 +648,7 @@(api.macros/defendpoint :post "/:id/password-reset-url" :- [:map [:password_reset_url :string]]"Generate a password reset URL for a user. Admins can share this URL directly with the user.The link expires in 48 hours."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](api/check-superuser)(let [user (api/check-404 (users-rest.db/user-active-and-type id))]@@ -670,7 +670,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/:id""Disable a `User`. This does not remove the `User` from the DB, but instead disables their account."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](api/check-superuser);; don't technically need to because the internal user is already 'deleted' (deactivated), but keeps the warnings consistent@@ -692,7 +692,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :put "/:id/modal/:modal""Indicate that a user has been informed about the vast intricacies of 'the' Query Builder."- [{:keys [id modal]} :- [:map+ [{:keys [id modal]} :- [:map {:closed true}[:id ms/PositiveInt][:modal [:enum "qbnewb" "datasetnewb"]]]](users/check-self-or-superuser id)diff --git a/src/metabase/util/cron.clj b/src/metabase/util/cron.cljindex ff92dd3a60c..e68b4b6e21b 100644--- a/src/metabase/util/cron.clj+++ b/src/metabase/util/cron.clj@@ -44,7 +44,7 @@(mr/def ::ScheduleMap(mu/with-api-error-message[:map- {:error/message "Expanded schedule map"}+ {:closed true :error/message "Expanded schedule map"}[:schedule_type [:enum "hourly" "daily" "weekly" "monthly"]][:schedule_day {:optional true} [:maybe [:enum "sun" "mon" "tue" "wed" "thu" "fri" "sat"]]][:schedule_frame {:optional true} [:maybe [:enum "first" "mid" "last"]]]@@ -52,6 +52,10 @@[:schedule_minute {:optional true} [:maybe ::CronMinute]]](i18n/deferred-tru "value must be a valid schedule map. See schema in metabase.util.cron for details.")))+(def schedule-keys+ "The keys of a [[ScheduleMap]]."+ [:schedule_type :schedule_day :schedule_frame :schedule_hour :schedule_minute])+(def ScheduleMap"Schema for a frontend-parsable schedule map. Used for Pulses and DB scheduling."[:ref ::ScheduleMap])diff --git a/src/metabase/util/malli/schema.clj b/src/metabase/util/malli/schema.cljindex 1a23d6a47f7..175eaca8d11 100644--- a/src/metabase/util/malli/schema.clj+++ b/src/metabase/util/malli/schema.clj@@ -4,11 +4,13 @@For example the PositiveInt can be defined as (mr/def ::positive-int pos-int?)"(:require[clojure.string :as str]+ [clojure.walk :as walk]+ [malli.core :as mc][metabase.util :as u][metabase.util.date-2 :as u.date][metabase.util.i18n :as i18n :refer [deferred-tru]]- [metabase.util.json :as json][metabase.util.malli :as mu]+ [metabase.util.malli.registry :as mr][metabase.util.password :as u.password][toucan2.core :as t2]))@@ -16,6 +18,18 @@;;; -------------------------------------------------- Utils --------------------------------------------------+(defn- stringify-keys+ "Turn the keyword keys of `x`, if it is a map, into strings, keeping their namespaces -- and, when `recursive?`, the+ keys of every map nested inside it too. Request decoding keywordizes every JSON object key; this undoes that for the+ objects we do not type."+ ([x]+ (stringify-keys x false))+ ([x recursive?]+ (if recursive?+ (walk/postwalk stringify-keys x)+ (cond-> x+ (map? x) (update-keys #(if (keyword? %) (u/qualified-name %) %))))))+;;; TODO -- consider renaming this to `InstanceOfModel` to differentiate it from [[InstanceOfClass]];;;;;; TODO (Cam 9/29/25) -- maybe we should just automatically generate schemas for all the known models@@ -202,12 +216,74 @@[:fn #(isa? (keyword %) :entity/*)](deferred-tru "value must be a valid entity type (keyword or string).")))-(def Map- "Schema for a valid map. Open: it constrains nothing about its keys, so its contents pass through as they arrived."+(defn- open-map+ "A map whose keys are deliberately not ours to declare. The marker property is what lets+ [[metabase.api.macros.defendpoint.closed-schemas]] accept it; nothing outside this namespace should set it."+ [description](mu/with-api-error-message- [:map {:closed false}]+ [:map {:closed false, ::mr/deliberately-open true, :description description}](deferred-tru "Value must be a map.")))+(def VisualizationSettings+ "Chart-rendering settings authored by the frontend. The backend stores and echoes them and reads no fixed key set, so+ the keys are whatever the visualization the user picked needs."+ (open-map "visualization settings"))++(def DatabaseDetails+ "Connection details for a Database. The keys are the driver's `connection-properties`, so they differ per driver and+ are not knowable here."+ (open-map "database connection details"))++(def DatabaseSettings+ "A Database's `:settings`: database-local settings, whose keys are owned by the settings registry rather than by this+ schema. Not for any other bag of settings."+ (open-map "database settings"))++(defn string-keyed-map+ "Schema for a JSON object whose keys are not ours to declare, as a `:map-of` string keys to `value-schema`.+ Normalizing stringifies its keys -- a request on its way in, or a keywordized JSON column read back from the+ application database -- so the value looks the way it did on the wire and nothing can quietly start reading it by+ keyword. Only the keys of the map itself, unless `recursive?`, which stringifies the keys of every map nested inside+ it as well. Dispatching on `map?` keeps a value that is not a map out of the `:map-of`, whose request-decoding strip+ step would otherwise throw on it instead of leaving it to validation."+ ([value-schema]+ (string-keyed-map value-schema false))+ ([value-schema recursive?]+ (mu/with-api-error-message+ [:multi {:dispatch map?}+ [true [:map-of {:decode/normalize {:enter #(stringify-keys % recursive?)}} :string value-schema]]+ [false (mu/with-api-error-message [:fn map?] (deferred-tru "Value must be a map."))]]+ (deferred-tru "Value must be a map."))))++(def OpaqueJSONObject+ "A JSON object this code stores, echoes back or forwards as it arrived, and never reads by key: a+ [[string-keyed-map]] of anything, stringified all the way down. Under no circumstances may its keys be keywords: a+ map this code builds and reads by keyword is not opaque and gets a schema of its own. The marker property is what+ lets [[metabase.api.macros.defendpoint.closed-schemas]] accept the `:any`."+ (mu/with (string-keyed-map :any true) {::mr/deliberately-open true}))++(defn string-keyed-object+ "Schema for a JSON object of which this code reads a few keys and keeps the rest as they arrived: an+ [[OpaqueJSONObject]] whose `entries` declare, with string keys, the keys this code reads and their types.++ (string-keyed-object [\"id\" :int] [\"label\" {:optional true} [:maybe :string]])++ Every key of the object is a string, the declared ones included, so the map never mixes keyword and string keys and+ code reads the declared keys the same way it would any other: `(get attrs \"id\")`. Decoding stringifies the keys of+ the object itself first of all -- a request on its way in, or a keywordized JSON column read back from the+ application database -- so the declared entries, their defaults included, are found under their string keys; the+ values of the undeclared keys are stringified all the way down, the declared ones only as their schemas say. Prefer a+ fully typed map when the keys are known: this is for objects another party owns, like an editor's node attributes."+ [& entries]+ (doseq [[k] entries]+ (assert (string? k) (str "string-keyed-object keys must be strings, got: " (pr-str k))))+ (into [:map+ {:decode/string {:enter stringify-keys}+ :decode/json {:enter stringify-keys}+ :decode/normalize {:enter stringify-keys}}+ [::mc/default OpaqueJSONObject]]+ entries))+(def Email"Schema for a valid email string."(mu/with-api-error-message@@ -246,18 +322,6 @@[:fn #(u/ignore-exceptions (boolean (u.date/parse %)))]](deferred-tru "value must be a valid date string")))-(def JSONString- "Schema for a string that is valid serialized JSON."- (mu/with-api-error-message- [:and- :string- [:fn #(try- (json/decode %)- true- (catch Throwable _- false))]]- (deferred-tru "value must be a valid JSON string.")))-(def BooleanValue"Schema for a valid representation of a boolean(one of `\"true\"` or `true` or `\"false\"` or `false`.).@@ -278,24 +342,25 @@(mu/with-api-error-message(deferred-tru "value must be a valid boolean string (''true'' or ''false'')."))))+(def FieldValue+ "One value of a Field: a JSON scalar as kept in the `field_values.values` and `human_readable_values` columns, or, on+ the way there, a UUID or `java.time` object as the query returned it."+ [:maybe [:or :string number? :boolean uuid? (InstanceOfClass java.time.temporal.Temporal)]])+(def RemappedFieldValue"Has two components:- 1. <value-of-field> (can be anything)+ 1. <value-of-field>2. <value-of-remapped-field> (must be a string)"- [:tuple :any :string])+ [:tuple FieldValue :string])(def NonRemappedFieldValue"Has one component: <value-of-field>"- [:tuple :any])+ [:tuple FieldValue])(def FieldValuesList"Schema for a valid list of values for a field, in contexts where the field can have a remapped field."[:sequential [:or RemappedFieldValue NonRemappedFieldValue]])-(def FieldValue- "One stored value of a Field, as kept in the `field_values.values` and `human_readable_values` columns."- [:maybe [:or :string number? :boolean]])-(def FieldValues"The stored values of a Field: the decoded `field_values.values` or `human_readable_values` column."[:sequential FieldValue])@@ -308,11 +373,11 @@;;; TODO -- move to `embedding`(def EmbeddingParams- "Schema for a valid map of embedding params."+ "Schema for a valid map of embedding params: parameter slug -> how the embed treats that parameter. The slugs are the+ embed author's, so the map is string-keyed on its way in; it is stored as JSON and read back keywordized like every+ other JSON column."(mu/with-api-error-message- [:maybe [:map-of- :keyword- [:enum "disabled" "enabled" "locked"]]]+ [:maybe (string-keyed-map [:enum "disabled" "enabled" "locked"])](deferred-tru "value must be a valid embedding params map.")))(def ValidLocalediff --git a/src/metabase/warehouse_schema/models/field_values.clj b/src/metabase/warehouse_schema/models/field_values.cljindex 81ab782c284..84dfeec92be 100644--- a/src/metabase/warehouse_schema/models/field_values.clj+++ b/src/metabase/warehouse_schema/models/field_values.clj@@ -385,7 +385,8 @@::lib.schema.metadata/column]](try(let [field (cond-> field- (t2/model field) (lib-be/instance->metadata :metadata/column))+ ;; a caller may hand us a Field hydrated with its Table, which is not part of column metadata+ (t2/model field) (-> (dissoc :table) (lib-be/instance->metadata :metadata/column)))result ((requiring-resolve 'metabase.warehouse-schema.metadata-from-qp/table-query)(:table-id field)(fn [query]diff --git a/src/metabase/warehouse_schema_rest/api/field.clj b/src/metabase/warehouse_schema_rest/api/field.cljindex bc094549bc4..88cbcd6a58d 100644--- a/src/metabase/warehouse_schema_rest/api/field.clj+++ b/src/metabase/warehouse_schema_rest/api/field.clj@@ -52,9 +52,9 @@:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id""Get `Field` with ID."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]- {include-editable-data-model? :include_editable_data_model} :- [:map+ {include-editable-data-model? :include_editable_data_model} :- [:map {:closed true}[:include_editable_data_model {:default false} ms/BooleanValue]]](schema.field/get-field id {:include-editable-data-model? include-editable-data-model?}))@@ -63,7 +63,7 @@"Get unique Table IDs for a list of Field IDs."[_route-params_query-params- {:keys [field_ids]} :- [:map+ {:keys [field_ids]} :- [:map {:closed true}[:field_ids [:sequential ms/PositiveInt]]]](api/check-400 (<= (count field_ids) max-field-ids-for-table-id-lookup)(format "field_ids may contain at most %d IDs." max-field-ids-for-table-id-lookup))@@ -140,13 +140,13 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :put "/:id""Update `Field` with ID."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-params{display-name :display_namecoercion-strategy :coercion_strategyjson-unfolding :json_unfolding- :as body} :- [:map+ :as body} :- [:map {:closed true}[:caveats {:optional true} [:maybe ms/NonBlankString]][:description {:optional true} [:maybe ms/NonBlankString]][:display_name {:optional true} [:maybe ms/NonBlankString]]@@ -157,7 +157,7 @@[:visibility_type {:optional true} [:maybe FieldVisibilityType]][:data_sensitivity {:optional true} [:maybe FieldDataSensitivity]][:has_field_values {:optional true} [:maybe ::lib.schema.metadata/column.has-field-values]]- [:settings {:optional true} [:maybe ms/Map]]+ [:settings {:optional true} [:maybe ms/VisualizationSettings]][:nfc_path {:optional true} [:maybe [:sequential ms/NonBlankString]]][:json_unfolding {:optional true} [:maybe :boolean]]]](let [field (t2/hydrate (api/write-check :model/Field id) :dimensions)@@ -209,14 +209,15 @@(update-nested-fields-on-json-unfolding-change! field json-unfolding));; return updated field. note the fingerprint on this might be out of date if the task below would replace them;; but that shouldn't matter for the datamodel page- (u/prog1 (-> (warehouse-schema-rest.db/field id)- (t2/hydrate :dimensions :has_field_values)- (field/hydrate-target-with-write-perms))- (events/publish-event! :event/field-update {:object <> :user-id api/*current-user-id*})- (when (not= effective-type (:effective_type field))- (analytics/track-event! :snowplow/simple_event {:event "field_effective_type_change" :target_id id})- ;; Run with admin perms to match behavior during normal sync.- (quick-task/submit-task! (fn [] (request/as-admin (sync/refingerprint-field! <>))))))))+ (let [updated (warehouse-schema-rest.db/field id)]+ (u/prog1 (-> updated+ (t2/hydrate :dimensions :has_field_values)+ (field/hydrate-target-with-write-perms))+ (events/publish-event! :event/field-update {:object <> :user-id api/*current-user-id*})+ (when (not= effective-type (:effective_type field))+ (analytics/track-event! :snowplow/simple_event {:event "field_effective_type_change" :target_id id})+ ;; Run with admin perms to match behavior during normal sync.+ (quick-task/submit-task! (fn [] (request/as-admin (sync/refingerprint-field! updated)))))))));;; ------------------------------------------------- Field Metadata -------------------------------------------------@@ -226,7 +227,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id/summary""Get the count and distinct count of `Field` with ID."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](let [field (api/read-check :model/Field id)][[:count (metadata-from-qp/field-count field)]@@ -240,11 +241,11 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :post "/:id/dimension""Sets the dimension for the given field at ID"- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-params{dimension-type :type, dimension-name :name, human-readable-field-id :human_readable_field_id}- :- [:map+ :- [:map {:closed true}[:type [:enum "internal" "external"]][:name ms/NonBlankString][:human_readable_field_id {:optional true} [:maybe ms/PositiveInt]]]]@@ -275,7 +276,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/:id/dimension""Remove the dimension associated to field at ID"- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](api/write-check :model/Field id)(warehouse-schema-rest.db/delete-dimensions-for-field! id)@@ -289,7 +290,7 @@"If a Field's value of `has_field_values` is `:list`, return a list of all the distinct values of the Field (orremapped Field), and (if defined by a User) a map of human-readable remapped values. If `has_field_values` is not`:list`, checks whether we should create FieldValues for this Field; if so, creates and returns them."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](let [field (api/query-check (warehouse-schema-rest.db/field id))](parameters.field/field->values field)))@@ -312,11 +313,11 @@(api.macros/defendpoint :post "/:id/values""Update the fields values and human-readable values for a `Field` whose semantic type is`category`/`city`/`state`/`country` or whose base type is `type/Boolean`. The human-readable values are optional."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-params- {value-pairs :values} :- [:map- [:values [:sequential [:or [:tuple :any] [:tuple :any ms/NonBlankString]]]]]]+ {value-pairs :values} :- [:map {:closed true}+ [:values ms/FieldValuesList]]](let [field (api/write-check :model/Field id)](api/check (field-values/field-should-have-field-values? field)[400 (str "You can only update the human readable values of a mapped values of a Field whose value of "@@ -340,7 +341,7 @@(api.macros/defendpoint :post "/:id/rescan_values""Manually trigger an update for the FieldValues for this Field. Only applies to Fields that are eligible forFieldValues."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](analytics/track-event! :snowplow/simple_event {:event "field_manual_scan" :target_id id})(let [field (api/write-check (warehouse-schema-rest.db/field id))@@ -365,7 +366,7 @@(api.macros/defendpoint :post "/:id/discard_values""Discard the FieldValues belonging to this Field. Only applies to fields that have FieldValues. If this Field'sDatabase is set up to automatically sync FieldValues, they will be recreated during the next cycle."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](field-values/clear-field-values-for-field! (api/write-check (warehouse-schema-rest.db/field id))){:status :success})@@ -379,10 +380,10 @@(api.macros/defendpoint :get "/:id/search/:search-id""Search for values of a Field with `search-id` that start with `value`. See docstring for[[metabase.parameters.field/search-values]] for a more detailed explanation."- [{:keys [id search-id]} :- [:map+ [{:keys [id search-id]} :- [:map {:closed true}[:id ms/PositiveInt][:search-id ms/PositiveInt]]- {:keys [value]} :- [:map+ {:keys [value]} :- [:map {:closed true}[:value {:optional true} ms/NonBlankString]]](when-not value(api/check-400 (request/limit) "Limit required if value is omitted"))@@ -398,10 +399,10 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id/remapping/:remapped-id""Fetch remapped Field values."- [{:keys [id remapped-id]} :- [:map+ [{:keys [id remapped-id]} :- [:map {:closed true}[:id ms/PositiveInt][:remapped-id ms/PositiveInt]]- {:keys [value]} :- [:map+ {:keys [value]} :- [:map {:closed true}[:value ms/NonBlankString]]](let [field (api/read-check :model/Field id)remapped-field (api/read-check :model/Field remapped-id)@@ -414,6 +415,6 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id/related""Return related entities."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](-> (warehouse-schema-rest.db/field id) api/read-check xrays/related))diff --git a/src/metabase/warehouse_schema_rest/api/table.clj b/src/metabase/warehouse_schema_rest/api/table.cljindex 04c62dd08d4..82ca4498466 100644--- a/src/metabase/warehouse_schema_rest/api/table.clj+++ b/src/metabase/warehouse_schema_rest/api/table.clj@@ -2,7 +2,6 @@"/api/table endpoints."(:require[clojure.java.io :as io]- [malli.core :as mc][metabase.api.common :as api][metabase.api.macros :as api.macros][metabase.collections.core :as collections]@@ -75,7 +74,7 @@[_{:keys [term visibility-type data-layer data-source owner-user-id owner-email orphan-only unused-onlypublished-only can-query can-write include-transform-targets]}- :- [:map+ :- [:map {:closed true}[:term {:optional true} :string][:visibility-type {:optional true} :string][:data-layer {:optional true} ::data-layers]@@ -122,10 +121,10 @@:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id""Get `Table` with ID."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]{:keys [include_editable_data_model]}- :- [:map+ :- [:map {:closed true}[:include_editable_data_model {:optional true} [:maybe :boolean]]]];; partial schema only:- [:map {:closed false}@@ -143,7 +142,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:table-id/data""Get the data for the given table"- [{:keys [table-id]} :- [:map [:table-id ms/PositiveInt]]]+ [{:keys [table-id]} :- [:map {:closed true} [:table-id ms/PositiveInt]]](let [table (warehouse-schema-rest.db/table table-id)db-id (:db_id table)](api/query-check table)@@ -242,10 +241,10 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :put "/:id""Update `Table` with ID."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-params- body :- [:map+ body :- [:map {:closed true}[:display_name {:optional true} [:maybe ms/NonBlankString]][:entity_type {:optional true} [:maybe ms/EntityTypeKeywordOrString]][:visibility_type {:optional true} [:maybe TableVisibilityType]]@@ -272,7 +271,7 @@Deprecated, should use PUT /table/edit from now on."[_route-params_query-params- {:keys [ids], :as body} :- [:map+ {:keys [ids], :as body} :- [:map {:closed true}[:ids [:sequential ms/PositiveInt]][:display_name {:optional true} [:maybe ms/NonBlankString]][:entity_type {:optional true} [:maybe ms/EntityTypeKeywordOrString]]@@ -307,10 +306,10 @@data model, while `false` checks that they have data access perms for the table. Defaults to `false`.These options are provided for use in the Admin Edit Metadata page."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]{:keys [include_sensitive_fields include_hidden_fields include_editable_data_model]}- :- [:map+ :- [:map {:closed true}[:include_sensitive_fields {:default false} [:maybe ms/BooleanValue]][:include_hidden_fields {:default false} [:maybe ms/BooleanValue]][:include_editable_data_model {:default false} [:maybe ms/BooleanValue]]]]@@ -327,7 +326,7 @@:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/card__:id/query_metadata""Return metadata for the 'virtual' table for a Card."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](first (schema.table/batch-fetch-card-query-metadatas [id] {:include-database? true})))@@ -341,7 +340,7 @@(api.macros/defendpoint :get "/card__:id/fks""Return FK info for the 'virtual' table for a Card. This is always empty, so this endpointserves mainly as a placeholder to avoid having to change anything on the frontend."- [_route-params :- [:map+ [_route-params :- [:map {:closed true}[:id ms/PositiveInt]]][]) ; return empty array@@ -351,7 +350,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id/fks""Get all foreign keys whose destination is a `Field` that belongs to this `Table`."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](api/read-check :model/Table id)(when-let [field-ids (seq (warehouse-schema-rest.db/active-unretired-field-ids-for-table id))]@@ -377,7 +376,7 @@(api.macros/defendpoint :post "/:id/rescan_values""Manually trigger an update for the FieldValues for the Fields belonging to this Table. Only applies to Fields thatare eligible for FieldValues."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](let [table (api/write-check (warehouse-schema-rest.db/table id))](events/publish-event! :event/table-manual-scan {:object table :user-id api/*current-user-id*})@@ -401,7 +400,7 @@(api.macros/defendpoint :post "/:id/discard_values""Discard the FieldValues belonging to the Fields in this Table. Only applies to fields that have FieldValues. Ifthis Table's Database is set up to automatically sync FieldValues, they will be recreated during the next cycle."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](api/write-check (warehouse-schema-rest.db/table id))(when-let [field-ids (warehouse-schema-rest.db/field-ids-for-table id)]@@ -414,20 +413,20 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id/related""Return related entities."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](-> (warehouse-schema-rest.db/table id) api/read-check xrays/related))(api.macros/defendpoint :put "/:id/fields/order" :- [:map[:success [:= true]]]"Reorder fields"- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-params;; Accept either a bare sequential (legacy) or a wrapped {:field_order [...]} body.body :- [:or[:sequential ms/PositiveInt]- [:map [:field_order [:sequential ms/PositiveInt]]]]]+ [:map {:closed true} [:field_order [:sequential ms/PositiveInt]]]]](let [field-order (if (map? body) (:field_order body) body)](-> (warehouse-schema-rest.db/table id) api/write-check (table/custom-order-fields! field-order))){:success true})@@ -453,15 +452,14 @@"The multipart parts a CSV upload may carry. A part under any other name is rejected rather than dropped, so a secondfile cannot be smuggled past the upload: `::mc/default` keeps the extra parts, and the check below refuses them."[:and- [:map- [:file- [:map+ (ms/string-keyed-object+ ["file"+ [:map {:closed true}[:filename :string][:tempfile (ms/InstanceOfClass java.io.File)]]]- [:collection_id {:optional true} :string]- [::mc/default [:map-of :keyword :any]]]+ ["collection_id" {:optional true} :string])(mu/with-api-error-message- [:fn (fn [parts] (every? #{:file :collection_id} (keys parts)))]+ [:fn (fn [parts] (every? #{"file" "collection_id"} (keys parts)))](deferred-tru "unexpected multipart part"))]);; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to@@ -475,10 +473,10 @@The file may be at most 50 MB; larger uploads are rejected with a 413 response."{:multipart {:max-file-size upload/max-upload-size-bytes:max-file-count upload/max-upload-part-count}}- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-params- {:keys [file]} :- CsvUploadParts]+ {:strs [file]} :- CsvUploadParts](update-csv! {:table-id id:filename (:filename file):file (:tempfile file)@@ -495,10 +493,10 @@The file may be at most 50 MB; larger uploads are rejected with a 413 response."{:multipart {:max-file-size upload/max-upload-size-bytes:max-file-count upload/max-upload-part-count}}- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-params- {:keys [file]} :- CsvUploadParts]+ {:strs [file]} :- CsvUploadParts](update-csv! {:table-id id:filename (:filename file):file (:tempfile file)@@ -518,7 +516,7 @@:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :post "/:id/sync_schema""Trigger a manual update of the schema metadata for this `Table`."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](let [table (api/check-404 (warehouse-schema-rest.db/table id))database (api/check-404 (warehouse-schema-rest.db/non-destination-database (:db_id table)))]diff --git a/src/metabase/warehouses_rest/api.clj b/src/metabase/warehouses_rest/api.cljindex 4e41f1bdf58..a127c32fc90 100644--- a/src/metabase/warehouses_rest/api.clj+++ b/src/metabase/warehouses_rest/api.clj@@ -361,7 +361,7 @@[_route-params{:keys [include saved include_editable_data_model exclude_uneditable_details include_only_uploadable include_analyticsrouter_database_id can-query can-write-metadata]}- :- [:map+ :- [:map {:closed true}[:include {:optional true} (mu/with-api-error-message[:maybe [:enum "tables" "schemas"]](deferred-tru "include must be either empty, ''tables'', or ''schemas''"))]@@ -485,10 +485,10 @@[[metabase.warehouses.models.database]] uses the implementation of [[metabase.models.interface/can-write?]] for `:model/Database`in [[metabase.warehouses.models.database]] to exclude the `details` field, if the requesting user lacks permission to change thedatabase details."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]{:keys [include include_editable_data_model exclude_uneditable_details]}- :- [:map+ :- [:map {:closed true}[:include {:optional true} [:maybe [:enum "tables" "tables.fields"]]][:include_editable_data_model {:optional true} ms/MaybeBooleanValue][:exclude_uneditable_details {:optional true} ms/MaybeBooleanValue]]]@@ -511,7 +511,7 @@(api.macros/defendpoint :get "/:id/usage_info""Get usage info for a database.Returns a map with keys are models and values are the number of entities that use this database."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](api/check-superuser)(check-database-exists id)@@ -590,10 +590,10 @@permissions, if Enterprise Edition code is available and a token with the advanced-permissions feature is present.In addition, if the user has no data access for the DB (aka block permissions), it will return only the DB name, IDand tables, with no additional metadata."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]{:keys [include_hidden include_editable_data_model remove_inactive skip_fields]}- :- [:map+ :- [:map {:closed true}[:include_hidden {:default false} [:maybe ms/BooleanValue]][:include_editable_data_model {:default false} [:maybe ms/BooleanValue]][:remove_inactive {:default false} [:maybe ms/BooleanValue]]@@ -663,9 +663,9 @@Tables are returned in the format `[table_name \"Table\"]`;When Fields have a semantic_type, they are returned in the format `[field_name \"table_name base_type semantic_type\"]`When Fields lack a semantic_type, they are returned in the format `[field_name \"table_name base_type\"]`"- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]- {:keys [prefix substring]} :- [:map+ {:keys [prefix substring]} :- [:map {:closed true}[:prefix {:optional true} [:maybe ms/NonBlankString]][:substring {:optional true} [:maybe ms/NonBlankString]]]](api/read-check (warehouses/get-database id))@@ -699,9 +699,9 @@"Return a list of `Card` autocomplete suggestions for a given `query` in a given `Database`.This is intended for use with the ACE Editor when the User is typing in a template tag for a `Card`, e.g. {{#...}}."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]- {:keys [query include_dashboard_questions]} :- [:map+ {:keys [query include_dashboard_questions]} :- [:map {:closed true}[:query ms/NonBlankString][:include_dashboard_questions {:optional true} ms/BooleanValue]]](api/read-check (warehouses/get-database id))@@ -720,7 +720,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id/fields""Get a list of all `Fields` in `Database`."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](warehouses/get-database id)(perms/prime-table-perms-cache {:db-ids #{id}})@@ -745,9 +745,9 @@:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id/idfields""Get a list of all primary key `Fields` for `Database`."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]- {:keys [include_editable_data_model]} :- [:map+ {:keys [include_editable_data_model]} :- [:map {:closed true}[:include_editable_data_model {:default false} [:maybe ms/BooleanValue]]]](let [[db-perm-check field-perm-check] (if include_editable_data_model[check-db-data-model-perms mi/can-write?]@@ -769,10 +769,10 @@_query-params{:keys [name engine details is_full_sync is_on_demand schedules auto_run_queries cache_ttl connection_source provider_name]:as body}- :- [:map+ :- [:map {:closed true}[:name ms/NonBlankString][:engine DBEngineString]- [:details ms/Map]+ [:details ms/DatabaseDetails][:is_full_sync {:default true} [:maybe ms/BooleanValue]][:is_on_demand {:default false} [:maybe ms/BooleanValue]][:schedules {:optional true} [:maybe sync.schedules/ExpandedSchedulesMap]]@@ -833,10 +833,10 @@;; TODO - why do we pass the DB in under the key `details`?[_route-params_query-params- {{:keys [engine details]} :details} :- [:map- [:details [:map+ {{:keys [engine details]} :details} :- [:map {:closed true}+ [:details [:map {:closed true}[:engine DBEngineString]- [:details ms/Map]]]]]+ [:details ms/DatabaseDetails]]]]](api/check-superuser)(let [details-or-error (warehouses/test-connection-details engine details)];; details that come back without a `:valid` key at all are... valid!@@ -929,18 +929,18 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :put "/:id""Update a `Database`."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-params{:keys [name engine details write_data_details is_full_sync is_on_demand description caveatspoints_of_interest schedules auto_run_queries refingerprint cache_ttl settings provider_name]:as body}- :- [:map+ :- [:map {:closed true}[:name {:optional true} [:maybe ms/NonBlankString]][:engine {:optional true} [:maybe DBEngineString]][:refingerprint {:optional true} [:maybe :boolean]]- [:details {:optional true} [:maybe ms/Map]]- [:write_data_details {:optional true} [:maybe ms/Map]]+ [:details {:optional true} [:maybe ms/DatabaseDetails]]+ [:write_data_details {:optional true} [:maybe ms/DatabaseDetails]][:schedules {:optional true} [:maybe sync.schedules/ExpandedSchedulesMap]][:is_full_sync {:optional true} [:maybe ms/BooleanValue]][:is_on_demand {:optional true} [:maybe ms/BooleanValue]]@@ -950,7 +950,7 @@[:auto_run_queries {:optional true} [:maybe :boolean]][:cache_ttl {:optional true} [:maybe ms/PositiveInt]][:provider_name {:optional true} [:maybe :string]]- [:settings {:optional true} [:maybe ms/Map]]+ [:settings {:optional true} [:maybe ms/DatabaseSettings]][:is_stub {:optional true} [:maybe :boolean]]]](when (true? (:is_stub body))(throw (ex-info (tru "is_stub may not be set via the API")@@ -1076,7 +1076,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :delete "/:id""Delete a `Database`."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](api/check-superuser)(t2/with-transaction [_conn]@@ -1101,7 +1101,7 @@:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :post "/:id/sync_schema""Trigger a manual update of the schema metadata for this `Database`."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]];; just wrap this in a future so it happens async(let [db (api/write-check (warehouses/get-database id {:exclude-uneditable-details? true}))]@@ -1136,7 +1136,7 @@(api.macros/defendpoint :post "/:id/dismiss_spinner""Manually set the initial sync status of the `Database` and correspondingtables to be `complete` (see #20863)"- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]];; manual full sync needs to be async, but this is a simple update of `Database`(let [db (api/write-check (warehouses/get-database id {:exclude-uneditable-details? true}))@@ -1167,7 +1167,7 @@:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :post "/:id/rescan_values""Trigger a manual scan of the field values for this `Database`."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]];; just wrap this is a future so it happens async(let [db (api/write-check (warehouses/get-database id {:exclude-uneditable-details? true}))]@@ -1199,7 +1199,7 @@:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :post "/:id/discard_values""Discards all saved field values for this `Database`."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](let [db (api/write-check (warehouses/get-database id {:exclude-uneditable-details? true}))](events/publish-event! :event/database-discard-field-values {:object db :user-id api/*current-user-id*})@@ -1237,7 +1237,7 @@:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id/syncable_schemas""Returns a list of all syncable schemas found for the database `id`."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](let [db (warehouses/get-database id)](api/check-403 (or (:is_attached_dwh db)@@ -1290,12 +1290,12 @@Optional filters:- `can-query=true` - filter to only schemas containing tables the user can query- `can-write-metadata=true` - filter to only schemas containing tables the user can edit metadata for"- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]{:keys [include_editable_data_modelinclude_hiddencan-query- can-write-metadata]} :- [:map+ can-write-metadata]} :- [:map {:closed true}[:include_editable_data_model {:default false} [:maybe ms/BooleanValue]][:include_hidden {:default false} [:maybe ms/BooleanValue]][:can-query {:optional true} [:maybe :boolean]]@@ -1380,10 +1380,10 @@Optional filters:- `can-query=true` - filter to only tables the user can query- `can-write-metadata=true` - filter to only tables the user can edit metadata for"- [{:keys [id schema]} :- [:map+ [{:keys [id schema]} :- [:map {:closed true}[:id ms/PositiveInt][:schema ms/NonBlankString]]- {:keys [include_hidden include_editable_data_model can-query can-write-metadata include_measures]} :- [:map+ {:keys [include_hidden include_editable_data_model can-query can-write-metadata include_measures]} :- [:map {:closed true}[:include_hidden {:default false} [:maybe ms/BooleanValue]][:include_editable_data_model {:default false} [:maybe ms/BooleanValue]][:can-query {:optional true} [:maybe :boolean]]@@ -1415,9 +1415,9 @@Optional filters:- `can-query=true` - filter to only tables the user can query- `can-write-metadata=true` - filter to only tables the user can edit metadata for"- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]- {:keys [schema include_hidden include_editable_data_model can-query can-write-metadata include_measures]} :- [:map+ {:keys [schema include_hidden include_editable_data_model can-query can-write-metadata include_measures]} :- [:map {:closed true}[:schema {:optional true} [:maybe :string]][:include_hidden {:default false} [:maybe ms/BooleanValue]][:include_editable_data_model {:default false} [:maybe ms/BooleanValue]]@@ -1441,7 +1441,7 @@(api.macros/defendpoint :get ["/:virtual-db/schema/:schema":virtual-db (re-pattern (str lib.schema.id/saved-questions-virtual-database-id))]"Returns a list of Tables for the saved questions virtual database."- [{:keys [schema]} :- [:map+ [{:keys [schema]} :- [:map {:closed true}[:schema :string]]](when (lib-be/enable-nested-queries)(->> (source-query-cards@@ -1457,8 +1457,8 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:id/healthcheck""Reports whether the database can currently connect"- [{:keys [id]} :- [:map [:id ms/PositiveInt]]- {:keys [connection-type]} :- [:map [:connection-type {:optional true} ::driver.conn/connection-type]]]+ [{:keys [id]} :- [:map {:closed true} [:id ms/PositiveInt]]+ {:keys [connection-type]} :- [:map {:closed true} [:connection-type {:optional true} ::driver.conn/connection-type]]](api/check-superuser)(let [{:as database :keys [engine]} (api/check-404 (warehouses-rest.db/database id))connection-type (or connection-type :default)@@ -1478,7 +1478,7 @@(api.macros/defendpoint :get ["/:virtual-db/datasets/:schema":virtual-db (re-pattern (str lib.schema.id/saved-questions-virtual-database-id))]"Returns a list of Tables for the datasets virtual database."- [{:keys [schema]} :- [:map+ [{:keys [schema]} :- [:map {:closed true}[:schema :string]]](when (lib-be/enable-nested-queries)(->> (source-query-cards@@ -1535,7 +1535,7 @@(api.macros/defendpoint :get "/:id/settings-available" :- [:map [:settings ::available-settings]]"Get all database-local settings and their availability for the given database."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](let [database (api/read-check (warehouses/get-database id))]{:settings (database-local-settings database)}))diff --git a/src/metabase/xrays/api/automagic_dashboards.clj b/src/metabase/xrays/api/automagic_dashboards.cljindex 772ee407431..b21b46e441b 100644--- a/src/metabase/xrays/api/automagic_dashboards.clj+++ b/src/metabase/xrays/api/automagic_dashboards.clj@@ -92,7 +92,7 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/database/:id/candidates""Return a list of candidates for automagic dashboards ordered by interestingness."- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]](-> (xrays.db/database id)api/read-check@@ -219,10 +219,10 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:entity/:entity-id-or-query""Return an automagic dashboard for entity `entity` with id `id`."- [{:keys [entity entity-id-or-query]} :- [:map+ [{:keys [entity entity-id-or-query]} :- [:map {:closed true}[:entity Entity][:entity-id-or-query ::entity-id-or-query]]- {:keys [show]} :- [:map+ {:keys [show]} :- [:map {:closed true}[:show {:optional true} [:maybe [:or [:= "all"] nat-int?]]]]](get-automagic-dashboard entity entity-id-or-query show))@@ -252,7 +252,7 @@:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:entity/:entity-id-or-query/query_metadata""Return all metadata for an automagic dashboard for entity `entity` with id `id`."- [{:keys [entity entity-id-or-query]} :- [:map+ [{:keys [entity entity-id-or-query]} :- [:map {:closed true}[:entity Entity][:entity-id-or-query ::entity-id-or-query]]](dashboard-metadata (get-automagic-dashboard entity entity-id-or-query nil)))@@ -355,7 +355,7 @@(api.macros/defendpoint :get "/model_index/:model-index-id/primary_key/:pk-id""Return an automagic dashboard for an entity detail specified by `entity`with id `id` and a primary key of `indexed-value`."- [{:keys [model-index-id pk-id]} :- [:map+ [{:keys [model-index-id pk-id]} :- [:map {:closed true}[:model-index-id :int][:pk-id :int]]](api/let-404 [model-index (xrays.db/model-index model-index-id)@@ -377,12 +377,12 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/:entity/:entity-id-or-query/rule/:prefix/:dashboard-template""Return an automagic dashboard for entity `entity` with id `id` using dashboard-template `dashboard-template`."- [{:keys [entity entity-id-or-query prefix dashboard-template]} :- [:map+ [{:keys [entity entity-id-or-query prefix dashboard-template]} :- [:map {:closed true}[:entity Entity][:entity-id-or-query ::entity-id-or-query][:prefix Prefix][:dashboard-template DashboardTemplate]]- {:keys [show]} :- [:map+ {:keys [show]} :- [:map {:closed true}[:show {:optional true} Show]]](-> (->entity entity entity-id-or-query)(automagic-dashboards.core/automagic-analysis {:show (coerce-show show)@@ -395,11 +395,11 @@(api.macros/defendpoint :get "/:entity/:entity-id-or-query/cell/:cell-query""Return an automagic dashboard analyzing cell in automagic dashboard for entity `entity` defined by query`cell-query`."- [{:keys [entity entity-id-or-query cell-query]} :- [:map+ [{:keys [entity entity-id-or-query cell-query]} :- [:map {:closed true}[:entity Entity][:entity-id-or-query ::entity-id-or-query][:cell-query ::cell-query]]- {:keys [show]} :- [:map+ {:keys [show]} :- [:map {:closed true}[:show {:optional true} Show]]](-> (->entity entity entity-id-or-query)(automagic-dashboards.core/automagic-analysis {:show (coerce-show show)@@ -412,13 +412,13 @@(api.macros/defendpoint :get "/:entity/:entity-id-or-query/cell/:cell-query/rule/:prefix/:dashboard-template""Return an automagic dashboard analyzing cell in question with id `id` defined by query `cell-query` usingdashboard-template `dashboard-template`."- [{:keys [entity entity-id-or-query cell-query prefix dashboard-template]} :- [:map+ [{:keys [entity entity-id-or-query cell-query prefix dashboard-template]} :- [:map {:closed true}[:entity Entity][:entity-id-or-query ::entity-id-or-query][:prefix Prefix][:dashboard-template DashboardTemplate][:cell-query ::cell-query]]- {:keys [show]} :- [:map+ {:keys [show]} :- [:map {:closed true}[:show {:optional true} Show]]](-> (->entity entity entity-id-or-query)(automagic-dashboards.core/automagic-analysis {:show (coerce-show show)@@ -435,12 +435,12 @@[{:keys [entityentity-id-or-querycomparison-entity- comparison-entity-id-or-query]} :- [:map+ comparison-entity-id-or-query]} :- [:map {:closed true}[:entity-id-or-query ::entity-id-or-query][:entity Entity][:comparison-entity ComparisonEntity][:comparison-entity-id-or-query ::entity-id-or-query]]- {:keys [show]} :- [:map+ {:keys [show]} :- [:map {:closed true}[:show {:optional true} Show]]](let [left (->entity entity entity-id-or-query)right (->entity comparison-entity comparison-entity-id-or-query)@@ -461,14 +461,14 @@prefixdashboard-templatecomparison-entity- comparison-entity-id-or-query]} :- [:map+ comparison-entity-id-or-query]} :- [:map {:closed true}[:entity Entity][:entity-id-or-query ::entity-id-or-query][:prefix Prefix][:dashboard-template DashboardTemplate][:comparison-entity ComparisonEntity][:comparison-entity-id-or-query ::entity-id-or-query]]- {:keys [show]} :- [:map+ {:keys [show]} :- [:map {:closed true}[:show {:optional true} Show]]](let [left (->entity entity entity-id-or-query)right (->entity comparison-entity comparison-entity-id-or-query)@@ -490,13 +490,13 @@entity-id-or-querycell-querycomparison-entity- comparison-entity-id-or-query]} :- [:map+ comparison-entity-id-or-query]} :- [:map {:closed true}[:entity Entity][:entity-id-or-query ::entity-id-or-query][:cell-query ::base-64-encoded-json][:comparison-entity ComparisonEntity][:comparison-entity-id-or-query ::entity-id-or-query]]- {:keys [show]} :- [:map+ {:keys [show]} :- [:map {:closed true}[:show {:optional true} Show]]](let [left (->entity entity entity-id-or-query)right (->entity comparison-entity comparison-entity-id-or-query)@@ -519,7 +519,7 @@prefixdashboard-templatecomparison-entity- comparison-entity-id-or-query]} :- [:map+ comparison-entity-id-or-query]} :- [:map {:closed true}[:entity Entity][:entity-id-or-query ::entity-id-or-query][:prefix Prefix]@@ -527,7 +527,7 @@[:cell-query ::base-64-encoded-json][:comparison-entity ComparisonEntity][:comparison-entity-id-or-query ::entity-id-or-query]]- {:keys [show]} :- [:map+ {:keys [show]} :- [:map {:closed true}[:show {:optional true} Show]]](let [left (->entity entity entity-id-or-query)right (->entity comparison-entity comparison-entity-id-or-query)diff --git a/src/metabase/xrays/automagic_dashboards/interesting.clj b/src/metabase/xrays/automagic_dashboards/interesting.cljindex e5def11ee97..83c28c9f2d1 100644--- a/src/metabase/xrays/automagic_dashboards/interesting.clj+++ b/src/metabase/xrays/automagic_dashboards/interesting.clj@@ -89,6 +89,12 @@(can-use? :hour) :hour))(if (can-use? :day) :day :hour))))+(def ^:private xray-field-keys+ "What X-rays pins on a Field row while it works, and what hydration added, none of which belongs on the Lib column+ the Field becomes."+ [:db :link :aggregation :max-cardinality :max_cardinality :field-type :field_type :links_to :score :named :dimensions+ :name_field :target :xrays/database-id])+(mu/defn field->metadata :- ::lib.schema.metadata/column"Convert a Field from the app DB to Lib column metadata, and do a bunch of weird additional transformations thatI (Cam) do not really understand (see below).@@ -99,7 +105,7 @@(let [col (if fk-target-field-id(-> (xrays.db/metadata-column fk-target-field-id)(assoc :fk-field-id id, :lib/source :source/implicitly-joinable))- (lib-be/instance->metadata field :metadata/column))]+ (lib-be/instance->metadata (apply dissoc field xray-field-keys) :metadata/column))](cond-> collink(assoc :fk-field-id link, :lib/source :source/implicitly-joinable)diff --git a/test/metabase/agent_api/api_test.clj b/test/metabase/agent_api/api_test.cljindex f9d820e3bca..2221d3c778a 100644--- a/test/metabase/agent_api/api_test.clj+++ b/test/metabase/agent_api/api_test.clj@@ -1859,15 +1859,16 @@(is (some? (-> resp :resources first :error))))))(deftest decode-and-validate-query-strips-extra-keys-test- (testing "base64 query payloads are decoded, validated, and stripped of undeclared properties"- (let [encoded (u/encode-base64 (json/encode {:database (mt/id)- :type "query"- :query {:source-table (mt/id :orders)- :a 1- :a/b 2}}))+ (testing "base64 query payloads are decoded, validated, and stripped of the query processor's internal keys"+ ;; `:qp/source-card-id` and `:qp/stage-had-source-card` are keys the QP adds to a query while it runs and that+ ;; permissions later read, so a client must never be able to send them in.+ (let [encoded (u/encode-base64 (json/encode {:database (mt/id)+ :type "query"+ :qp/source-card-id 1+ :query {:source-table (mt/id :orders)+ :qp/stage-had-source-card 1}}))q (#'agent-api.api/decode-and-validate-query encoded)](is (= :mbql/query (:lib/type q)))- (is (not (contains? q :a)))- (is (not (contains? q :a/b)))- (is (every? (fn [stage] (not (some #(contains? stage %) [:a :a/b]))) (:stages q))- "undeclared properties are stripped from every stage"))))+ (is (not (contains? q :qp/source-card-id)))+ (is (every? (fn [stage] (not (contains? stage :qp/stage-had-source-card))) (:stages q))+ "internal keys are stripped from every stage"))))diff --git a/test/metabase/api/macros/defendpoint/closed_schemas_test.clj b/test/metabase/api/macros/defendpoint/closed_schemas_test.cljnew file mode 100644index 00000000000..eb0c05aa6d4--- /dev/null+++ b/test/metabase/api/macros/defendpoint/closed_schemas_test.clj@@ -0,0 +1,145 @@+(ns metabase.api.macros.defendpoint.closed-schemas-test+ (:require+ [clojure.test :refer :all]+ [malli.core :as mc]+ [metabase.api.macros.defendpoint.closed-schemas :as closed-schemas]+ [metabase.lib.schema.common :as lib.schema.common]+ [metabase.util.malli.registry :as mr]+ [metabase.util.malli.schema :as ms]))++(set! *warn-on-reflection* true)++(mr/def ::closed+ [:map {:closed true} [:a :int]])++(mr/def ::open+ [:map [:a :int]])++(mr/def ::nested+ [:map {:closed true}+ [:inner ::open]])++(mr/def ::recursive+ [:map {:closed true}+ [:children {:optional true} [:sequential [:ref ::recursive]]]+ [:extra {:optional true} ::open]])++(defn- kinds [schema]+ (mapv :kind (closed-schemas/findings schema)))++(deftest ^:parallel closed-maps-and-the-deliberately-open-schemas-pass-test+ (are [schema] (empty? (kinds schema))+ [:map {:closed true} [:a :int]]+ ::closed+ [:ref ::closed]+ [:maybe [:sequential ::closed]]+ [:merge ::closed [:map {:closed true} [:b :int]]]+ [:multi {:dispatch :type}+ [:a [:map {:closed true} [:type [:= :a]]]]+ [:b [:map {:closed true} [:type [:= :b]]]]]+ ms/DatabaseDetails+ ms/VisualizationSettings+ ms/DatabaseSettings+ ms/OpaqueJSONObject+ (ms/string-keyed-map :string)+ [:map-of :string :int]+ [:map-of ::closed :int]))++(deftest ^:parallel open-maps-are-found-test+ (are [schema] (= [:open-map] (kinds schema))+ [:map [:a :int]]+ [:map {:closed false} [:a :int]]+ [:map]+ :map+ [:maybe :map]+ ::open+ [:ref ::open]+ [:sequential ::open]+ ::nested+ [:map {:closed true} [:a ::open]]+ [:or :int ::open]+ [:multi {:dispatch :type} [:a [:map [:type [:= :a]]]]]))++(deftest ^:parallel keyword-keyed-map-of-is-found-test+ (are [schema] (= [:keyword-keyed-map-of] (kinds schema))+ [:map-of :keyword :int]+ [:map-of [:keyword {:description "a key"}] :int]+ [:map {:closed true} [:bag [:map-of :keyword :string]]])+ (testing "a `:some` key is both an open bag of keys and a value of any type"+ (is (= [:keyword-keyed-map-of :any] (kinds [:map-of :some :string])))))++(deftest ^:parallel any-is-found-test+ (are [schema] (= [:any] (kinds schema))+ :any+ any?+ :some+ map?+ [:maybe :any]+ [:map {:closed true} [:value :any]]+ [:map {:closed true} [:settings map?]]+ [:map-of :string :any]+ (ms/string-keyed-map :any)))++(deftest ^:parallel values-are-not-walked-test+ (are [schema] (empty? (kinds schema))+ [:enum :type/Text :type/Integer]+ [:= :any]+ [:fn map?]))++(deftest ^:parallel a-default-entry-declares-the-other-keys-test+ (testing "a map with a `::mc/default` entry is not open: the default schema says what the other keys are"+ (is (empty? (kinds [:map [:a :int] [::mc/default (ms/string-keyed-map :string)]])))+ (testing "but that schema is checked like any other"+ (is (= [:any] (kinds [:map [:a :int] [::mc/default [:map-of :string :any]]]))))))++(deftest ^:parallel any-as-a-conjunct-is-a-carrier-test+ (testing "an `:any` conjunct constrains nothing the other conjuncts do not already constrain"+ (are [schema] (empty? (kinds schema))+ [:and [:map {:closed true} [:a :int]] :any]+ [:and [:map {:closed true} [:a :int]] [:schema {:decode/normalize identity} :any]]+ [:and :int [:multi {:dispatch pos?} [true :int] [false :any]]]))+ (testing "a map entry inside a conjunct is a hole again"+ (is (= [:any] (kinds [:and [:map {:closed true} [:a :any]] [:fn map?]]))))+ (testing "and so is anything inside a collection or an alternative"+ (are [schema] (= [:any] (kinds schema))+ [:and [:sequential :any] [:fn seq]]+ [:and [:tuple :int :any] [:fn vector?]]+ [:and [:maybe :any] [:fn some?]]+ [:and [:or :int :any] [:fn some?]])))++(deftest ^:parallel internal-keys-the-api-strips-are-skipped-test+ (let [strips [:map {:closed true, :decode/api lib.schema.common/remove-internal-keys}+ [:a :int]+ [:qp/internal {:optional true} [:map [:anything :any]]]]]+ (is (empty? (kinds strips)))+ (testing "only when the map's API decoder really strips them"+ (is (= [:open-map :any] (kinds (assoc strips 1 {:closed true})))))+ (testing "and never the default entry, whose key is not a key at all"+ (is (= [:any] (kinds [:map {:closed true, :decode/api lib.schema.common/remove-internal-keys}+ [::mc/default [:map-of :string :any]]]))))))++(deftest ^:parallel every-finding-carries-its-trail-test+ (is (= [{:kind :open-map, :trail [::nested :inner ::open]}]+ (map #(select-keys % [:kind :trail]) (closed-schemas/findings ::nested)))))++(deftest ^:parallel recursive-schemas-terminate-test+ (is (= [:open-map] (kinds ::recursive))))++(deftest ^:parallel registry-keys-are-walked-once-test+ (let [visited (atom #{})]+ (is (= [:open-map] (mapv :kind (closed-schemas/findings ::nested visited))))+ (is (contains? @visited ::nested))+ (testing "a second walk through the same visited set skips the keys it already saw"+ (is (empty? (closed-schemas/findings ::nested visited))))))++(deftest check-throws-with-the-offending-schemas-test+ (testing "off in prod, and off when disabled"+ (binding [closed-schemas/*enabled* false]+ (is (nil? (closed-schemas/check! :body [:map [:a :int]])))))+ (binding [closed-schemas/*enabled* true]+ (is (nil? (closed-schemas/check! :body [:map {:closed true} [:a :int]])))+ (testing "response schemas are not checked: only a request is stripped"+ (is (nil? (closed-schemas/check! :response [:map [:a :int]]))))+ (is (thrown-with-msg? clojure.lang.ExceptionInfo+ #"The body schema of this endpoint reaches schemas that do not declare their shape"+ (closed-schemas/check! :body [:map {:closed true} [:bag [:map [:a :int]]]])))))diff --git a/test/metabase/api/macros/defendpoint/tools_manifest_test.clj b/test/metabase/api/macros/defendpoint/tools_manifest_test.cljindex a600e96d615..a453d0bcd8e 100644--- a/test/metabase/api/macros/defendpoint/tools_manifest_test.clj+++ b/test/metabase/api/macros/defendpoint/tools_manifest_test.clj@@ -340,7 +340,7 @@(api.macros/defendpoint :get "/v1/test/:id""A test endpoint for tools manifest generation."{:tool {:name "test_get_thing"}}- [{:keys [id]} :- [:map [:id :int]]]+ [{:keys [id]} :- [:map {:closed true} [:id :int]]]{:id id});; 2. POST with body params and annotation override@@ -350,7 +350,7 @@:annotations {:read-only? true}}}[_route-params_query-params- body :- [:map [:name :string]]]+ body :- [:map {:closed true} [:name :string]]]body);; 3. DELETE — tests DELETE annotations@@ -359,7 +359,7 @@{:tool {:name "delete_test"}};; binding exists only to carry the param schema into the generated tool manifest[#_{:clj-kondo/ignore [:unused-binding]}- {:keys [id]} :- [:map [:id :int]]]+ {:keys [id]} :- [:map {:closed true} [:id :int]]]nil);; 4. GET with query params (including tool/description) and response schema@@ -370,7 +370,7 @@[_route-params;; binding exists only to carry the param schema into the generated tool manifest#_{:clj-kondo/ignore [:unused-binding]}- {:keys [q limit]} :- [:map+ {:keys [q limit]} :- [:map {:closed true}[:q :string][:limit {:optional true}[:maybe [:int {:description "Max results"@@ -384,22 +384,22 @@{:tool {:name "test_resource_action":annotations {:read-only? true}:task-support :parallel}}- [{:keys [id]} :- [:map [:id :int]]+ [{:keys [id]} :- [:map {:closed true} [:id :int]]_query-params;; binding exists only to carry the param schema into the generated tool manifest#_{:clj-kondo/ignore [:unused-binding]}- body :- [:map [:action :string]]]+ body :- [:map {:closed true} [:action :string]]]{:id id :status "active"});; 6. PUT with route + query + body params — tests PUT annotations + 3-way merge(api.macros/defendpoint :put "/v1/test-resource/:id""Update a test resource."{:tool {:name "test_resource"}}- [{:keys [id]} :- [:map [:id :int]]+ [{:keys [id]} :- [:map {:closed true} [:id :int]];; binding exists only to carry the param schema into the generated tool manifest#_{:clj-kondo/ignore [:unused-binding]}- {:keys [dry-run]} :- [:map [:dry-run {:optional true} [:maybe :boolean]]]- body :- [:map [:name :string]]]+ {:keys [dry-run]} :- [:map {:closed true} [:dry-run {:optional true} [:maybe :boolean]]]+ body :- [:map {:closed true} [:name :string]]]{:id id :name (:name body)})(deftest ^:parallel check-tool-uniqueness-testdiff --git a/test/metabase/api/macros_test.clj b/test/metabase/api/macros_test.cljindex 554415d41d1..41f7cc7b85c 100644--- a/test/metabase/api/macros_test.clj+++ b/test/metabase/api/macros_test.clj@@ -18,7 +18,8 @@'{:method :post:route {:path "/move"}:docstr "Moves a number of Cards to a single collection or dashboard."- :params {:route {:binding _route-params, :schema [:map]}, :query {:binding _query-params, :schema [:map]}}+ :params {:route {:binding _route-params, :schema [:map {:closed true}]}+ :query {:binding _query-params, :schema [:map {:closed true}]}}:body [(neat)]}'(:post "/move"@@ -33,8 +34,8 @@'{:method :post:route {:path "/move"}:docstr "Moves a number of Cards to a single collection or dashboard."- :params {:route {:binding _route-params, :schema [:map]}- :query {:binding _query-params, :schema [:map]}+ :params {:route {:binding _route-params, :schema [:map {:closed true}]}+ :query {:binding _query-params, :schema [:map {:closed true}]}:body {:binding {:keys [card_ids], :as body}:schema [:map [:card_ids [:sequential ms/PositiveInt]]]}:request {:binding request@@ -55,8 +56,8 @@(raise e))))'{:method :post:route {:path "/move"}- :params {:route {:binding _route-params, :schema [:map]}- :query {:binding _query-params, :schema [:map]}+ :params {:route {:binding _route-params, :schema [:map {:closed true}]}+ :query {:binding _query-params, :schema [:map {:closed true}]}:body {:binding {:keys [card_ids], :as body}, :schema :map}:request {:binding _request}:respond {:binding respond}@@ -175,7 +176,8 @@:route {:path "/test"}:docstr "Deprecated endpoint.":metadata {:deprecated "0.50.0", :multipart true}- :params {:route {:binding _route-params, :schema [:map]}, :query {:binding _query-params, :schema [:map]}}+ :params {:route {:binding _route-params, :schema [:map {:closed true}]}+ :query {:binding _query-params, :schema [:map {:closed true}]}}:body [(test)]})))(deftest ^:parallel decode-strips-undeclared-keys-test@@ -186,15 +188,24 @@{:a 1, :b 2}{:a 1}+ ;; a closed map is stripped, not rejected: stripping happens during decoding, so by the time the schema+ ;; validates the value the undeclared key is already gone and the request is served rather than 400ed+ [:map {:closed true} [:a {:optional true} :int]]+ {:a 1, :b 2}+ {:a 1}+;; `{:closed false}` opts out, for the values we deliberately pass through as they arrived -- a query, viz- ;; settings, database details, a settings bag+ ;; settings, database details, a settings bag. See the open maps in [[metabase.util.malli.schema]].[:map {:closed false} [:a {:optional true} :int]]{:a 1, :b 2}{:a 1, :b 2}- ;; stripping recurses. A parameter's `:options` are spliced into the filter clause the parameter becomes, so an- ;; option the schema does not name must not survive decoding. The schema stays open -- an unknown option is not- ;; a 400 -- so this is what keeps such a key from reaching the clause.+ ;; stripping recurses: an undeclared key nested inside a declared one goes too+ [:map [:a [:map {:closed true} [:b {:optional true} :int]]]]+ {:a {:b 1, :c 2}}+ {:a {:b 1}}++ ;; ...through registry schemas too: a parameter's `:options` only keep the options this version knows::lib.schema.parameter/parameter{:type :string/contains, :value ["A"], :options {:case-sensitive false, :lib/uuid "not-yours"}}{:type :string/contains, :value ["A"], :options {:case-sensitive false}})))diff --git a/test/metabase/api/open_api_test.clj b/test/metabase/api/open_api_test.cljindex 7e99d1d90d6..4ce62ea3298 100644--- a/test/metabase/api/open_api_test.clj+++ b/test/metabase/api/open_api_test.clj@@ -13,15 +13,15 @@(api.macros/defendpoint :get "/:id""docstring"- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]]{:id (str id)})(api.macros/defendpoint :post "/:id""docstring"- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]- {:keys [value]} :- [:map+ {:keys [value]} :- [:map {:closed true}[:value ::lib.schema.common/non-blank-string]]]{:id (str id):value value})@@ -29,7 +29,7 @@(api.macros/defendpoint :post "/export""docstring"[_route-params- {:keys [collection settings]} :- [:map+ {:keys [collection settings]} :- [:map {:closed true}[:collection [:maybe (ms/QueryVectorOf ms/PositiveInt)]][:settings [:maybe ms/BooleanValue]][:data-model ms/MaybeBooleanValue]]]@@ -38,34 +38,34 @@(api.macros/defendpoint :get "/rename""this one renames query parameter trying to trick us (actually doesn't really trick us much anymore with defendpoint 2)"[_route-params- {c :count} :- [:map+ {c :count} :- [:map {:closed true}[:count {:optional true} ms/PositiveInt]]]{:count c})(api.macros/defendpoint :put "/complex/:id""More complex body schema"- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-params- {:keys [data]} :- [:map- [:data [:map+ {:keys [data]} :- [:map {:closed true}+ [:data [:map {:closed true}[:name {:optional true} [:maybe ::lib.schema.common/non-blank-string]][:dashcards (ms/maps-with-unique-key- [:sequential [:map+ [:sequential [:map {:closed true}[:id int?]- [:params {:optional true} [:maybe [:sequential [:map+ [:params {:optional true} [:maybe [:sequential [:map {:closed true}[:param_id ::lib.schema.common/non-blank-string]- [:target :any]]]]]]]+ [:target :string]]]]]]]:id)]]]]]{:id id :data data})(api.macros/defendpoint :post "/:id/upload""docstring"{:multipart true}- [{:keys [id]} :- [:map+ [{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]_query-params- {:keys [file]} :- [:map+ {:keys [file]} :- [:map {:closed true}[:file (mu/with ms/File {:description "File to upload"})]]]{:id id :data file})@@ -197,10 +197,10 @@(->(api.macros/defendpoint :get "add/:a""Adds id, qp-one, qp-two, and body."- [{:keys [a]} :- [:map [:a :int]]- {:keys [b c]} :- [:map [:b :int] [:c :int]]- {:keys [d]} :- [:map [:d :int]]- {{e :e} :headers} :- [:map [:headers [:map [:e :int]]]]]+ [{:keys [a]} :- [:map {:closed true} [:a :int]]+ {:keys [b c]} :- [:map {:closed true} [:b :int] [:c :int]]+ {:keys [d]} :- [:map {:closed true} [:d :int]]+ {{e :e} :headers} :- [:map {:closed true} [:headers [:map {:closed true} [:e :int]]]]](+ a b c d e))(api.macros/call-core-fn{:a 5} ;; route paramsdiff --git a/test/metabase/app_db/custom_migrations/pulse_to_notification_test.clj b/test/metabase/app_db/custom_migrations/pulse_to_notification_test.cljindex f8a4bab01e9..3ae1d88726b 100644--- a/test/metabase/app_db/custom_migrations/pulse_to_notification_test.clj+++ b/test/metabase/app_db/custom_migrations/pulse_to_notification_test.clj@@ -119,7 +119,8 @@(testing "migrate alert with multiple channels 1 slack, 1 email with 1 external recipient and one user, 1 disabled email, one http"(with-test-setup!(mt/with-temp [:model/Card {card-id :id} {}- :model/Channel {channel-id :id} {:type "channel/http"}]+ :model/Channel {channel-id :id} {:type "channel/http"+ :details {:url "https://example.com/hook", :auth-method "none"}}](let [alert-id (create-alert! {} card-id [{:channel_type "email":enabled true:details (json/encode {:emails ["[email protected]"]})diff --git a/test/metabase/audit_app/events/audit_log_test.clj b/test/metabase/audit_app/events/audit_log_test.cljindex 88e91bfc505..219786c7b54 100644--- a/test/metabase/audit_app/events/audit_log_test.clj+++ b/test/metabase/audit_app/events/audit_log_test.clj@@ -573,7 +573,7 @@(mt/with-current-user (mt/user->id :rasta)(mt/with-temp [:model/Document {doc-id :id} {}:model/Comment comment {:target_id doc-id- :content "{}"}]+ :content {:type "doc", :content []}}](testing :event/comment-create(is (= {:object comment}(events/publish-event! :event/comment-create {:object comment})))diff --git a/test/metabase/channel/impl/http_test.clj b/test/metabase/channel/impl/http_test.cljindex ceaef44e993..844e0cab52c 100644--- a/test/metabase/channel/impl/http_test.clj+++ b/test/metabase/channel/impl/http_test.clj@@ -190,14 +190,14 @@(is (true? (can-connect? {:url (str url "/user"):method "get":auth-method "header"- :auth-info {:x-api-key "SECRET"}}))))+ :auth-info {"x-api-key" "SECRET"}}))))(testing "fail to connect with header auth"(is (= {:request-status 401:request-body "Unauthorized"}(exception-data (can-connect? {:url (str url "/user"):method "get":auth-method "header"- :auth-info {:x-api-key "WRONG"}}))))))))+ :auth-info {"x-api-key" "WRONG"}}))))))))(deftest can-connect-query-param-auth-test(mt/with-temporary-setting-values [http-channel-allowed-networks :allow-all]@@ -213,16 +213,16 @@(is (true? (can-connect? {:url (str url "/user"):method "get":auth-method "query-param"- :auth-info {:username "qnkhuat"- :password "secretpassword"}}))))+ :auth-info {"username" "qnkhuat"+ "password" "secretpassword"}}))))(testing "fail to connect with query-param auth"(is (= {:request-status 401:request-body "Unauthorized"}(exception-data (can-connect? {:url (str url "/user"):method "get":auth-method "query-param"- :auth-info {:username "qnkhuat"- :password "wrongpassword"}}))))))))+ :auth-info {"username" "qnkhuat"+ "password" "wrongpassword"}}))))))))(deftest can-connect-request-body-auth-test(mt/with-temporary-setting-values [http-channel-allowed-networks :allow-all]@@ -237,14 +237,14 @@(is (true? (can-connect? {:url (str url "/user"):method "post":auth-method "request-body"- :auth-info {:token "SECRET_TOKEN"}}))))+ :auth-info {"token" "SECRET_TOKEN"}}))))(testing "fail to connect with request-body auth"(is (= {:request-status 401:request-body "Unauthorized"}(exception-data (can-connect? {:url (str url "/user"):method "post":auth-method "request-body"- :auth-info {:token "WRONG_TOKEN"}}))))))))+ :auth-info {"token" "WRONG_TOKEN"}}))))))))(deftest can-connect?-errors-test(testing "throws an appriopriate errors if details are invalid"@@ -304,28 +304,28 @@(channel/send! {:type :channel/http:details {:url "https://www.secret_service.xyz":auth-method "header"- :auth-info {:Authorization "Bearer 123"}+ :auth-info {"Authorization" "Bearer 123"}:method "get"}}{:headers {:X-Request-Id "123"}})(is (= (merge default-request{:method :get:url "https://www.secret_service.xyz"- :headers {:Authorization "Bearer 123"- :X-Request-Id "123"}})+ :headers {"Authorization" "Bearer 123"+ :X-Request-Id "123"}})(first @requests)))))(testing "preserves req query-params when use auth-method=:query-param"(with-captured-http-requests [requests](channel/send! {:type :channel/http:details {:url "https://www.secret_service.xyz":auth-method "query-param"- :auth-info {:token "123"}+ :auth-info {"token" "123"}:method "get"}}{:query-params {:page 1}})(is (= (merge default-request{:method :get:url "https://www.secret_service.xyz"- :query-params {:token "123"- :page 1}})+ :query-params {"token" "123"+ :page 1}})(first @requests)))))))(deftest send!-humanized-invalid-url-testdiff --git a/test/metabase/comments/api_test.clj b/test/metabase/comments/api_test.cljindex a416e1aef1c..7ee41d78286 100644--- a/test/metabase/comments/api_test.clj+++ b/test/metabase/comments/api_test.clj@@ -136,7 +136,7 @@(str (:common_name (mt/fetch-user :lucky)) " replied to a thread"))}]}]}(first (swap-vals! mt/inbox empty))))))))(testing "creates a comment for part of an entity"- (let [part-id (-> doc :content first :attrs :_id)+ (let [part-id (get-in doc [:content 0 :attrs "_id"])created (mt/user-http-request :rasta :post 200 "comment/"{:target_type "document":target_id doc-id@@ -222,7 +222,7 @@(testing "updates comment content"(is (=? {:content {:text "Updated content"}}(mt/user-http-request :rasta :put 200 (str "comment/" comment-id)- {:content {"text" "Updated content"}}))))+ {:content {"type" "text" "text" "Updated content"}}))))(testing "updates comment resolution status"(is (=? {:is_resolved true}(mt/user-http-request :rasta :put 200 (str "comment/" comment-id)@@ -233,7 +233,7 @@(mt/with-temp [:model/Document {doc-id :id} {}:model/Comment {c-id :id} {:target_id doc-id :creator_id (mt/user->id :rasta)}](is (= "You don't have permissions to do that."- (mt/user-http-request :lucky :put 403 (str "comment/" c-id) {:content {:text "hi"}})))+ (mt/user-http-request :lucky :put 403 (str "comment/" c-id) {:content {:type "text" :text "hi"}})))(is (= "You don't have permissions to do that."(mt/user-http-request :lucky :delete 403 (str "comment/" c-id)))))))@@ -411,7 +411,7 @@(testing "PUT /api/comment/:id - users without document access cannot update comments"(is (= "You don't have permissions to do that."(mt/user-http-request :lucky :put 403 (str "comment/" restricted-comment-id)- {:content {:text "Updated by lucky"}}))))+ {:content {:type "text" :text "Updated by lucky"}}))))(testing "DELETE /api/comment/:id - users without document access cannot delete comments"(is (= "You don't have permissions to do that."(mt/user-http-request :lucky :delete 403 (str "comment/" restricted-comment-id)))))diff --git a/test/metabase/comments/models/comment_test.clj b/test/metabase/comments/models/comment_test.cljindex b645f4cca17..996f11f1788 100644--- a/test/metabase/comments/models/comment_test.clj+++ b/test/metabase/comments/models/comment_test.clj@@ -3,6 +3,7 @@[clojure.test :refer :all][metabase.comments.api-test :as at][metabase.comments.models.comment :as comment]+ [metabase.comments.schema :as comments.schema][toucan2.core :as t2]))(deftest exploration-comment-url-test@@ -25,13 +26,17 @@(deftest comment-test(testing "mentions are parsed correctly"+ ;; `mentions` reads its `attrs` string-keyed, the shape content takes once normalized on its way into+ ;; or out of the app DB -- `comments.schema/normalize-content` mimics that for this raw tiptap fixture.(is (= [6](comment/mentions- (at/tiptap- [:p- "omg is that you? "- [:smartLink {:entityId 6 :model "user"}]]))))+ (comments.schema/normalize-content+ (at/tiptap+ [:p+ "omg is that you? "+ [:smartLink {:entityId 6 :model "user"}]])))))(is (= [6](comment/mentions- (at/tiptap- [:smartLink {:entityId 6 :model "user"}]))))))+ (comments.schema/normalize-content+ (at/tiptap+ [:smartLink {:entityId 6 :model "user"}])))))))diff --git a/test/metabase/comments/render_test.clj b/test/metabase/comments/render_test.cljindex 052c292ad4b..5dc4190621a 100644--- a/test/metabase/comments/render_test.clj+++ b/test/metabase/comments/render_test.clj@@ -67,7 +67,7 @@(is (= "<h2>Title</h2>"(render/content->html {:type "doc":content [{:type "heading"- :attrs {:level 2}+ :attrs {"level" 2}:content [{:type "text" :text "Title"}]}]}))))(testing "bullet list"(is (= "<ul><li><p>one</p></li><li><p>two</p></li></ul>"@@ -115,25 +115,25 @@(is (= "<a href=\"http://localhost:3000/question/42\">My Question</a>"(render/content->html {:type "doc":content [{:type "smartLink"- :attrs {:entityId 42- :model "card"- :label "My Question"- :href "/question/42"}}]})))))+ :attrs {"entityId" 42+ "model" "card"+ "label" "My Question"+ "href" "/question/42"}}]})))))(testing "smartLink user mention renders as plain text (no link)"(is (= "@42"(render/content->html {:type "doc":content [{:type "smartLink"- :attrs {:entityId 42- :model "user"}}]}))))+ :attrs {"entityId" 42+ "model" "user"}}]}))))(testing "smartLink ignores href — phishing URL cannot be injected"(mt/with-temporary-setting-values [site-url "http://localhost:3000"](is (= "<a href=\"http://localhost:3000/question/1\">Phishing</a>"(render/content->html {:type "doc":content [{:type "smartLink"- :attrs {:entityId 1- :model "card"- :label "Phishing"- :href "https://evil.example"}}]}))))))+ :attrs {"entityId" 1+ "model" "card"+ "label" "Phishing"+ "href" "https://evil.example"}}]}))))))(deftest content->html-xss-test(testing "HTML in text content is escaped"@@ -162,16 +162,16 @@(is (= "<a href=\"http://localhost:3000/question/1\"><img src=x></a>"(render/content->html {:type "doc":content [{:type "smartLink"- :attrs {:entityId 1- :model "card"- :label "<img src=x>"}}]})))))+ :attrs {"entityId" 1+ "model" "card"+ "label" "<img src=x>"}}]})))))(testing "smartLink with unknown model renders as plain text"(is (= "My Thing"(render/content->html {:type "doc":content [{:type "smartLink"- :attrs {:entityId 1- :model "unknown"- :label "My Thing"}}]}))))+ :attrs {"entityId" 1+ "model" "unknown"+ "label" "My Thing"}}]}))))(testing "non-string text values are coerced and rendered as plain text"(is (= "<p>42</p>"(render/content->html {:type "doc"diff --git a/test/metabase/dashboards_rest/api_test.clj b/test/metabase/dashboards_rest/api_test.cljindex 8e6925933f7..3e84b552078 100644--- a/test/metabase/dashboards_rest/api_test.clj+++ b/test/metabase/dashboards_rest/api_test.clj@@ -5191,7 +5191,6 @@:type :temporal-unit:sectionId "temporal-unit"}]})(t2/update! :model/DashboardCard :id dashcard-id {:parameter_mappings [{:parameter_id "30d7efb0"- :type :temporal-unit:card_id card-id:target [:dimension(mt/$ids orders !day.$created_at)]}]})diff --git a/test/metabase/documents/models/document_ast_reference_test.clj b/test/metabase/documents/models/document_ast_reference_test.cljindex 2a59b868a33..1587038d85e 100644--- a/test/metabase/documents/models/document_ast_reference_test.clj+++ b/test/metabase/documents/models/document_ast_reference_test.clj@@ -24,7 +24,7 @@:document (ast-with {:model "card" :entityId non-integer-id})}](let [doc (t2/select-one :model/Document :id doc-id)](testing "the stored value round-trips unchanged — the precondition for the rest of the test"- (is (= non-integer-id (-> doc :document :content first :content first :attrs :entityId))))+ (is (= non-integer-id (get-in doc [:document :content 0 :content 0 :attrs "entityId"]))))(testing "the export transform performs no lookup for the malformed reference"(let [lookups (atom [])](with-redefs [t2/select-one (fn [& args] (swap! lookups conj args) nil)]diff --git a/test/metabase/documents/models/document_test.clj b/test/metabase/documents/models/document_test.cljindex 00649a0b666..2cd73c098ab 100644--- a/test/metabase/documents/models/document_test.clj+++ b/test/metabase/documents/models/document_test.clj@@ -459,8 +459,8 @@:document {:type "doc":content [{:type "paragraph":content [{:type "smartLink"- :attrs {:entityId [{:model "Card" :id 789}]- :model "card"}}]}]}+ :attrs {"entityId" [{:model "Card" :id 789}]+ "model" "card"}}]}]}:content_type "application/json+vnd.prose-mirror":serdes/meta [{:model "Document" :id "test-entity-id"}]}deps (serdes/deserialization-dependencies document)]@@ -474,14 +474,14 @@:document {:type "doc":content [{:type "paragraph":content [{:type "smartLink"- :attrs {:entityId [{:model "Card" :id 789}]- :model "card"}}+ :attrs {"entityId" [{:model "Card" :id 789}]+ "model" "card"}}{:type "smartLink"- :attrs {:entityId [{:model "Dashboard" :id 456}]- :model "dashboard"}}+ :attrs {"entityId" [{:model "Dashboard" :id 456}]+ "model" "dashboard"}}{:type "smartLink"- :attrs {:entityId [{:model "Table" :id 321}]- :model "table"}}]}]}+ :attrs {"entityId" [{:model "Table" :id 321}]+ "model" "table"}}]}]}:content_type "application/json+vnd.prose-mirror":serdes/meta [{:model "Document" :id "test-entity-id"}]}deps (serdes/deserialization-dependencies document)]@@ -501,8 +501,8 @@:content [{:type "listItem":content [{:type "paragraph":content [{:type "smartLink"- :attrs {:entityId [{:model "Card" :id 999}]- :model "card"}}]}]}]}]}+ :attrs {"entityId" [{:model "Card" :id 999}]+ "model" "card"}}]}]}]}]}:content_type "application/json+vnd.prose-mirror":serdes/meta [{:model "Document" :id "test-entity-id"}]}deps (serdes/deserialization-dependencies document)]@@ -529,11 +529,11 @@:document {:type "doc":content [{:type "paragraph":content [{:type "smartLink"- :attrs {:entityId [{:model "Unknown" :id 789}]- :model "unknown-model"}}+ :attrs {"entityId" [{:model "Unknown" :id 789}]+ "model" "unknown-model"}}{:type "smartLink"- :attrs {:entityId [{:model "Card" :id 456}]- :model "card"}}]}]}+ :attrs {"entityId" [{:model "Card" :id 456}]+ "model" "card"}}]}]}:content_type "application/json+vnd.prose-mirror":serdes/meta [{:model "Document" :id "test-entity-id"}]}deps (serdes/deserialization-dependencies document)]@@ -547,10 +547,10 @@:document {:type "doc":content [{:type "paragraph":content [{:type "smartLink"- :attrs {:model "card"}}+ :attrs {"model" "card"}}{:type "smartLink"- :attrs {:entityId [{:model "Card" :id 456}]- :model "card"}}]}]}+ :attrs {"entityId" [{:model "Card" :id 456}]+ "model" "card"}}]}]}:content_type "application/json+vnd.prose-mirror":serdes/meta [{:model "Document" :id "test-entity-id"}]}deps (serdes/deserialization-dependencies document)]@@ -564,11 +564,11 @@:document {:type "doc":content [{:type "paragraph":content [{:type "smartLink"- :attrs {:entityId [{:model "Card" :id 789}]- :model "card"}}+ :attrs {"entityId" [{:model "Card" :id 789}]+ "model" "card"}}{:type "smartLink"- :attrs {:entityId [{:model "Card" :id 789}]- :model "card"}}]}]}+ :attrs {"entityId" [{:model "Card" :id 789}]+ "model" "card"}}]}]}:content_type "application/json+vnd.prose-mirror":serdes/meta [{:model "Document" :id "test-entity-id"}]}deps (serdes/deserialization-dependencies document)]@@ -594,10 +594,10 @@:document {:type "doc":content [{:type "paragraph":content [{:type "smartLink"- :attrs {:entityId [{:model "Card" :id 789}]}}+ :attrs {"entityId" [{:model "Card" :id 789}]}}{:type "smartLink"- :attrs {:entityId [{:model "Card" :id 456}]- :model "card"}}]}]}+ :attrs {"entityId" [{:model "Card" :id 456}]+ "model" "card"}}]}]}:content_type "application/json+vnd.prose-mirror":serdes/meta [{:model "Document" :id "test-entity-id"}]}deps (serdes/deserialization-dependencies document)]@@ -613,8 +613,8 @@:content [{:type "smartLink":attrs nil}{:type "smartLink"- :attrs {:entityId [{:model "Card" :id 456}]- :model "card"}}]}]}+ :attrs {"entityId" [{:model "Card" :id 456}]+ "model" "card"}}]}]}:content_type "application/json+vnd.prose-mirror":serdes/meta [{:model "Document" :id "test-entity-id"}]}deps (serdes/deserialization-dependencies document)]@@ -629,22 +629,22 @@:content [{:type "paragraph":content [{:type "text" :text "Check out this "}{:type "smartLink"- :attrs {:entityId [{:model "Card" :id 789}]- :model "card"}}+ :attrs {"entityId" [{:model "Card" :id 789}]+ "model" "card"}}{:type "text" :text " and this "}{:type "smartLink"- :attrs {:entityId [{:model "Dashboard" :id 456}]- :model "dashboard"}}]}+ :attrs {"entityId" [{:model "Dashboard" :id 456}]+ "model" "dashboard"}}]}{:type "heading"- :attrs {:level 2}+ :attrs {"level" 2}:content [{:type "text" :text "Section with table"}]}{:type "table":content [{:type "tableRow":content [{:type "tableCell":content [{:type "paragraph":content [{:type "smartLink"- :attrs {:entityId [{:model "Table" :id 321}]- :model "table"}}]}]}]}]}]}+ :attrs {"entityId" [{:model "Table" :id 321}]+ "model" "table"}}]}]}]}]}]}:content_type "application/json+vnd.prose-mirror":serdes/meta [{:model "Document" :id "test-entity-id"}]}deps (serdes/deserialization-dependencies document)]@@ -660,8 +660,8 @@:creator_id 456:document {:type "doc":content [{:type "smartLink"- :attrs {:entityId [{:model "Card" :id 456}]- :model "card"}}]}+ :attrs {"entityId" [{:model "Card" :id 456}]+ "model" "card"}}]}:content_type "application/json" ; Not prose-mirror:serdes/meta [{:model "Document" :id "test-entity-id"}]}deps (serdes/deserialization-dependencies document)]@@ -671,9 +671,9 @@(testing "Document descendants includes embedded cards"(mt/with-temp [:model/Document {document-id :id} {:document {:type "doc":content [{:type "cardEmbed"- :attrs {:id 456}}+ :attrs {"id" 456}}{:type "cardEmbed"- :attrs {:id 789}}]}+ :attrs {"id" 789}}]}:content_type "application/json+vnd.prose-mirror"}](let [descendants (serdes/descendants "Document" document-id {})](is (= {["Card" 456] {"Document" document-id}@@ -684,11 +684,11 @@(testing "Document descendants includes smart links"(mt/with-temp [:model/Document {document-id :id} {:document {:type "doc":content [{:type "smartLink"- :attrs {:entityId 456- :model "card"}}+ :attrs {"entityId" 456+ "model" "card"}}{:type "smartLink"- :attrs {:entityId 789- :model "dashboard"}}]}+ :attrs {"entityId" 789+ "model" "dashboard"}}]}:content_type "application/json+vnd.prose-mirror"}](let [descendants (serdes/descendants "Document" document-id {})](is (= {["Card" 456] {"Document" document-id}@@ -699,13 +699,13 @@(testing "Document descendants includes both embedded cards and smart links"(mt/with-temp [:model/Document {document-id :id} {:document {:type "doc":content [{:type "cardEmbed"- :attrs {:id 111}}+ :attrs {"id" 111}}{:type "smartLink"- :attrs {:entityId 222- :model "card"}}+ :attrs {"entityId" 222+ "model" "card"}}{:type "smartLink"- :attrs {:entityId 333- :model "table"}}]}+ :attrs {"entityId" 333+ "model" "table"}}]}:content_type "application/json+vnd.prose-mirror"}](let [descendants (serdes/descendants "Document" document-id {})](is (= {["Card" 111] {"Document" document-id}@@ -731,11 +731,11 @@(testing "Document descendants ignores smart links with unknown model types"(mt/with-temp [:model/Document {document-id :id} {:document {:type "doc":content [{:type "smartLink"- :attrs {:entityId 456- :model "card"}}+ :attrs {"entityId" 456+ "model" "card"}}{:type "smartLink"- :attrs {:entityId 789- :model "unknown-model"}}]}+ :attrs {"entityId" 789+ "model" "unknown-model"}}]}:content_type "application/json+vnd.prose-mirror"}](let [descendants (serdes/descendants "Document" document-id {})];; Should only include the known model type@@ -748,10 +748,10 @@(testing "Document descendants handles duplicate references correctly"(mt/with-temp [:model/Document {document-id :id} {:document {:type "doc":content [{:type "cardEmbed"- :attrs {:id 456}}+ :attrs {"id" 456}}{:type "smartLink"- :attrs {:entityId 456- :model "card"}}]}+ :attrs {"entityId" 456+ "model" "card"}}]}:content_type "application/json+vnd.prose-mirror"}](let [descendants (serdes/descendants "Document" document-id {})];; Should merge duplicate references - same card referenced twice@@ -771,14 +771,14 @@(testing "Document descendants correctly maps all supported smart link model types"(mt/with-temp [:model/Document {document-id :id} {:document {:type "doc":content [{:type "smartLink"- :attrs {:entityId 111- :model "card"}}+ :attrs {"entityId" 111+ "model" "card"}}{:type "smartLink"- :attrs {:entityId 222- :model "dashboard"}}+ :attrs {"entityId" 222+ "model" "dashboard"}}{:type "smartLink"- :attrs {:entityId 333- :model "table"}}]}+ :attrs {"entityId" 333+ "model" "table"}}]}:content_type "application/json+vnd.prose-mirror"}](let [descendants (serdes/descendants "Document" document-id {})](is (= {["Card" 111] {"Document" document-id}@@ -819,16 +819,16 @@(let [node (-> {:content_type "application/json+vnd.prose-mirror":document {:type "doc":content [{:type "cardEmbed"- :attrs {:id card-id- :stored_result_id 987654321}}]}}+ :attrs {"id" card-id+ "stored_result_id" 987654321}}]}}export-document-ast:contentfirst)](testing "still rewrites its Card :id to a portable serdes path — the ephemeral Card is a real serdes entity"- (is (vector? (-> node :attrs :id)))- (is (= "Card" (-> node :attrs :id first :model))))+ (is (vector? (get-in node [:attrs "id"])))+ (is (= "Card" (:model (first (get-in node [:attrs "id"]))))))(testing "drops :stored_result_id — a raw local id for a row that is not a serdes entity, which would resolve to an unrelated snapshot on import"- (is (not (contains? (:attrs node) :stored_result_id))))))))+ (is (not (contains? (:attrs node) "stored_result_id"))))))))(deftest document-serdes-live-card-embed-keeps-attrs-test(testing "A live cardEmbed exports its :id as a portable path and is otherwise untouched"@@ -837,12 +837,12 @@(let [node (-> {:content_type "application/json+vnd.prose-mirror":document {:type "doc":content [{:type "cardEmbed"- :attrs {:id card-id :_id "abc"}}]}}+ :attrs {"id" card-id "_id" "abc"}}]}}export-document-ast:contentfirst)]- (is (= "Card" (-> node :attrs :id first :model)))- (is (= "abc" (-> node :attrs :_id)))))))+ (is (= "Card" (:model (first (get-in node [:attrs "id"])))))+ (is (= "abc" (get-in node [:attrs "_id"])))))))(deftest serdes-extract-query-excludes-exploration-documents-test(testing "serdes never extracts an exploration Summary document"@@ -882,13 +882,13 @@{:content_type "application/json+vnd.prose-mirror":document {:type "doc":content [{:type "cardEmbed"- :attrs {:id card-id}}]}})+ :attrs {"id" card-id}}]}})imported (import-document-ast{:content_type "application/json+vnd.prose-mirror":document exported})](testing "export rewrites the id to a portable path"- (is (vector? (-> exported :content first :attrs :id))))+ (is (vector? (get-in exported [:content 0 :attrs "id"]))))(testing "import rewrites it back to this instance's Card id — on the serialized form the idis a serdes path, so any guard that expects a raw integer skips the node and leavesthe path in place"- (is (= card-id (-> imported :content first :attrs :id))))))))+ (is (= card-id (get-in imported [:content 0 :attrs "id"]))))))))diff --git a/test/metabase/documents/prose_mirror_test.clj b/test/metabase/documents/prose_mirror_test.cljindex 27714cb39d2..952f381bcbf 100644--- a/test/metabase/documents/prose_mirror_test.clj+++ b/test/metabase/documents/prose_mirror_test.clj@@ -330,15 +330,15 @@:content [{:type "paragraph":content [{:type "text" :text "see"}{:type prose-mirror/smart-link-type- :attrs {:model "card" :entityId "abc" :label "Orders Question"}}+ :attrs {"model" "card" "entityId" "abc" "label" "Orders Question"}}{:type "text" :text "and"}- {:type "mention" :attrs {:id 7 :label "Jane Doe"}}]}]}]+ {:type "mention" :attrs {"id" 7 "label" "Jane Doe"}}]}]}](is (= "see Orders Question and Jane Doe" (prose-mirror/ast->text ast)))))(testing "ignores nodes that render no inline prose (card embeds, label-less references, layout containers)"(let [ast {:type "doc":content [{:type "paragraph" :content [{:type "text" :text "before"}]}- {:type prose-mirror/card-embed-type :attrs {:id 42}}- {:type prose-mirror/smart-link-type :attrs {:model "card" :entityId "abc"}}+ {:type prose-mirror/card-embed-type :attrs {"id" 42}}+ {:type prose-mirror/smart-link-type :attrs {"model" "card" "entityId" "abc"}}{:type "paragraph" :content [{:type "text" :text "after"}]}]}](is (= "before after" (prose-mirror/ast->text ast)))))(testing "returns an empty string for an empty document"@@ -355,38 +355,38 @@(let [result (prose-mirror/insert-card-embed doc 42 nil)](is (= 3 (count (get-in result [:document :content]))))(is (= "resizeNode" (get-in result [:document :content 2 :type])))- (is (= 42 (:id (embed-attrs (get-in result [:document :content 2])))))- (is (uuid? (:_id (embed-attrs (get-in result [:document :content 2])))))))+ (is (= 42 (get (embed-attrs (get-in result [:document :content 2])) "id")))+ (is (uuid? (get (embed-attrs (get-in result [:document :content 2])) "_id")))))(testing "an index inserts before the block currently at that index"(let [result (prose-mirror/insert-card-embed doc 42 1)]- (is (= 42 (:id (embed-attrs (get-in result [:document :content 1])))))+ (is (= 42 (get (embed-attrs (get-in result [:document :content 1])) "id")))(is (= "two" (get-in result [:document :content 2 :content 0 :text])))))(testing "index 0 inserts at the very top"(is (= 42 (-> (prose-mirror/insert-card-embed doc 42 0)(get-in [:document :content 0])embed-attrs- :id))))+ (get "id")))))(testing "out-of-range indexes are clamped"(is (= 42 (-> (prose-mirror/insert-card-embed doc 42 99)(get-in [:document :content 2])embed-attrs- :id)))+ (get "id"))))(is (= 42 (-> (prose-mirror/insert-card-embed doc 42 -5)(get-in [:document :content 0])embed-attrs- :id))))+ (get "id")))))(testing "extra-attrs are merged onto the cardEmbed"- (let [result (prose-mirror/insert-card-embed doc 42 nil {:stored_result_id 9- :chart_href "/x"- :child_target_id "3"- :host_data {:query_ids [101 102]}})+ (let [result (prose-mirror/insert-card-embed doc 42 nil {"stored_result_id" 9+ "chart_href" "/x"+ "child_target_id" "3"+ "host_data" {:query_ids [101 102]}})attrs (embed-attrs (get-in result [:document :content 2]))]- (is (= 42 (:id attrs)))- (is (= 9 (:stored_result_id attrs)))- (is (= "/x" (:chart_href attrs)))- (is (= "3" (:child_target_id attrs)))- (is (= {:query_ids [101 102]} (:host_data attrs)))- (is (uuid? (:_id attrs)))))))+ (is (= 42 (get attrs "id")))+ (is (= 9 (get attrs "stored_result_id")))+ (is (= "/x" (get attrs "chart_href")))+ (is (= "3" (get attrs "child_target_id")))+ (is (= {:query_ids [101 102]} (get attrs "host_data")))+ (is (uuid? (get attrs "_id")))))))(deftest ^:parallel insert-card-embed-empty-document-test(testing "inserting into an empty or nil ast produces a doc with just the embed"@@ -399,8 +399,8 @@(is (= "doc" (get-in result [:document :type])))(is (= 1 (count (get-in result [:document :content]))))(is (= "resizeNode" (get-in result [:document :content 0 :type])))- (is (= 7 (:id attrs)))- (is (uuid? (:_id attrs)))))))+ (is (= 7 (get attrs "id")))+ (is (uuid? (get attrs "_id")))))))(deftest ^:parallel insert-card-embed-invalid-content-type-test(testing "throws for non-prose-mirror documents"@@ -412,11 +412,11 @@(deftest ^:parallel node-entity-id-test(testing "returns the id for a well-formed positive-integer reference"- (is (= 7 (prose-mirror/node-entity-id {:type prose-mirror/smart-link-type :attrs {:entityId 7}})))- (is (= 7 (prose-mirror/node-entity-id {:type prose-mirror/card-embed-type :attrs {:id 7}}))))+ (is (= 7 (prose-mirror/node-entity-id {:type prose-mirror/smart-link-type :attrs {"entityId" 7}})))+ (is (= 7 (prose-mirror/node-entity-id {:type prose-mirror/card-embed-type :attrs {"id" 7}}))))(testing "returns nil for any id that is not a positive integer"(doseq [id [{:a 1} {:b [1]} [{:c "x"}] "7" 0 -1 nil]]- (is (nil? (prose-mirror/node-entity-id {:type prose-mirror/smart-link-type :attrs {:entityId id}}))+ (is (nil? (prose-mirror/node-entity-id {:type prose-mirror/smart-link-type :attrs {"entityId" id}}))(str "smartLink entityId=" (pr-str id)))- (is (nil? (prose-mirror/node-entity-id {:type prose-mirror/card-embed-type :attrs {:id id}}))+ (is (nil? (prose-mirror/node-entity-id {:type prose-mirror/card-embed-type :attrs {"id" id}}))(str "cardEmbed id=" (pr-str id))))))diff --git a/test/metabase/documents/test_util.clj b/test/metabase/documents/test_util.cljindex eb3856eef74..48f0c1a91b8 100644--- a/test/metabase/documents/test_util.clj+++ b/test/metabase/documents/test_util.clj@@ -15,4 +15,4 @@"Build a ProseMirror document AST that embeds each id in `card-ids` as a `cardEmbed` node."[card-ids]{:type "doc"- :content (mapv (fn [id] {:type "cardEmbed" :attrs {:id id :name nil}}) card-ids)})+ :content (mapv (fn [id] {:type "cardEmbed" :attrs {"id" id "name" nil}}) card-ids)})diff --git a/test/metabase/embedding_rest/api/embed_test.clj b/test/metabase/embedding_rest/api/embed_test.cljindex 2b65638ebb7..8583e891c9e 100644--- a/test/metabase/embedding_rest/api/embed_test.clj+++ b/test/metabase/embedding_rest/api/embed_test.clj@@ -291,7 +291,6 @@;; merge of both places{:id "c",:type "date/single",- :display_name "c",:target ["variable" ["template-tag" "c"]],:name "c",:slug "c",@@ -472,7 +471,7 @@(card-query-url card response-format {:params {:venue_id 100}}){:request-options request-options})))(testing "If `:locked` parameter is present in URL params, request should fail"- (is (= "You can only specify a value for :venue_id in the JWT."+ (is (= "You can only specify a value for venue_id in the JWT."(let [url (card-query-url card response-format {:params {:venue_id 100}})](client/client :get 400 (str url (if (str/includes? url "format_rows")"&venue_id=100"@@ -484,10 +483,10 @@(do-response-formats [response-format _request-options](testing (str "check that if embedding is enabled globally and for the object requests fail if they pass a ""`:disabled` parameter")- (is (= "You're not allowed to specify a value for :venue_id."+ (is (= "You're not allowed to specify a value for venue_id."(client/client :get 400 (card-query-url card response-format {:params {:venue_id 100}})))))(testing "If a `:disabled` param is passed in the URL the request should fail"- (is (= "You're not allowed to specify a value for :venue_id."+ (is (= "You're not allowed to specify a value for venue_id."(let [url (card-query-url card response-format)](client/client :get 400 (str url (if (str/includes? url "format_rows")"&venue_id=200"@@ -499,7 +498,7 @@(with-temp-card [card {:enable_embedding true, :embedding_params {:venue_id "enabled"}}](do-response-formats [response-format request-options](testing "If `:enabled` param is present in both JWT and the URL, the request should fail"- (is (= "You can't specify a value for :venue_id if it's already set in the JWT."+ (is (= "You can't specify a value for venue_id if it's already set in the JWT."(let [url (card-query-url card response-format {:params {:venue_id 100}})](client/client :get 400 (str url (if (str/includes? url "format_rows")"&venue_id=100"@@ -564,7 +563,7 @@(is (= [[107]](mt/rows (client/client :get 202 (card-query-url card ""))))))(testing "you can't apply an empty param value if the parameter is disabled"- (is (= "You're not allowed to specify a value for :date."+ (is (= "You're not allowed to specify a value for date."(client/client :get 400 (str (card-query-url card "") "?date=")))))))(testing "if the param is locked"(mt/with-temp@@ -893,7 +892,6 @@:model/DashboardCard {_ :id} {:dashboard_id (:id dashboard):card_id card-id:parameter_mappings [{:card_id card-id- :slug "venue_name":parameter_id "foo":target [:dimension[:field (mt/id :venues :name) nil]]}@@ -939,12 +937,10 @@:model/DashboardCard {_ :id} {:dashboard_id (:id dashboard):card_id card-id:parameter_mappings [{:card_id card-id- :slug "venue_name":parameter_id "foo":target [:dimension[:field (mt/id :venues :name) nil]]}{:card_id card-id- :slug "venue_name_2":parameter_id "bar":target [:dimension[:field (mt/id :venues :name) nil]]}]}]@@ -1056,8 +1052,7 @@(mt/with-dynamic-fn-redefs [qp.constraints/default-query-constraints (constantly {:max-results 10, :max-results-bare-rows 10})](with-embedding-enabled-and-new-secret-key!(with-temp-dashcard [dashcard {:dash {:enable_embedding true}- :card {:dataset_query (assoc (mt/mbql-query venues)- :limit 1+ :card {:dataset_query (assoc (mt/mbql-query venues {:limit 1}):middleware{:add-default-userland-constraints? true:userland-query? true})}@@ -1130,17 +1125,17 @@(with-temp-dashcard [dashcard {:dash {:enable_embedding true, :embedding_params {:venue_id "disabled"}}}](testing (str "check that if embedding is enabled globally and for the object requests fail if they pass a ""`:disabled` parameter")- (is (= "You're not allowed to specify a value for :venue_id."+ (is (= "You're not allowed to specify a value for venue_id."(client/client :get 400 (dashcard-url dashcard {:params {:venue_id 100}})))))(testing "If a `:disabled` param is passed in the URL the request should fail"- (is (= "You're not allowed to specify a value for :venue_id."+ (is (= "You're not allowed to specify a value for venue_id."(client/client :get 400 (str (dashcard-url dashcard) "?venue_id=200"))))))))(deftest dashboard-enabled-params-test(with-embedding-enabled-and-new-secret-key!(with-temp-dashcard [dashcard {:dash {:enable_embedding true, :embedding_params {:venue_id "enabled"}}}](testing "If `:enabled` param is present in both JWT and the URL, the request should fail"- (is (= "You can't specify a value for :venue_id if it's already set in the JWT."+ (is (= "You can't specify a value for venue_id if it's already set in the JWT."(client/client :get 400 (str (dashcard-url dashcard {:params {:venue_id 100}}) "?venue_id=200")))))(testing "If an `:enabled` param is present in the JWT, that's ok"(is (=? {:status "completed"@@ -1186,7 +1181,7 @@(is (= [[107]](mt/rows (client/client :get 202 (dashcard-url dashcard))))))(testing "you can't apply an empty param value if the parameter is disabled"- (is (= "You're not allowed to specify a value for :date."+ (is (= "You're not allowed to specify a value for date."(client/client :get 400 (str (dashcard-url dashcard) "?date=")))))))(testing "if the param is locked"(mt/with-temp-vals-in-db :model/Dashboard (u/the-id dashboard) {:embedding_params {:date "locked"}}@@ -1542,7 +1537,7 @@(doseq [url-fn [values-url search-url]:let [url (str (url-fn {"price" 4}) "?_PRICE_=4")]](testing (str "\n" url)- (is (= "You can't specify a value for :price if it's already set in the JWT."+ (is (= "You can't specify a value for price if it's already set in the JWT."(client/client :get 400 url))))))))(deftest chain-filter-ignore-current-user-permissions-test@@ -1592,7 +1587,7 @@(doseq [url-fn [values-url search-url]:let [url (url-fn {"price" 4})]](testing (str "\n" url)- (is (= "You can only specify a value for :price in the JWT."+ (is (= "You can only specify a value for price in the JWT."(client/client :get 400 (str url "?_PRICE_=4"))))))))))(deftest chain-filter-disabled-params-test@@ -1611,13 +1606,13 @@(doseq [url-fn [values-url search-url]:let [url (url-fn {"price" 4})]](testing (str "\n" url)- (is (= "You're not allowed to specify a value for :price."+ (is (= "You're not allowed to specify a value for price."(client/client :get 400 url))))))(testing "Requests should fail if the URL has a disabled parameter"(doseq [url-fn [values-url search-url]:let [url (str (url-fn) "?_PRICE_=4")]](testing (str "\n" url)- (is (= "You're not allowed to specify a value for :price."+ (is (= "You're not allowed to specify a value for price."(client/client :get 400 url)))))))));; Pivot tables@@ -1768,10 +1763,10 @@:dashcard {:parameter_mappings []}}](testing (str "check that if embedding is enabled globally and for the object requests fail if they pass a ""`:disabled` parameter")- (is (= "You're not allowed to specify a value for :abc."+ (is (= "You're not allowed to specify a value for abc."(client/client :get 400 (pivot-dashcard-url dashcard (:dashboard_id dashcard) {:params {:abc 100}})))))(testing "If a `:disabled` param is passed in the URL the request should fail"- (is (= "You're not allowed to specify a value for :abc."+ (is (= "You're not allowed to specify a value for abc."(client/client :get 400 (str (pivot-dashcard-url dashcard) "?abc=200")))))))))(deftest pivot-dashcard-enabled-params-test@@ -1787,7 +1782,7 @@:card (api.pivots/pivot-card):dashcard {:parameter_mappings []}}](testing "If `:enabled` param is present in both JWT and the URL, the request should fail"- (is (= "You can't specify a value for :abc if it's already set in the JWT."+ (is (= "You can't specify a value for abc if it's already set in the JWT."(client/client :get 400 (str (pivot-dashcard-url dashcard (:dashboard_id dashcard) {:params {:abc 100}}) "?abc=200")))))(testing "If an `:enabled` param is present in the JWT, that's ok"(let [result (client/client :get 202 (pivot-dashcard-url dashcard (:dashboard_id dashcard) {:params {:abc 100}}))diff --git a/test/metabase/embedding_rest/api/preview_embed_test.clj b/test/metabase/embedding_rest/api/preview_embed_test.cljindex 6227c7349fd..071857a0880 100644--- a/test/metabase/embedding_rest/api/preview_embed_test.clj+++ b/test/metabase/embedding_rest/api/preview_embed_test.clj@@ -108,7 +108,7 @@(mt/user-http-request :crowberto :get 202 (card-query-url card {:_embedding_params {:venue_id "locked"}:params {:venue_id 100}}))))(testing "if `:locked` parameter is present in URL params, request should fail"- (is (= "You can only specify a value for :venue_id in the JWT."+ (is (= "You can only specify a value for venue_id in the JWT."(mt/user-http-request :crowberto :get 400 (str (card-query-url card {:_embedding_params {:venue_id "locked"}:params {:venue_id 100}})"?venue_id=200"))))))))))@@ -119,11 +119,11 @@(embed-test/with-embedding-enabled-and-new-secret-key!(embed-test/with-temp-card [card](testing "check that if embedding is enabled globally and for the object requests fail if they pass a `:disabled` parameter"- (is (= "You're not allowed to specify a value for :venue_id."+ (is (= "You're not allowed to specify a value for venue_id."(mt/user-http-request :crowberto :get 400 (card-query-url card {:_embedding_params {:venue_id "disabled"}:params {:venue_id 100}})))))(testing "If a `:disabled` param is passed in the URL the request should fail"- (is (= "You're not allowed to specify a value for :venue_id."+ (is (= "You're not allowed to specify a value for venue_id."(mt/user-http-request :crowberto :get 400 (str (card-query-url card {:_embedding_params {:venue_id "disabled"}})"?venue_id=200"))))))))))@@ -133,7 +133,7 @@(embed-test/with-embedding-enabled-and-new-secret-key!(embed-test/with-temp-card [card](testing "If `:enabled` param is present in both JWT and the URL, the request should fail"- (is (= "You can't specify a value for :venue_id if it's already set in the JWT."+ (is (= "You can't specify a value for venue_id if it's already set in the JWT."(mt/user-http-request :crowberto :get 400 (str (card-query-url card {:_embedding_params {:venue_id "enabled"}:params {:venue_id 100}})"?venue_id=200")))))@@ -177,7 +177,7 @@(is (= [[107]](mt/rows (mt/user-http-request :crowberto :get 202 (card-query-url card))))))(testing "you can't apply an empty param value if the parameter is disabled"- (is (= "You're not allowed to specify a value for :date."+ (is (= "You're not allowed to specify a value for date."(mt/user-http-request :crowberto :get 400 (str (card-query-url card {:_embedding_params {:date "disabled"}}) "?date=")))))))(testing "if the param is locked"(mt/with-temp@@ -297,7 +297,7 @@(mt/user-http-request :crowberto :get 202(dashcard-url dashcard {:_embedding_params {:venue_id "locked"}, :params {:venue_id 100}})))))(testing "If `:locked` parameter is present in URL params, request should fail"- (is (= "You can only specify a value for :venue_id in the JWT."+ (is (= "You can only specify a value for venue_id in the JWT."(mt/user-http-request :crowberto :get 400 (str (dashcard-url dashcard{:_embedding_params {:venue_id "locked"}, :params {:venue_id 100}})"?venue_id=200"))))))))))@@ -308,11 +308,11 @@(embed-test/with-embedding-enabled-and-new-secret-key!(embed-test/with-temp-dashcard [dashcard](testing "check that if embedding is enabled globally and for the object requests fail if they pass a `:disabled` parameter"- (is (= "You're not allowed to specify a value for :venue_id."+ (is (= "You're not allowed to specify a value for venue_id."(mt/user-http-request :crowberto :get 400 (dashcard-url dashcard{:_embedding_params {:venue_id "disabled"}, :params {:venue_id 100}})))))(testing "If a `:disabled` param is passed in the URL the request should fail"- (is (= "You're not allowed to specify a value for :venue_id."+ (is (= "You're not allowed to specify a value for venue_id."(mt/user-http-request :crowberto :get 400 (str (dashcard-url dashcard {:_embedding_params {:venue_id "disabled"}})"?venue_id=200"))))))))))@@ -322,7 +322,7 @@(embed-test/with-embedding-enabled-and-new-secret-key!(embed-test/with-temp-dashcard [dashcard](testing "If `:enabled` param is present in both JWT and the URL, the request should fail"- (is (= "You can't specify a value for :venue_id if it's already set in the JWT."+ (is (= "You can't specify a value for venue_id if it's already set in the JWT."(mt/user-http-request :crowberto :get 400 (str (dashcard-url dashcard {:_embedding_params {:venue_id "enabled"}:params {:venue_id 100}})"?venue_id=200")))))@@ -509,7 +509,6 @@:dashboard_id dashboard-id:parameter_mappings [{:parameter_id "_name_":card_id card-id- :type "string/=":target [:dimension [:template-tag "NAME"]]}]}](let [url (dashcard-url dashcard {:_embedding_params {:name "enabled"}})](is (= [[1]]diff --git a/test/metabase/explorations/api_test.clj b/test/metabase/explorations/api_test.cljindex aeb8065cac9..af90898a116 100644--- a/test/metabase/explorations/api_test.clj+++ b/test/metabase/explorations/api_test.clj@@ -315,7 +315,7 @@:metrics [{:card_id (:id metric):dimension_mappings [{:dimension_id (duid "d1"):table_id (mt/id :venues)- :target ["field" {} (mt/id :venues :price)]}]}]+ :target ["field" (mt/id :venues :price) nil]}]}]:dimensions [{:dimension_id (duid "d1") :display_name "Price":effective_type "type/Number"}]:timeline_ids [(:id tl)]}@@ -358,7 +358,7 @@:metrics [{:card_id (:id metric):dimension_mappings [{:dimension_id (duid "d1"):table_id (mt/id :venues)- :target ["field" {} (mt/id :venues :price)]}]}]+ :target ["field" (mt/id :venues :price) nil]}]}]:dimensions [{:dimension_id (duid "d1") :display_name "Price":effective_type "type/Number"}]:timeline_ids [(:id tl)]}@@ -377,7 +377,7 @@(let [mapping (fn [card-id][{:dimension_id (duid "d1"):table_id (mt/id :venues)- :target ["field" {} (mt/id :venues :price)]+ :target ["field" (mt/id :venues :price) nil]:card_id card-id}])dims [{:dimension_id (duid "d1") :display_name "Price" :effective_type "type/Number"}]body {:name "Naming"@@ -409,7 +409,7 @@:model/Timeline tl {:creator_id (:id u)}](let [mapping [{:dimension_id (duid "d1"):table_id (mt/id :venues)- :target ["field" {} (mt/id :venues :price)]}]+ :target ["field" (mt/id :venues :price) nil]}];; Two blocks sharing the same metric: one with d1, one with d2. Timelines are;; thread-scoped, sent once at the top level. Each block is stored verbatim — the;; shared metric is NOT deduped across blocks.@@ -542,8 +542,8 @@(mt/with-temp [:model/User u {:email "[email protected]"}:model/Card m1 (valid-metric-card (:id u)):model/Card m2 (valid-metric-card (:id u))]- (let [mapping [{:dimension_id (duid "category") :table_id (mt/id :venues) :target ["field" {} (mt/id :venues :category_id)]}- {:dimension_id (duid "price") :table_id (mt/id :venues) :target ["field" {} (mt/id :venues :price)]}]+ (let [mapping [{:dimension_id (duid "category") :table_id (mt/id :venues) :target ["field" (mt/id :venues :category_id) nil]}+ {:dimension_id (duid "price") :table_id (mt/id :venues) :target ["field" (mt/id :venues :price) nil]}]body {:name "matrix":metrics [{:card_id (:id m1) :dimension_mappings mapping}{:card_id (:id m2) :dimension_mappings mapping}]@@ -570,15 +570,15 @@these to the internal kebab-case shape via the `:metabase.metrics.core/dimension-mapping`schema the request schemas reference."[]- [{:dimension_id (duid "category") :table_id (mt/id :venues) :target ["field" {} (mt/id :venues :category_id)]}- {:dimension_id (duid "price") :table_id (mt/id :venues) :target ["field" {} (mt/id :venues :price)]}])+ [{:dimension_id (duid "category") :table_id (mt/id :venues) :target ["field" (mt/id :venues :category_id) nil]}+ {:dimension_id (duid "price") :table_id (mt/id :venues) :target ["field" (mt/id :venues :price) nil]}])(defn- stored-venues-dimension-mappings"Internal-shape (kebab-case) dimension mappings for direct t2 block fixtures — the canonicalstored shape, bypassing the API edge conversion."[]- [{:dimension-id (duid "category") :table-id (mt/id :venues) :target ["field" {} (mt/id :venues :category_id)]}- {:dimension-id (duid "price") :table-id (mt/id :venues) :target ["field" {} (mt/id :venues :price)]}])+ [{:dimension-id (duid "category") :table-id (mt/id :venues) :target ["field" (mt/id :venues :category_id) nil]}+ {:dimension-id (duid "price") :table-id (mt/id :venues) :target ["field" (mt/id :venues :price) nil]}])(defn- segment-filters"Extract :segment filter clauses (as `[:segment {} <id>]`) from a snapshot dataset_query at stage 0."@@ -673,7 +673,7 @@;; `column->computed-pair` in `metabase.lib-metric.dimension.jvm`),;; which for joined dimensions differs from the metric's source table:table_id (mt/id :people)- :target ["field" {} (mt/id :people :created_at)]}]+ :target ["field" (mt/id :people :created_at) nil]}]body {:name "dt":metrics [{:card_id (:id metric) :dimension_mappings mapping}]:dimensions [{:dimension_id (duid "created")@@ -691,7 +691,7 @@:model/Card metric (venues-metric-card (:id u))](let [mapping [{:dimension_id (duid "created"):table_id (mt/id :venues)- :target ["field" {} (mt/id :checkins :date)]}]+ :target ["field" (mt/id :checkins :date) nil]}]body {:name "date":metrics [{:card_id (:id metric) :dimension_mappings mapping}]:dimensions [{:dimension_id (duid "created")@@ -707,7 +707,7 @@:model/Card metric (assoc (products-monthly-metric-card (:id u)) :name "Sales")](let [mapping [{:dimension_id (duid "cat"):table_id (mt/id :products)- :target ["field" {} (mt/id :products :category)]}]+ :target ["field" (mt/id :products :category) nil]}]body {:name "facet":metrics [{:card_id (:id metric) :dimension_mappings mapping}]:dimensions [{:dimension_id (duid "cat") :display_name "Category"}]}@@ -735,7 +735,7 @@:model/Card metric (venues-metric-card (:id u))](let [mapping [{:dimension_id (duid "price"):table_id (mt/id :venues)- :target ["field" {} (mt/id :venues :price)]}]+ :target ["field" (mt/id :venues :price) nil]}]body {:name "no-facet":metrics [{:card_id (:id metric) :dimension_mappings mapping}]:dimensions [{:dimension_id (duid "price") :display_name "Price" :effective_type "type/Number"}]}@@ -752,7 +752,7 @@(let [mapping [{:dimension_id (duid "email");; :table_id is the target column's table, not the metric's source table:table_id (mt/id :people)- :target ["field" {} (mt/id :people :email)]}]+ :target ["field" (mt/id :people :email) nil]}]body {:name "high-card":metrics [{:card_id (:id metric) :dimension_mappings mapping}]:dimensions [{:dimension_id (duid "email") :display_name "Email"}]}@@ -770,7 +770,7 @@:definition (lib/->legacy-MBQL (let [mp (mt/metadata-provider)] (-> (lib/query mp (lib.metadata/table mp (mt/id :products))) (lib/filter (lib/> (lib.metadata/field mp (mt/id :products :price)) 50)))))}](let [mapping [{:dimension_id (duid "cat"):table_id (mt/id :products)- :target ["field" {} (mt/id :products :category)]}]+ :target ["field" (mt/id :products :category) nil]}]body {:name "facet-no-seg":metrics [{:card_id (:id metric) :dimension_mappings mapping}]:dimensions [{:dimension_id (duid "cat") :display_name "Category"}]}@@ -798,7 +798,7 @@;; `column->computed-pair` in `metabase.lib-metric.dimension.jvm`),;; which for joined dimensions differs from the metric's source table:table_id (mt/id :people)- :target ["field" {} (mt/id :people :created_at)]}]+ :target ["field" (mt/id :people :created_at) nil]}]body {:name "seg":metrics [{:card_id (:id metric) :dimension_mappings mapping}]:dimensions [{:dimension_id (duid "created")@@ -823,7 +823,7 @@;; `column->computed-pair` in `metabase.lib-metric.dimension.jvm`),;; which for joined dimensions differs from the metric's source table:table_id (mt/id :people)- :target ["field" {} (mt/id :people :created_at)]}]+ :target ["field" (mt/id :people :created_at) nil]}]body {:name "collapse":metrics [{:card_id (:id metric) :dimension_mappings mapping}]:dimensions [{:dimension_id (duid "created")@@ -859,7 +859,7 @@:metrics [{:card_id (:id metric):dimension_mappings [{:dimension_id (duid "d1"):table_id (mt/id :venues)- :target ["field" {} (mt/id :venues :price)]}]}]+ :target ["field" (mt/id :venues :price) nil]}]}]:dimensions [{:dimension_id (duid "d1") :display_name "Price":effective_type "type/Number"}]:timeline_ids [(:id tl)]}@@ -961,10 +961,10 @@:model/Card signups (valid-metric-card (:id u))](let [body {:name "applicability":metrics [{:card_id (:id revenue)- :dimension_mappings [{:dimension_id (duid "plan") :table_id (mt/id :venues) :target ["field" {} (mt/id :venues :category_id)]}]}+ :dimension_mappings [{:dimension_id (duid "plan") :table_id (mt/id :venues) :target ["field" (mt/id :venues :category_id) nil]}]}{:card_id (:id signups)- :dimension_mappings [{:dimension_id (duid "plan") :table_id (mt/id :venues) :target ["field" {} (mt/id :venues :category_id)]}- {:dimension_id (duid "channel") :table_id (mt/id :venues) :target ["field" {} (mt/id :venues :price)]}]}]+ :dimension_mappings [{:dimension_id (duid "plan") :table_id (mt/id :venues) :target ["field" (mt/id :venues :category_id) nil]}+ {:dimension_id (duid "channel") :table_id (mt/id :venues) :target ["field" (mt/id :venues :price) nil]}]}]:dimensions [{:dimension_id (duid "plan")} {:dimension_id (duid "channel")}]}resp (create-exploration! u body)all-queries (-> resp :threads first :queries)@@ -986,8 +986,8 @@:model/Card revenue (assoc (valid-metric-card (:id u)) :name "Revenue")](let [body {:name "naming":metrics [{:card_id (:id revenue)- :dimension_mappings [{:dimension_id (duid "country") :table_id (mt/id :venues) :target ["field" {} (mt/id :venues :category_id)]}- {:dimension_id (duid "no-name") :table_id (mt/id :venues) :target ["field" {} (mt/id :venues :price)]}]}]+ :dimension_mappings [{:dimension_id (duid "country") :table_id (mt/id :venues) :target ["field" (mt/id :venues :category_id) nil]}+ {:dimension_id (duid "no-name") :table_id (mt/id :venues) :target ["field" (mt/id :venues :price) nil]}]}]:dimensions [{:dimension_id (duid "country") :display_name "Country"}{:dimension_id (duid "no-name")}]}resp (create-exploration! u body)@@ -1020,8 +1020,8 @@(let [body {:name "ambig":metrics [{:card_id (:id revenue):dimension_mappings- [{:dimension_id users-created :table_id 1 :target ["field" {} 1]}- {:dimension_id orders-created :table_id 1 :target ["field" {} 2]}]}]+ [{:dimension_id users-created :table_id 1 :target ["field" 1 nil]}+ {:dimension_id orders-created :table_id 1 :target ["field" 2 nil]}]}]:dimensions [{:dimension_id users-created :display_name "Created At"}{:dimension_id orders-created :display_name "Created At"}]}by-dim (->> (create-exploration! u body)@@ -1033,8 +1033,8 @@(let [body {:name "no-ambig":metrics [{:card_id (:id revenue):dimension_mappings- [{:dimension_id users-created :table_id 1 :target ["field" {} 1]}- {:dimension_id users-country :table_id 1 :target ["field" {} 3]}]}]+ [{:dimension_id users-created :table_id 1 :target ["field" 1 nil]}+ {:dimension_id users-country :table_id 1 :target ["field" 3 nil]}]}]:dimensions [{:dimension_id users-created :display_name "Created At"}{:dimension_id users-country :display_name "Country"}]}by-dim (->> (create-exploration! u body)@@ -1050,8 +1050,8 @@(let [body {:name "dim-name":metrics [{:card_id (:id metric):dimension_mappings- [{:dimension_id (duid "country") :table_id 1 :target ["field" {} 1]}- {:dimension_id (duid "no-name") :table_id 1 :target ["field" {} 2]}]}]+ [{:dimension_id (duid "country") :table_id 1 :target ["field" 1 nil]}+ {:dimension_id (duid "no-name") :table_id 1 :target ["field" 2 nil]}]}]:dimensions [{:dimension_id (duid "country") :display_name "Country"}{:dimension_id (duid "no-name")}]}by-dim (->> (create-exploration! u body)@@ -1077,8 +1077,8 @@(let [body {:name "ambig":metrics [{:card_id (:id metric):dimension_mappings- [{:dimension_id users-created :table_id 1 :target ["field" {} 1]}- {:dimension_id orders-created :table_id 1 :target ["field" {} 2]}]}]+ [{:dimension_id users-created :table_id 1 :target ["field" 1 nil]}+ {:dimension_id orders-created :table_id 1 :target ["field" 2 nil]}]}]:dimensions [{:dimension_id users-created :display_name "Created At"}{:dimension_id orders-created :display_name "Created At"}]}by-dim (->> (create-exploration! u body)@@ -1094,7 +1094,7 @@(let [resp (create-exploration! u{:name "get-score":metrics [{:card_id (:id metric)- :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" {} 1]}]}]+ :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" 1 nil]}]}]:dimensions [{:dimension_id (duid "d1")}]})eid (:id resp)qid (-> resp :threads first :queries first :id)@@ -1174,7 +1174,7 @@(let [resp (create-exploration! u{:name "result":metrics [{:card_id (:id metric)- :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" {} 1]}]}]+ :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" 1 nil]}]}]:dimensions [{:dimension_id (duid "d1")}]})qid (-> resp :threads first :queries first :id)qp-out {:status :completed@@ -1196,7 +1196,7 @@(let [resp (create-exploration! u{:name "pending":metrics [{:card_id (:id metric)- :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" {} 1]}]}]+ :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" 1 nil]}]}]:dimensions [{:dimension_id (duid "d1")}]})qid (-> resp :threads first :queries first :id)body (mt/user-http-request u :get 409 (format "exploration/query/%d" qid))]@@ -1212,7 +1212,7 @@(let [resp (create-exploration! u{:name "errored":metrics [{:card_id (:id metric)- :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" {} 1]}]}]+ :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" 1 nil]}]}]:dimensions [{:dimension_id (duid "d1")}]})qid (-> resp :threads first :queries first :id);; stands in for a driver error carrying SQL and row values the reader can't query@@ -1238,7 +1238,7 @@{:name "qr-private":collection_id (:id (collection/user->personal-collection (:id owner))):metrics [{:card_id (:id metric)- :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" {} 1]}]}]+ :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" 1 nil]}]}]:dimensions [{:dimension_id (duid "d1")}]})qid (-> resp :threads first :queries first :id)](mt/user-http-request other :get 403 (format "exploration/query/%d" qid))))))@@ -1250,7 +1250,7 @@(let [resp (create-exploration! u{:name "page-mark":metrics [{:card_id (:id metric)- :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" {} 1]}]}]+ :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" 1 nil]}]}]:dimensions [{:dimension_id (duid "d1")}]})eid (:id resp)page-id (-> resp :threads first :blocks first :pages first :id)@@ -1275,7 +1275,7 @@{:name "page-mark-private":collection_id (:id (collection/user->personal-collection (:id owner))):metrics [{:card_id (:id metric)- :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" {} 1]}]}]+ :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" 1 nil]}]}]:dimensions [{:dimension_id (duid "d1")}]})page-id (-> resp :threads first :blocks first :pages first :id)](mt/user-http-request other :put 403 (format "exploration/page/%d/starred" page-id) {:starred true})))))@@ -1292,7 +1292,7 @@(let [resp (create-exploration! u{:name "page-hide":metrics [{:card_id (:id metric)- :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" {} 1]}]}]+ :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" 1 nil]}]}]:dimensions [{:dimension_id (duid "d1")}]})eid (:id resp)page-id (-> resp :threads first :blocks first :pages first :id)@@ -1315,8 +1315,8 @@(let [resp (create-exploration! u{:name "pages-hide-bulk":metrics [{:card_id (:id metric)- :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" {} 1]}- {:dimension_id (duid "d2") :table_id 1 :target ["field" {} 2]}]}]+ :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" 1 nil]}+ {:dimension_id (duid "d2") :table_id 1 :target ["field" 2 nil]}]}]:dimensions [{:dimension_id (duid "d1")} {:dimension_id (duid "d2")}]})eid (:id resp)page-ids (->> (mt/user-http-request u :get 200 (format "exploration/%d" eid))@@ -1337,7 +1337,7 @@{:name "page-hide-private":collection_id (:id (collection/user->personal-collection (:id owner))):metrics [{:card_id (:id metric)- :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" {} 1]}]}]+ :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" 1 nil]}]}]:dimensions [{:dimension_id (duid "d1")}]})page-id (-> resp :threads first :blocks first :pages first :id)](mt/user-http-request other :put 403 "exploration/pages/hidden" {:page_ids [page-id] :hidden true})))))@@ -1353,7 +1353,7 @@:model/Card metric (assoc (venues-metric-card (:id u)) :name "Number of venues"):model/Timeline tl {:creator_id (:id u) :name "Releases"}](let [filter-value 2- field-ref ["field" {} (mt/id :venues :price)]+ field-ref ["field" (mt/id :venues :price) nil]body {:name "base drill":prompt "why down?":metrics [{:card_id (:id metric) :dimension_mappings (venues-dimension-mappings)}]@@ -1397,13 +1397,13 @@(let [price-page (some #(when (str/includes? (:name %) "Price") %) (:pages new-block))](is (some? price-page))(is (= [{:operator "="- :field_ref field-ref+ :field_ref (assoc field-ref 2 {}):value filter-value:dimension_name "Price":display_value "2"}](map #(select-keys % [:operator :field_ref :value :dimension_name :display_value])(:explore_filters new-block)))- "block node echoes persisted explore_filters")+ "block node echoes persisted explore_filters, with its field ref normalized")(is (str/includes? (:name price-page) "Price")"page short name is heading-relative, without the clicked value prefix")(is (= "Number of venues by Price" (:long_name price-page)))))@@ -1438,7 +1438,7 @@(-> src :blocks first :pages)))drill {:page_id page-id:explore_filters [{:operator "="- :field_ref ["field" {} (mt/id :venues :price)]+ :field_ref ["field" (mt/id :venues :price) nil]:value 2:display_value "2"}]}](testing "control: drilling a thread the caller can see succeeds"@@ -1476,7 +1476,7 @@(mt/user-http-request u :post 200 (format "exploration/%d/explore-further" expl-id){:page_id page-id:explore_filters [{:operator "="- :field_ref ["field" {} (mt/id :venues :price)]+ :field_ref ["field" (mt/id :venues :price) nil]:value 2:display_value "2"}]}))(let [new-thread-id (->> (t2/select :model/ExplorationThread@@ -1500,7 +1500,7 @@page-id (-> resp :threads first :blocks first :pages first :id)body {:page_id page-id:explore_filters [{:operator "="- :field_ref ["field" {} (mt/id :venues :category_id)]+ :field_ref ["field" (mt/id :venues :category_id) nil]:value 1:display_value "1"}]}](mt/user-http-request other :post 403 (format "exploration/%d/explore-further" expl-id) body)@@ -1520,7 +1520,7 @@:timeline_ids [(:id tl)]:blocks [{:name "Group":metrics [{:card_id (:id metric)- :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" {} 1]}]}]+ :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" 1 nil]}]}]:dimensions [{:dimension_id (duid "d1")}]}]})eid (:id resp)tid (-> resp :threads first :id)@@ -1567,7 +1567,7 @@(let [resp (create-exploration! u{:name "append-use":metrics [{:card_id (:id metric)- :dimension_mappings [{:dimension_id (duid "d1") :table_id (mt/id :venues) :target ["field" {} (mt/id :venues :price)]}]}]+ :dimension_mappings [{:dimension_id (duid "d1") :table_id (mt/id :venues) :target ["field" (mt/id :venues :price) nil]}]}]:dimensions [{:dimension_id (duid "d1") :display_name "Price" :effective_type "type/Number"}]})eid (:id resp)qid (-> resp :threads first :queries first :id)@@ -1586,7 +1586,7 @@(format "exploration/%d/summary/append" eid)(assoc append-display+viz :exploration_query_ids [qid]))card-id (-> (t2/select-one-fn :document :model/Document :id (:id doc))- :content last :content first :attrs :id)+ :content last :content first :attrs (get "id"))use-row (t2/select-one :model/StoredResultUse :stored_result_id sr-id :card_id card-id)attrs (-> (t2/select-one-fn :document :model/Document :id (:id doc)):content last :content first :attrs)]@@ -1596,13 +1596,13 @@"appending records a stored_result_use row for the source snapshot")(is (nil? (:exploration_id use-row))"the card-use row has no exploration_id")- (is (= sr-id (:stored_result_id attrs)))- (is (string? (:chart_href attrs)))- (is (string? (:child_target_id attrs)))- (is (= [qid] (get-in attrs [:host_data :query_ids])))- (is (nil? (get-in attrs [:host_data :explore_filters]))+ (is (= sr-id (get attrs "stored_result_id")))+ (is (string? (get attrs "chart_href")))+ (is (string? (get attrs "child_target_id")))+ (is (= [qid] (get-in attrs ["host_data" :query_ids])))+ (is (nil? (get-in attrs ["host_data" :explore_filters]))"unfiltered charts omit explore_filters from host_data")- (is (uuid? (parse-uuid (str (:_id attrs))))+ (is (uuid? (parse-uuid (str (get attrs "_id"))))"_id is stamped for per-node identity (string after JSON round-trip)")(is (false? (:is_placeholder doc))"first append clears is_placeholder"))))))@@ -1612,7 +1612,7 @@(mt/with-temp [:model/User u {:email "[email protected]"}:model/Card metric (venues-metric-card (:id u))](let [filter-value 2- field-ref ["field" {} (mt/id :venues :price)]+ field-ref ["field" (mt/id :venues :price) nil]created (create-exploration! u{:name "append-filters":metrics [{:card_id (:id metric)@@ -1642,12 +1642,12 @@(assoc append-display+viz :exploration_query_ids [qid]))attrs (-> (t2/select-one-fn :document :model/Document :id (:id doc)):content last :content first :attrs)]- (is (= [qid] (get-in attrs [:host_data :query_ids])))+ (is (= [qid] (get-in attrs ["host_data" :query_ids])))(is (=? [{:operator "=":value filter-value:dimension_name "Price":display_value "2"}]- (get-in attrs [:host_data :explore_filters]))))))))+ (get-in attrs ["host_data" :explore_filters]))))))))(deftest exploration-append-rolls-back-on-failure-test(testing "When a write fails partway through, the composite StoredResult / Card / use rows all roll back — no orphans"@@ -1656,7 +1656,7 @@(let [resp (create-exploration! u{:name "append-rollback":metrics [{:card_id (:id metric)- :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" {} 1]}]}]+ :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" 1 nil]}]}]:dimensions [{:dimension_id (duid "d1")}]})qid (-> resp :threads first :queries first :id)doc-id (-> resp :document :id)@@ -1692,7 +1692,7 @@(let [resp (create-exploration! u{:name "append-single":metrics [{:card_id (:id metric)- :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" {} 1]}]}]+ :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" 1 nil]}]}]:dimensions [{:dimension_id (duid "d1")}]})qid (-> resp :threads first :queries first :id)doc-id (-> resp :document :id)@@ -1731,7 +1731,7 @@:metrics [{:card_id (:id metric):dimension_mappings [{:dimension_id (duid "d1"):table_id (mt/id :venues)- :target ["field" {} (mt/id :venues :price)]}]}]+ :target ["field" (mt/id :venues :price) nil]}]}]:dimensions [{:dimension_id (duid "d1") :display_name "Price":effective_type "type/Number"}]})eid (:id resp)@@ -1750,8 +1750,8 @@(assoc append-display+viz :exploration_query_ids [qid]))(let [attrs (-> (t2/select-one-fn :document :model/Document :id doc-id):content last :content first :attrs)- sr-id (:stored_result_id attrs)- old-card-id (:id attrs)+ sr-id (get attrs "stored_result_id")+ old-card-id (get attrs "id")draft-id -10;; Simulate the editor forking the embed into a negative-id draft card on save.updated (mt/user-http-request u :put 200 (format "document/%d" doc-id)@@ -1888,7 +1888,7 @@(let [resp (mt/user-http-request u :post 200 "exploration"{:name "http-delete":metrics [{:card_id (:id metric)- :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" {} 1]}]}]+ :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" 1 nil]}]}]:dimensions [{:dimension_id (duid "d1")}]})eid (:id resp)];; Live exploration: delete via HTTP.@@ -1898,7 +1898,7 @@(let [resp2 (mt/user-http-request u :post 200 "exploration"{:name "trash-then-delete":metrics [{:card_id (:id metric)- :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" {} 1]}]}]+ :dimension_mappings [{:dimension_id (duid "d1") :table_id 1 :target ["field" 1 nil]}]}]:dimensions [{:dimension_id (duid "d1")}]})eid2 (:id resp2)](mt/user-http-request u :put 200 (format "exploration/%d" eid2) {:archived true})@@ -1976,12 +1976,12 @@(deftest blocks-tree-explore-further-naming-test(testing "filtered blocks expose explore_filters on the block node with unprefixed page names"(let [filters [{:operator "="- :field_ref ["field" {} 1]+ :field_ref ["field" 1 nil]:value "texas":dimension_name "State":display_value "Texas"}{:operator "="- :field_ref ["field" {} 2]+ :field_ref ["field" 2 nil]:value "2024":dimension_name "Year":display_value "2024"}]@@ -2489,7 +2489,7 @@a (insert-explore-fixture! common)b (insert-explore-fixture! common)body {:explore_filters [{:operator "="- :field_ref ["field" {} (mt/id :venues :name)]+ :field_ref ["field" (mt/id :venues :name) nil]:value "Texas":display_value "Texas"}]}](testing "cross-exploration page is rejected"@@ -2520,7 +2520,7 @@:dimension_mappings (venues-dimension-mappings)}]:dimensions [{:dimension_id "price" :display_name "Price"}]})filter-spec {:operator "between"- :field_ref ["field" {} (mt/id :venues :price)]+ :field_ref ["field" (mt/id :venues :price) nil]:values [1 3]:display_value "1 - 3"}hydrated (explore-further-and-hydrate! :crowberto@@ -2533,7 +2533,7 @@:exploration_thread_id (:id new-thread))](is (= "Number of venues → Price: 1 - 3" (:name new-thread)))(is (= [{:operator "between"- :field_ref ["field" {} (mt/id :venues :price)]+ :field_ref ["field" (mt/id :venues :price) {}]:values [1 3]:display_value "1 - 3":dimension_name "Price"}]@@ -2554,11 +2554,11 @@(-> (lib/query mp (lib.metadata/table mp (mt/id :venues)))(lib/aggregate (lib/count)))))}](let [prior {:operator "="- :field_ref ["field" {} (mt/id :venues :name)]+ :field_ref ["field" (mt/id :venues :name) nil]:value "Texas":display_value "Texas"}new-f {:operator "="- :field_ref ["field" {} (mt/id :venues :price)]+ :field_ref ["field" (mt/id :venues :price) nil]:value 2:display_value "2"}src (insert-explore-fixture!@@ -2580,7 +2580,8 @@[:not= :exploration_block.exploration_thread_id (:thread-id src)]]})first)filters (:explore_filters (first (:metrics new-block)))]- (is (= [prior new-f]+ (is (= [(assoc prior :field_ref [:field (mt/id :venues :name) nil])+ (assoc new-f :field_ref [:field (mt/id :venues :price) nil])](mapv #(select-keys % [:operator :field_ref :value :display_value]) filters))"both the prior (Texas) and the newly clicked (price) filter are present, in drill order"))))))@@ -2609,7 +2610,7 @@(str "exploration/" (:exploration-id src) "/explore-further"){:page_id (:page-id src):explore_filters [{:operator "="- :field_ref ["field" {} (mt/id :venues :price)]+ :field_ref ["field" (mt/id :venues :price) nil]:value 2:display_value "2"}]})(let [new-thread (t2/select-one :model/ExplorationThread@@ -2642,11 +2643,11 @@(str "exploration/" (:exploration-id src) "/explore-further"){:page_id (:page-id src):explore_filters [{:operator "="- :field_ref ["field" {} (mt/id :venues :category_id)]+ :field_ref ["field" (mt/id :venues :category_id) nil]:value "gadget":display_value "gadget"}{:operator "="- :field_ref ["field" {} (mt/id :venues :price)]+ :field_ref ["field" (mt/id :venues :price) nil]:value 2:display_value "2"}]})(let [new-thread (t2/select-one :model/ExplorationThread@@ -2692,7 +2693,7 @@(:query_ids page))(:id page))))))_ (is (some? page-id) "find the users-created page")- filter-spec {:operator "=" :field_ref ["field" {} users-field] :value 40.7 :display_value "40.7"}+ filter-spec {:operator "=" :field_ref ["field" users-field nil] :value 40.7 :display_value "40.7"}hydrated (explore-further-and-hydrate! u expl-id page-id [filter-spec])new-thread (->> hydrated :threads (sort-by :position) last)persisted (t2/select-one :model/ExplorationBlock :exploration_thread_id (:id new-thread))]@@ -2761,7 +2762,7 @@page-id (-> resp :threads first :blocks first :pages first :id)body {:page_id page-id:explore_filters [{:operator "="- :field_ref ["field" {} (mt/id :venues :category_id)]+ :field_ref ["field" (mt/id :venues :category_id) nil]:value 1:display_value "1"}]}threads-before (t2/count :model/ExplorationThread :exploration_id expl-id)]@@ -2794,7 +2795,7 @@:metrics [{:card_id (:id metric):dimension_mappings [{:dimension_id (duid "d1"):table_id (mt/id :venues)- :target ["field" {} (mt/id :venues :price)]}]}]+ :target ["field" (mt/id :venues :price) nil]}]}]:dimensions [{:dimension_id (duid "d1") :display_name "Price":effective_type "type/Number"}]})tid (-> created :threads first :id)@@ -2835,10 +2836,10 @@:metrics [{:card_id (:id metric):dimension_mappings [{:dimension_id (duid "d1"):table_id (mt/id :venues)- :target ["field" {} (mt/id :venues :price)]}+ :target ["field" (mt/id :venues :price) nil]}{:dimension_id (duid "d2"):table_id (mt/id :venues)- :target ["field" {} (mt/id :venues :name)]}]}]+ :target ["field" (mt/id :venues :name) nil]}]}]:dimensions [{:dimension_id (duid "d1") :display_name "Price":effective_type "type/Number"}{:dimension_id (duid "d2") :display_name "Name"diff --git a/test/metabase/legacy_mbql/schema_test.cljc b/test/metabase/legacy_mbql/schema_test.cljcindex 20b1ce65101..bf211ad7831 100644--- a/test/metabase/legacy_mbql/schema_test.cljc+++ b/test/metabase/legacy_mbql/schema_test.cljc@@ -50,7 +50,9 @@(testing "Make sure our schema validates `:field` clauses correctly"(doseq [[clause expected] {[:field 1 nil] true[:field 1 {}] false- [:field 1 {:x true}] true+ ;; a real option -- the map is closed, so a non-empty map only validates when what is+ ;; in it is declared+ [:field 1 {:join-alias "Wow"}] true[:field 1 2] false[:field "wow" nil] false[:field "wow" {}] falsediff --git a/test/metabase/legacy_mbql/util_test.cljc b/test/metabase/legacy_mbql/util_test.cljcindex fbf109ee700..5d872e9a285 100644--- a/test/metabase/legacy_mbql/util_test.cljc+++ b/test/metabase/legacy_mbql/util_test.cljc@@ -118,35 +118,39 @@(mbql.u/expression-with-name {} "wow")))))(t/deftest ^:parallel update-field-options-test- (t/is (= [:field 1 {:wow true}]- (mbql.u/update-field-options [:field 1 nil] assoc :wow true)+ ;; the options exercised here (`:display-name`, `:name`, `:binning`) are real declared ref options. Ref options are+ ;; a closed schema in MBQL 4 as well as MBQL 5, so a stand-in key like `:wow` would be rejected as this function's+ ;; input before it did any of the updating this test is about.+ (t/is (= [:field 1 {:display-name "Wow"}]+ (mbql.u/update-field-options [:field 1 nil] assoc :display-name "Wow")(mu/disable-enforcement- (mbql.u/update-field-options [:field 1 {}] assoc :wow true))- (mbql.u/update-field-options [:field 1 {:wow false}] assoc :wow true)))- (t/is (= [:field 1 {:a 1, :b 2}]- (mbql.u/update-field-options [:field 1 {:a 1}] assoc :b 2)))+ (mbql.u/update-field-options [:field 1 {}] assoc :display-name "Wow"))+ (mbql.u/update-field-options [:field 1 {:display-name "Meh"}] assoc :display-name "Wow")))+ (t/is (= [:field 1 {:name "a", :display-name "b"}]+ (mbql.u/update-field-options [:field 1 {:name "a"}] assoc :display-name "b")))(t/testing "Should remove empty options"(t/is (= [:field 1 nil]- (mbql.u/update-field-options [:field 1 {:a 1}] dissoc :a))))+ (mbql.u/update-field-options [:field 1 {:name "a"}] dissoc :name))))(t/testing "Should normalize the clause"(t/is (= [:field 1 nil]- (mbql.u/update-field-options [:field 1 {:a {:b 1}}] assoc-in [:a :b] nil))))+ (mbql.u/update-field-options [:field 1 {:binning {:strategy :default}}]+ assoc-in [:binning :strategy] nil))))(t/testing "Should work with `:expression` and `:aggregation` references as well"- (t/is (= [:expression "wow" {:a 1}]- (mbql.u/update-field-options [:expression "wow"] assoc :a 1)))- (t/is (= [:expression "wow" {:a 1, :b 2}]- (mbql.u/update-field-options [:expression "wow" {:b 2}] assoc :a 1)))- (t/is (= [:aggregation 0 {:a 1}]- (mbql.u/update-field-options [:aggregation 0] assoc :a 1)))- (t/is (= [:aggregation 0 {:a 1, :b 2}]- (mbql.u/update-field-options [:aggregation 0 {:b 2}] assoc :a 1)))+ (t/is (= [:expression "wow" {:name "a"}]+ (mbql.u/update-field-options [:expression "wow"] assoc :name "a")))+ (t/is (= [:expression "wow" {:name "a", :display-name "b"}]+ (mbql.u/update-field-options [:expression "wow" {:display-name "b"}] assoc :name "a")))+ (t/is (= [:aggregation 0 {:name "a"}]+ (mbql.u/update-field-options [:aggregation 0] assoc :name "a")))+ (t/is (= [:aggregation 0 {:name "a", :display-name "b"}]+ (mbql.u/update-field-options [:aggregation 0 {:display-name "b"}] assoc :name "a")));; in the future when we make the 3-arg version the normalized/"official" version we will probably want to stop;; doing this.(t/testing "Remove empty options entirely from `:expression` and `:aggregation` (for now)"(t/is (= [:expression "wow"]- (mbql.u/update-field-options [:expression "wow" {:b 2}] dissoc :b)))+ (mbql.u/update-field-options [:expression "wow" {:display-name "b"}] dissoc :display-name)))(t/is (= [:aggregation 0]- (mbql.u/update-field-options [:aggregation 0 {:b 2}] dissoc :b))))))+ (mbql.u/update-field-options [:aggregation 0 {:display-name "b"}] dissoc :display-name))))))(t/deftest ^:parallel with-temporal-unit-test(t/is (= [:field 1 {:temporal-unit :day}]diff --git a/test/metabase/lib/convert_test.cljc b/test/metabase/lib/convert_test.cljcindex 98d2f9c16d8..57ef6a0b6bf 100644--- a/test/metabase/lib/convert_test.cljc+++ b/test/metabase/lib/convert_test.cljc@@ -601,7 +601,7 @@:metabase.query-processor.util.add-alias-info/source-table 224}]]{:name "avg":metabase.query-processor.util.add-alias-info/desired-alias "avg"- :metabase.query-processor.util.add-alias-info/position 1+ :metabase.query-processor.util.add-alias-info/source-table 224:metabase.query-processor.util.add-alias-info/source-alias "avg"}]]:source-table 224}:type :query}))@@ -1033,17 +1033,20 @@(deftest ^:parallel convert-aggregation-reference-test(testing "Don't wrap :aggregation in :aggregation options when converting between legacy and MBQL 5"+ ;; the alias options are spelled out in full, the way `metabase.query-processor.util.add-alias-info` writes them:+ ;; ref options are a closed schema in both MBQL versions, so an undeclared key would be dropped in the round trip+ ;; and this test would be measuring the stripping rather than the conversion.(let [query {:database 2:type :query:query {:aggregation [[:aggregation-options- [:sum [:field 100 {:source-table 12, :source-alias "TOTAL"}]]+ [:sum [:field 100 {:metabase.query-processor.util.add-alias-info/source-table 12+ :metabase.query-processor.util.add-alias-info/source-alias "TOTAL"}]]{:name "sum"}]]- :order-by [[:asc [:aggregation 0 {:desired-alias "sum", :position 1}]]+ :order-by [[:asc [:aggregation 0 {:metabase.query-processor.util.add-alias-info/desired-alias "sum"}]][:asc- [:field 99 {:source-table 12- :source-alias "PRODUCT_ID"- :desired-alias "PRODUCT_ID"- :position 0}]]]+ [:field 99 {:metabase.query-processor.util.add-alias-info/source-table 12+ :metabase.query-processor.util.add-alias-info/source-alias "PRODUCT_ID"+ :metabase.query-processor.util.add-alias-info/desired-alias "PRODUCT_ID"}]]]:source-table 12}}](is (= query(-> query lib.convert/->mbql5 lib.convert/->legacy-MBQL))))))diff --git a/test/metabase/lib/drill_thru/quick_filter_test.cljc b/test/metabase/lib/drill_thru/quick_filter_test.cljcindex f5fd7162db9..5531f193f84 100644--- a/test/metabase/lib/drill_thru/quick_filter_test.cljc+++ b/test/metabase/lib/drill_thru/quick_filter_test.cljc@@ -421,8 +421,13 @@(lib/available-drill-thrus query context))drilled (lib/drill-thru query -1 nil drill "=")](is (=? [[:= {}- [:field {:binning {:strategy :default, :lib/type :metabase.lib.binning/binning}} (:id total-col)]+ [:field {:binning {:strategy :default}} (:id total-col)]40]](lib/filters drilled)))+ (testing "the binning that lands in the query is plain options, with none of the `:lib/type`/`:metadata-fn`+ bookkeeping [[metabase.lib.binning/binning]] tags its return value with"+ (is (= [{:strategy :default}]+ (for [[_tag _opts [_field field-opts _id]] (lib/filters drilled)]+ (:binning field-opts)))))(is (= #{(:id count-col) (:id total-col)}(set (map :id (lib/returned-columns drilled)))))))diff --git a/test/metabase/lib/drill_thru/test_util.cljc b/test/metabase/lib/drill_thru/test_util.cljcindex cc6c474e7ff..2289ea6c239 100644--- a/test/metabase/lib/drill_thru/test_util.cljc+++ b/test/metabase/lib/drill_thru/test_util.cljc@@ -282,8 +282,9 @@[{:keys [mbql row]} :- [:map] ;; TODO: Better type? Does one exist?query-kind :- [:enum :mbql :native]{:keys [column-name click-type query-type], :as _test-case} :- TestCase]- (let [cols (cond->> (lib/returned-columns mbql -1 (lib.util/query-stage mbql -1))- true (map #(assoc % ::was-breakout-in-original-query? (:lib/breakout? %)))+ (let [returned (lib/returned-columns mbql -1 (lib.util/query-stage mbql -1))+ breakouts (into #{} (comp (filter :lib/breakout?) (map :name)) returned)+ cols (cond->> returned(= query-kind :native) (map #(-> %(assoc :lib/source :source/native)(dissoc :lib/breakout? :lib/expression-name :lib/join-alias))))@@ -298,7 +299,7 @@(if (some? v) v :null)))dimensions (when (= query-type :aggregated)(for [col cols- :when (and (::was-breakout-in-original-query? col)+ :when (and (contains? breakouts (:name col))(not= (:name col) column-name))]{:column col:column-ref (get refs (:name col))diff --git a/test/metabase/lib/metadata/result_metadata_test.cljc b/test/metabase/lib/metadata/result_metadata_test.cljcindex 7c74a8a0ac6..f3ad9dafd99 100644--- a/test/metabase/lib/metadata/result_metadata_test.cljc+++ b/test/metabase/lib/metadata/result_metadata_test.cljc@@ -15,6 +15,7 @@[metabase.lib.test-util.macros :as lib.tu.macros][metabase.lib.test-util.notebook-helpers :as lib.tu.notebook][metabase.lib.util :as lib.util]+ [metabase.query-processor.util.add-alias-info :as-alias add-alias-info][metabase.util.malli :as mu]))#?(:cljs (comment metabase.test-runner.assert-exprs.approximately-equal/keep-me))@@ -1135,16 +1136,34 @@(map ::result-metadata/field-ref (#'result-metadata/deduplicate-field-refs cols)))))))(deftest ^:parallel remove-namespaced-options-test+ ;; `::add-alias-info/desired-alias` stands in for the namespaced keys this drops -- an option a piece of middleware+ ;; really does add to a ref -- and `:base-type` for the plain ones it has to keep. Made-up keys would not do: ref+ ;; options are a closed schema, so a key nobody declares never survives to reach this function.(are [clause expected] (= expected(#'result-metadata/remove-namespaced-options clause))- [:field 1 {::namespaced true}] [:field 1 nil]- [:field 1 {::namespaced true, :a 1}] [:field 1 {:a 1}]- [:expression "wow"] [:expression "wow"]- [:expression "wow" {::namespaced true}] [:expression "wow"]- [:expression "wow" {::namespaced true, :a 1}] [:expression "wow" {:a 1}]- [:aggregation 0] [:aggregation 0]- [:aggregation 0 {::namespaced true}] [:aggregation 0]- [:aggregation 0 {::namespaced true, :a 1}] [:aggregation 0 {:a 1}]))+ [:field 1 {::add-alias-info/desired-alias "ID"}]+ [:field 1 nil]++ [:field 1 {::add-alias-info/desired-alias "ID", :base-type :type/Integer}]+ [:field 1 {:base-type :type/Integer}]++ [:expression "wow"]+ [:expression "wow"]++ [:expression "wow" {::add-alias-info/desired-alias "wow"}]+ [:expression "wow"]++ [:expression "wow" {::add-alias-info/desired-alias "wow", :base-type :type/Integer}]+ [:expression "wow" {:base-type :type/Integer}]++ [:aggregation 0]+ [:aggregation 0]++ [:aggregation 0 {::add-alias-info/desired-alias "count"}]+ [:aggregation 0]++ [:aggregation 0 {::add-alias-info/desired-alias "count", :base-type :type/Integer}]+ [:aggregation 0 {:base-type :type/Integer}]))(deftest ^:parallel always-include-desired-column-alias-test(testing "Populate source and desired column aliases for native queries without stage metadata"diff --git a/test/metabase/lib/query/test_spec_test.cljc b/test/metabase/lib/query/test_spec_test.cljcindex bcbe7010320..74970513094 100644--- a/test/metabase/lib/query/test_spec_test.cljc+++ b/test/metabase/lib/query/test_spec_test.cljc@@ -1184,7 +1184,7 @@:display-name "Custom Name":default "Foo":required true- :widget-type "string/contains"+ :widget-type :string/contains:id string?}](lib/template-tags query))))))@@ -1218,7 +1218,7 @@:display-name "Custom Name":default "Foo":required true- :widget-type "string/contains"+ :widget-type :string/contains:id string?}](lib/template-tags query))))))@@ -1241,6 +1241,6 @@:display-name "Custom Name":default "Foo":required true- :widget-type "string/contains"+ :widget-type :string/contains:id string?}](lib/template-tags query))))))diff --git a/test/metabase/lib/schema/metadata/fingerprint_test.cljc b/test/metabase/lib/schema/metadata/fingerprint_test.cljcindex 2d194af8022..44224e55809 100644--- a/test/metabase/lib/schema/metadata/fingerprint_test.cljc+++ b/test/metabase/lib/schema/metadata/fingerprint_test.cljc@@ -26,17 +26,16 @@"type/Number" {"q1" 1.459}}}))))(deftest ^:parallel fingerprint-schema-test- (testing "allows for extra keywords"- (let [base {:global- {:distinct-count 2, :nil% 0.0}}]+ (testing "every map in a fingerprint declares its keys"+ (let [base {:global {:distinct-count 2, :nil% 0.0}}]+ (is (not (me/humanize (mr/explain ::lib.schema.metadata.fingerprint/fingerprint base))))(doseq [path [[:type :type/Text][:type :type/Number][:type :type/DateTime][:global][:experimental]- [:top-level][]]]- (is (not (me/humanize- (mr/explain- ::lib.schema.metadata.fingerprint/fingerprint- (assoc-in base (conj path :extra-key) (rand-nth [3 :extra-value 4.0 {:stuff :stuff}]))))))))))+ (is (me/humanize+ (mr/explain+ ::lib.schema.metadata.fingerprint/fingerprint+ (assoc-in base (conj path :extra-key) (rand-nth [3 :extra-value 4.0 {:stuff :stuff}])))))))))diff --git a/test/metabase/lib/schema/parameter_test.cljc b/test/metabase/lib/schema/parameter_test.cljcindex 2cf7e4fa21e..d2213c55775 100644--- a/test/metabase/lib/schema/parameter_test.cljc+++ b/test/metabase/lib/schema/parameter_test.cljc@@ -133,7 +133,6 @@{:include-current true} true{} true{:case-sensitive "yes"} false- ;; An unrecognized option is not a validation error: the map stays open so a new frontend option does not 400- ;; against an older backend. Such a key never reaches the clause either way, because request decoding strips+ ;; the options map is closed: an option this version does not know is not valid, and request decoding strips;; it -- see `decode-strips-undeclared-keys-test` in [[metabase.api.macros-test]].- {:lib/uuid "not-yours"} true)))+ {:lib/uuid "not-yours"} false)))diff --git a/test/metabase/lib/schema_test.cljc b/test/metabase/lib/schema_test.cljcindex 11b3c189dde..f107166048f 100644--- a/test/metabase/lib/schema_test.cljc+++ b/test/metabase/lib/schema_test.cljc@@ -109,10 +109,13 @@:fields [[:aggregation {:lib/uuid (str (random-uuid))} bad-ref]]}[(str "Invalid :aggregation reference: no aggregation with uuid " bad-ref)]- ;; if we forget to remove legacy ag refs from some part of the query make sure we get a useful error message.- {:lib/type :mbql.stage/mbql- :some-other-section {:field-ref [:aggregation 0]}}- ["Invalid :aggregation reference: [:aggregation 0]"]+ ;; if we forget to remove legacy ag refs from some part of the query make sure we get a useful error message+ ;; alongside whatever the slot they were left in says about them.+ {:lib/type :mbql.stage/mbql+ :source-table 1+ :fields [[:aggregation 0]]}+ {:fields [["invalid tuple size 2, expected 3"]]+ :malli/error ["Invalid :aggregation reference: [:aggregation 0]"]};; don't recurse into joins.{:lib/type :mbql.stage/mbql@@ -386,14 +389,12 @@:id "aa000001-0000-0000-0000-000000000001":display-name "Minimum Total":default 50- :required true- :sectionid "number"}+ :required true}{:type :date:name "after_date":id "aa000002-0000-0000-0000-000000000002":display-name "After Date"- :default "2024-01-01"- :sectionid "date"}+ :default "2024-01-01"}{:type :text:name "user_id":id "aa000003-0000-0000-0000-000000000003"@@ -403,8 +404,7 @@:name "is_active":id "aa000004-0000-0000-0000-000000000004":display-name "Is Active"- :default true- :sectionid "boolean"}]}]})+ :default true}]}]})(deftest ^:parallel external-test;; this one is not valid according to the internal schema because itdiff --git a/test/metabase/lib/serialize_test.cljc b/test/metabase/lib/serialize_test.cljcindex de2aa1e8708..237663ad8d1 100644--- a/test/metabase/lib/serialize_test.cljc+++ b/test/metabase/lib/serialize_test.cljc@@ -1,14 +1,19 @@(ns metabase.lib.serialize-test(:require- [clojure.test :refer [deftest is testing]]+ [clojure.test :refer [are deftest is testing]][metabase.lib.core][metabase.lib.schema :as-alias lib.schema][metabase.lib.schema.binning :as-alias lib.schema.binning]+ [metabase.lib.schema.common :as lib.schema.common][metabase.lib.schema.constraints :as-alias lib.schema.constraints]+ [metabase.lib.schema.info :as-alias lib.schema.info]+ [metabase.lib.schema.join :as-alias lib.schema.join]+ [metabase.lib.schema.metadata :as-alias lib.schema.metadata][metabase.lib.schema.middleware-options :as-alias lib.schema.middleware-options][metabase.lib.schema.parameter :as-alias lib.schema.parameter][metabase.lib.schema.template-tag :as-alias lib.schema.template-tag]- [metabase.lib.serialize :as lib.serialize]))+ [metabase.lib.serialize :as lib.serialize]+ [metabase.util.malli.registry :as mr]))(comment metabase.lib.core/keep-me)@@ -103,3 +108,232 @@:native "SELECT *":params [#t "2022-10-03T00:00"]}]:database 1})))))++;;;;+;;;; Internal (query processor / permissions / sandboxing) keys.+;;;;+;;;; Every namespaced key that middleware `assoc`es onto a query, stage, join or clause-options map at runtime is+;;;; declared as an optional entry on the corresponding schema, so those schemas can be closed. Declaring them must+;;;; NOT stop them from being stripped when a query crosses the REST API / app DB boundary -- that is what these tests+;;;; check.+;;;;++(defn- declared-internal-keys+ "The [[lib.schema.common/internal-key?]] keys declared as map entries in the (unresolved) form of `schema-name`.+ Driving the tests below off this rather than off a hand-written list means they cannot drift from the schemas: a+ newly declared key is automatically required to appear in the fixture query and to get stripped.++ Only descends into vectors and seqs so that schema property maps (`{:decode/api ...}` and friends, whose keys are+ also namespaced) are not mistaken for entries."+ [schema-name]+ (into #{}+ (comp (filter vector?)+ (keep first)+ (filter lib.schema.common/internal-key?))+ (tree-seq (some-fn vector? seq?) seq (mr/schema schema-name))))++(def ^:private external-remap+ "One `:metabase.query-processor.middleware.add-remaps/external-remapping`-shaped map."+ {:id 1+ :name "Category"+ :field-id 2+ :field-name "CATEGORY_ID"+ :human-readable-field-id 3+ :human-readable-field-name "NAME"})++(def ^:private options-internal-keys+ "Every internal key middleware adds to a clause/ref options map."+ {:qp/ignore-coercion true+ :qp/allow-coercion-for-columns-without-integer-qp.add.source-table true+ :qp/native-sandbox-column.force-coercion-strategy :Coercion/UNIXSeconds->DateTime+ :metabase.query-processor.util.add-alias-info/source-table 1+ :metabase.query-processor.util.add-alias-info/source-alias "ID"+ :metabase.query-processor.util.add-alias-info/desired-alias "ID_2"+ :metabase.query-processor.util.add-alias-info/nfc-path ["parent" "child"]+ :metabase.query-processor.util.add-alias-info/resolved {:lib/type :metadata/column+ :name "ID"+ :base-type :type/Integer}+ :metabase.query-processor.util.transformations.nest-breakouts/externally-remapped-field true+ :metabase.query-processor.middleware.add-remaps/new-field-dimension-id 1+ :metabase.query-processor.middleware.add-remaps/original-field-dimension-id 1+ :metabase.driver.sql.query-processor/forced-alias true+ :metabase.driver.sql.query-processor/add-cast :bit+ :metabase.driver.sql.query-processor/wrap-in-case true+ :metabase.driver.sql.parameters.substitution/compiling-field-filter? true+ :metabase.driver.sqlserver/optimized-bucketing? true+ :metabase.driver.mongo.query-processor/join-local "Cat"})++(def ^:private stage-internal-keys+ "Every internal key middleware adds to a stage, other than the native-only `:query-permissions/referenced-card-ids`."+ {:qp/stage-is-from-source-card 1+ :qp/stage-had-source-card 1+ :qp/added-implicit-fields? true+ :qp/skip-persisted-cache true+ :persisted-info/native "SELECT * FROM cache_1"+ :source-query/model? true+ :source-query/native-model? false+ :query-permissions/sandboxed-table 1+ :metabase-enterprise.sandbox.query-processor.middleware.sandboxing/sandbox? true+ :metabase.query-processor.middleware.add-remaps/remaps [external-remap]+ :metabase.query-processor.middleware.cumulative-aggregations/replaced-indexes #{0}+ :metabase.query-processor.middleware.add-implicit-joins/reused-join-aliases #{"Cat"}+ :metabase.query-processor.util.add-alias-info/desired-alias->escaped {"ID" "ID_2"}+ :metabase.query-processor.util.add-alias-info/join-alias->escaped {"Cat" "Cat_2"}})++(def ^:private join-internal-keys+ "Every internal key middleware adds to a join."+ {:qp/is-implicit-join true+ :qp/keep-default-join-alias true+ :metabase.query-processor.middleware.add-implicit-joins/original-position 0+ :metabase.query-processor.util.add-alias-info/alias "Cat"+ :metabase.query-processor.util.add-alias-info/original-alias "Cat"+ :metabase.lib.join/replace-alias true})++(def ^:private clean-native-stage+ {:lib/type :mbql.stage/native+ :native "SELECT * FROM venues"+ :template-tags []})++(def ^:private clean-join+ {:lib/type :mbql/join+ :alias "Cat"+ :stages [{:lib/type :mbql.stage/mbql, :source-table 2}]+ :conditions [[:= {:lib/uuid "00000000-0000-0000-0000-000000000002"}+ [:field {:lib/uuid "00000000-0000-0000-0000-000000000003", :base-type :type/Integer} "ID"]+ [:field {:lib/uuid "00000000-0000-0000-0000-000000000004"+ :base-type :type/Integer+ :join-alias "Cat"}+ "ID"]]]})++(def ^:private clean-mbql-stage+ {:lib/type :mbql.stage/mbql+ :fields [[:field {:lib/uuid "00000000-0000-0000-0000-000000000001", :base-type :type/Integer} "ID"]]+ :joins [clean-join]+ :limit 100})++(def ^:private clean-query+ "The fixture query with none of the internal keys on it -- what everything below should decode back down to.+ `:viz-settings` and `:user-parameters` are in here rather than with the internal keys because their names are not+ namespaced, so they survive decoding."+ {:lib/type :mbql/query+ :database 1+ :stages [clean-native-stage clean-mbql-stage]+ :parameters []+ :viz-settings {:column_settings {}}+ :user-parameters [{:type :category, :id "p1", :value 1}]+ :info {:context :ad-hoc}})++(def ^:private query-internal-keys+ "Every internal key middleware adds to the top level of a query."+ {:lib.convert/converted? true+ :qp/compiled {:query "SELECT 1", :params [1]}+ :qp/compiled-inline {:query "SELECT 1"}+ :qp/source-card-id 1+ :qp/skip-result-metadata-persistence true+ :qp.pivot/unremapped-breakout-combination [0 1]+ :qp.pivot/remapped-breakout-combination [0]+ :qp.pivot/num-remapped-cols 3+ :qp.pivot/num-unremapped-breakouts 2+ :qp.pivot/num-remapped-breakouts 3+ :qp.pivot/remapped-indexes {0 1}+ :query-permissions/referenced-card-ids #{1}+ :destination-database/id 2+ :impersonation/role "analyst"+ :impersonation/admin? true+ :impersonation/allow-write? false+ :metabase.query-processor.util.add-alias-info/original clean-query+ :metabase.query-processor.middleware.add-remaps/external-remaps [external-remap]+ :metabase-enterprise.sandbox.query-processor.middleware.sandboxing/original-metadata+ [{:name "ID", :display_name "ID", :base_type :type/Integer}]})++(def ^:private dirty-query+ "A realistic MBQL 5 query carrying every internal key declared on the query, stage, join and options schemas, the way+ it would look part-way through the query processor pipeline."+ (-> clean-query+ (merge query-internal-keys)+ (assoc-in [:stages 0] (merge clean-native-stage+ stage-internal-keys+ {:query-permissions/referenced-card-ids #{1}}))+ (assoc-in [:stages 1] (merge clean-mbql-stage stage-internal-keys))+ (assoc-in [:stages 1 :joins 0] (merge clean-join join-internal-keys))+ (assoc-in [:stages 1 :fields 0 1] (merge {:lib/uuid "00000000-0000-0000-0000-000000000001", :base-type :type/Integer}+ options-internal-keys))))++(def ^:private column-internal-keys+ "Every internal key Lib and the query processor add to a column metadata map -- the ones declared by this pass plus+ the handful that were already declared before it."+ {:qp/implicit-field? true+ :qp/native-sandbox-column.force-coercion-strategy :Coercion/UNIXSeconds->DateTime+ :qp/native-sandbox-column.propagate-coercion? true+ :metabase.lib.metadata.result-metadata/field-ref [:field 1 nil]+ :metabase.lib.metadata.result-metadata/source :breakout+ :metabase.lib.metadata.result-metadata/remove-join-alias? true+ :metabase.lib.field.resolution/fallback-metadata? true+ :metabase.driver.mongo.query-processor/source-alias "ID"+ :metabase.driver.mongo.query-processor/join-field "Cat"+ :metabase.driver.mongo.query-processor/inherited? true+ :metabase.lib.join/target {:lib/type :metadata/column+ :name "CATEGORY"+ :base-type :type/Text}+ :metabase.lib.underlying/original {:lib/type :metadata/column+ :name "CATEGORY"+ :base-type :type/Text}+ :metabase.lib.underlying/temporal-unit :month+ :metabase.lib.underlying/binning {:strategy :default}+ :metabase.lib.join/HACK-from-incomplete-join? true+ :metabase.query-processor.pivot/idx 0+ :dimension/id 1+ :dimension/name "Category"+ :dimension/type :external+ :dimension/human-readable-field-id 2+ :values/values [1 2]+ :values/human-readable-values ["One" "Two"]})++(def ^:private info-internal-keys+ "Every internal key added to a query's `:info`."+ {:metadata/own-model-query? true+ :metadata/model-metadata [{:lib/type :metadata/column, :name "ID", :base-type :type/Integer}]+ :pivot/original-query clean-query+ :pivot/result-metadata :none})++(deftest ^:parallel internal-keys-fixture-covers-the-schemas-test+ (testing "the fixtures carry every internal key the schemas declare, so these tests cannot drift"+ (are [schema fixture-keys] (= #{} (set (remove (set fixture-keys) (declared-internal-keys schema))))+ ::lib.schema.common/options (keys options-internal-keys)+ ::lib.schema.join/join (keys join-internal-keys)+ ::lib.schema/query (keys query-internal-keys)+ ::lib.schema/stage.common (keys stage-internal-keys)+ ::lib.schema/stage.mbql (keys stage-internal-keys)+ ::lib.schema/stage.native (cons :query-permissions/referenced-card-ids (keys stage-internal-keys))+ ::lib.schema.metadata/column (keys column-internal-keys)+ ::lib.schema.info/info (keys info-internal-keys))))++(deftest ^:parallel internal-keys-are-valid-mbql-test+ (testing "a query carrying all of these keys is still a valid MBQL 5 query -- i.e. the declared schemas match reality"+ (is (nil? (mr/explain ::lib.schema/query dirty-query)))))++(deftest ^:parallel strip-internal-keys-from-query-test+ (testing "prepare-after-deserialization strips every internal key and leaves the query itself alone"+ (is (= clean-query+ (lib.serialize/prepare-after-deserialization dirty-query)))))++(deftest ^:parallel strip-internal-keys-on-serialization-test+ (testing "prepare-for-serialization strips them too, plus the run-time-only keys it always drops"+ (is (= (dissoc clean-query :info :parameters :viz-settings)+ (lib.serialize/prepare-for-serialization dirty-query)))))++(deftest ^:parallel internal-keys-stripped-from-column-metadata-but-not-info-test+ (testing (str "internal keys declared on :metabase.lib.schema.metadata/column are stripped on deserialization while "+ "`lib`-namespaced keys stay; the ones on :metabase.lib.schema.info/info are set by the server on its own "+ "queries and survive")+ (let [clean-column {:lib/type :metadata/column+ :name "ID"+ :base-type :type/Integer+ :lib/original-ref-style-for-result-metadata-purposes :original-ref-style/id}+ column (merge clean-column column-internal-keys)+ query (-> clean-query+ (assoc-in [:stages 1 :lib/stage-metadata] {:lib/type :metadata/results, :columns [column]})+ (update :info merge info-internal-keys))]+ (is (nil? (mr/explain ::lib.schema/query query)))+ (is (= (assoc-in query [:stages 1 :lib/stage-metadata :columns 0] clean-column)+ (lib.serialize/prepare-after-deserialization query))))))diff --git a/test/metabase/lib/stage_test.cljc b/test/metabase/lib/stage_test.cljcindex cadaa47af69..e21ef9cf703 100644--- a/test/metabase/lib/stage_test.cljc+++ b/test/metabase/lib/stage_test.cljc@@ -737,16 +737,18 @@base-type [nil :type/Date]effective-type [nil :type/Date]inherited-temporal-unit [nil :default]- ;; make sure random keys don't affect this either- nonsense-key [nil 1337]- lib-key [nil "PRODUCTS"]+ ;; make sure options that have nothing to do with bucketing don't affect this either. They have to be+ ;; options the schema actually declares -- a made-up key is dropped before the ref is ever resolved, so it+ ;; could not tell us anything.+ irrelevant-option [nil :type/Category]+ irrelevant-lib-option [nil "PRODUCTS"]:let [opts (cond-> {:join-alias "People"}temporal-unit (assoc :temporal-unit temporal-unit)base-type (assoc :base-type base-type)effective-type (assoc :effective-type effective-type)inherited-temporal-unit (assoc :inherited-temporal-unit inherited-temporal-unit)- nonsense-key (assoc :nonsense-key nonsense-key)- lib-key (assoc :lib/nonsense-key lib-key))+ irrelevant-option (assoc :semantic-type irrelevant-option)+ irrelevant-lib-option (assoc :lib/source-name irrelevant-lib-option))clause [:field (meta/id :people :birth-date) opts]]](testing (pr-str (lib/->mbql5 clause))(testing `lib/returned-columnsdiff --git a/test/metabase/lib/test_metadata.cljc b/test/metabase/lib/test_metadata.cljcindex 1eac9c8e4ca..ea3b60b00be 100644--- a/test/metabase/lib/test_metadata.cljc+++ b/test/metabase/lib/test_metadata.cljc@@ -2449,8 +2449,7 @@:display-name "ID":database-required true:points-of-interest nil- :fingerprint {:global {:distinct-count 2, :nil% 0.0}- :type {:type/UUID {}}}+ :fingerprint {:global {:distinct-count 2, :nil% 0.0}}:lib/type :metadata/column})(defmethod field-metadata-method [:gh/issues :reporter-id]@@ -2812,8 +2811,7 @@:preview-display true:database-required true:points-of-interest nil- :fingerprint {:global {:distinct-count 150, :nil% 0.0}- :type {:type/UUID {}}}+ :fingerprint {:global {:distinct-count 150, :nil% 0.0}}:lib/type :metadata/column})(defmethod field-metadata-method [:gh/comments :author-id]@@ -2916,8 +2914,7 @@:preview-display true:database-required true:points-of-interest nil- :fingerprint {:global {:distinct-count 200, :nil% 0.0}- :type {:type/UUID {}}}+ :fingerprint {:global {:distinct-count 200, :nil% 0.0}}:lib/type :metadata/column})(defmethod field-metadata-method [:gh/comments :body-markdown]diff --git a/test/metabase/lib_be/models/transforms_test.clj b/test/metabase/lib_be/models/transforms_test.cljindex 4a002b47cc3..4df2842ce1e 100644--- a/test/metabase/lib_be/models/transforms_test.clj+++ b/test/metabase/lib_be/models/transforms_test.clj@@ -164,18 +164,21 @@:card-id 123}}}}))))))(deftest transform-query-out-strips-internal-keys-test+ ;; `:qp/source-card-id` is one of the keys the query processor adds to a query mid-pipeline, so the schema declares+ ;; it and a query carrying it is valid MBQL. What keeps a client from forging one is that it is stripped here, on+ ;; the way out of the app DB, and again on the way in.(testing "an internal namespaced key is stripped when a dataset_query is read back out of the app DB"(is (not (contains? ((:out lib-be/transform-query)- (json/encode {:database (mt/id)- :type :query- :query {:source-table (mt/id :venues)}- :a/b 1}))- :a/b)))))+ (json/encode {:database (mt/id)+ :type :query+ :query {:source-table (mt/id :venues)}+ :qp/source-card-id 1}))+ :qp/source-card-id)))))(deftest card-dataset-query-strips-internal-keys-test(testing "a forged internal namespaced key in a Card's :dataset_query does not survive a round-trip through the app DB"- (mt/with-temp [:model/Card {card-id :id} {:dataset_query {:database (mt/id)- :type :query- :query {:source-table (mt/id :venues)}- :a/b 1}}]- (is (not (contains? (:dataset_query (t2/select-one :model/Card :id card-id)) :a/b))))))+ (mt/with-temp [:model/Card {card-id :id} {:dataset_query {:database (mt/id)+ :type :query+ :query {:source-table (mt/id :venues)}+ :qp/source-card-id 1}}]+ (is (not (contains? (:dataset_query (t2/select-one :model/Card :id card-id)) :qp/source-card-id))))))diff --git a/test/metabase/lib_metric/binning_test.cljc b/test/metabase/lib_metric/binning_test.cljcindex 5a7d167c571..2a714af50e6 100644--- a/test/metabase/lib_metric/binning_test.cljc+++ b/test/metabase/lib_metric/binning_test.cljc@@ -221,10 +221,10 @@(deftest ^:parallel with-binning-preserves-other-options-test(testing "with-binning preserves other options"- (let [projection [:dimension {:lib/uuid "test-uuid" :display-name "Test"} uuid-numeric]+ (let [projection [:dimension {:lib/uuid "00000000-0000-4000-8000-000000000042" :display-name "Test"} uuid-numeric]binning {:strategy :default}result (lib-metric.projection/with-binning projection binning)]- (is (= "test-uuid" (:lib/uuid (second result))))+ (is (= "00000000-0000-4000-8000-000000000042" (:lib/uuid (second result))))(is (= "Test" (:display-name (second result))))(is (= binning (:binning (second result)))))))diff --git a/test/metabase/lib_metric/temporal_bucket_test.cljc b/test/metabase/lib_metric/temporal_bucket_test.cljcindex f5edc22a239..55b91b65e7c 100644--- a/test/metabase/lib_metric/temporal_bucket_test.cljc+++ b/test/metabase/lib_metric/temporal_bucket_test.cljc@@ -203,8 +203,8 @@(deftest ^:parallel with-temporal-bucket-preserves-other-options-test(testing "with-temporal-bucket preserves other options"- (let [projection [:dimension {:lib/uuid "test-uuid" :display-name "Test"} uuid-datetime]+ (let [projection [:dimension {:lib/uuid "00000000-0000-4000-8000-000000000042" :display-name "Test"} uuid-datetime]result (lib-metric.projection/with-temporal-bucket projection :month)]- (is (= "test-uuid" (:lib/uuid (second result))))+ (is (= "00000000-0000-4000-8000-000000000042" (:lib/uuid (second result))))(is (= "Test" (:display-name (second result))))(is (= :month (:temporal-unit (second result)))))))diff --git a/test/metabase/logger/api_test.clj b/test/metabase/logger/api_test.cljindex 72feca6ef21..5d0a887d361 100644--- a/test/metabase/logger/api_test.clj+++ b/test/metabase/logger/api_test.clj@@ -153,15 +153,14 @@{:duration 1, :duration_unit :hours, :log_levels {"my.namespace" :ok"my.other.namespace" :catastophic}}))))(testing "invalid log_levels type"- (are [value json-type] (= {:specific-errors {:log_levels [(str "invalid type, received: " json-type)]}- :errors {:_error (format "Log levels should be an object, %s received" json-type)}}- (mt/user-http-request :crowberto :post 400 "logger/adjustment"- {:duration 1, :duration_unit :hours, :log_levels value}))- [] "array"- 4.2 "number"- false "boolean"- "ll" "string"- nil "null")))+ (are [value] (= "Value must be a map."+ (:log_levels (:errors (mt/user-http-request :crowberto :post 400 "logger/adjustment"+ {:duration 1, :duration_unit :hours, :log_levels value}))))+ []+ 4.2+ false+ "ll"+ nil)))(deftest ^:synchronized analytic-events-test(snowplow-test/with-fake-snowplow-collectordiff --git a/test/metabase/metabot/agent/user_context_test.clj b/test/metabase/metabot/agent/user_context_test.cljindex 80ee05e674e..a79aa389746 100644--- a/test/metabase/metabot/agent/user_context_test.clj+++ b/test/metabase/metabot/agent/user_context_test.clj@@ -169,7 +169,7 @@(deftest ^:parallel format-viewing-context-test-2c(testing "formats question entity"(let [context {:user_is_viewing [{:type "question"- :id 789+ :id Integer/MAX_VALUE:name "Top Customers"}]}result (user-context/format-viewing-context context)](is (some? result))@@ -179,7 +179,7 @@(deftest ^:parallel format-viewing-context-test-2d(testing "formats metric entity"(let [context {:user_is_viewing [{:type "metric"- :id 111+ :id (dec Integer/MAX_VALUE):name "Total Revenue"}]}result (user-context/format-viewing-context context)](is (some? result))@@ -189,7 +189,7 @@(deftest ^:parallel format-viewing-context-test-2e(testing "formats dashboard entity"(let [context {:user_is_viewing [{:type "dashboard"- :id 222+ :id (- Integer/MAX_VALUE 2):name "Executive Dashboard"}]}result (user-context/format-viewing-context context)](is (some? result))diff --git a/test/metabase/metabot/api/conversations_test.clj b/test/metabase/metabot/api/conversations_test.cljindex ead0d35697c..8933dad7163 100644--- a/test/metabase/metabot/api/conversations_test.clj+++ b/test/metabase/metabot/api/conversations_test.clj@@ -669,7 +669,7 @@body))))))(deftest record-saved-entity-strips-extra-query-keys-test- (testing "POST /api/metabot/conversations/:id/saved-entity validates and strips undeclared keys from :dataset_query"+ (testing "POST /api/metabot/conversations/:id/saved-entity strips the query processor's internal keys from :dataset_query"(let [user-id (mt/user->id :crowberto)](mt/with-model-cleanup [:model/Card](mt/with-temp [:model/MetabotConversation {convo-id :id} {:user_id user-id}@@ -678,9 +678,13 @@(str "metabot/conversations/" convo-id "/saved-entity"){:chart_id "chart-1":card {:name "Venues"- :dataset_query (assoc (venues-query) :a 1 :a/b 2)+ ;; internal keys the QP adds while a query runs; a client+ ;; must not be able to smuggle them in through a save+ :dataset_query (-> (venues-query)+ (assoc :qp/source-card-id 1)+ (assoc-in [:stages 0 :qp/stage-had-source-card] 1)):display "bar"}})stored (:dataset_query (t2/select-one :model/Card :id (:id created)))](is (= :mbql/query (:lib/type stored)))- (is (not (contains? stored :a)))- (is (not (contains? stored :a/b)))))))))+ (is (not (contains? stored :qp/source-card-id)))+ (is (not (contains? (first (:stages stored)) :qp/stage-had-source-card)))))))))diff --git a/test/metabase/metabot/tools/deftool_test.clj b/test/metabase/metabot/tools/deftool_test.cljindex 1c97c47f024..ca61fb12ece 100644--- a/test/metabase/metabot/tools/deftool_test.clj+++ b/test/metabase/metabot/tools/deftool_test.clj@@ -39,9 +39,8 @@(deftest ^:parallel invoke-tool-with-args-test(testing "invoke-tool with arguments schema that encodes keys"(mr/def ::test-args- [:and- [:map [:user_id :int]]- [:map {:encode/tool-api-request #(set/rename-keys % {:user_id :user-id})}]])+ [:map {:closed true, :encode/tool-api-request #(set/rename-keys % {:user_id :user-id})}+ [:user_id :int]])(let [received-args (atom nil)handler (fn [args](reset! received-args args)diff --git a/test/metabase/metabot/tools/save_entity_test.clj b/test/metabase/metabot/tools/save_entity_test.cljindex 3f39610e95f..76601e3f6a0 100644--- a/test/metabase/metabot/tools/save_entity_test.clj+++ b/test/metabase/metabot/tools/save_entity_test.clj@@ -169,7 +169,7 @@(defn- card-embed [card-id]{:type "resizeNode"- :content [{:type "cardEmbed" :attrs {:id card-id :_id string?}}]})+ :content [{:type "cardEmbed" :attrs {"id" card-id "_id" string?}}]})(deftest save-to-document-test(mt/with-current-user (mt/user->id :crowberto)diff --git a/test/metabase/notification/models_test.clj b/test/metabase/notification/models_test.cljindex 1859295cd82..10d7f425a2e 100644--- a/test/metabase/notification/models_test.clj+++ b/test/metabase/notification/models_test.clj@@ -37,9 +37,7 @@(testing "success if :payload_type is supported"(is (some? (t2/select-one:model/Notification- (t2/insert-returning-pk! :model/Notification {:payload_type :notification/system-event- :created_at :%now- :updated_at :%now})))))+ (t2/insert-returning-pk! :model/Notification {:payload_type :notification/system-event})))))(testing "failed if payload_type is invalid"(is (thrown-with-msg? Exception #"Value does not match schema*"(t2/insert! :model/Notification {:payload_type :notification/not-existed}))))))diff --git a/test/metabase/public_sharing_rest/api_test.clj b/test/metabase/public_sharing_rest/api_test.cljindex f36d21b06e8..11730114f82 100644--- a/test/metabase/public_sharing_rest/api_test.clj+++ b/test/metabase/public_sharing_rest/api_test.clj@@ -393,9 +393,9 @@:b {:type "date", :name "b", :display_name "b" :id "b" :default "B TAG"}:c {:type "date", :name "c", :display_name "c" :id "c" :default "C TAG"}:d {:type "date", :name "d", :display_name "d" :id "d" :default "D TAG"}}}}- :parameters [{:type "date", :name "a", :display_name "a" :id "a" :default "A param"}- {:type "date", :name "b", :display_name "b" :id "b" :default "B param"}- {:type "date", :name "c", :display_name "c" :id "c" :default "C param"+ :parameters [{:type "date", :name "a", :id "a" :default "A param"}+ {:type "date", :name "b", :id "b" :default "B param"}+ {:type "date", :name "c", :id "c" :default "C param":values_source_type "static-list" :values_source_config {:values ["BBQ" "Bakery" "Bar"]}}]:embedding_params {:a "locked", :b "disabled", :c "enabled", :d "enabled"}})@@ -409,7 +409,6 @@(mt/with-temp [:model/Card card (assoc (card-with-embedded-params) :public_uuid (str (random-uuid)))](is (= [{:type "date/single",:name "a",- :display_name "a",:id "a",:default "A TAG",:target ["variable" ["template-tag" "a"]],@@ -417,7 +416,6 @@:required false}{:type "date/single",:name "b",- :display_name "b",:id "b",:default "B TAG",:target ["variable" ["template-tag" "b"]],@@ -427,7 +425,6 @@;; merge of both places{:type "date/single",:name "c",- :display_name "c",:slug "c",;; order importance: the default from template-tag is in the final result:default "C TAG",diff --git a/test/metabase/pulse/models/pulse_test.clj b/test/metabase/pulse/models/pulse_test.cljindex 222401f411f..9fd92231561 100644--- a/test/metabase/pulse/models/pulse_test.clj+++ b/test/metabase/pulse/models/pulse_test.clj@@ -504,10 +504,10 @@:model/Database {db-id :id} {:engine :h2}:model/Table {table-id :id} {:db_id db-id}:model/Collection {collection-id :id} {:name "Test Collection"}- :model/Card card {:dataset_query {:database db-id- :type :query- :collection_id collection-id- :query {:source-table table-id}}}+ :model/Card card {:collection_id collection-id+ :dataset_query {:database db-id+ :type :query+ :query {:source-table table-id}}}:model/PermissionsGroup {group-id :id} {}:model/PermissionsGroupMembership _ {:user_id user-id :group_id group-id}];; Grant read access on the card but no download permission@@ -538,10 +538,10 @@:model/Database {db-id :id} {:engine :h2}:model/Table {table-id :id} {:db_id db-id}:model/Collection {collection-id :id} {:name "Test Collection"}- :model/Card card {:dataset_query {:database db-id- :collection_id collection-id- :type :query- :query {:source-table table-id}}}+ :model/Card card {:collection_id collection-id+ :dataset_query {:database db-id+ :type :query+ :query {:source-table table-id}}}:model/PermissionsGroup {group-id :id} {}:model/PermissionsGroupMembership _ {:user_id user-id :group_id group-id}];; Grant read and download permissionsdiff --git a/test/metabase/queries/models/card_test.clj b/test/metabase/queries/models/card_test.cljindex 488d7c8cb96..77be084d3ff 100644--- a/test/metabase/queries/models/card_test.clj+++ b/test/metabase/queries/models/card_test.clj@@ -1459,7 +1459,6 @@:name "Card with parameter reference":parameters [{:id "test-param":name "test-param"- :display_param "test param":type :category:values_source_type "card":values_source_config {:card_id remote-synced-card-id}}]}]diff --git a/test/metabase/queries_rest/api/card_test.clj b/test/metabase/queries_rest/api/card_test.cljindex 5b7b58faa93..d463336c365 100644--- a/test/metabase/queries_rest/api/card_test.clj+++ b/test/metabase/queries_rest/api/card_test.clj@@ -1956,7 +1956,7 @@(testing "Admin should be able to update Card's embedding params"(mt/user-http-request :crowberto :put 200 (str "card/" (u/the-id card)){:embedding_params {:abc "enabled"}})- (is (= {:abc "enabled"}+ (is (= {"abc" "enabled"}(t2/select-one-fn :embedding_params :model/Card :id (u/the-id card)))))))))(deftest update-embedding-type-to-nil-testdiff --git a/test/metabase/query_processor/middleware/add_implicit_joins_test.clj b/test/metabase/query_processor/middleware/add_implicit_joins_test.cljindex 43d928d0bf4..d44a5410d0a 100644--- a/test/metabase/query_processor/middleware/add_implicit_joins_test.clj+++ b/test/metabase/query_processor/middleware/add_implicit_joins_test.clj@@ -769,26 +769,26 @@:fk-field-id %product-id}]:fields [[:field%product-id- {::namespaced true}]+ {:qp/ignore-coercion true}][:field%products.title{:source-field %product-id:join-alias "PRODUCTS__via__PRODUCT_ID"- ::namespaced true}]]}- :fields [[:field %product-id {::namespaced true}]+ :qp/ignore-coercion true}]]}+ :fields [[:field %product-id {:qp/ignore-coercion true}][:field%products.title{:source-field %product-id:join-alias "PRODUCTS__via__PRODUCT_ID"- ::namespaced true}]]})+ :qp/ignore-coercion true}]]})(-> (lib.tu.macros/mbql-query orders{:source-query {:source-table $$orders:fields [[:field%product-id- {::namespaced true}]+ {:qp/ignore-coercion true}][:field%products.title- {:source-field %product-id, ::namespaced true}]]}+ {:source-field %product-id, :qp/ignore-coercion true}]]}:source-metadata [{:base_type :type/Text:coercion_strategy nil:display_name "Product → Title"@@ -801,10 +801,10 @@:semantic_type nil:settings nil:table_id $$products}]- :fields [[:field %product-id {::namespaced true}]+ :fields [[:field %product-id {:qp/ignore-coercion true}][:field%products.title- {:source-field %product-id, ::namespaced true}]]})+ {:source-field %product-id, :qp/ignore-coercion true}]]})add-implicit-joins(m/dissoc-in [:query :source-metadata]))))))diff --git a/test/metabase/query_processor/middleware/add_remaps_test.clj b/test/metabase/query_processor/middleware/add_remaps_test.cljindex 3255f103c2f..fc0b3dd5110 100644--- a/test/metabase/query_processor/middleware/add_remaps_test.clj+++ b/test/metabase/query_processor/middleware/add_remaps_test.clj@@ -86,7 +86,7 @@(doseq [category-name-options (lib.tu.macros/$ids venues[{:source-field %category-id}{:source-field %category-id- ::some-other-namespaced-key true}])]+ :qp/ignore-coercion true}])](testing (format "\ncategories.name field options = %s" (pr-str category-name-options))(let [{:keys [remaps query]} (#'qp.add-remaps/add-fk-remaps(lib/querydiff --git a/test/metabase/query_processor/middleware/add_rows_truncated_test.clj b/test/metabase/query_processor/middleware/add_rows_truncated_test.cljindex fae8d4797c6..4e2e98100f8 100644--- a/test/metabase/query_processor/middleware/add_rows_truncated_test.clj+++ b/test/metabase/query_processor/middleware/add_rows_truncated_test.clj@@ -79,7 +79,7 @@(-> (mt/mbql-query venues {:order-by [[:asc $id]]})qp/userland-query(assoc :constraints {:max-results-bare-rows 5- :max-result 10})))+ :max-results 10})))rows-truncated-info (select-keys (:data result) [:rows_truncated])](is (= {:rows_truncated 5}(if (seq rows-truncated-info)diff --git a/test/metabase/query_processor/middleware/cache_test.clj b/test/metabase/query_processor/middleware/cache_test.cljindex 8c188e62207..6b350bbd305 100644--- a/test/metabase/query_processor/middleware/cache_test.clj+++ b/test/metabase/query_processor/middleware/cache_test.clj@@ -156,7 +156,7 @@(merge {:cache-strategy (ttl-strategy):lib/type :mbql/query:database 1- :stages [{:lib/type :mbql.stage/mbql, :source-table 2, :abc :def}]}+ :stages [{:lib/type :mbql.stage/mbql, :source-table 2}]}query-kvs))(def ^:private ^:dynamic *rows*diff --git a/test/metabase/query_processor/middleware/parameters/mbql_test.clj b/test/metabase/query_processor/middleware/parameters/mbql_test.cljindex a2571c45ae1..0682124d5ac 100644--- a/test/metabase/query_processor/middleware/parameters/mbql_test.clj+++ b/test/metabase/query_processor/middleware/parameters/mbql_test.clj@@ -62,7 +62,7 @@[:= [:field (meta/id :venues :name) nil] "Cam's Toucannery"])(expand-parameters(query-with-parameters- {:hash "abc123"+ {:id "abc123":name "foo":type "id":target [:dimension [:field (meta/id :venues :name) nil]]@@ -74,7 +74,7 @@[:= [:field (meta/id :orders :id) nil] 9223372036854775808])(expand-parameters(query-with-parameters- {:hash "abc123"+ {:id "abc123":name "foo":type "id":target [:dimension [:field (meta/id :orders :id) nil]]@@ -89,12 +89,12 @@[:= [:field (meta/id :venues :id) nil] 999]])(expand-parameters(-> (query-with-parameters- {:hash "abc123"+ {:id "abc123":name "foo":type :id:target [:dimension [:field (meta/id :venues :name) nil] nil]:value "Cam's Toucannery"}- {:hash "def456"+ {:id "def456":name "bar":type :category:target [:dimension [:field (meta/id :venues :id) nil] {}]@@ -121,7 +121,7 @@(lib.tu.macros/mbql-5-query venues{:stages [{:aggregation [[:count {}]]:breakout [[:field {:temporal-unit :day} %price]]- :parameters [{:hash "abc123"+ :parameters [{:id "abc123":name "foo":type "id";; stage-number should get ignored by this@@ -139,7 +139,7 @@{}[:field {:base-type :type/Integer} "count"]0]]- :parameters [{:hash "def456"+ :parameters [{:id "def456":name "bar":type :number/<=:target [:dimension [:field "count" {:base-type :type/Integer}] {:stage-number 1}]@@ -160,7 +160,7 @@(is (=? (expanded-query-with-filter expected-filter-clause)(expand-parameters(query-with-parameters- {:hash "abc123"+ {:id "abc123":name "foo":type :date:target [:dimension [:field (meta/id :users :last-login) nil]]@@ -176,7 +176,7 @@(is (=? (expanded-query-with-filter expected-filter-clause)(expand-parameters(query-with-parameters- {:hash "abc123"+ {:id "abc123":name "foo":type :date/single:target [:dimension [:field (meta/id :users :last-login) nil]]@@ -206,7 +206,7 @@(qp/process-query(mt/query checkins{:query {:aggregation [[:count]]}- :parameters [{:hash "abc123"+ :parameters [{:id "abc123":name "foo":type "date":target [:dimension $date]@@ -224,7 +224,7 @@(qp/process-query(mt/query checkins{:query {:aggregation [[:count]]}- :parameters [{:hash "abc123"+ :parameters [{:id "abc123":name "foo":type :number:target [:dimension $id]diff --git a/test/metabase/query_processor/middleware/permissions_test.clj b/test/metabase/query_processor/middleware/permissions_test.cljindex 54f2ec54dc8..5d35d1fa969 100644--- a/test/metabase/query_processor/middleware/permissions_test.clj+++ b/test/metabase/query_processor/middleware/permissions_test.clj@@ -9,6 +9,7 @@[metabase.lib-be.core :as lib-be][metabase.lib.core :as lib][metabase.lib.metadata :as lib.metadata]+ [metabase.lib.serialize :as lib.serialize][metabase.lib.test-metadata :as meta][metabase.permissions.core :as perms][metabase.query-processor.middleware.permissions :as qp.perms]@@ -748,28 +749,35 @@#"You do not have permissions to run this query"(qp/process-query (mt/mbql-query venues {:limit 1})))))(testing "Query carrying a :query-permissions/perms value is still rejected"+ ;; the value is dropped by the `:decode/api` decoder every incoming query goes through, so by the time the+ ;; permissions middleware looks at the query there is nothing there to trust(is (thrown-with-msg?clojure.lang.ExceptionInfo#"You do not have permissions to run this query"- (qp/process-query (assoc (mt/mbql-query venues {:limit 1})- :query-permissions/perms {:gtaps {:perms/view-data :unrestricted- :perms/create-queries {(mt/id :venues) :query-builder}}})))))))))+ (-> (lib/query (mt/metadata-provider) (mt/mbql-query venues {:limit 1}))+ (assoc :query-permissions/perms {:gtaps {:perms/view-data :unrestricted+ :perms/create-queries {(mt/id :venues) :query-builder}}})+ lib.serialize/prepare-after-deserialization+ qp/process-query))))))))(deftest e2e-ignore-user-supplied-sandboxed-tables-test(testing "You shouldn't be able to bypass security restrictions by passing in `:query-permissions/sandboxed-table` in the query"(mt/with-no-data-perms-for-all-users!(perms/set-table-permission! (perms/all-users-group) (mt/id :venues) :perms/create-queries :no)(perms/set-database-permission! (perms/all-users-group) (mt/id) :perms/view-data :unrestricted)- (let [bad-query {:database (mt/id), :type :query, :query {:source-query {:native "SELECT * FROM VENUES LIMIT 1"- :query-permissions/sandboxed-table (mt/id :venues)}}- :query-permissions/perms {:gtaps {:perms/view-data :unrestricted- :perms/create-queries :query-builder-and-native}}}]- (mt/with-test-user :rasta+ (mt/with-test-user :rasta+ (let [bad-query (-> (lib/query (mt/metadata-provider)+ {:database (mt/id), :type :query+ :query {:source-query {:native "SELECT * FROM VENUES LIMIT 1"}}})+ (assoc-in [:stages 0 :query-permissions/sandboxed-table] (mt/id :venues))+ (assoc :query-permissions/perms {:gtaps {:perms/view-data :unrestricted+ :perms/create-queries :query-builder-and-native}}))](testing "Query carrying :query-permissions/sandboxed-table and perms keys is still rejected"+ ;; both keys are dropped by the `:decode/api` decoder every incoming query goes through(is (thrown-with-msg?clojure.lang.ExceptionInfo#"You do not have permissions to run this query"- (qp/process-query bad-query)))))))))+ (qp/process-query (lib.serialize/prepare-after-deserialization bad-query))))))))))(deftest e2e-ignore-user-supplied-compiled-from-mbql-key(testing "Make sure the NATIVE query fails to run if current user doesn't have perms even if you try to include an MBQL :query"diff --git a/test/metabase/query_processor/parameters/operators_test.clj b/test/metabase/query_processor/parameters/operators_test.cljindex abdc9f0d3ae..605078818e6 100644--- a/test/metabase/query_processor/parameters/operators_test.clj+++ b/test/metabase/query_processor/parameters/operators_test.clj@@ -48,14 +48,14 @@(deftest ^:parallel to-clause-test-4b(testing "string operations"(testing "with options"- (is (=? [:starts-with {:case-insensitive false} [:field {:source-field 5} 26] "foo"]+ (is (=? [:starts-with {:case-sensitive false} [:field {:source-field 5} 26] "foo"](params.ops/to-clause {:type :string/starts-with:target [:dimension[:field26{:source-field 5}]]:value ["foo"]- :options {:case-insensitive false}}))))))+ :options {:case-sensitive false}}))))))(deftest ^:parallel to-clause-test-4c(testing "string operations"@@ -72,14 +72,14 @@(testing "string operations"(testing "with multiple arguments"(testing "with options"- (is (=? [:starts-with {:case-insensitive false} [:field {:source-field 5} 26] "foo" "bar"]+ (is (=? [:starts-with {:case-sensitive false} [:field {:source-field 5} 26] "foo" "bar"](params.ops/to-clause {:type :string/starts-with:target [:dimension[:field26{:source-field 5}]]:value ["foo" "bar"]- :options {:case-insensitive false}})))))))+ :options {:case-sensitive false}})))))))(deftest ^:parallel to-clause-test-5(testing "string operations"diff --git a/test/metabase/query_processor/parameters/values_test.clj b/test/metabase/query_processor/parameters/values_test.cljindex b859f1a64f3..18249b5f593 100644--- a/test/metabase/query_processor/parameters/values_test.clj+++ b/test/metabase/query_processor/parameters/values_test.clj@@ -729,17 +729,20 @@(query->params-map query))))))(deftest ^:parallel dont-be-too-strict-test- (testing "values-for-tag should allow unknown keys (used only by FE) (#13868)"- (testing "\nUnknown key 'filteringParameters'"+ (testing "values-for-tag should allow the extra keys the FE sends along (#13868)"+ ;; `:filteringParameters` used to stand in for "some key the FE tacked on". Template tags and parameters are+ ;; closed schemas now, and the request decoder drops whatever they do not declare before a query gets here, so+ ;; the keys that actually have to survive are the *declared* ones nothing in this code path reads.+ (testing "\nExtra declared key 'id'"(testing "in tag"(is (= "2"(value-for-tag- {:name "id"- :display-name "ID"- :type :text- :required true- :default "100"- :filteringParameters "222b245f"}+ {:name "id"+ :display-name "ID"+ :type :text+ :required true+ :default "100"+ :id "222b245f"}[{:type :category:target [:variable [:template-tag "id"]]:value "2"}]))))@@ -751,10 +754,10 @@:type :text:required true:default "100"}- [{:type :category- :target [:variable [:template-tag "id"]]- :value "2"- :filteringParameters "222b245f"}])))))))+ [{:type :category+ :target [:variable [:template-tag "id"]]+ :value "2"+ :id "222b245f"}])))))))(deftest ^:parallel parse-card-include-parameters-test(testing "Parsing a Card reference should return a `ReferencedCardQuery` record that includes its parameters (#12236)"diff --git a/test/metabase/query_processor/preprocess_test.clj b/test/metabase/query_processor/preprocess_test.cljindex e0d92728965..c844b729239 100644--- a/test/metabase/query_processor/preprocess_test.clj+++ b/test/metabase/query_processor/preprocess_test.clj@@ -11,6 +11,7 @@[metabase.lib.metadata.calculation :as lib.metadata.calculation][metabase.lib.metadata.result-metadata :as lib.metadata.result-metadata][metabase.lib.schema.util :as lib.schema.util]+ [metabase.lib.serialize :as lib.serialize][metabase.lib.test-metadata :as meta][metabase.lib.test-util :as lib.tu][metabase.lib.test-util.macros :as lib.tu.macros]@@ -640,6 +641,16 @@(qp.preprocess/query->expected-cols query))))))))(deftest ^:parallel remove-internal-keys-test- (testing "an internal namespaced key supplied in an incoming query does not survive preprocessing"- (is (not (contains? (qp.preprocess/preprocess (assoc (mt/mbql-query venues) :a/b 1))- :a/b)))))+ (testing "an internal namespaced key supplied in an incoming query is stripped at the deserialization boundary"+ ;; `:qp/source-card-id` is one of the internal keys the query processor adds mid-pipeline, so `::lib.schema/query`+ ;; declares it and a query carrying it is perfectly valid MBQL -- what stops a client from forging one is that+ ;; the `:decode/api` decoder every incoming query goes through drops it before preprocessing starts.+ (is (not (contains? (lib.serialize/prepare-after-deserialization+ (lib/query meta/metadata-provider+ (assoc (lib.tu.macros/mbql-query venues) :qp/source-card-id 1)))+ :qp/source-card-id))))+ (testing "a key that no schema declares is rejected outright rather than quietly ignored"+ (is (thrown-with-msg?+ clojure.lang.ExceptionInfo+ #"disallowed key"+ (qp.preprocess/preprocess (assoc (mt/mbql-query venues) :a/b 1))))))diff --git a/test/metabase/query_processor/util/add_alias_info_test.clj b/test/metabase/query_processor/util/add_alias_info_test.cljindex a2d11b1abd1..4ce96302cea 100644--- a/test/metabase/query_processor/util/add_alias_info_test.clj+++ b/test/metabase/query_processor/util/add_alias_info_test.clj@@ -1392,10 +1392,10 @@(lib/aggregate $q (lib/count)));; Inject stale :inherited-temporal-unit into the breakout field ref, simulating a card;; saved when the source column had :minute granularity.- ;; Legacy field refs are [:field name-or-id opts-map].+ ;; MBQL 5 field refs are [:field opts-map id], so the options live at index 1.model-2-query (lib/update-query-stagemodel-2-query -1- assoc-in [:breakouts 0 1 :inherited-temporal-unit] :minute)+ assoc-in [:breakout 0 1 :inherited-temporal-unit] :minute)mp (lib.tu/mock-metadata-providermp{:cards [{:id 2diff --git a/test/metabase/segments/models/segment_test.clj b/test/metabase/segments/models/segment_test.cljindex 588187ddbab..1387e282645 100644--- a/test/metabase/segments/models/segment_test.clj+++ b/test/metabase/segments/models/segment_test.clj@@ -53,8 +53,7 @@(t2/query-one {:update :segment:set {:definition (json/encode {:filter "X"})}:where [:= :id segment-id]})- (is (= {}- (:definition (t2/select-one :model/Segment :id segment-id)))))))+ (is (nil? (:definition (t2/select-one :model/Segment :id segment-id)))))))(testing "...but should still throw them on insert"(is (thrown? Exception(t2/insert! :model/Segment {:table_id (mt/id :venues)diff --git a/test/metabase/sync/analyze/fingerprint_test.clj b/test/metabase/sync/analyze/fingerprint_test.cljindex fc811caf911..3722616e4b1 100644--- a/test/metabase/sync/analyze/fingerprint_test.clj+++ b/test/metabase/sync/analyze/fingerprint_test.clj@@ -285,13 +285,13 @@;; fingerprinters/fingerprinter is a multimethod, so we can't use with-dynamic-fn-redefs(with-redefs [qp/process-query (fn [_query rff](transduce identity (rff :metadata) [[1] [2] [3] [4] [5]]))- fingerprinters/fingerprinter (constantly (fingerprinters/constant-fingerprinter {:experimental {:fake-fingerprint? true}}))]+ fingerprinters/fingerprinter (constantly (fingerprinters/constant-fingerprinter {:global {:distinct-count 5, :nil% 0.0}}))](is (= {:no-data-fingerprints 0:failed-fingerprints 0:updated-fingerprints 1:fingerprints-attempted 1}(#'sync.fingerprint/fingerprint-fields! (t2/select-one :model/Table :id (data/id :venues)) [field])))- (is (= {:fingerprint {:experimental {:fake-fingerprint? true}}+ (is (= {:fingerprint {:global {:distinct-count 5, :nil% 0.0}}:fingerprint_version 3:last_analyzed nil}(into {} (t2/select-one [:model/Field :fingerprint :fingerprint_version :last_analyzed] :id (u/the-id field))))))))))diff --git a/test/metabase/test/util.clj b/test/metabase/test/util.cljindex 260ec4c454c..a025d1372e6 100644--- a/test/metabase/test/util.clj+++ b/test/metabase/test/util.clj@@ -152,7 +152,7 @@(fn [_] (default-timestamped{:target_type "document":creator_id (rasta-id)- :content {:text (u.random/random-name)}}))+ :content {:type "text", :text (u.random/random-name)}})):model/Dashboard(fn [_] (default-timestampeddiff --git a/test/metabase/tiles/api_test.clj b/test/metabase/tiles/api_test.cljindex 4f8b71b083e..30049772532 100644--- a/test/metabase/tiles/api_test.clj+++ b/test/metabase/tiles/api_test.clj@@ -326,16 +326,15 @@:status-code))))))(deftest ^:parallel query-schema-strips-extra-keys-test- (testing "the ad-hoc tile query schema decodes a JSON query, validates it, and strips undeclared properties"+ (testing "the ad-hoc tile query schema decodes a JSON query, validates it, and strips the query processor's internal keys"(let [decoded (api.macros/decode-and-validate-params:query ::api.tiles/query- (json/encode {:database (mt/id)- :type "query"- :query {:source-table (mt/id :people)- :a 1- :a/b 2}}))]+ (json/encode {:database (mt/id)+ :type "query"+ :qp/source-card-id 1+ :query {:source-table (mt/id :people)+ :qp/stage-had-source-card 1}}))](is (= :mbql/query (:lib/type decoded)))- (is (not (contains? decoded :a)))- (is (not (contains? decoded :a/b)))- (is (every? (fn [stage] (not (some #(contains? stage %) [:a :a/b]))) (:stages decoded))- "undeclared properties are stripped from every stage"))))+ (is (not (contains? decoded :qp/source-card-id)))+ (is (every? (fn [stage] (not (contains? stage :qp/stage-had-source-card))) (:stages decoded))+ "internal keys are stripped from every stage"))))diff --git a/test/metabase/util/malli/schema_test.clj b/test/metabase/util/malli/schema_test.cljindex 68801cc1fac..a1387a6df9b 100644--- a/test/metabase/util/malli/schema_test.clj+++ b/test/metabase/util/malli/schema_test.clj@@ -30,9 +30,15 @@{:schema ms/FieldTypeKeywordOrString:failed-cases [1 :type/FK]:success-cases [:type/Float "type/Float"]}- {:schema ms/Map+ {:schema ms/VisualizationSettings:failed-cases [[] 1 "a"]:success-cases [{} {:a :b}]}+ {:schema ms/DatabaseDetails+ :failed-cases [[] 1 "a"]+ :success-cases [{} {:a :b}]}+ {:schema ms/OpaqueJSONObject+ :failed-cases [[] 1 "a" {:a :b}]+ :success-cases [{} {"a" {:b 1}}]}{:schema ms/Email:failed-cases ["abc.com" 1]:success-cases ["[email protected]"]}@@ -42,12 +48,9 @@{:schema ms/TemporalString:failed-cases ["random string"]:success-cases ["2019-10-28T13:14:15" "2019-10-28"]}- {:schema ms/JSONString- :failed-cases ["string"]- :success-cases ["{\"a\": 1}"]}{:schema ms/EmbeddingParams- :failed-cases [{:key "value"}]- :success-cases [{:key "disabled"}]}+ :failed-cases [{"key" "value"} {:key "disabled"}]+ :success-cases [{"key" "disabled"}]}{:schema ms/ValidLocale:failed-cases ["locale"]:success-cases ["en" "es"]}diff --git a/test/metabase/xrays/api/automagic_dashboards_test.clj b/test/metabase/xrays/api/automagic_dashboards_test.cljindex 52fee25b60c..57fcc20efca 100644--- a/test/metabase/xrays/api/automagic_dashboards_test.clj+++ b/test/metabase/xrays/api/automagic_dashboards_test.clj@@ -621,15 +621,16 @@(is (not (contains? opts :a/b)))))))(deftest adhoc-query-decode-strips-extra-keys-test- (testing "adhoc queries are validated and stripped of undeclared properties"+ (testing "adhoc queries are validated and stripped of the query processor's internal keys"+ ;; `:qp/stage-had-source-card` is a key the QP adds to a stage while a query runs and that permissions later read,+ ;; so a client must never be able to send it in through an x-ray's adhoc query.(mt/with-test-user :rasta(let [q {:database (mt/id):type "query"- :query {:source-table (mt/id :venues)- :a 1- :a/b 2}}+ :query {:source-table (mt/id :venues)+ :qp/stage-had-source-card 1}}dq (:dataset_query (#'api.magic/adhoc-query-instance q))](is (mr/validate ::ads/query dq)"decoded adhoc query is a valid MBQL query")- (is (every? (fn [stage] (not (some #(contains? stage %) [:a :a/b]))) (:stages dq))- "undeclared properties are stripped from every stage")))))+ (is (every? (fn [stage] (not (contains? stage :qp/stage-had-source-card))) (:stages dq))+ "internal keys are stripped from every stage")))))