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
Schemas for API docs (#79521)
Alexander Polyankinab962a316a2f
diff --git a/.clj-kondo/config/modules/config.edn b/.clj-kondo/config/modules/config.ednindex 42c6139d970..6ea4f1426f5 100644--- a/.clj-kondo/config/modules/config.edn+++ b/.clj-kondo/config/modules/config.edn@@ -1206,7 +1206,6 @@metabase.lib.schema.refmetabase.lib.schema.template-tagmetabase.lib.schema.temporal-bucketing- metabase.lib.schema.test-specmetabase.lib.schema.utilmetabase.lib.schema.validatemetabase.lib.types.isa@@ -1380,7 +1379,6 @@eventsexplorationsinterestingness- legacy-mbqlliblib-bellm@@ -1793,6 +1791,7 @@libmodelsnotification+ parameterspermissionspremium-featuresquery-processordiff --git a/.clj-kondo/ratchets.edn b/.clj-kondo/ratchets.ednindex b1338065fd1..edcf6f3a9cb 100644--- a/.clj-kondo/ratchets.edn+++ b/.clj-kondo/ratchets.edn@@ -12,7 +12,7 @@:deprecated-namespace 95:deprecated-var 79:discouraged-java-method 3- :discouraged-namespace 80+ :discouraged-namespace 79:discouraged-var 107:equals-true 1:main-without-gen-class 1@@ -20,12 +20,12 @@:metabase/disallow-hardcoded-driver-names-in-tests 34:metabase/discourage-millis-duration 1:metabase/i-like-making-cams-eyes-bleed-with-horrifically-long-tests 13- :metabase/modules 8+ :metabase/modules 7:metabase/namespace-name 4:metabase/prefer-with-dynamic-fn-redefs 28:metabase/test-helpers-use-non-thread-safe-functions 17:metabase/validate-defendpoint-has-response-schema 441- :metabase/validate-defendpoint-query-params-use-kebab-case 40+ :metabase/validate-defendpoint-query-params-use-kebab-case 47:metabase/validate-defendpoint-route-uses-kebab-case 44:metabase/validate-deftest 9:missing-docstring 10diff --git a/enterprise/backend/src/metabase_enterprise/action_v2/api.clj b/enterprise/backend/src/metabase_enterprise/action_v2/api.cljindex c4c85af022a..2a03660d21d 100644--- a/enterprise/backend/src/metabase_enterprise/action_v2/api.clj+++ b/enterprise/backend/src/metabase_enterprise/action_v2/api.clj@@ -26,8 +26,11 @@:string])(mr/def ::api-action-expression- "A more relaxed version of ::action-expression that can still have opaque identifiers inside inside."- :map)+ "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)(mr/def ::api-action-id-or-expression"All the various ways of referring to an action with the v2 APIs."@@ -147,11 +150,13 @@[{}{}{: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[:action ::api-action-id-or-expression][:scope ::types/scope.raw]- [:params {:optional true} :map]- [:input {:optional true} :map]]]+ [:params {:optional true} ms/Map]+ [:input {:optional true} ms/Map]]];; This check should be redundant in practice with the permission checks within perform-action!;; Since test coverage is light and the logic is so simple, we've decided to be extra cautious for now.(api/check-superuser)@@ -185,10 +190,11 @@[{}{}{:keys [action scope inputs params]}+ ;; see the note on `POST /execute` for why `inputs` and `params` are open:- [:map[:action ::api-action-id-or-expression][:scope ::types/scope.raw]- [:inputs [:sequential {:min 1} :map]]+ [:inputs [:sequential {:min 1} ms/Map]][:params {:optional true} [:map-of :keyword :any]]]];; This check should be redundant in practice with the permission checks within perform-action!;; Since test coverage is light and the logic is so simple, we've decided to be extra cautious for now.diff --git a/enterprise/backend/src/metabase_enterprise/advanced_permissions/api/application.clj b/enterprise/backend/src/metabase_enterprise/advanced_permissions/api/application.cljindex 69af811e250..22bfce53a99 100644--- a/enterprise/backend/src/metabase_enterprise/advanced_permissions/api/application.clj+++ b/enterprise/backend/src/metabase_enterprise/advanced_permissions/api/application.clj@@ -49,7 +49,11 @@force? :force} :- [:map[:skip-graph {:default false} [:maybe ms/BooleanValue]][:force {:default false} [:maybe ms/BooleanValue]]]- body :- :map]+ body :- [:map+ [:revision ms/Int]+ ;; 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]]]]](api/check-superuser)(-> bodydejsonify-graphdiff --git a/enterprise/backend/src/metabase_enterprise/cache/strategies.clj b/enterprise/backend/src/metabase_enterprise/cache/strategies.cljindex aeff6cab2b7..10b63ccf6b6 100644--- a/enterprise/backend/src/metabase_enterprise/cache/strategies.clj+++ b/enterprise/backend/src/metabase_enterprise/cache/strategies.clj@@ -19,22 +19,20 @@;;; `:invalidated-at` keys(mr/def ::cache-strategy"Schema for a caching strategy used internally"- [:and- :metabase.cache.api/cache-strategy.base.ee- [:multi {:dispatch :type}- [:nocache :metabase.cache.api/cache-strategy.nocache]- [:ttl [:merge- :metabase.cache.api/cache-strategy.ttl- [:map- [:invalidated-at {:optional true} some?]]]]- [:duration [:merge- :metabase.cache.api/cache-strategy.ee.duration- [:map- [:invalidated-at {:optional true} some?]]]]- [:schedule [:merge- :metabase.cache.api/cache-strategy.ee.schedule- [:map- [:invalidated-at {:optional true} some?]]]]]])+ [:multi {:dispatch :type}+ [:nocache :metabase.cache.api/cache-strategy.nocache]+ [:ttl [:merge+ :metabase.cache.api/cache-strategy.ttl+ [:map+ [:invalidated-at {:optional true} some?]]]]+ [:duration [:merge+ :metabase.cache.api/cache-strategy.ee.duration+ [:map+ [:invalidated-at {:optional true} some?]]]]+ [:schedule [:merge+ :metabase.cache.api/cache-strategy.ee.schedule+ [:map+ [:invalidated-at {:optional true} some?]]]]]);;; Querying DBdiff --git a/enterprise/backend/src/metabase_enterprise/cloud_proxy/api.clj b/enterprise/backend/src/metabase_enterprise/cloud_proxy/api.cljindex 0ca91f3e3e7..7159c654311 100644--- a/enterprise/backend/src/metabase_enterprise/cloud_proxy/api.clj+++ b/enterprise/backend/src/metabase_enterprise/cloud_proxy/api.clj@@ -16,6 +16,21 @@"mb-plan-change-plan""mb-plan-change-plan-preview"})+(def ^:private OperationParams+ "Malli schema for the POST body: the parameters of the Harbormaster Store operation named by `:operation-id`.++ Parameters are named in kebab-case only, which is both what the FE sends (see+ `frontend/src/metabase/api/cloud-proxy.ts`) and what the Store client expects. Callers that spell them+ snake_case (`new_plan_alias`) are normalized by the `:decode/api` hook before validation, so the decoded+ body is forwarded as-is. The parameters span operations rather than being keyed by them because a body+ schema cannot dispatch on the `:operation-id` route param, and each is therefore optional -- the operation+ itself rejects parameters that don't belong to it, or are missing. Adding an operation to the allowlists+ above means adding its parameters here."+ [:map {:decode/api {:enter m.util/deep-kebab-keys}}+ [:plan-alias {:optional true} ms/NonBlankString]+ [:new-plan-alias {:optional true} ms/NonBlankString]+ [:force-end-trial {:optional true} :boolean]])+(def ^:private non-superuser-operation-allowlist#{"list-plans""get-plan"@@ -27,9 +42,10 @@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 [:operation-id ms/NonBlankString]]+ [{:keys [operation-id]} :- [:map+ [:operation-id ms/NonBlankString]]_query-params- body :- [:maybe :map]]+ body :- [:maybe OperationParams]](when-not (premium-features/is-hosted?)(throw (ex-info "This endpoint is only available for hosted instances" {:status-code 400})))(when-not (contains? (into non-superuser-operation-allowlist superuser-operation-allowlist) operation-id)@@ -37,7 +53,6 @@(when-not (contains? non-superuser-operation-allowlist operation-id)(api/check-superuser))(->> body- m.util/deep-kebab-keys(hm.client/call operation-id)m.util/deep-snake-keys))diff --git a/enterprise/backend/src/metabase_enterprise/content_translation/routes.clj b/enterprise/backend/src/metabase_enterprise/content_translation/routes.cljindex a2cb71d0ea6..4d0b4e51bbe 100644--- a/enterprise/backend/src/metabase_enterprise/content_translation/routes.clj+++ b/enterprise/backend/src/metabase_enterprise/content_translation/routes.clj@@ -75,6 +75,7 @@["file"[:map[:filename :string]+ [:size :int][:tempfile (ms/InstanceOfClass java.io.File)]]]]]]](api/check-superuser)(let [file (get-in multipart-params ["file" :tempfile])]diff --git a/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/api.clj b/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/api.cljindex 45c687a886f..88f9f8bfe26 100644--- a/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/api.clj+++ b/enterprise/backend/src/metabase_enterprise/custom_viz_plugin/api.clj@@ -47,6 +47,17 @@;;; ------------------------------------------------ Schemas ------------------------------------------------+(def ^:private BundleUploadRequest+ "The multipart request carrying a tar.gz bundle. `:size` is what [[check-upload!]] enforces the size limit with, so+ it has to be declared here for it to survive param decoding."+ [:map+ [:multipart-params+ [:map+ ["file" [:map+ [:filename :string]+ [:size ms/IntGreaterThanOrEqualToZero]+ [:tempfile (ms/InstanceOfClass File)]]]]]])+(def ^:private CustomVizPluginResponse[:map[:id ms/PositiveInt]@@ -131,13 +142,7 @@[_route-params_query-params_body- {{file "file"} :multipart-params, :as _request}- :- [:map- [:multipart-params- [:map- ["file" [:map- [:filename :string]- [:tempfile (ms/InstanceOfClass File)]]]]]]]+ {{file "file"} :multipart-params, :as _request} :- BundleUploadRequest](api/check-superuser)(let [tempfile (check-upload! file)](try@@ -247,13 +252,7 @@[{:keys [id]} :- [:map [:id ms/PositiveInt]]_query-params_body- {{file "file"} :multipart-params, :as _request}- :- [:map- [:multipart-params- [:map- ["file" [:map- [:filename :string]- [:tempfile (ms/InstanceOfClass File)]]]]]]]+ {{file "file"} :multipart-params, :as _request} :- BundleUploadRequest](let [existing (api/write-check (custom-viz-plugin/select-one-non-blob :id id))tempfile (check-upload! file)](trydiff --git a/enterprise/backend/src/metabase_enterprise/replacement/api.clj b/enterprise/backend/src/metabase_enterprise/replacement/api.cljindex b6c6cd2dd96..1affa1cab52 100644--- a/enterprise/backend/src/metabase_enterprise/replacement/api.clj+++ b/enterprise/backend/src/metabase_enterprise/replacement/api.clj@@ -11,6 +11,7 @@[metabase.api.macros :as api.macros][metabase.api.routes.common :refer [+auth]][metabase.transforms.core :as transforms]+ [metabase.transforms.schema :as transforms.schema][ring.util.response :as response][toucan2.core :as t2]))@@ -97,7 +98,7 @@:- [:map[:card_id ::replacement.schema/source-entity-id][:transform_name :string]- [:transform_target :map]+ [:transform_target ::transforms.schema/transform-target][:target_collection_id {:optional true} [:maybe ::replacement.schema/source-entity-id]][:transform_tag_ids {:optional true} [:maybe [:sequential pos-int?]]]]](api/check-superuser)diff --git a/enterprise/backend/src/metabase_enterprise/scim/v2/api.clj b/enterprise/backend/src/metabase_enterprise/scim/v2/api.cljindex f4b22bead12..6f1a2e8a7c6 100644--- a/enterprise/backend/src/metabase_enterprise/scim/v2/api.clj+++ b/enterprise/backend/src/metabase_enterprise/scim/v2/api.clj@@ -68,9 +68,14 @@[:Operations[:sequential [:map[:op ms/NonBlankString]- [:value [:or [:map-of [:or :keyword :string]- [:or ms/NonBlankString ms/BooleanValue]]- ms/NonBlankString ms/BooleanValue]]]]]])+ ;; 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 [:map-of [:or :keyword :string]+ [:or ms/NonBlankString ms/BooleanValue]]]+ [:scalar [:or ms/NonBlankString ms/BooleanValue]]]]]]]])(def SCIMGroup"Malli schema for a SCIM group."diff --git a/enterprise/backend/src/metabase_enterprise/sso/api/saml.clj b/enterprise/backend/src/metabase_enterprise/sso/api/saml.cljindex b0d7ca47402..2b6eb1cb86f 100644--- a/enterprise/backend/src/metabase_enterprise/sso/api/saml.clj+++ b/enterprise/backend/src/metabase_enterprise/sso/api/saml.clj@@ -7,6 +7,7 @@[metabase.premium-features.core :as premium-features][metabase.settings.core :as setting][metabase.util.i18n :refer [tru]]+ [metabase.util.malli.schema :as ms][saml20-clj.core :as saml]))(set! *warn-on-reflection* true)@@ -27,7 +28,9 @@[:saml-attribute-email {:optional true} [:maybe :string]][:saml-attribute-firstname {:optional true} [:maybe :string]][:saml-attribute-group {:optional true} [:maybe :string]]- [:saml-attribute-group-mappings {:optional true} [:maybe :map]]+ ;; 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-attribute-tenant {:optional true} [:maybe :string]][:saml-attribute-lastname {:optional true} [:maybe :string]][:saml-enabled {:optional true} [:maybe :boolean]][:saml-group-sync {: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 be1f830cb28..9a6ce477244 100644--- a/enterprise/backend/src/metabase_enterprise/sso/api/sso.clj+++ b/enterprise/backend/src/metabase_enterprise/sso/api/sso.clj@@ -33,10 +33,17 @@;; 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;;-#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}+#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema+ :metabase/validate-defendpoint-query-params-use-kebab-case]}(api.macros/defendpoint :get "/""SSO entry-point for an SSO user that has not logged in yet"- [_route-params _query-params _body request]+ [_route-params+ _query-params :- [:map+ [:jwt {:optional true} [:maybe :string]]+ [:preferred_method {:optional true} [:maybe :string]]+ [:redirect {:optional true} [:maybe :string]]+ [:return_to {:optional true} [:maybe :string]]]+ _body request](try(sso.i/sso-get request)(catch Throwable e@@ -63,7 +70,15 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :post "/""Route the SSO backends call with successful login details"- [_route-params _query-params _body request]+ [_route-params+ _query-params :- [:map+ [:SAMLResponse {:optional true} [:maybe :string]]+ [:RelayState {:optional true} [:maybe :string]]]+ _body :- [:maybe [:map+ [:jwt {:optional true} [:maybe :string]]+ [:SAMLResponse {:optional true} [:maybe :string]]+ [:RelayState {:optional true} [:maybe :string]]]]+ request](try(sso.i/sso-post request)(catch Throwable e@@ -122,7 +137,8 @@this provides a path for them to do so."[_route-params_query-params- {:keys [jwt]} :- [:map [:jwt ms/NonBlankString]]+ {:keys [jwt]} :- [:map+ [:jwt ms/NonBlankString]]request](when-not (sso-settings/jwt-enabled-and-configured)(throw (ex-info "JWT authentication is not enabled"@@ -140,7 +156,16 @@:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :post "/handle_slo""Handles client confirmation of saml logout via slo"- [_route-params _query-params _body request]+ [_route-params+ _query-params :- [:map+ [:SAMLRequest {:optional true} [:maybe :string]]+ [:SAMLResponse {:optional true} [:maybe :string]]+ [:RelayState {:optional true} [:maybe :string]]]+ _body :- [:maybe [:map+ [:SAMLRequest {:optional true} [:maybe :string]]+ [:SAMLResponse {:optional true} [:maybe :string]]+ [:RelayState {:optional true} [:maybe :string]]]]+ request](try(if (sso-settings/saml-slo-enabled)(sso.i/sso-handle-slo request)@@ -159,8 +184,11 @@#_{: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 [:key ProviderKey]]- _query-params _body request]+ [{provider-key :key} :- [:map+ [:key ProviderKey]]+ _query-params :- [:map+ [:redirect {:optional true} [:maybe :string]]]+ _body request](try(oidc-integration/sso-initiate provider-key request)(catch Throwable e@@ -172,8 +200,12 @@#_{: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 [:key ProviderKey]]- _query-params _body request]+ [{provider-key :key} :- [:map+ [:key ProviderKey]]+ _query-params :- [:map+ [:code {:optional true} [:maybe :string]]+ [:state {:optional true} [:maybe :string]]]+ _body request](try(oidc-integration/sso-callback provider-key request)(catch Throwable ediff --git a/enterprise/backend/src/metabase_enterprise/tenants/models.clj b/enterprise/backend/src/metabase_enterprise/tenants/models.cljindex 27cda602553..b5a23411e25 100644--- a/enterprise/backend/src/metabase_enterprise/tenants/models.clj+++ b/enterprise/backend/src/metabase_enterprise/tenants/models.clj@@ -8,6 +8,7 @@[metabase.util :as u][metabase.util.i18n :refer [deferred-tru tru]][metabase.util.malli :as mu]+ [metabase.util.malli.registry :as mr][metabase.util.malli.schema :as ms][methodical.core :as methodical][toucan2.core :as t2]))@@ -63,8 +64,7 @@:id{:default 0}))-(def Attributes- "Attributes attached to a tenant that will be passed down to users in the tenant."+(def ^:private StrictAttributes[:map-of[:and(mu/with-api-error-message@@ -75,6 +75,19 @@(deferred-tru "attribute keys must not start with `@`"))]:any])+(def Attributes+ "Attributes attached to a tenant that will be passed down to users in the tenant.++ [[StrictAttributes]] can't be the request schema directly: request decoding drops `:map-of` entries that don't+ match their schema, so an `@`-prefixed key would be quietly discarded and the tenant saved without it. Decoding+ 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]+ (mu/with-api-error-message+ [:fn #(mr/validate StrictAttributes %)]+ (deferred-tru "attribute keys must be a keyword or string and must not start with `@`"))])+(defenterprise user->tenant-collection-and-descendant-ids"EE version of user->tenant-collection-and-descendant-ids. Returns a vector of the tenant collection ID and alldescendant collection IDs for the user's tenant, or an empty vector if the user has no tenant."diff --git a/enterprise/backend/src/metabase_enterprise/transforms_inspector/api.clj b/enterprise/backend/src/metabase_enterprise/transforms_inspector/api.cljindex 3c61bbc9b92..e404461933a 100644--- a/enterprise/backend/src/metabase_enterprise/transforms_inspector/api.clj+++ b/enterprise/backend/src/metabase_enterprise/transforms_inspector/api.clj@@ -121,7 +121,7 @@_query-params{query :query, lens-params :lens_params}:- [:map- [:query [:map [:database {:optional true} [:maybe :int]]]]+ [:query ms/Map][:lens_params {:optional true} [:maybe [:map-of :keyword :any]]]]](let [transform (api/read-check :model/Transform id)](transforms.core/check-feature-enabled! transform)diff --git a/enterprise/backend/test/metabase_enterprise/tenants/api_test.clj b/enterprise/backend/test/metabase_enterprise/tenants/api_test.cljindex c57199b716e..cf7ee1dbe22 100644--- a/enterprise/backend/test/metabase_enterprise/tenants/api_test.clj+++ b/enterprise/backend/test/metabase_enterprise/tenants/api_test.clj@@ -276,7 +276,9 @@response (mt/user-http-request :crowberto :post 400 "ee/tenant/" tenant-data)](is (contains? (:errors response) :attributes))(is (contains? (:specific-errors response) :attributes))- (is (contains? (get-in response [:specific-errors :attributes]) (keyword "@system")))))))+ (is (re-find #"must not start with `@`" (get-in response [:errors :attributes])))+ (testing "nothing is written"+ (is (nil? (t2/select-one :model/Tenant :name "Invalid Tenant"))))))))(deftest can-update-tenant-attributes-via-put-test(testing "Can update tenant attributes via PUT"@@ -327,7 +329,7 @@{:attributes invalid-attrs})](is (contains? (:errors response) :attributes))(is (contains? (:specific-errors response) :attributes))- (is (contains? (get-in response [:specific-errors :attributes]) (keyword "@system")))+ (is (re-find #"must not start with `@`" (get-in response [:errors :attributes])));; Original attributes should remain unchanged(is (= {"valid" "value"} (:attributes (t2/select-one :model/Tenant :id id))))))))diff --git a/src/metabase/actions/schema.clj b/src/metabase/actions/schema.cljindex dd7783183d1..220575eb4b2 100644--- a/src/metabase/actions/schema.clj+++ b/src/metabase/actions/schema.clj@@ -14,7 +14,8 @@(mr/def ::type[:enum- {:description (deferred-tru "Unsupported action type")}+ {:decode/normalize keyword+ :description (deferred-tru "Unsupported action type")}:http:implicit:query])@@ -36,12 +37,14 @@[:headers {:optional true} [:maybe string?]][:parameters {:optional true} [:maybe ::parameters.schema/parameters]]])-(mr/def ::http-action- [:map- [:template {:optional true} [:maybe ::http-action.template]]+(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]]])+(mr/def ::http-action+ (into [:map] http-action-entries))+(mr/def ::implicit-action.kind[:enum{:decode/normalize keyword@@ -53,15 +56,19 @@:bulk/update:bulk/delete])+(def ^:private implicit-action-entries+ [[:kind {:optional true} [:maybe ::implicit-action.kind]]])+(mr/def ::implicit-action- [:map- [:kind {:optional true} [:maybe ::implicit-action.kind]]])+ (into [:map] implicit-action-entries))-(mr/def ::query-action- [:map- [:database_id {:optional true} [:maybe ::lib.schema.id/database]]+(def ^:private query-action-entries+ [[:database_id {:optional true} [:maybe ::lib.schema.id/database]][:dataset_query {:optional true} [:maybe ::queries.schema/query]]])+(mr/def ::query-action+ (into [:map] query-action-entries))+(mu/defn- action-schema [schema-type :- [:enum :select :update :insert]];; `required-for-insert` = you have to specify this when you insert a row;;@@ -69,39 +76,41 @@;; but its value is populated automatically on `INSERT` or `UPDATE`.(let [required-for-insert (case schema-type(:select :update) {:optional true}- :insert {})]- [:and- (into- [:map]- cat- [(case schema-type- :select [[:id ::id]]- :update [[:id {:optional true} ::id]]- :insert nil)- [[:name required-for-insert :string]- [:type required-for-insert ::type]- [: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]]- [: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]]])])- [:multi- {:dispatch :type}- [:http ::http-action]- [:implicit ::implicit-action]- [:query ::query-action]- [nil :map]]]))+ :insert {})+ common (into+ []+ cat+ [(case schema-type+ :select [[:id ::id]]+ :update [[:id {:optional true} ::id]]+ :insert nil)+ [[:name required-for-insert :string]+ [:type required-for-insert ::type]+ [: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]]+ [: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]]])])]+ (mu/dispatched-map+ ;; dispatch on the normalized type so a JSON string picks the same branch as a keyword+ (comp keyword :type)+ common+ [[:http http-action-entries]+ [:implicit implicit-action-entries]+ [:query query-action-entries]+ ;; a partial update need not repeat `:type`; accept every type's keys rather than dropping them+ [nil (into [] 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/agent_api/api.clj b/src/metabase/agent_api/api.cljindex c2fd976ee3c..837feb843c1 100644--- a/src/metabase/agent_api/api.clj+++ b/src/metabase/agent_api/api.clj@@ -190,11 +190,13 @@(including operators, joins, expressions, multi-stage queries, and FK conventions).Closed map: any extra top-level keys (notably the legacy `source_entity` /- `referenced_entities` envelope from before the repr migration) are rejected with a 400 so- callers don't silently send fields the server ignores.+ `referenced_entities` envelope from before the repr migration) are dropped during request+ decoding, so a caller still sending the old shape is served.- The inner `:query` value is intentionally typed as a plain `:map` at this boundary rather- than `::lib.schema/external-query`. Reasons:+ The inner `:query` value is intentionally typed as an open map ([[ms/Map]]) at this boundary+ rather than `::lib.schema/external-query`. Being open matters: a closed map with no declared+ entries would have every key stripped before the handler saw it. Reasons for not naming the+ real schema:1. Deep MBQL-shape validation runs inside the representations pipeline(`metabot.tools.construct/execute-representations-query` calls `repr/validate-query`@@ -208,7 +210,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.")}- :map]+ ms/Map];; 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`).@@ -457,8 +459,9 @@/v2/construct-query.The string-vs-object `:query` distinction is what the `:dispatch` keys on. Each branch is a- closed map: extra top-level keys (e.g. the legacy `source_entity` / `referenced_entities`- envelope, or sending `:query` and `:continuation_token` simultaneously) are rejected with a 400."+ closed map, so top-level keys it doesn't declare (e.g. the legacy `source_entity` /+ `referenced_entities` envelope, or a `:query` sent alongside a `:continuation_token`) are+ dropped before the handler runs."[:multi {:dispatch (fn [m](cond(:continuation_token m) :continuation@@ -925,7 +928,7 @@[:display {:optional true} [:maybe ::card-display]][:description {:optional true} [:maybe :string]][:collection_id {:optional true} [:maybe ms/PositiveInt]]- [:visualization_settings {:optional true} [:maybe :map]]])+ [:visualization_settings {:optional true} [:maybe ms/Map]]])(mr/def ::create-question-response[:map@@ -975,7 +978,7 @@[:display {:optional true} [:maybe ::card-display]][:description {:optional true} [:maybe :string]][:collection_id {:optional true} [:maybe ms/PositiveInt]]- [:visualization_settings {:optional true} [:maybe :map]]])+ [:visualization_settings {:optional true} [:maybe ms/Map]]])(mr/def ::create-metric-response[:map@@ -1041,7 +1044,7 @@[:description {:optional true} [:maybe :string]][:collection_id {:optional true} [:maybe ms/PositiveInt]][:display {:optional true} [:maybe ::card-display]]- [:visualization_settings {:optional true} [:maybe :map]]+ [:visualization_settings {:optional true} [:maybe ms/Map]][:archived {:optional true} [:maybe :boolean]][:query {:optional true} [:maybe ms/NonBlankString]]])@@ -1099,7 +1102,7 @@[:description {:optional true} [:maybe :string]][:collection_id {:optional true} [:maybe ms/PositiveInt]][:display {:optional true} [:maybe ::card-display]]- [:visualization_settings {:optional true} [:maybe :map]]+ [:visualization_settings {:optional true} [:maybe ms/Map]][:archived {:optional true} [:maybe :boolean]][:query {:optional true} [:maybe ms/NonBlankString]]])@@ -1310,8 +1313,6 @@The add actions take an optional `tab_id` (a tab on this dashboard); omitted, new cards land onthe dashboard's first tab."[:multi {:dispatch :action}- ;; Branches are closed so an inapplicable key (e.g. `display_size` on `add_heading`, which is- ;; always full-width) fails validation instead of being silently ignored.["add" [:map {:closed true}[:action [:= "add"]][:card_id ms/PositiveInt]@@ -1320,6 +1321,7 @@["add_heading" [:map {:closed true}[:action [:= "add_heading"]][:text ms/NonBlankString]+ [:display_size {:optional true} [:nil {:error/message "headings are always full-width"}]][:tab_id {:optional true} [:maybe ms/PositiveInt]]]]["add_text" [:map {:closed true}[:action [:= "add_text"]]diff --git a/src/metabase/analytics/api/proxy.clj b/src/metabase/analytics/api/proxy.cljindex fcff4eb3347..2f5b7ecfb36 100644--- a/src/metabase/analytics/api/proxy.clj+++ b/src/metabase/analytics/api/proxy.clj@@ -13,10 +13,19 @@[metabase.analytics.settings :as analytics.settings][metabase.api.macros :as api.macros][metabase.util.json :as json]- [metabase.util.log :as log]))+ [metabase.util.log :as log]+ [metabase.util.malli.schema :as ms]))(def ^:private forward-timeout-ms 5000)+(def ^:private Tp2Payload+ "Schema for the Snowplow `tp2` request envelope, mirroring the collector's own `payload_data` JSON schema: the iglu+ URI of that schema plus one entry per event, keyed by tracker field name (`e`, `p`, `tv`, `ue_px`, ...). The tracker+ stringifies every field value, so the values are always strings."+ [:map+ [:schema ms/NonBlankString]+ [:data [:sequential [:map-of :keyword :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.;;@@ -26,7 +35,7 @@`connect-src` CSP."[_route-params_query-params- body]+ body :- Tp2Payload](let [collector-url (str (analytics.settings/snowplow-url) "/com.snowplowanalytics.snowplow/tp2")](try(let [response (http/post collector-urldiff --git a/src/metabase/api/macros.clj b/src/metabase/api/macros.cljindex 8426ee8ce53..7830c4fded6 100644--- a/src/metabase/api/macros.clj+++ b/src/metabase/api/macros.clj@@ -308,7 +308,15 @@(mtx/json-transformer)(mtx/default-value-transformer){:name :api}- {:name :normalize}))+ {: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+ ;; 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+ ;; them before they are recognized.+ (mtx/strip-extra-keys-transformer)))(def ^:private encode-transformer(mtx/transformer@@ -360,7 +368,11 @@(defn- invalid-params-specific-errors [explanation](-> explanation(update :value redact-files)- (update :errors (partial mapv #(update % :value redact-files)))+ ;; `:in` and `:path` come back lazy for some schemas (`:multi`, for one) and spell checking `peek`s them+ (update :errors (partial mapv #(-> %+ (update :value redact-files)+ (m/update-existing :in vec)+ (m/update-existing :path vec))))me/with-spell-checking(me/humanize {:wrap mu/humanize-include-value})))diff --git a/src/metabase/cache/api.clj b/src/metabase/cache/api.cljindex 4faef574bd7..b0455deb43c 100644--- a/src/metabase/cache/api.clj+++ b/src/metabase/cache/api.clj@@ -8,7 +8,7 @@[metabase.premium-features.core :as premium-features][metabase.request.core :as request][metabase.util.cron :as u.cron]- [metabase.util.i18n :refer [tru trun]]+ [metabase.util.i18n :refer [deferred-tru tru trun]][metabase.util.malli :as mu][metabase.util.malli.registry :as mr][metabase.util.malli.schema :as ms]@@ -18,17 +18,22 @@;;; TODO (Cam 10/3/25) -- move these schemas into a `.schemas` namespace to follow module shape guidelines-(mr/def ::cache-strategy.base.oss- [:map- [:type [:enum :nocache :ttl]]])+(defn- cache-strategy-dispatch+ "`:multi` dispatch for a cache strategy.-(mr/def ::cache-strategy.base.ee- [:map- [:type [:enum :nocache :ttl :duration :schedule]]])+ `:type` arrives from JSON as a string, and `:multi` dispatches before the branch that would coerce it to a keyword+ runs, so the dispatch has to do the coercion itself. A sibling `[:map [:type [:enum ...]]]` guard can't do it for+ us: request decoding would then strip every key the guard doesn't name, emptying out the strategy."+ [strategy]+ (let [strategy-type (:type strategy)]+ (when (or (keyword? strategy-type) (string? strategy-type))+ (keyword strategy-type))))(mr/def ::cache-strategy.nocache- [:map ; not closed due to a way it's used in tests for clarity- [:type [:= :nocache]]])+ [:map+ [:type [:= :nocache]]+ ;; a free-form label round-tripped through `:config`; tests use it to tell configs apart+ [:name {:optional true} [:maybe :string]]])(mr/def ::cache-strategy.ttl[:map {:closed true}@@ -38,11 +43,13 @@(mr/def ::cache-strategy.oss"Schema for a caching strategy (OSS)"- [:and- ::cache-strategy.base.oss- [:multi {:dispatch :type}- [:nocache ::cache-strategy.nocache]- [:ttl ::cache-strategy.ttl]]])+ [:multi {:description (deferred-tru "cache strategy :type must be one of :nocache, :ttl")+ :dispatch cache-strategy-dispatch+ :error/fn (fn [{:keys [value]} _]+ (tru "invalid cache strategy :type {0}, must be one of :nocache, :ttl"+ (pr-str (:type value))))}+ [:nocache ::cache-strategy.nocache]+ [:ttl ::cache-strategy.ttl]])(mr/def ::cache-strategy.ee.duration[:map {:closed true}@@ -62,13 +69,15 @@;;; the optional `:invalidated-at` keys(mr/def ::cache-strategy.ee"Schema for a caching strategy in EE when we have an premium token with `:cache-granular-controls`."- [:and- ::cache-strategy.base.ee- [:multi {:dispatch :type}- [:nocache ::cache-strategy.nocache]- [:ttl ::cache-strategy.ttl]- [:duration ::cache-strategy.ee.duration]- [:schedule ::cache-strategy.ee.schedule]]])+ [:multi {:description (deferred-tru "cache strategy :type must be one of :nocache, :ttl, :duration, :schedule")+ :dispatch cache-strategy-dispatch+ :error/fn (fn [{:keys [value]} _]+ (tru "invalid cache strategy :type {0}, must be one of :nocache, :ttl, :duration, :schedule"+ (pr-str (:type value))))}+ [:nocache ::cache-strategy.nocache]+ [:ttl ::cache-strategy.ttl]+ [:duration ::cache-strategy.ee.duration]+ [:schedule ::cache-strategy.ee.schedule]])(mr/def ::cache-strategy(if config/ee-available?diff --git a/src/metabase/channel/api/channel.clj b/src/metabase/channel/api/channel.cljindex d12cc966866..7b79638aef8 100644--- a/src/metabase/channel/api/channel.clj+++ b/src/metabase/channel/api/channel.clj@@ -56,7 +56,7 @@[:name ms/NonBlankString][:description {:optional true} [:maybe ms/NonBlankString]][:type ChannelType]- [:details :map]+ [:details ms/Map][:active {:optional true} [:maybe {:default true} :boolean]]]](perms/check-has-application-permission :setting)(when (t2/exists? :model/Channel :name channel-name)@@ -88,7 +88,7 @@[:name {:optional true} [:maybe ms/NonBlankString]][:description {:optional true} [:maybe ms/NonBlankString]][:type {:optional true} [:maybe ChannelType]]- [:details {:optional true} [:maybe :map]]+ [:details {:optional true} [:maybe ms/Map]][:active {:optional true} [:maybe :boolean]]]](let [channel-before-update (api/write-check (t2/select-one :model/Channel id))](t2/update! :model/Channel id body)@@ -122,6 +122,6 @@_query-params{:keys [type details]} :- [:map[:type ChannelType]- [:details :map]]]+ [:details ms/Map]]](perms/check-has-application-permission :setting)(test-channel-connection! type details))diff --git a/src/metabase/channel/models/channel.clj b/src/metabase/channel/models/channel.cljindex b7648e702fb..8150d098f13 100644--- a/src/metabase/channel/models/channel.clj+++ b/src/metabase/channel/models/channel.clj@@ -42,7 +42,8 @@[:map[:name string?][:type :keyword]- [:details :map]+ ;; 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?]]])@@ -115,16 +116,20 @@[: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))]]])+(mr/def ::ChannelTemplate"Channel Template schema."- [:merge- [:map- [:channel_type [:fn #(= "channel" (-> % keyword namespace))]]]- [:multi {:dispatch :channel_type}- [:channel/email- [:map- [:details ::ChannelTemplateEmailDetails]]]- [::mc/default [:map]]]])+ (mu/dispatched-map+ ;; keywordize: the raw JSON body has `:channel_type` as a string, which would match no branch+ (comp keyword :channel_type)+ channel-template-entries+ [[:channel/email [[:details ::ChannelTemplateEmailDetails]]]+ [::mc/default []]]))(mr/def ::ChannelTemplateEmailDetailsUserProvided"Email template details schema for API-provided templates. Only handlebars-text is allowed;@@ -137,14 +142,12 @@(mr/def ::ChannelTemplateUserProvided"Channel Template schema for API-provided templates. Does not allow handlebars-resource."- [:merge- [:map- [:channel_type [:fn #(= "channel" (-> % keyword namespace))]]]- [:multi {:dispatch :channel_type}- [:channel/email- [:map- [:details ::ChannelTemplateEmailDetailsUserProvided]]]- [::mc/default [:map]]]])+ (mu/dispatched-map+ ;; keywordize: the raw JSON body has `:channel_type` as a string, which would match no branch+ (comp keyword :channel_type)+ channel-template-entries+ [[:channel/email [[:details ::ChannelTemplateEmailDetailsUserProvided]]]+ [::mc/default []]]))(defn- check-valid-channel-template[channel-template]diff --git a/src/metabase/collections_rest/api.clj b/src/metabase/collections_rest/api.cljindex c0ee7dc05bd..c1d0fe01999 100644--- a/src/metabase/collections_rest/api.clj+++ b/src/metabase/collections_rest/api.clj@@ -1611,7 +1611,7 @@{:keys [namespace revision groups]} :- [:map[:namespace {:optional true} [:maybe ms/NonBlankString]][:revision {:optional true} [:maybe ms/Int]]- [:groups :map]]]+ [:groups ms/Map]]](api/check-superuser)(update-graph! namespace(decode-graph {:revision revision :groups groups})diff --git a/src/metabase/comments/api.clj b/src/metabase/comments/api.cljindex 7bccadcc49e..68df84aa4f4 100644--- a/src/metabase/comments/api.clj+++ b/src/metabase/comments/api.clj@@ -58,16 +58,18 @@[:and{:error/message "Comment content must be valid JSON":json-schema {:type "object"}}- [:map]]+ ms/Map](deferred-tru "Comment content must be valid JSON.")))(def CommentContext- "Validation for comment context - expects JSON map"+ "Context stored alongside a comment: a JSON blob whose shape depends on what was commented on. Only `timeline_id` is+ read back, by [[metabase.comments.models.comment]] when building an exploration comment URL."(mu/with-api-error-message[:and{:error/message "Comment context must be a valid JSON object":json-schema {:type "object"}}- [:map]]+ [:map {:closed false}+ [:timeline_id {:optional true} ms/PositiveInt]]](deferred-tru "Comment context must be a valid JSON object.")))(def CreateCommentdiff --git a/src/metabase/dashboards/models/dashboard.clj b/src/metabase/dashboards/models/dashboard.cljindex d7f10849b13..931c81c6226 100644--- a/src/metabase/dashboards/models/dashboard.clj+++ b/src/metabase/dashboards/models/dashboard.clj@@ -367,7 +367,7 @@[:map[:id ms/NonBlankString][:name ms/NonBlankString]- [:mappings [:maybe [:set ::parameters.schema/parameter-mapping]]]])+ [:mappings [:maybe [:set ::parameters.schema/parameter-mapping-with-dashcard]]]])(mu/defn dashboard->resolved-params :- [:map-of ms/NonBlankString ParamWithMapping]"Return map of Dashboard parameter key -> param with resolved `:mappings` (see the `:resolved-params` hydrationdiff --git a/src/metabase/dashboards_rest/api.clj b/src/metabase/dashboards_rest/api.cljindex 323218eea5d..87a2f24e15a 100644--- a/src/metabase/dashboards_rest/api.clj+++ b/src/metabase/dashboards_rest/api.clj@@ -60,19 +60,6 @@(set! *warn-on-reflection* true)-;;; TODO -- why don't we use [[metabase.util.malli.schema/Parameter]] for this? Are the parameters passed here-;;; different?-(def ParameterWithID- "Schema for a parameter map with an string `:id`. This is the shape of runtime parameter *overrides* the FE sends- when running a dashcard query or exporting a dashboard -- distinct from the stored parameter declarations- (`::parameters.schema/parameters`), which also require `:type`."- (mu/with-api-error-message- [:and- [:map- [:id ms/NonBlankString]]- [:map-of :keyword :any]]- (deferred-tru "value must be a parameter map with an ''id'' key")))-(defn- dashboards-list [filter-option](as-> (t2/select :model/Dashboard {:where [:and (case (or (keyword filter-option) :all)(:all :archived) true@@ -659,7 +646,7 @@_query-params{:keys [parameters paper_size]} :- [:map[:parameters {:optional true} [:maybe [:or- [:sequential ParameterWithID]+ [:sequential ::parameters.schema/parameter-with-value];; JSON-string form for <form>-driven;; downloads, mirroring the dashcard;; export-format endpoint@@ -674,7 +661,7 @@(string? parameters) json/decode+kw);; the array form is validated by the endpoint schema, but a JSON string only proves it's *valid JSON* --;; once decoded it must still be a well-formed parameter list, or it's a 400 (not a 500)- _ (api/check-400 (mr/validate [:maybe [:sequential ParameterWithID]] params))+ _ (api/check-400 (mr/validate [:maybe [:sequential ::parameters.schema/parameter-with-value]] params))pdf-bytes (channel.render/render-dashboard-to-pdf id api/*current-user-id*(or params [])(keyword (or paper_size "a4")))@@ -896,20 +883,26 @@(def ^:private UpdatedDashboardCard[:map;; id can be negative, it indicates a new card and BE should create them- [:id int?]- [:size_x ms/PositiveInt]- [:size_y ms/PositiveInt]- [:row ms/IntGreaterThanOrEqualToZero]- [:col ms/IntGreaterThanOrEqualToZero]- [:parameter_mappings {:optional true} [:maybe [:ref ::parameters.schema/parameter-mappings]]]- [:inline_parameters {:optional true} [:maybe [:sequential ms/NonBlankString]]]- [:series {:optional true} [:maybe [:sequential map?]]]])+ [:id int?]+ [:size_x ms/PositiveInt]+ [:size_y ms/PositiveInt]+ [:row ms/IntGreaterThanOrEqualToZero]+ [:col ms/IntGreaterThanOrEqualToZero]+ [:card_id {:optional true} [:maybe ms/PositiveInt]]+ [: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]]+ [:inline_parameters {:optional true} [:maybe [:sequential ms/NonBlankString]]]+ [:series {:optional true} [:maybe [:sequential ms/Map]]]])(def ^:private UpdatedDashboardTab[:map;; id can be negative, it indicates a new card and BE should create them- [:id ms/Int]- [:name ms/NonBlankString]])+ [:id ms/Int]+ [:name ms/NonBlankString]+ ;; tab order -- `metabase.dashboards.models.dashboard-tab/do-update-tabs!` writes it alongside `:name`+ [:position {:optional true} ms/IntGreaterThanOrEqualToZero]])(defn- track-dashcard-and-tab-events![{dashboard-id :id :as dashboard}@@ -1137,6 +1130,7 @@[:position {:optional true} [:maybe ms/PositiveInt]][:width {:optional true} [:enum "fixed" "full"]][:archived {:optional true} [:maybe :boolean]]+ [:auto_apply_filters {:optional true} [:maybe :boolean]][:collection_id {:optional true} [:maybe ms/PositiveInt]][:collection_position {:optional true} [:maybe ms/PositiveInt]][:cache_ttl {:optional true} [:maybe ms/PositiveInt]]@@ -1450,7 +1444,7 @@_query-params{:keys [dashboard_load_id], :as body} :- [:map[:dashboard_load_id {:optional true} [:maybe ms/NonBlankString]]- [:parameters {:optional true} [:maybe [:sequential ParameterWithID]]]]]+ [:parameters {:optional true} [:maybe [:sequential ::parameters.schema/parameter-with-value]]]]](with-dashboard-load-id dashboard_load_id(m/mapply qp.dashboard/process-query-for-dashcard(merge@@ -1480,7 +1474,7 @@pivot-results? :pivot_results}:- [:map[:parameters {:optional true} [:maybe [:or- [:sequential ParameterWithID]+ [:sequential ::parameters.schema/parameter-with-value];; support <form> encoded params for backwards compatibility... see;; https://metaboat.slack.com/archives/C010L1Z4F9S/p1738003606875659ms/JSONString]]]@@ -1517,7 +1511,7 @@[:card-id ms/PositiveInt]]_query-paramsbody :- [:map- [:parameters {:optional true} [:maybe [:sequential ParameterWithID]]]]]+ [:parameters {:optional true} [:maybe [:sequential ::parameters.schema/parameter-with-value]]]]](m/mapply qp.dashboard/process-query-for-dashcard(mergebodydiff --git a/src/metabase/documents/api/document.clj b/src/metabase/documents/api/document.cljindex ab0b6b81eb6..c342bec1fb2 100644--- a/src/metabase/documents/api/document.clj+++ b/src/metabase/documents/api/document.clj@@ -19,6 +19,7 @@[metabase.util.i18n :refer [tru]][metabase.util.json :as json][metabase.util.malli :as mu]+ [metabase.util.malli.registry :as mr][metabase.util.malli.schema :as ms][toucan2.core :as t2]))@@ -36,13 +37,27 @@[:result_metadata {:optional true} [:maybe [:sequential ms/Map]]][:cache_ttl {:optional true} [:maybe ms/PositiveInt]]])+(defn- cards-to-create-schema+ "Request schema for the `cards` map: placeholder id -> new card.++ The strict `[:map-of key-schema CardCreateSchema]` can't be the request schema directly. Request decoding strips+ `:map-of` entries that don't match their schema, so an unusable card would be quietly dropped and the document+ saved without it. Decoding therefore sees a permissive `[:map-of :int :any]` — enough to turn the JSON string keys+ into ints — and the `:fn` re-checks the strict shape afterwards, so a bad card is a 400."+ [key-schema]+ (let [strict [:map-of key-schema CardCreateSchema]]+ [:and+ [:map-of :int :any]+ [:fn {:error/message "value must map a card placeholder id to a card"}+ #(mr/validate strict %)]]))+(def ^:private DocumentCreateOptions[:map[:name m.document/DocumentName][:document :any][:collection_id {:optional true} [:maybe ms/PositiveInt]][:collection_position {:optional true} [:maybe ms/PositiveInt]]- [:cards {:optional true} [:maybe [:map-of [:int {:max -1}] CardCreateSchema]]]])+ [:cards {:optional true} [:maybe (cards-to-create-schema [:int {:max -1}])]]])(def ^:private DocumentUpdateOptions[:map@@ -50,7 +65,7 @@[:document {:optional true} :any][:collection_id {:optional true} [:maybe ms/PositiveInt]][:collection_position {:optional true} [:maybe ms/PositiveInt]]- [:cards {:optional true} [:maybe [:map-of :int CardCreateSchema]]]+ [:cards {:optional true} [:maybe (cards-to-create-schema :int)]][:archived {:optional true} [:maybe :boolean]]])(defn- create-card!diff --git a/src/metabase/eid_translation/api.clj b/src/metabase/eid_translation/api.cljindex 56dcf14a24d..be0e968a393 100644--- a/src/metabase/eid_translation/api.clj+++ b/src/metabase/eid_translation/api.clj@@ -13,5 +13,5 @@[_route-params_query-params{:keys [entity_ids]} :- [:map- [:entity_ids :map]]]+ [:entity_ids [:map-of :keyword [:sequential :string]]]]]{:entity_ids (eid-translation/model->entity-ids->ids entity_ids)})diff --git a/src/metabase/embedding_rest/api/common.clj b/src/metabase/embedding_rest/api/common.cljindex 415ad3c066d..4847417e0ec 100644--- a/src/metabase/embedding_rest/api/common.clj+++ b/src/metabase/embedding_rest/api/common.clj@@ -41,6 +41,13 @@[:param-key ms/NonBlankString][:prefix ms/NonBlankString]])+(def QueryParams+ "Malli schema for the raw query-string parameter map of the embed query and param-values endpoints: dashboard/card+ parameter 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]]]])+(comment;; load dynamic model resolution code... should already be loaded by [[metabase.core.init]] so this is mostly here for;; the benefit of testsdiff --git a/src/metabase/embedding_rest/api/embed.clj b/src/metabase/embedding_rest/api/embed.cljindex 33615358af4..56c385dc43b 100644--- a/src/metabase/embedding_rest/api/embed.clj+++ b/src/metabase/embedding_rest/api/embed.clj@@ -15,6 +15,7 @@:dashboard <dashboard-id>}:params <params>}"(:require+ [malli.core :as mc][metabase.api.common :as api][metabase.api.macros :as api.macros][metabase.eid-translation.core :as eid-translation]@@ -114,7 +115,7 @@:params <parameters>}"[{:keys [token]} :- [:map[:token api.embed.common/EncodedToken]]- query-params :- :map]+ 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)));; TODO (Cam 10/28/25) -- fix this endpoint so it uses kebab-case for query parameters for consistency with the rest@@ -134,7 +135,8 @@pivot? :pivot_results:as query-params} :- [:map[:format_rows {:default false} :boolean]- [:pivot_results {:default false} :boolean]]]+ [:pivot_results {:default false} :boolean]+ [::mc/default api.embed.common/QueryParams]]](run-query-for-unsigned-token-async(unsign-and-translate-ids token)export-format@@ -210,7 +212,7 @@[:token api.embed.common/EncodedToken][:dashcard-id ms/PositiveInt][:card-id ms/PositiveInt]]- query-params :- :map]+ query-params :- api.embed.common/QueryParams](process-query-for-dashcard-with-signed-token token dashcard-id card-id :api(api.embed.common/parse-query-params query-params)))@@ -240,7 +242,8 @@pivot? :pivot_results:as query-params} :- [:map[:format_rows {:default false} :boolean]- [:pivot_results {:default false} :boolean]]]+ [:pivot_results {:default false} :boolean]+ [::mc/default api.embed.common/QueryParams]]](process-query-for-dashcard-with-signed-token tokendashcard-idcard-id@@ -269,7 +272,7 @@[{:keys [token param-key]} :- [:map[:token api.embed.common/EncodedToken][:param-key ms/NonBlankString]]- query-params]+ query-params :- api.embed.common/QueryParams](api.embed.common/dashboard-param-values token param-key nil(api.embed.common/parse-query-params query-params)))@@ -280,7 +283,7 @@(api.macros/defendpoint :get "/dashboard/:token/params/:param-key/search/:prefix""Embedded version of chain filter search endpoint."[{:keys [token param-key prefix]} :- api.embed.common/SearchParams- query-params]+ query-params :- api.embed.common/QueryParams](api.embed.common/dashboard-param-values token param-key prefix(api.embed.common/parse-query-params query-params)))@@ -293,7 +296,8 @@[{:keys [token param-key]} :- [:map[:token api.embed.common/EncodedToken][:param-key ms/NonBlankString]]- {:keys [value]}]+ {:keys [value]} :- [:map+ [:value :string]]](api.embed.common/dashboard-param-remapped-value token param-key (codec/url-decode value)));; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to@@ -338,7 +342,8 @@[{:keys [token param-key]} :- [:map[:token api.embed.common/EncodedToken][:param-key ms/NonBlankString]]- {:keys [value]} :- [:map [:value :string]]]+ {:keys [value]} :- [:map+ [:value :string]]](let [unsigned (unsign-and-translate-ids token)card-id (api.embed.common/unsigned-token->card-id unsigned)card (api/check-404 (t2/select-one :model/Card card-id))]@@ -361,7 +366,7 @@:params <parameters>}"[{:keys [token]} :- [:map[:token api.embed.common/EncodedToken]]- query-params :- :map]+ 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):qp qp.pivot/run-pivot-query))@@ -377,7 +382,7 @@[:token api.embed.common/EncodedToken][:dashcard-id ms/PositiveInt][:card-id ms/PositiveInt]]- query-params :- :map]+ query-params :- api.embed.common/QueryParams](process-query-for-dashcard-with-signed-token token dashcard-id card-id:api (api.embed.common/parse-query-params query-params):qp qp.pivot/run-pivot-query))diff --git a/src/metabase/embedding_rest/api/theme.clj b/src/metabase/embedding_rest/api/theme.cljindex 8f29e0e7685..9cbc825750d 100644--- a/src/metabase/embedding_rest/api/theme.clj+++ b/src/metabase/embedding_rest/api/theme.clj@@ -18,7 +18,7 @@[:id ms/PositiveInt][:entity_id ms/NonBlankString][:name ms/NonBlankString]- [:settings :map]+ [:settings ms/Map][:created_at (ms/InstanceOfClass java.time.temporal.Temporal)][:updated_at (ms/InstanceOfClass java.time.temporal.Temporal)]])@@ -42,7 +42,7 @@_query-params{:keys [name settings]} :- [:map[:name ms/NonBlankString]- [:settings :map]]]+ [:settings ms/Map]]](t2/insert-returning-instance! :model/EmbeddingTheme{:name name:settings settings}))@@ -53,7 +53,7 @@_query-params{:keys [name settings]} :- [:map[:name {:optional true} [:maybe ms/NonBlankString]]- [:settings {:optional true} [:maybe :map]]]]+ [:settings {:optional true} [:maybe ms/Map]]]](api/check-404 (t2/exists? :model/EmbeddingTheme :id id))(t2/update! :model/EmbeddingTheme id(cond-> {}@@ -88,7 +88,7 @@{:keys [themes]} :- [:map[:themes [:sequential [:map[:name ms/NonBlankString]- [:settings :map]]]]]]+ [:settings ms/Map]]]]]](locking seed-defaults-lock(t2/with-transaction [_conn](when-not (embedding.settings/default-embedding-themes-seeded)diff --git a/src/metabase/legacy_mbql/schema.cljc b/src/metabase/legacy_mbql/schema.cljcindex 0e40bccd2de..23618956909 100644--- a/src/metabase/legacy_mbql/schema.cljc+++ b/src/metabase/legacy_mbql/schema.cljc@@ -1754,9 +1754,9 @@"Schema for a valid value for a `:source-query`."[:and;; normalize the keys in the map first so we can check for the presence of `:native` versus `:mbql` in the `:multi`- ;; schema below- [:map- {:decode/normalize lib.schema.common/normalize-map}]+ ;; schema below. Carried on the `:and` rather than on a keyless `[:map ...]` sibling, which would declare no keys+ ;; and so strip the whole query while decoding.+ {:decode/normalize lib.schema.common/normalize-map}[:multi{:dispatch (fn [x](if ((every-pred map? :native) x)@@ -1856,11 +1856,16 @@[:effective_type {:optional true} ::lib.schema.common/base-type][:converted_timezone {:optional true} [:maybe [:ref ::lib.schema.expression.temporal/timezone-id]]][:field_ref {:optional true} [:maybe [:ref ::Reference]]]+ ;; implicit-join provenance -- the FE renders "Orders → Category" from these, and drill-thru needs them to+ ;; rebuild the `:source-field` option+ [:fk_field_id {:optional true} [:maybe ::lib.schema.id/field]]+ [:fk_target_field_id {:optional true} [:maybe ::lib.schema.id/field]];; Fingerprint is required in order to use BINNING[:fingerprint {:optional true} [:maybe [:ref ::lib.schema.metadata.fingerprint/fingerprint]]][:id {:optional true} [:maybe ::lib.schema.id/field]];; 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}]]][:source {:optional true} [:maybe [:ref ::lib.schema.metadata/column.legacy-source]]][:unit {:optional true} [:maybe [:ref ::lib.schema.temporal-bucketing/unit]]][:visibility_type {:optional true} [:maybe [:ref ::lib.schema.metadata/column.visibility-type]]]]@@ -2086,9 +2091,10 @@;; {: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]+ [:map {:closed false}]];;;; CONSTRAINTS;;@@ -2197,8 +2203,9 @@(mr/def ::Query[:and- [:map- {:decode/normalize #'normalize-query}]+ ;; carried here rather than on a keyless `[:map ...]` sibling, which would declare no keys and so strip the whole+ ;; query while decoding+ {:decode/normalize #'normalize-query};; need to move source metadata to the correct location FIRST so it gets normalized by the schema below[:ref ::CheckQueryDoesNotHaveSourceMetadata][:mapdiff --git a/src/metabase/lib/schema.cljc b/src/metabase/lib/schema.cljcindex 39690308ca8..03c77659f63 100644--- a/src/metabase/lib/schema.cljc+++ b/src/metabase/lib/schema.cljc@@ -373,8 +373,6 @@;; it's supposed to be added to the top level. Investigate whether this was just a;; mistake or what.:middleware)}- [:map- [:lib/type [:ref ::stage.type]]][:multi {:dispatch lib-type:error/message "Invalid stage :lib/type: expected :mbql.stage/native or :mbql.stage/mbql"}[:mbql.stage/native [:ref ::stage.native]]diff --git a/src/metabase/lib/schema/binning.cljc b/src/metabase/lib/schema/binning.cljcindex 852ce4cfa56..831eeb20346 100644--- a/src/metabase/lib/schema/binning.cljc+++ b/src/metabase/lib/schema/binning.cljc@@ -29,9 +29,10 @@(mr/def ::binning"Schema for `:binning` options passed to a `:field` clause."[:and- [:map- {:decode/normalize lib.schema.common/normalize-map}- [:strategy [:ref ::strategy]]]+ {:decode/normalize (fn [binning]+ (when-some [binning (lib.schema.common/normalize-map binning)]+ (cond-> binning+ (:strategy binning) (update :strategy lib.schema.common/normalize-keyword))))}[:multi {:dispatch (fn [x](keyword (some #(get x %) [:strategy "strategy"]))):error/fn (fn [{:keys [value]} _]diff --git a/src/metabase/lib/schema/common.cljc b/src/metabase/lib/schema/common.cljcindex dc1c81be5f9..5d88ea51918 100644--- a/src/metabase/lib/schema/common.cljc+++ b/src/metabase/lib/schema/common.cljc@@ -161,7 +161,10 @@[x](normalize-keyword x))-(defn- normalize-base-type [x]+(defn normalize-base-type+ "Normalize `x` to a base type keyword, repairing the lower-cased type names some prod fingerprints were stored+ under (#63397). Returns `nil` if it isn't keyword-able."+ [x](when-let [k (normalize-base-type* x)](or (cond(isa? k :type/*)@@ -279,7 +282,19 @@[:semantic-type {:optional true} [:maybe ::semantic-or-relation-type]][:database-type {:optional true} [:maybe ::non-blank-string]][:name {:optional true} [:maybe ::non-blank-string]]- [:display-name {:optional true} [:maybe ::non-blank-string]]]+ [:display-name {:optional true} [:maybe ::non-blank-string]]+ ;; the keys clauses add to a plain options map. Clause-specific option schemas (`::lib.schema.ref/field.options`+ ;; and friends) declare the rest; they all have to be named here because a map schema strips whatever it doesn't+ ;; declare.+ ;;+ ;; the name an expression is defined under, on the expression's own clause+ [:lib/expression-name {:optional true} ::non-blank-string]+ ;; `:contains`/`:starts-with`/`:ends-with` and the other string filters+ [:case-sensitive {:optional true} :boolean]+ ;; `:time-interval`+ [:include-current {:optional true} :boolean]+ ;; the name an aggregation is referenced by+ [:lib/source-name {:optional true} ::non-blank-string]](disallowed-keys{:ident ":ident is deprecated and should not be included in options maps"})])diff --git a/src/metabase/lib/schema/expression.cljc b/src/metabase/lib/schema/expression.cljcindex f4e8611b545..b6e26235033 100644--- a/src/metabase/lib/schema/expression.cljc+++ b/src/metabase/lib/schema/expression.cljc@@ -1,6 +1,7 @@(ns metabase.lib.schema.expression(:refer-clojure :exclude [some empty? #?(:clj for)])(:require+ [malli.core :as mc][metabase.lib.dispatch :as lib.dispatch][metabase.lib.hierarchy :as lib.hierarchy][metabase.lib.options :as lib.options]@@ -235,8 +236,11 @@[:ref ::expression][:cat#_tag :any+ ;; `::mc/default` because this only checks and normalizes the name -- the rest of the options map is validated by+ ;; `::expression` above, and would otherwise be stripped here before it got there.#_opts [:map- [:lib/expression-name [:string {:decode/normalize common/normalize-string-key}]]]+ [:lib/expression-name [:string {:decode/normalize common/normalize-string-key}]]+ [::mc/default :any]]#_args [:* :any]][:fn{:error/message "non-aggregation expression"}diff --git a/src/metabase/lib/schema/measure.cljc b/src/metabase/lib/schema/measure.cljcindex d65f30fb42b..4f607370bc6 100644--- a/src/metabase/lib/schema/measure.cljc+++ b/src/metabase/lib/schema/measure.cljc@@ -25,7 +25,11 @@A measure stage must have exactly one aggregation and no other query clauses."[:and::lib.schema/stage.mbql- [:map [:source-table ::lib.schema.id/table]]+ ;; checked with `:fn` rather than a `[:map [:source-table ...]]` conjunct: a map conjunct declares only the keys it+ ;; names, so it would strip every other key of the stage before the sibling `::lib.schema/stage.mbql` saw it+ [:fn+ {:error/message "A measure stage must have a :source-table"}+ #(mr/validate ::lib.schema.id/table (:source-table %))][:fn{:error/message "A measure stage must have exactly one aggregation"}#(= (count (:aggregation %)) 1)]@@ -51,5 +55,7 @@[:fn{:error/message "A measure must have exactly one stage"}#(= (-> % :stages count) 1)]- [:map- [:stages [:sequential [:ref ::stage]]]]])+ ;; likewise `:fn` rather than a `[:map [:stages ...]]` conjunct, which would strip every other key of the query+ [:fn+ {:error/message "A measure definition's stages must be measure stages"}+ #(mr/validate [:sequential [:ref ::stage]] (:stages %))]])diff --git a/src/metabase/lib/schema/metadata.cljc b/src/metabase/lib/schema/metadata.cljcindex 39943413ed9..b556b5502b0 100644--- a/src/metabase/lib/schema/metadata.cljc+++ b/src/metabase/lib/schema/metadata.cljc@@ -1,5 +1,5 @@(ns metabase.lib.schema.metadata- (:refer-clojure :exclude [get-in])+ (:refer-clojure :exclude [empty? get-in])(:require#?@(:clj([metabase.util.regex :as u.regex]))@@ -13,7 +13,7 @@[metabase.lib.schema.template-tag :as lib.schema.template-tag][metabase.lib.schema.temporal-bucketing :as lib.schema.temporal-bucketing][metabase.util.malli.registry :as mr]- [metabase.util.performance :refer [get-in]]))+ [metabase.util.performance :refer [empty? get-in]]));;; Column vs Field?;;;@@ -637,8 +637,21 @@(mr/def ::card.query"Saved query. This is possibly still a legacy query, but should already be normalized.Call [[metabase.lib.convert/->mbql5]] on it as needed."- [:map- {:decode/normalize normalize-card-query}])+ ;; dispatched rather than written as a keyless `[:map {:decode/normalize ...}]`, which declares no keys and so+ ;; would strip the whole query while decoding+ [:multi {:dispatch (fn [query]+ (cond+ (empty? query) :empty+ (:lib/type query) :mbql5+ :else :legacy))}+ ;; Cards may be saved with an empty query -- see `:metabase.queries.schema/query`+ [:empty [:= {} {}]]+ [:mbql5 [:schema+ {:decode/normalize normalize-card-query}+ [:ref :metabase.lib.schema/query]]]+ [:legacy [:schema+ {:decode/normalize normalize-card-query}+ [:ref :metabase.legacy-mbql.schema/Query]]]])(defn- normalize-card [card](when card@@ -725,8 +738,11 @@(mr/def ::measure.definition"Measure definition query. This should be an MBQL5 query with a single stage and one aggregation.Strict validation via :metabase.lib.schema.measure/definition happens in metabase.measures.models.measure."- [:map- {:decode/normalize normalize-measure-definition}])+ ;; wrapped in `[:schema ...]` rather than written as a keyless `[:map {:decode/normalize ...}]`, which declares no+ ;; keys and so would strip the whole definition while decoding+ [:schema+ {:decode/normalize normalize-measure-definition}+ [:ref :metabase.lib.schema/query]])(defn- mock-measure [measure](cond-> measurediff --git a/src/metabase/lib/schema/metadata/fingerprint.cljc b/src/metabase/lib/schema/metadata/fingerprint.cljcindex b7870c3d097..5c0a4d091b0 100644--- a/src/metabase/lib/schema/metadata/fingerprint.cljc+++ b/src/metabase/lib/schema/metadata/fingerprint.cljc@@ -1,7 +1,8 @@(ns metabase.lib.schema.metadata.fingerprint(:require[metabase.lib.schema.common :as lib.schema.common]- [metabase.util.malli.registry :as mr]))+ [metabase.util.malli.registry :as mr]+ [metabase.util.performance :as perf]))(mr/def ::percent"Schema for something represting a percentage. A floating-point value between (inclusive) 0 and 1."@@ -59,8 +60,12 @@(mr/def ::fingerprint.type-specific"Schema for type-specific fingerprint information."[:and- {:decode/normalize lib.schema.common/normalize-map-no-kebab-case}- [:map-of ::lib.schema.common/base-type :map]+ ;; the keys are base types, and prod has fingerprints stored under lower-cased ones (#63397), so normalize them+ ;; here -- a `[:map-of ::lib.schema.common/base-type ...]` conjunct would do it too, but `:map-of` silently drops+ ;; the entries it can't normalize instead of surfacing them+ {:decode/normalize (fn [m]+ (some-> (lib.schema.common/normalize-map-no-kebab-case m)+ (perf/update-keys lib.schema.common/normalize-base-type)))}[:map[:type/Number {:optional true} [:ref ::fingerprint.number]][:type/Text {:optional true} [:ref ::fingerprint.text]]diff --git a/src/metabase/lib/schema/parameter.cljc b/src/metabase/lib/schema/parameter.cljcindex 06dd1229baa..ed36a27a368 100644--- a/src/metabase/lib/schema/parameter.cljc+++ b/src/metabase/lib/schema/parameter.cljc@@ -357,6 +357,12 @@{:encode/for-hashing #'sort-parameter-values}:any])+(mr/def ::parameter.options+ "Options the frontend attaches to a parameter value."+ [:map+ [:case-sensitive {:optional true} :boolean]+ [:include-current {:optional true} :boolean]])+(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.@@ -364,6 +370,7 @@Note that this is different from the parameter declarations that are saved as part of Dashboards and Cards; for THATschema refer to `:metabase.parameters.schema/parameter`."[:and+ {:description "parameter must be a map with a :type key"}[:map{:decode/normalize #'normalize-parameter}[:type [:ref ::type]]@@ -380,8 +387,9 @@;; The following are not used by the code in this namespace but may or may not be specified depending on what the;; code that constructs the query params is doing. We can go ahead and ignore these when present.[:slug {:optional true} ::lib.schema.common/non-blank-string]- [:default {:optional true} :any]- [:required {:optional true} :any]]+ [:default {:optional true} [:ref ::parameter.value]]+ [:required {:optional true} [:maybe :boolean]]+ [:options {:optional true} [:maybe [:ref ::parameter.options]]]]::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 e3cf1fe5a0d..90f3c52fb0c 100644--- a/src/metabase/lib/schema/ref.cljc+++ b/src/metabase/lib/schema/ref.cljc@@ -88,6 +88,9 @@[:binning {:optional true} [:ref ::binning/binning]][:lib/original-binning {:optional true} [:ref ::binning/binning]][:lib/original-effective-type {:optional true} [:ref ::common/base-type]]+ ;; marks a `:base-type` that lib added itself, so converting this ref back to legacy knows to drop it again --+ ;; see `metabase.lib.field/lib-metadata-key->ref-option-key`+ [:lib/transformation-added-base-type {:optional true} [:maybe :boolean]];;;; For implicitly joinable columns, the ID of the FK field used to perform the implicit join.;; E.g. if the query is against `ORDERS` and the field ref is for `PRODUCTS.CATEGORY`, then `:source-field`diff --git a/src/metabase/lib/schema/template_tag.cljc b/src/metabase/lib/schema/template_tag.cljcindex c36552bb873..323353fbe22 100644--- a/src/metabase/lib/schema/template_tag.cljc+++ b/src/metabase/lib/schema/template_tag.cljc@@ -64,8 +64,12 @@[:dimension {:optional true} [:ref :mbql.clause/field]]]])(mr/def ::field-filter.options+ "Options appended to the filter clause a Field Filter template tag generates. These get merged into the parameter+ value 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}+ [:case-sensitive {:optional true} :boolean]+ [:include-current {:optional true} :boolean]]);; Example:;;@@ -189,9 +193,10 @@(mr/def ::template-tag[:and- {:decode/normalize common/normalize-map}- [:map- [:type [:ref ::type]]]+ {:decode/normalize (fn [tag]+ (when-some [tag (common/normalize-map tag)]+ (cond-> tag+ (:type tag) (update :type common/normalize-keyword))))}[:multi {:dispatch #(keyword (:type %))}[:temporal-unit [:ref ::temporal-unit]][:dimension [:ref ::field-filter]]diff --git a/src/metabase/lib_metric/schema.cljc b/src/metabase/lib_metric/schema.cljcindex 88dc4b35291..63ff0db42fa 100644--- a/src/metabase/lib_metric/schema.cljc+++ b/src/metabase/lib_metric/schema.cljc@@ -23,9 +23,10 @@(mr/def ::binning"Schema for `:binning` options passed to a `:dimension` clause."[:and- [:map- {:decode/normalize lib.schema.common/normalize-map}- [:strategy [:ref ::binning-strategy]]]+ {:decode/normalize (fn [binning]+ (when-some [binning (lib.schema.common/normalize-map binning)]+ (cond-> binning+ (:strategy binning) (update :strategy lib.schema.common/normalize-keyword))))}[:multi {:dispatch (fn [x](keyword (some #(get x %) [:strategy "strategy"]))):error/fn (fn [{:keys [value]} _]diff --git a/src/metabase/measures/api.clj b/src/metabase/measures/api.cljindex 6ffbbfa2703..c04819dd305 100644--- a/src/metabase/measures/api.clj+++ b/src/metabase/measures/api.clj@@ -22,7 +22,7 @@[:id ms/PositiveInt][:name ms/NonBlankString][:table_id ms/PositiveInt]- [:definition :map]+ [:definition ms/Map][:description {:optional true} [:maybe :string]][:archived :boolean][:creator_id ms/PositiveInt]@@ -158,7 +158,7 @@_query-paramsbody :- [:map[:name {:optional true} [:maybe ms/NonBlankString]]- [:definition {:optional true} [:maybe :map]]+ [:definition {:optional true} [:maybe ms/Map]][:revision_message ms/NonBlankString][:archived {:optional true} [:maybe :boolean]][:description {:optional true} [:maybe :string]]]]diff --git a/src/metabase/metabot/api/conversations.clj b/src/metabase/metabot/api/conversations.cljindex 15bc6e060c5..bb6d7024700 100644--- a/src/metabase/metabot/api/conversations.clj+++ b/src/metabase/metabot/api/conversations.clj@@ -82,9 +82,9 @@[:map[:name ms/NonBlankString][:description {:optional true} [:maybe :string]]- [:dataset_query :map]+ [:dataset_query ms/Map][:display ms/NonBlankString]- [:visualization_settings {:optional true} [:maybe :map]]+ [:visualization_settings {:optional true} [:maybe ms/Map]][:collection_id {:optional true} [:maybe ms/PositiveInt]][:dashboard_id {:optional true} [:maybe ms/PositiveInt]][:dashboard_tab_id {:optional true} [:maybe ms/PositiveInt]]])@@ -100,9 +100,9 @@[:id ms/PositiveInt][:name ms/NonBlankString][:description {:optional true} [:maybe :string]]- [:dataset_query :map]+ [:dataset_query ms/Map][:display :keyword]- [:visualization_settings {:optional true} [:maybe :map]]+ [:visualization_settings {:optional true} [:maybe ms/Map]][: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/context.clj b/src/metabase/metabot/context.cljindex 7db97860375..80ad5554390 100644--- a/src/metabase/metabot/context.clj+++ b/src/metabase/metabot/context.clj@@ -1,15 +1,13 @@(ns metabase.metabot.context(:require[clojure.java.io :as io]- [malli.core]+ [malli.core :as mc][medley.core :as m][metabase.activity-feed.core :as activity-feed][metabase.api.common :as api][metabase.config.core :as config]- ^{:clj-kondo/ignore [:discouraged-namespace :metabase/modules]} [metabase.legacy-mbql.schema :as mbql.s][metabase.lib-be.core :as lib-be][metabase.lib.core :as lib]- [metabase.lib.schema :as lib.schema][metabase.metabot.config :as metabot.config][metabase.metabot.curation :as curation][metabase.metabot.settings :as metabot.settings]@@ -19,6 +17,7 @@[metabase.util.log :as log][metabase.util.malli :as mu][metabase.util.malli.registry :as mr]+ [metabase.util.malli.schema :as ms][toucan2.core :as t2])(:import(java.time OffsetDateTime)@@ -70,34 +69,38 @@"Schema for the `:type` key of `:user_is_viewing` item."(into [:enum] item-types))+(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)+(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}- [:or- ::lib.schema/query- ::mbql.s/Query]]])+ [:query {:optional true} ItemQuerySchema]])(def QcItemSchema"Schema viewing context item with query and charts."[:map+ [::mc/default :any][:type (into [:enum] item-types-qc)]- [:query- {:optional true}- [:or- ::lib.schema/query- ::mbql.s/Query]]+ [:query {:optional true} ItemQuerySchema][:chart_configs{:optional true}[:vector[:map- [:query- {:optional true}- [:or- ::lib.schema/query- ::mbql.s/Query]]]]]])+ [::mc/default :any]+ [:query {:optional true} ItemQuerySchema]]]]])(def ViewingItemSchema"Schema of user is viewing item."@@ -107,6 +110,7 @@[:and[:map-of :keyword :any][:map+ [::mc/default :any][:user_is_viewing {:optional true} [:vector ViewingItemSchema]]]])(defn- query-for-sql-parsingdiff --git a/src/metabase/metrics/api.clj b/src/metabase/metrics/api.cljindex 3b3d26471a4..7c193811ef2 100644--- a/src/metabase/metrics/api.clj+++ b/src/metabase/metrics/api.clj@@ -45,7 +45,7 @@[:map[:dimensions [:sequential ::metrics.dimension/dimension]][:dimension_mappings [:sequential ::metrics.dimension/dimension-mapping]]- [:dataset_query {:optional true} :map]+ [:dataset_query {:optional true} ms/Map][:database_id {:optional true} [:maybe ms/PositiveInt]][:result_column_name {:optional true} [:maybe :string]]]])diff --git a/src/metabase/notification/api/notification.clj b/src/metabase/notification/api/notification.cljindex 167b786fd7c..37544115ddc 100644--- a/src/metabase/notification/api/notification.clj+++ b/src/metabase/notification/api/notification.clj@@ -26,17 +26,13 @@(mr/def ::NotificationApiInput"Notification schema for API input. Like FullyHydratedNotification but restricts templatesto user-provided types only (no handlebars-resource)."- [:merge- ::models.notification/FullyHydratedNotification- [:map- [:handlers {:optional true}- [:sequential- [:merge- ::models.notification/NotificationHandler- [:map- [:template {:optional true} [:maybe ::models.channel/ChannelTemplateUserProvided]]- [:channel {:optional true} [:maybe ::models.channel/Channel]]- [:recipients {:optional true} [:sequential ::models.notification/NotificationRecipient]]]]]]]])+ (models.notification/hydrated-notification-schema+ [:merge+ ::models.notification/NotificationHandler+ [:map+ [:template {:optional true} [:maybe ::models.channel/ChannelTemplateUserProvided]]+ [:channel {:optional true} [:maybe ::models.channel/Channel]]+ [:recipients {:optional true} [:sequential ::models.notification/NotificationRecipient]]]]))(defn- check-no-resource-templates!"Validate that no handler uses handlebars-resource templates. That type is internal only."diff --git a/src/metabase/notification/models.clj b/src/metabase/notification/models.cljindex 66fd0cdabde..d88c4cf47f7 100644--- a/src/metabase/notification/models.clj+++ b/src/metabase/notification/models.clj@@ -98,20 +98,23 @@:id{:default []}))+(def ^:private notification-entries+ "Entries every notification map has, whatever its `:payload_type`."+ [[:payload_type (ms/enum-decode-keyword notification-types)]+ [:id {:optional true} ms/PositiveInt]+ [:active {:optional true} [:maybe :boolean]]])+(mr/def ::Notification- [:merge- [:map- [:payload_type (ms/enum-decode-keyword notification-types)]]- [:multi {:dispatch (comp keyword :payload_type)}- [:notification/system-event- [:map- [:payload_id {:optional true} nil?]]]+ (mu/dispatched-map+ (comp keyword :payload_type)+ notification-entries+ [[:notification/system-event+ [[:payload_id {:optional true} nil?]]][:notification/card- [:map- ;; optional during creation- [:payload_id {:optional true} int?]+ ;; both optional during creation+ [[:payload_id {:optional true} int?][:creator_id {:optional true} int?]]]- [:notification/testing :any]]])+ [:notification/testing :any]]))(defn- validate-notification[notification]@@ -188,19 +191,20 @@(mr/def ::NotificationSubscription"Schema for :model/NotificationSubscription."- [:merge [:map- [:type (ms/enum-decode-keyword subscription-types)]]- [:multi {:dispatch (comp keyword :type)}- [:notification-subscription/system-event- [:map- [:event_name [:or :keyword :string]]+ (mu/dispatched-map+ (comp keyword :type)+ [[:type (ms/enum-decode-keyword subscription-types)]+ ;; the API sends a negative id for a subscription that is being added+ [:id {:optional true} :int]+ [:notification_id {:optional true} ms/PositiveInt]]+ [[:notification-subscription/system-event+ [[:event_name [:or :keyword :string]][:cron_schedule {:optional true} nil?]]][:notification-subscription/cron- [:map- [:cron_schedule :string]+ [[:cron_schedule :string][:event_name {:optional true} nil?];; enum values can change depending on UI- [:ui_display_type {:optional true} [:maybe (into [:enum] subscription-ui-display-types)]]]]]])+ [:ui_display_type {:optional true} [:maybe (into [:enum] subscription-ui-display-types)]]]]]))(defn- validate-subscription"Validate a NotificationSubscription."@@ -303,6 +307,7 @@(mr/def ::NotificationHandler[:map;; optional during insertion+ [:id {:optional true} ms/PositiveInt][:notification_id {:optional true} ms/PositiveInt][:channel_type {:decode/json keyword} [:fn #(= "channel" (-> % keyword namespace))]][:channel_id {:optional true} [:maybe ms/PositiveInt]]@@ -342,34 +347,31 @@(mr/def ::NotificationRecipient"Schema for :model/NotificationRecipient."- [:merge [:map- [:type (ms/enum-decode-keyword notification-recipient-types)]- [:notification_handler_id {:optional true} ms/PositiveInt]]- [:multi {:dispatch (comp keyword :type)}- [:notification-recipient/user- [:map- [:user_id ms/PositiveInt]+ (mu/dispatched-map+ (comp keyword :type)+ [[:type (ms/enum-decode-keyword notification-recipient-types)]+ [:id {:optional true} ms/PositiveInt]+ [:notification_handler_id {:optional true} ms/PositiveInt]]+ [[:notification-recipient/user+ [[:user_id ms/PositiveInt][:permissions_group_id {:optional true} [:fn nil?]][:details {:optional true} [:fn empty?]]]][:notification-recipient/group- [:map- [:permissions_group_id ms/PositiveInt]+ [[:permissions_group_id ms/PositiveInt][:user_id {:optional true} [:fn nil?]][:details {:optional true} [:fn empty?]]]][:notification-recipient/raw-value- [:map- [:details [:map {:closed true}+ [[:details [:map {:closed true}[:value :any][:channel_id {:optional true} [:maybe :string]]]][:user_id {:optional true} [:fn nil?]][:permissions_group_id {:optional true} [:fn nil?]]]][:notification-recipient/template- [:map- [:details [:map {:closed true}+ [[:details [:map {:closed true}[:pattern :string][:is_optional {:optional true} :boolean]]][:user_id {:optional true} [:fn nil?]]- [:permissions_group_id {:optional true} [:fn nil?]]]]]])+ [:permissions_group_id {:optional true} [:fn nil?]]]]]))(defn- check-valid-recipient[recipient]@@ -411,10 +413,14 @@(mr/def ::NotificationCard"Schema for :model/NotificationCard."[:map- [:card_id ms/PositiveInt]- [:card {:optional true} [:maybe :map]]- [:send_condition {:optional true} (ms/enum-decode-keyword card-subscription-send-conditions)]- [:send_once {:optional true} :boolean]])+ [:card_id ms/PositiveInt]+ ;; nil on an unsaved notification, e.g. the one POST /api/pulse/test builds to send a test alert+ [:id {:optional true} [:maybe 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]]+ [:send_condition {:optional true} (ms/enum-decode-keyword card-subscription-send-conditions)]+ [:send_once {:optional true} :boolean]])(t2/define-before-insert :model/NotificationCard[instance]@@ -507,23 +513,33 @@;; Public APIs ;;;; ------------------------------------------------------------------------------------------------;;+(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+ we hand back out."+ [handler-schema]+ (let [entries (into notification-entries+ [;; 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?]]+ [:payload_id {:optional true} [:maybe int?]]+ [:subscriptions {:optional true} [:sequential [:ref ::NotificationSubscription]]]+ [:handlers {:optional true} [:sequential handler-schema]]])]+ (mu/dispatched-map+ (comp keyword :payload_type)+ entries+ [[:notification/card [[:payload [:ref ::NotificationCard]]]]+ [::mc/default []]])))+(mr/def ::FullyHydratedNotification"Fully hydrated notification."- [:merge- ::Notification- [:map- [:creator {:optional true} [:maybe :map]]- [:subscriptions {:optional true} [:sequential ::NotificationSubscription]]- [:handlers {:optional true} [:sequential [:merge- ::NotificationHandler- [:map- [:template {:optional true} [:maybe ::models.channel/ChannelTemplate]]- [:channel {:optional true} [:maybe ::models.channel/Channel]]- [:recipients {:optional true} [:sequential ::NotificationRecipient]]]]]]]- [:multi {:dispatch (comp keyword :payload_type)}- [:notification/card [:map- [:payload ::NotificationCard]]]- [::mc/default :map]]])+ (hydrated-notification-schema+ [:merge+ ::NotificationHandler+ [:map+ [:template {:optional true} [:maybe ::models.channel/ChannelTemplate]]+ [:channel {:optional true} [:maybe ::models.channel/Channel]]+ [:recipients {:optional true} [:sequential ::NotificationRecipient]]]]))(mu/defn hydrate-notification :- [:or ::FullyHydratedNotification [:sequential ::FullyHydratedNotification]]"Fully hydrate notifictitons."diff --git a/src/metabase/oauth_server/api/oauth.clj b/src/metabase/oauth_server/api/oauth.cljindex d7bbd51ee54..a8b7808c47e 100644--- a/src/metabase/oauth_server/api/oauth.clj+++ b/src/metabase/oauth_server/api/oauth.clj@@ -5,6 +5,7 @@[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]@@ -14,6 +15,7 @@[metabase.request.core :as request][metabase.system.core :as system][metabase.util.log :as log]+ [metabase.util.malli.schema :as ms][metabase.util.throttle :as u.throttle][oidc-provider.core :as oidc][oidc-provider.protocol :as proto]@@ -188,7 +190,21 @@(api.macros/defendpoint :post "/register":- [:map [:status [:enum 201 400 403 404 429]] [:body :any]]"Handles dynamic client registration (RFC 7591)."- [_route-params _query-params body :- :any+ [_route-params+ _query-params+ body :- [: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+ [:application_type {:optional true} [:maybe :string]]+ [:client_name {:optional true} [:maybe :string]]+ [:client_uri {:optional true} [:maybe :string]]+ [:contacts {:optional true} [:maybe [:sequential :string]]]+ [:grant_types {:optional true} [:maybe [:sequential :string]]]+ [:logo_uri {:optional true} [:maybe :string]]+ [:redirect_uris {:optional true} [:maybe [:sequential :string]]]+ [:response_types {:optional true} [:maybe [:sequential :string]]]+ [:scope {:optional true} [:maybe :string]]+ [:token_endpoint_auth_method {:optional true} [:maybe :string]]]]request](if-not (oauth-settings/oauth-server-dynamic-registration-enabled){:status 403@@ -236,8 +252,10 @@(api.macros/defendpoint :get "/register/:client-id":- [:map [:status [:enum 200 401 404]] [:body :map]]"Handles client configuration read (RFC 7592)."- [{:keys [client-id]}- _query-params _body+ [{:keys [client-id]} :- [:map+ [:client-id ms/NonBlankString]]+ _query-params+ _bodyrequest](or (when-let [provider (oauth-server/get-provider)](let [token (oauth-server/extract-bearer-token request)]@@ -251,10 +269,23 @@:body body})))){:status 404 :body {:error "not_found"}}))+#_{:clj-kondo/ignore [:metabase/validate-defendpoint-query-params-use-kebab-case]}(api.macros/defendpoint :get "/authorize":- [:map [:status [:enum 200 302 400 404]] [:body [:or :string :map]]]"Handles the authorization endpoint (GET /oauth/authorize)."- [_route-params query-params _body+ [_route-params+ query-params :- [:map+ [:client_id {:optional true} [:maybe :string]]+ [:response_type {:optional true} [:maybe :string]]+ [:redirect_uri {:optional true} [:maybe :string]]+ [:scope {:optional true} [:maybe :string]]+ [:state {:optional true} [:maybe :string]]+ [: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]]]+ _bodyrequest](if-not (:metabase-user-id request){:status 302@@ -288,7 +319,22 @@(api.macros/defendpoint :post "/authorize/decision":- [:map [:status [:enum 302 400 401 403 404 429]] [:body [:or :string :map]]]"Handles the authorization decision (POST /oauth/authorize/decision)."- [_route-params _query-params body+ [_route-params+ _query-params+ body :- [:map {: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]]+ [:client_id {:optional true} [:maybe :string]]+ [:response_type {:optional true} [:maybe :string]]+ [:redirect_uri {:optional true} [:maybe :string]]+ [:scope {:optional true} [:maybe :string]]+ [:state {:optional true} [:maybe :string]]+ [: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]]]request](if-not (:metabase-user-id request){:status 401@@ -331,7 +377,19 @@(api.macros/defendpoint :post "/token":- [:map [:status [:enum 200 400 401 404 429]] [:body :map]]"Handles the token endpoint (POST /oauth/token)."- [_route-params _query-params body+ [_route-params+ _query-params+ body :- [:map {: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]]+ [:refresh_token {:optional true} [:maybe :string]]+ [:client_id {:optional true} [:maybe :string]]+ [: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]]]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@@ -363,7 +421,13 @@(api.macros/defendpoint :post "/revoke":- [:map [:status [:enum 200 404]]]"Handles the token revocation endpoint (POST /oauth/revoke) per RFC 7009."- [_route-params _query-params _body+ [_route-params+ _query-params+ _body :- [:map {: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]]+ [:client_secret {:optional true} [:maybe :string]]]request](or (when-let [provider (oauth-server/get-provider)]((oidc/revocation-handler provider) request))diff --git a/src/metabase/parameters/schema.cljc b/src/metabase/parameters/schema.cljcindex 63a85d0535d..c8ec0080659 100644--- a/src/metabase/parameters/schema.cljc+++ b/src/metabase/parameters/schema.cljc@@ -76,20 +76,28 @@[:map{:description "parameter must be a map with :id and :type keys":decode/normalize lib.schema.common/normalize-map-no-kebab-case}- [:default {:optional true} :any]+ [: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]]][: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.+ [:isMultiSelect {:optional true} [:maybe :boolean]][:mappings {:optional true} [:maybe [:or[:sequential [:ref ::parameter-mapping]][:set [:ref ::parameter-mapping]]]]][:name {:optional true} :string]+ [:options {:optional true} [:maybe [:ref ::lib.schema.parameter/parameter.options]]]+ [: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][:slug {:optional true} :string][:target {:optional true} [:ref ::lib.schema.parameter/target]][:temporal_units {:optional true} [:maybe [:sequential ::lib.schema.temporal-bucketing/unit]]][:type [:ref ::lib.schema.parameter/type]]+ ;; the currently selected value. Dashboard subscriptions save their filter values on the parameter itself.+ [:value {:optional true} [:ref ::lib.schema.parameter/parameter.value]][:values_query_type {:optional true} [:maybe ::values-query-type]][:values_source_config {:optional true} [:maybe ::values-source-config]][:values_source_type {:optional true} [:maybe ::values-source-type]]])@@ -130,6 +138,21 @@{:in (comp mi/json-in normalize-parameters):out (comp (mi/catch-normalization-exceptions normalize-parameters) mi/json-out-with-keywordization)}))+(mr/def ::parameter-with-value+ "A parameter *value* supplied when running a query, as opposed to a stored parameter declaration. These are the keys+ 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"}+ [: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`+ [:name {:optional true} [:maybe ::lib.schema.common/non-blank-string]]+ [:type {:optional true} [:maybe [:ref ::lib.schema.parameter/type]]]+ [:value {:optional true} [:ref ::lib.schema.parameter/parameter.value]]+ [:default {:optional true} [:ref ::lib.schema.parameter/parameter.value]]+ [:target {:optional true} [:maybe [:ref ::lib.schema.parameter/target]]]+ [:options {:optional true} [:maybe [:ref ::lib.schema.parameter/parameter.options]]]])+(mr/def ::parameter-mapping"Schema for a valid Parameter Mapping"[:map@@ -141,8 +164,7 @@:description "parameter_mapping must be a map with :parameter_id and :target keys"}[:parameter_id ::lib.schema.parameter/id][:target ::lib.schema.parameter/target]- [:card_id {:optional true} [:maybe ::lib.schema.id/card]]- [:dashcard {:optional true} :map]])+ [:card_id {:optional true} [:maybe ::lib.schema.id/card]]])(mu/defn normalize-parameter-mapping :- ::parameter-mapping"Normalize `parameter-mappings` when coming out of the application database or in via an API request."@@ -163,3 +185,12 @@"Toucan 2 transform for columns that are sequences of Card/Dashboard parameter mappings."{:in (comp mi/json-in normalize-parameter-mappings):out (comp (mi/catch-normalization-exceptions normalize-parameter-mappings) mi/json-out-with-keywordization)}))++(mr/def ::parameter-mapping-with-dashcard+ "A `::parameter-mapping` resolved against the DashboardCard that carries it. The `:dashcard` is attached server-side+ by the `:resolved-params` hydration, so it is deliberately not part of `::parameter-mapping`: no client ever sends+ one."+ [:merge+ [:ref ::parameter-mapping]+ [:map+ [:dashcard :map]]])diff --git a/src/metabase/permissions_rest/api.clj b/src/metabase/permissions_rest/api.cljindex d8c2f0e9f53..da501559dab 100644--- a/src/metabase/permissions_rest/api.clj+++ b/src/metabase/permissions_rest/api.clj@@ -89,7 +89,32 @@{:keys [skip-graph force]} :- [:map[:skip-graph {:default false} [:maybe ms/BooleanValue]][:force {:default false} [:maybe ms/BooleanValue]]]- body :- :map]+ body :- [:map+ ;; keyed by group id, then by database id -- `::permissions-rest.schema/strict-api-permissions-graph`+ ;; below turns both back into the ints the graph is stored under, and checks the per-database+ ;; permissions, so the value stays open here+ [:groups [:map-of :keyword [:maybe ms/Map]]]+ [:revision {:optional true} [:maybe ms/Int]]+ [:force {:optional true} [:maybe :boolean]]+ ;; sandboxes without an `:id` are created, ones with an `:id` are updated -- and only in the keys the+ ;; request actually carries, so `:card_id`/`:attribute_remappings` have to keep their present/absent+ ;; distinction+ [:sandboxes {:optional true}+ [:maybe [:sequential+ [:map+ [:id {:optional true} ms/PositiveInt]+ [:group_id {:optional true} ms/PositiveInt]+ [:table_id {:optional true} ms/PositiveInt]+ [:card_id {:optional true} [:maybe ms/PositiveInt]]+ ;; user attribute name -> the parameter target it is remapped to+ [:attribute_remappings {:optional true} [:maybe ms/Map]]+ [:permission_id {:optional true} [:maybe ms/PositiveInt]]]]]]+ [:impersonations {:optional true}+ [:maybe [:sequential+ [:map+ [:group_id ms/PositiveInt]+ [:db_id ms/PositiveInt]+ [:attribute ms/NonBlankString]]]]]]](api/check-superuser)(let [new-graph (mc/decode ::permissions-rest.schema/strict-api-permissions-graphbodydiff --git a/src/metabase/public_sharing_rest/api.clj b/src/metabase/public_sharing_rest/api.cljindex 6683f4bd3a4..3dbd9b67d2f 100644--- a/src/metabase/public_sharing_rest/api.clj+++ b/src/metabase/public_sharing_rest/api.clj@@ -14,6 +14,7 @@[metabase.models.interface :as mi][metabase.parameters.dashboard :as parameters.dashboard][metabase.parameters.params :as params]+ [metabase.parameters.schema :as parameters.schema][metabase.public-sharing.validation :as public-sharing.validation][metabase.queries.core :as queries][metabase.query-processor.card :as qp.card]@@ -177,14 +178,16 @@;; 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;;-#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}+#_{:clj-kondo/ignore [:metabase/validate-defendpoint-query-params-use-kebab-case+ :metabase/validate-defendpoint-has-response-schema]}(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[:uuid ms/UUIDString]]{:keys [parameters]} :- [:map- [:parameters {:optional true} [:maybe ms/JSONString]]]]+ [:parameters {:optional true} [:maybe ms/JSONString]]+ [:ignore_cache {:optional true} [:maybe ms/BooleanValue]]]](process-query-for-card-with-public-uuid uuid :api (json/decode+kw parameters)));; TODO (Cam 10/28/25) -- fix this endpoint so it uses kebab-case for query parameters for consistency with the rest@@ -204,7 +207,8 @@{:keys [parameters format_rows pivot_results]} :- [:map[:format_rows {:default false} :boolean][:pivot_results {:default false} :boolean]- [:parameters {:optional true} [:maybe ms/JSONString]]]]+ [:parameters {:optional true} [:maybe ms/JSONString]]+ [:csv_include_bom {:optional true} [:maybe ms/BooleanValue]]]](process-query-for-card-with-public-uuiduuidexport-format@@ -274,11 +278,14 @@;; 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;;-#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}+#_{:clj-kondo/ignore [:metabase/validate-defendpoint-query-params-use-kebab-case+ :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- [:uuid ms/UUIDString]]]+ [:uuid ms/UUIDString]]+ _query-params :- [:map+ [:dashboard_load_id {:optional true} [:maybe ms/NonBlankString]]]](public-sharing.validation/check-public-sharing-enabled)(u/prog1 (dashboard-with-uuid uuid)(events/publish-event! :event/dashboard-read {:object-id (:id <>), :user-id api/*current-user-id*})))@@ -324,7 +331,8 @@;; 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;;-#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}+#_{:clj-kondo/ignore [:metabase/validate-defendpoint-query-params-use-kebab-case+ :metabase/validate-defendpoint-has-response-schema]}(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."@@ -333,7 +341,8 @@[:dashcard-id ms/PositiveInt][:card-id ms/PositiveInt]]{:keys [parameters]} :- [:map- [:parameters {:optional true} [:maybe ms/JSONString]]]]+ [:parameters {:optional true} [:maybe ms/JSONString]]+ [:ignore_cache {:optional true} [:maybe ms/BooleanValue]]]](public-sharing.validation/check-public-sharing-enabled)(let [card (api/check-404 (t2/select-one :model/Card :id card-id :archived false))dashboard (api/check-404 (t2/select-one :model/Dashboard :public_uuid uuid, :archived false))@@ -365,9 +374,10 @@(fn [x](cond-> x(string? x) json/decode+kw))}- [:sequential :map]]]+ [:sequential ::parameters.schema/parameter-with-value]]][:format_rows {:default false} ms/BooleanValue]- [:pivot_results {:default false} ms/BooleanValue]]]+ [:pivot_results {:default false} ms/BooleanValue]+ [:csv_include_bom {:optional true} [:maybe ms/BooleanValue]]]](public-sharing.validation/check-public-sharing-enabled)(let [card (api/check-404 (t2/select-one :model/Card :id card-id :archived false))dashboard (api/check-404 (t2/select-one :model/Dashboard :public_uuid uuid, :archived false))@@ -383,6 +393,12 @@:format-rows? format_rows:pivot? pivot_results}))))+(def ^:private ActionParameterValue+ "A value submitted for an action execution parameter, keyed by parameter id. The FE types these as+ `string | number | boolean | null` (`ParametersForActionExecution` in `metabase-types/api/actions.ts`); dates and+ other rich types are submitted in their string form."+ [:maybe [:or :string number? :boolean]])+(api.macros/defendpoint :post "/dashboard/:uuid/dashcard/:dashcard-id/execute/values" :- [:map-of :string :any]"Fetches the values for filling in execution parameters. Pass PK parameters and values to select.@@ -392,7 +408,7 @@[:dashcard-id ms/PositiveInt]]_query-params{:keys [parameters]} :- [:map- [:parameters [:map-of :string :any]]]]+ [:parameters [:map-of :string ActionParameterValue]]]](public-sharing.validation/check-public-sharing-enabled)(let [dashboard-id (api/check-404 (t2/select-one-pk :model/Dashboard :public_uuid uuid :archived false))](api/check-404 (t2/select-one-pk :model/DashboardCard :id dashcard-id :dashboard_id dashboard-id))@@ -415,7 +431,8 @@[:dashcard-id ms/PositiveInt]]_query-params{:keys [parameters], :as _body} :- [:map- [:parameters {:optional true} [:maybe [:map-of :keyword :any]]]]]+ [:parameters {:optional true} [:maybe [:map-of :keyword ActionParameterValue]]]+ [:modelId {:optional true} [:maybe ms/PositiveInt]]]](let [throttle-message (try(throttle/check dashcard-execution-throttle dashcard-id)nil@@ -528,7 +545,7 @@[{:keys [uuid param-key]} :- [:map[:uuid ms/UUIDString][:param-key ms/NonBlankString]]- {:keys [value]} :- [:map [:value :any]]]+ {:keys [value]} :- [:map [:value :string]]](public-sharing.validation/check-public-sharing-enabled)(let [card (t2/select-one :model/Card :public_uuid uuid, :archived false)](request/as-admin@@ -560,7 +577,7 @@[:uuid ms/UUIDString][:param-key ms/NonBlankString][:query ms/NonBlankString]]- constraint-param-key->value]+ constraint-param-key->value :- [:map-of string? any?]](public-sharing.validation/check-public-sharing-enabled)(let [dashboard (dashboard-with-uuid-for-param-values uuid)](request/as-admin@@ -576,7 +593,7 @@[{:keys [uuid param-key]} :- [:map[:uuid ms/UUIDString][:param-key ms/NonBlankString]]- {:keys [value]} :- [:map [:value :any]]]+ {:keys [value]} :- [:map [:value :string]]](public-sharing.validation/check-public-sharing-enabled)(let [dashboard (dashboard-with-uuid-for-param-values uuid)](request/as-admin@@ -590,21 +607,24 @@;; 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;;-#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}+#_{:clj-kondo/ignore [:metabase/validate-defendpoint-query-params-use-kebab-case+ :metabase/validate-defendpoint-has-response-schema]}(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[:uuid ms/UUIDString]]{:keys [parameters]} :- [:map- [:parameters {:optional true} [:maybe ms/JSONString]]]]+ [:parameters {:optional true} [:maybe ms/JSONString]]+ [:ignore_cache {:optional true} [:maybe ms/BooleanValue]]]](process-query-for-card-with-public-uuid uuid :api (json/decode+kw parameters):qp qp.pivot/run-pivot-query));; 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;;-#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}+#_{:clj-kondo/ignore [:metabase/validate-defendpoint-query-params-use-kebab-case+ :metabase/validate-defendpoint-has-response-schema]}(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."@@ -613,7 +633,8 @@[:card-id ms/PositiveInt][:dashcard-id ms/PositiveInt]]{:keys [parameters]} :- [:map- [:parameters {:optional true} [:maybe ms/JSONString]]]]+ [:parameters {:optional true} [:maybe ms/JSONString]]+ [:ignore_cache {:optional true} [:maybe ms/BooleanValue]]]](public-sharing.validation/check-public-sharing-enabled)(let [card (api/check-404 (t2/select-one :model/Card :id card-id :archived false))dashboard (api/check-404 (t2/select-one :model/Dashboard :public_uuid uuid, :archived false))@@ -829,10 +850,11 @@_query-params{:keys [parameters format_rows pivot_results]} :- [:map[:parameters {:optional true} [:maybe [:or- [:sequential ms/Map]+ [:sequential ::parameters.schema/parameter-with-value]ms/JSONString]]][:format_rows {:default false} ms/BooleanValue]- [:pivot_results {:default false} ms/BooleanValue]]]+ [:pivot_results {:default false} ms/BooleanValue]+ [:csv_include_bom {:optional true} [:maybe ms/BooleanValue]]]](public-sharing.validation/check-public-sharing-enabled)(let [card (validate-card-in-public-document uuid card-id)](process-query-for-card-with-iddiff --git a/src/metabase/pulse/api/pulse.clj b/src/metabase/pulse/api/pulse.cljindex c938c538ee8..b29f4c52aa9 100644--- a/src/metabase/pulse/api/pulse.clj+++ b/src/metabase/pulse/api/pulse.clj@@ -17,6 +17,7 @@[metabase.events.core :as events][metabase.models.interface :as mi][metabase.notification.core :as notification]+ [metabase.parameters.schema :as parameters.schema][metabase.permissions.core :as perms][metabase.premium-features.core :as premium-features][metabase.pulse.models.pulse :as models.pulse]@@ -145,6 +146,21 @@(events/publish-event! :event/pulse-create {:object pulse :user-id api/*current-user-id*})pulse)))+(def ^:private PulseChannel+ "The fields [[metabase.pulse.models.pulse-channel/create-pulse-channel!]] reads off a channel."+ [:map+ [:id {:optional true} :any]+ [:channel_type :any]+ [:enabled {:optional true} :any]+ [:pulse_id {:optional true} :any]+ [:channel_id {:optional true} :any]+ [:details {:optional true} ms/Map]+ [:recipients {:optional true} [:sequential ms/Map]]+ [:schedule_type {:optional true} :any]+ [:schedule_day {:optional true} :any]+ [:schedule_hour {:optional true} :any]+ [:schedule_frame {:optional true} :any]])+;; 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;;@@ -161,12 +177,12 @@:- [:map[:name ms/NonBlankString][:cards [:+ models.pulse/CoercibleToCardRef]]- [:channels [:+ :map]]+ [:channels [:+ PulseChannel]][:skip_if_empty {:default false} [:maybe :boolean]][:collection_id {:optional true} [:maybe ms/PositiveInt]][:collection_position {:optional true} [:maybe ms/PositiveInt]][:dashboard_id {:optional true} [:maybe ms/PositiveInt]]- [:parameters {:optional true} [:maybe [:sequential :map]]]]+ [:parameters {:optional true} [:maybe [:sequential ::parameters.schema/parameter]]]]request](create-pulse-with-perm-checks!cards@@ -233,11 +249,12 @@{:keys [cards], :as pulse-updates} :- [:map[:name {:optional true} [:maybe ms/NonBlankString]][:cards {:optional true} [:maybe [:+ models.pulse/CoercibleToCardRef]]]- [:channels {:optional true} [:maybe [:+ :map]]]+ [:channels {:optional true} [:maybe [:+ PulseChannel]]][:skip_if_empty {:default false} [:maybe :boolean]][:collection_id {:optional true} [:maybe ms/PositiveInt]]+ [:collection_position {:optional true} [:maybe ms/PositiveInt]][:archived {:default false} [:maybe :boolean]]- [:parameters {:optional true} [:maybe [:sequential ms/Map]]]]]+ [:parameters {:optional true} [:maybe [:sequential ::parameters.schema/parameter]]]]];; do various perms checks(try(perms/check-has-application-permission :monitoring)@@ -321,14 +338,22 @@[_route-params_query-params{:keys [cards channels] :as body} :- [:map+ ;; 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+ [:id {:optional true} [:maybe ms/PositiveInt]][:name ms/NonBlankString][:cards [:+ models.pulse/CoercibleToCardRef]]- [:channels [:+ :map]]+ [:channels [:+ PulseChannel]][:skip_if_empty {:default false} [:maybe :boolean]][:disable_links {:default false} [:maybe :boolean]][:collection_id {:optional true} [:maybe ms/PositiveInt]][:collection_position {:optional true} [:maybe ms/PositiveInt]]- [:dashboard_id {:optional true} [:maybe ms/PositiveInt]]]+ [:dashboard_id {:optional true} [:maybe ms/PositiveInt]]+ [:parameters {:optional true} [:maybe [:sequential ::parameters.schema/parameter-with-value]]]+ [:alert_condition {:optional true} [:maybe models.pulse/AlertConditions]]+ [:alert_first_only {:optional true} [:maybe :boolean]]+ [:alert_above_goal {:optional true} [:maybe :boolean]]]request];; Check permissions on cards that exist. Placeholders and iframes don't matter.(check-card-read-permissionsdiff --git a/src/metabase/queries_rest/api/card.clj b/src/metabase/queries_rest/api/card.cljindex 26c23685ede..6c65ee08714 100644--- a/src/metabase/queries_rest/api/card.clj+++ b/src/metabase/queries_rest/api/card.clj@@ -912,7 +912,8 @@:- [:map[:ignore_cache {:default false} :boolean][:collection_preview {:optional true} [:maybe :boolean]]- [:dashboard_id {:optional true} [:maybe ms/PositiveInt]]]]+ [:dashboard_id {:optional true} [:maybe ms/PositiveInt]]+ [:parameters {:optional true} [:maybe [:sequential ::parameters.schema/parameter-with-value]]]]](let [resolved-card-id (eid-translation/->id-or-404 :card card-id)card (api/check-404 (t2/select-one :model/Card resolved-card-id))](when dashboard_iddiff --git a/src/metabase/query_processor/api.clj b/src/metabase/query_processor/api.cljindex fe7dab5019d..867b521d3e1 100644--- a/src/metabase/query_processor/api.clj+++ b/src/metabase/query_processor/api.clj@@ -97,7 +97,7 @@"Execute a query and retrieve the results in the usual format. The query will not use the cache."[_route-params_query-params- query :- [:map+ query :- [:map {:closed false}[:database {:optional true} [:maybe :int]]]](run-streaming-query(-> query@@ -139,11 +139,13 @@;; `<form>` submissions... see https://metaboat.slack.com/archives/C010L1Z4F9S/p1738003606875659:- [:map[:query [:map- {:decode/api (fn [x]+ {:closed false+ :decode/api (fn [x](cond-> x(string? x) json/decode+kw))}]][:visualization_settings {:default {}} [:map- {:decode/api (fn [x]+ {:closed false+ :decode/api (fn [x](cond-> x(string? x) (json/decode viz-setting-key-fn)))}]][:format_rows {:default false} ms/BooleanValue]@@ -184,7 +186,7 @@visibility_type :sensitive in the response."[_route-params_query-params- query :- [:map+ query :- [:map {:closed false}[:database ms/PositiveInt][:settings {:optional true} [:maybe [:map[:include_sensitive_fields {:optional true} :boolean]]]]]]@@ -201,7 +203,7 @@"Fetch a native version of an MBQL query."[_route-params_query-params- {:keys [database pretty] :as query} :- [:map+ {:keys [database pretty] :as query} :- [:map {:closed false}[:database ms/PositiveInt][:pretty {:default true} [:maybe :boolean]]]](model-persistence/with-persisted-substituion-disabled@@ -217,7 +219,7 @@"Generate a pivoted dataset for an ad-hoc query"[_route-params_query-params- {:keys [database] :as query} :- [:map+ {:keys [database] :as query} :- [:map {:closed false}[:database ms/PositiveInt]]](api/read-check :model/Database database)(let [info {:executed-by api/*current-user-id*diff --git a/src/metabase/search/api.clj b/src/metabase/search/api.cljindex 1dab528d962..33ef5bf90e1 100644--- a/src/metabase/search/api.clj+++ b/src/metabase/search/api.clj@@ -2,6 +2,7 @@(: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]@@ -189,7 +190,8 @@[_route-params{:keys [context], :as overrides} :- [:map[:context {:default :default} :keyword]- [:search_engine {:optional true} :any]]]+ [:search_engine {:optional true} :any]+ [::mc/default [:map-of :keyword :string]]]];; remove cookie;; normalize so overrides are stored under the same key search reads them from(let [context (search.config/normalized-context context)diff --git a/src/metabase/segments/api.clj b/src/metabase/segments/api.cljindex 9cafc1a7dc3..b7351f66d45 100644--- a/src/metabase/segments/api.clj+++ b/src/metabase/segments/api.clj@@ -121,7 +121,7 @@_query-paramsbody :- [:map[:name {:optional true} [:maybe ms/NonBlankString]]- [:definition {:optional true} [:maybe :map]]+ [:definition {:optional true} [:maybe ms/Map]][:revision_message ms/NonBlankString][:archived {:optional true} [:maybe :boolean]][:caveats {:optional true} [:maybe :string]]diff --git a/src/metabase/segments/schema.clj b/src/metabase/segments/schema.cljindex ae9412d45c6..37bdbeb0a92 100644--- a/src/metabase/segments/schema.clj+++ b/src/metabase/segments/schema.clj@@ -29,5 +29,8 @@[:fn{:error/message "A segment must have exactly one stage"}#(= (-> % :stages count) 1)]- [:map- [:stages [:sequential [:ref ::stage.segment]]]]])+ ;; checked with `:fn` rather than a `[:map [:stages ...]]` conjunct: a map conjunct declares only the keys it names,+ ;; so it would strip every other key of the query before the sibling `::lib.schema/query` saw it+ [:fn+ {:error/message "A segment's stages must be segment stages"}+ #(mr/validate [:sequential [:ref ::stage.segment]] (:stages %))]])diff --git a/src/metabase/slackbot/api.clj b/src/metabase/slackbot/api.cljindex 30208b8ba05..7c72afaeb29 100644--- a/src/metabase/slackbot/api.clj+++ b/src/metabase/slackbot/api.clj@@ -624,10 +624,13 @@#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :post "/interactive""Handle interactive payloads from Slack (button clicks, modal submissions)."- [_route-params _query-params _body request]+ [_route-params+ _query-params+ {:keys [payload]} :- [:map+ [:payload ms/NonBlankString]]+ request](assert-valid-slack-req request)- (let [payload (-> (get-in request [:params :payload])- (json/decode true))]+ (let [payload (json/decode payload true)](case (:type payload)"block_actions"(let [actions (:actions payload)diff --git a/src/metabase/slackbot/events.clj b/src/metabase/slackbot/events.cljindex 917e5d1e142..0124f00cc55 100644--- a/src/metabase/slackbot/events.clj+++ b/src/metabase/slackbot/events.clj@@ -1,7 +1,8 @@(ns metabase.slackbot.events"Event definitions for slackbot."(:require- [clojure.string :as str]))+ [clojure.string :as str]+ [malli.core :as mc]))(def SlackEventsResponse"Malli schema for Slack events API response"@@ -54,7 +55,9 @@[:type [:= "event_callback"]][:event [:map[:type :string]- [:event_ts :string]]]])+ [:event_ts :string]+ [::mc/default [:map-of :keyword :any]]]]+ [::mc/default [:map-of :keyword :any]]])(defn user-message?"Check if event is from a user (not a bot)."diff --git a/src/metabase/sso/api/ldap.clj b/src/metabase/sso/api/ldap.cljindex ba2c44dad11..fc7210bc129 100644--- a/src/metabase/sso/api/ldap.clj+++ b/src/metabase/sso/api/ldap.clj@@ -7,6 +7,7 @@[metabase.settings.core :as setting][metabase.sso.ldap :as ldap][metabase.sso.settings :as sso.settings]+ [metabase.util.malli.schema :as ms][toucan2.core :as t2]))(set! *warn-on-reflection* true)@@ -28,15 +29,26 @@[_route-params_query-paramssettings :- [:map- [:ldap-port {:optional true} [:maybe- ;; treat empty string as nil- {:decode/api (fn [x]- (when-not (= x "")- x))}- pos-int?]]- [:ldap-password {:optional true} [:maybe :string]]- [:ldap-host {:optional true} [:maybe :string]]- [:ldap-enabled {:optional true} [:maybe :boolean]]]]+ [:ldap-port {:optional true} [:maybe+ ;; treat empty string as nil+ {:decode/api (fn [x]+ (when-not (= x "")+ x))}+ pos-int?]]+ [:ldap-password {:optional true} [:maybe :string]]+ [:ldap-host {:optional true} [:maybe :string]]+ [:ldap-enabled {:optional true} [:maybe :boolean]]+ [:ldap-security {:optional true} [:maybe [:enum "none" "ssl" "starttls"]]]+ [:ldap-bind-dn {:optional true} [:maybe :string]]+ [:ldap-user-base {:optional true} [:maybe :string]]+ [:ldap-user-filter {:optional true} [:maybe :string]]+ [:ldap-attribute-email {:optional true} [:maybe :string]]+ [:ldap-attribute-firstname {:optional true} [:maybe :string]]+ [:ldap-attribute-lastname {:optional true} [:maybe :string]]+ [: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]]]]]](api/check-superuser)(let [ldap-settings (-> settings(update :ldap-password update-password-if-needed)diff --git a/src/metabase/testing_api/api.clj b/src/metabase/testing_api/api.cljindex 8e3f319efa5..68ebd693de2 100644--- a/src/metabase/testing_api/api.clj+++ b/src/metabase/testing_api/api.clj@@ -14,7 +14,6 @@[metabase.lib.core :as lib][metabase.lib.schema :as lib.schema][metabase.lib.schema.id :as lib.schema.id]- [metabase.lib.schema.test-spec :as lib.schema.test-spec][metabase.mcp.usage :as mcp.usage][metabase.permissions.core :as perms][metabase.premium-features.core :refer [defenterprise]]@@ -266,10 +265,13 @@"Creates a query from a test query spec."[_route-params_query-params- {:keys [database], :as query-spec} :- [:merge- [:map- [:database ::lib.schema.id/database]]- [:ref ::lib.schema.test-spec/test-query-spec]]]+ {: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)))@@ -302,10 +304,13 @@"Creates a native query from a test query spec."[_route-params_query-params- {:keys [database], :as native-query-spec} :- [:merge- [:map- [:database ::lib.schema.id/database]]- [:ref ::lib.schema.test-spec/test-native-query-spec]]]+ {: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)))diff --git a/src/metabase/tiles/api.clj b/src/metabase/tiles/api.cljindex c7c2064c03e..631b2220796 100644--- a/src/metabase/tiles/api.clj+++ b/src/metabase/tiles/api.clj@@ -286,7 +286,7 @@{:decode/api (fn [s](when (string? s)(json/decode+kw s)))}- ::parameters.schema/parameters])+ [:sequential ::parameters.schema/parameter-with-value]]);; 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 happendiff --git a/src/metabase/users/schema.clj b/src/metabase/users/schema.cljindex e943cc7e8ea..d664b7a74c6 100644--- a/src/metabase/users/schema.clj+++ b/src/metabase/users/schema.clj@@ -1,5 +1,6 @@(ns metabase.users.schema(:require+ [clojure.string :as str][metabase.util.i18n :refer [deferred-tru]][metabase.util.malli :as mu][metabase.util.malli.registry :as mr]@@ -7,15 +8,18 @@(def LoginAttributes"Login attributes, currently not collected for LDAP or Google Auth. Will ultimately be stored as JSON."- [:map-of- [:and+ [:and+ [:map-of(mu/with-api-error-messagems/KeywordOrString(deferred-tru "login attribute keys must be a keyword or string"))- (mu/with-api-error-message- [:fn (fn [k] (re-matches #"^(?!@).*" (name k)))]- (deferred-tru "login attribute keys must not start with `@`"))]- :any])+ :any]+ ;; 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+ [:fn (fn [attributes]+ (not-any? #(str/starts-with? (name %) "@") (keys attributes)))]+ (deferred-tru "login attribute keys must not start with `@`"))])(def NewUser"Required/optionals parameters needed to create a new user (for any backend)"diff --git a/src/metabase/users_rest/api.clj b/src/metabase/users_rest/api.cljindex 67763b4868c..c106268196d 100644--- a/src/metabase/users_rest/api.clj+++ b/src/metabase/users_rest/api.clj@@ -417,6 +417,10 @@[:first_name {:optional true} [:maybe ms/NonBlankString]][:last_name {:optional true} [:maybe ms/NonBlankString]][:email ms/Email]+ ;; `invite-user!` passes this through to `create-and-invite-user!`; without it the new user gets a random+ ;; password and can never log in. Deliberately not `ms/ValidPassword`: admins provisioning accounts here+ ;; have never been held to the complexity rules that `PUT /api/user/:id/password` enforces.+ [:password {:optional true} [:maybe ms/NonBlankString]][:user_group_memberships {:optional true} [:maybe [:sequential ::users.schema/user-group-membership]]][:login_attributes {:optional true} [:maybe users.schema/LoginAttributes]][:source {:optional true, :default :admin} [:maybe keyword?]]@@ -591,7 +595,8 @@[:id ms/PositiveInt]]_query-params{:keys [password old_password]} :- [:map- [:password ms/ValidPassword]]+ [:password ms/ValidPassword]+ [:old_password {:optional true} [:maybe :string]]]request](users/check-self-or-superuser id)(api/let-404 [user (t2/select-one [:model/User :id :last_login :password_salt :password],diff --git a/src/metabase/util/malli.cljc b/src/metabase/util/malli.cljcindex bad08579efb..2f29fd7b051 100644--- a/src/metabase/util/malli.cljc+++ b/src/metabase/util/malli.cljc@@ -150,3 +150,17 @@(mc/children schema)):and (some map-schema-keys (mc/children schema))nil)))++(core/defn dispatched-map+ "A `:multi` schema on `dispatch` whose every branch declares `common-entries` on top of its own entries.++ This is what `[:merge [:map common-entries] [:multi ...]]` looks like it does, but does not: `:merge` pushes itself+ inside each branch, nesting a second dispatch there instead of adding the common keys to it. A branch given+ anything other than a vector of entries is used as its own schema."+ [dispatch common-entries branches]+ (into [:multi {:dispatch dispatch}]+ (map (core/fn [[dispatch-value entries]]+ [dispatch-value (if (vector? entries)+ (into (into [:map] common-entries) entries)+ entries)]))+ branches))diff --git a/src/metabase/util/malli/schema.clj b/src/metabase/util/malli/schema.cljindex 99ea6882103..adb237bb5ae 100644--- a/src/metabase/util/malli/schema.clj+++ b/src/metabase/util/malli/schema.clj@@ -215,9 +215,9 @@(deferred-tru "value must be a valid entity type (keyword or string).")))(def Map- "Schema for a valid map."+ "Schema for a valid map. Open: it constrains nothing about its keys, so its contents pass through as they arrived."(mu/with-api-error-message- :map+ [:map {:closed false}](deferred-tru "Value must be a map.")))(def Emaildiff --git a/src/metabase/warehouse_schema_rest/api/table.clj b/src/metabase/warehouse_schema_rest/api/table.cljindex fc7081b08a1..1fc475199c1 100644--- a/src/metabase/warehouse_schema_rest/api/table.clj+++ b/src/metabase/warehouse_schema_rest/api/table.clj@@ -3,6 +3,7 @@(:require[clojure.java.io :as io][clojure.string :as str]+ [malli.core :as mc][metabase.api.common :as api][metabase.api.macros :as api.macros][metabase.app-db.core :as app-db]@@ -25,7 +26,7 @@[metabase.sync.core :as sync][metabase.upload.core :as upload][metabase.util :as u]- [metabase.util.i18n :refer [tru]]+ [metabase.util.i18n :refer [deferred-tru tru]][metabase.util.log :as log][metabase.util.malli :as mu][metabase.util.malli.registry :as mr]@@ -459,6 +460,21 @@(tru "There was an error uploading the file"))}})(finally (io/delete-file (:file options) :silently))))+(def ^:private CsvUploadParts+ "The multipart parts a CSV upload may carry. A part under any other name is rejected rather than dropped, so a second+ file cannot be smuggled past the upload: `::mc/default` keeps the extra parts, and the check below refuses them."+ [:and+ [:map+ ["file"+ [:map+ [:filename :string]+ [:tempfile (ms/InstanceOfClass java.io.File)]]]+ ["collection_id" {:optional true} :string]+ [::mc/default [:map-of :string :any]]]+ (mu/with-api-error-message+ [: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;; use our API + we will need it when we make auto-TypeScript-signature generation happen;;@@ -474,16 +490,8 @@[:id ms/PositiveInt]]_query-params_body- ;; Closed so a file part smuggled under another part name is rejected; collection_id is the text field the- ;; frontend sends alongside the file.{:keys [multipart-params], :as _request} :- [:map- [:multipart-params- [:map {:closed true}- ["file"- [:map- [:filename :string]- [:tempfile (ms/InstanceOfClass java.io.File)]]]- ["collection_id" {:optional true} :string]]]]]+ [:multipart-params CsvUploadParts]]](update-csv! {:table-id id:filename (get-in multipart-params ["file" :filename]):file (get-in multipart-params ["file" :tempfile])@@ -504,16 +512,8 @@[:id ms/PositiveInt]]_query-params_body- ;; Closed so a file part smuggled under another part name is rejected; collection_id is the text field the- ;; frontend sends alongside the file.{:keys [multipart-params], :as _request} :- [:map- [:multipart-params- [:map {:closed true}- ["file"- [:map- [:filename :string]- [:tempfile (ms/InstanceOfClass java.io.File)]]]- ["collection_id" {:optional true} :string]]]]]+ [:multipart-params CsvUploadParts]]](update-csv! {:table-id id:filename (get-in multipart-params ["file" :filename]):file (get-in multipart-params ["file" :tempfile])diff --git a/src/metabase/warehouses_rest/api.clj b/src/metabase/warehouses_rest/api.cljindex ffd55e976e7..27e87776baa 100644--- a/src/metabase/warehouses_rest/api.clj+++ b/src/metabase/warehouses_rest/api.clj@@ -984,7 +984,7 @@{{:keys [engine details]} :details} :- [:map[:details [:map[:engine DBEngineString]- [:details :map]]]]]+ [:details ms/Map]]]]](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!@@ -1083,6 +1083,8 @@[:details {:optional true} [:maybe ms/Map]][:write_data_details {:optional true} [:maybe ms/Map]][:schedules {:optional true} [:maybe sync.schedules/ExpandedSchedulesMap]]+ [:is_full_sync {:optional true} [:maybe ms/BooleanValue]]+ [:is_on_demand {:optional true} [:maybe ms/BooleanValue]][:description {:optional true} [:maybe :string]][:caveats {:optional true} [:maybe :string]][:points_of_interest {:optional true} [:maybe :string]]diff --git a/test/metabase/agent_api/api_test.clj b/test/metabase/agent_api/api_test.cljindex ced7b82744e..2f43323e0db 100644--- a/test/metabase/agent_api/api_test.clj+++ b/test/metabase/agent_api/api_test.clj@@ -305,25 +305,22 @@(is (=? {:error "unknown-stage-key"} response))(is (re-find #"aggregation" (:message response)))))))-(deftest construct-query-rejects-legacy-envelope-test+(deftest construct-query-ignores-legacy-envelope-test(testing (str "Legacy `source_entity` / `referenced_entities` envelope from the pre-repr program API "- "is rejected by the now-closed request schema, instead of being silently ignored. "- "This guards against a regression where the LLM's stale memory keeps sending the old "- "shape and we silently drop the extra keys.")- (is (=? {:specific-errors {:source_entity #(some (fn [s] (re-find #"disallowed key" s)) %)}}- (mt/user-http-request :rasta :post 400 "agent/v2/construct-query"+ "is dropped by the request schema, so a caller still sending the old shape is served.")+ (is (=? {:query string?}+ (mt/user-http-request :rasta :post 200 "agent/v2/construct-query"{:query (orders-query):source_entity {:type "table" :id (mt/id :orders)}}))))- (testing "`/v2/query` fresh-query branch rejects the legacy envelope as well"- (is (=? {:specific-errors {:referenced_entities #(some (fn [s] (re-find #"disallowed key" s)) %)}}- (mt/user-http-request :rasta :post 400 "agent/v2/query"- {:query (orders-query :limit 5)- :referenced_entities []}))))- (testing "`/v2/query` continuation_token branch rejects extra keys (closed schema)"- (is (=? {:specific-errors {:query #(some (fn [s] (re-find #"disallowed key" s)) %)}}- (mt/user-http-request :rasta :post 400 "agent/v2/query"- {:continuation_token "not-a-real-token"- :query (orders-query :limit 5)})))))+ (testing "`/v2/query` fresh-query branch drops the legacy envelope as well"+ (is (some? (mt/user-http-request :rasta :post 202 "agent/v2/query"+ {:query (orders-query :limit 5)+ :referenced_entities []}))))+ (testing "`/v2/query` stays on the continuation branch when a stray `:query` rides along"+ (is (re-find #"base64-encoded JSON object"+ (mt/user-http-request :rasta :post 400 "agent/v2/query"+ {:continuation_token "not-a-real-token"+ :query (orders-query :limit 5)})))))(deftest execute-query-test(testing "Executes a query and returns results with column metadata"diff --git a/test/metabase/cache/api_test.clj b/test/metabase/cache/api_test.cljindex 71a6be54947..e35f9cda7ce 100644--- a/test/metabase/cache/api_test.clj+++ b/test/metabase/cache/api_test.clj@@ -35,10 +35,12 @@(mt/with-model-cleanup [:model/CacheConfig](mt/with-premium-features #{}(testing "But no advanced strategies can be used"- (is (=? {:specific-errors {:strategy {:type ["should be either :nocache or :ttl, received: :schedule" string?]}}- :errors {:strategy {:type "enum of :nocache, :ttl"}}}- (mt/user-http-request :crowberto :put 400 "cache/"- {:model "root"- :model_id 0- :strategy {:type "schedule"- :schedule "0/2 * * * * ?"}})))))))+ (let [response (mt/user-http-request :crowberto :put 400 "cache/"+ {:model "root"+ :model_id 0+ :strategy {:type "schedule"+ :schedule "0/2 * * * * ?"}})]+ (is (= {:strategy "cache strategy :type must be one of :nocache, :ttl"}+ (:errors response)))+ (is (re-find #"invalid cache strategy :type \"schedule\", must be one of :nocache, :ttl"+ (first (get-in response [:specific-errors :strategy])))))))))diff --git a/test/metabase/dashboards_rest/api_test.clj b/test/metabase/dashboards_rest/api_test.cljindex f43ad897b87..2cb40bdbfe7 100644--- a/test/metabase/dashboards_rest/api_test.clj+++ b/test/metabase/dashboards_rest/api_test.clj@@ -2262,7 +2262,6 @@:size_y 4:parameter_mappings [{:parameter_id "abc":card_id 123- :hash "abc":target [:dimension [:template-tag "foo"]]}]:visualization_settings {}}]:tabs []}))]@@ -2275,7 +2274,7 @@:row 4:series []:dashboard_tab_id nil- :parameter_mappings [{:parameter_id "abc" :card_id 123, :hash "abc", :target ["dimension" ["template-tag" "foo"]]}]+ :parameter_mappings [{:parameter_id "abc" :card_id 123, :target ["dimension" ["template-tag" "foo"]]}]:visualization_settings {}:created_at true:updated_at true@@ -2289,7 +2288,7 @@:size_y 4:col 4:row 4- :parameter_mappings [{:parameter_id "abc", :card_id 123, :hash "abc", :target [:dimension [:template-tag "foo"]]}]+ :parameter_mappings [{:parameter_id "abc", :card_id 123, :target [:dimension [:template-tag "foo"]]}]:visualization_settings {}}](map (partial into {})(t2/select [:model/DashboardCard :size_x :size_y :col :row :parameter_mappings :visualization_settings]@@ -2445,7 +2444,6 @@:size_y 4:parameter_mappings [{:parameter_id "abc":card_id 123- :hash "abc":target [:dimension [:template-tag "foo"]]}]:visualization_settings {}}]:tabs []}))))))@@ -3878,7 +3876,7 @@{:parameters [{:id "_THIS_PARAMETER_DOES_NOT_EXIST_":value 3}]}))))(testing "Should return sensible error message for invalid parameter input"- (is (= {:errors {:parameters "nullable sequence of value must be a parameter map with an 'id' key"},+ (is (= {:errors {:parameters "nullable sequence of parameter must be a map with an :id key"},:specific-errors {:parameters ["invalid type, received: {:_PRICE_ 3}"]}}(mt/user-http-request :rasta :post 400 url{:parameters {"_PRICE_" 3}}))))@@ -5476,6 +5474,26 @@(is (= (set (map :id original-param-cards))(set (map :id updated-param-cards)))))))))))+(deftest dashboard-update-preserves-widget-shape-parameter-keys-test+ (testing "PUT /api/dashboard/:id round-trips the parameter keys that decide how the widget renders"+ (mt/with-temp [:model/Dashboard {dashboard-id :id} {}]+ (with-dashboards-in-writeable-collection! [dashboard-id]+ (let [parameter {:name "Title"+ :display-name "Title"+ :slug "title"+ :id "_TITLE_"+ :type "string/contains"+ :sectionId "string"+ :isMultiSelect false+ :options {:case-sensitive false}+ :value ["Awesome"]}]+ (mt/user-http-request :rasta :put 200 (str "dashboard/" dashboard-id)+ {:parameters [parameter]})+ (is (= [(-> parameter+ (update :type keyword)+ (assoc :sectionId "string"))]+ (:parameters (t2/select-one :model/Dashboard :id dashboard-id)))))))))+(deftest dashboard-update-mixed-parameter-changes-test(testing "PUT /api/dashboard/:id correctly handles mix of unchanged and changed parameters"(mt/with-temp [:model/Card {source-card-id-1 :id} {:database_id (mt/id)diff --git a/test/metabase/data_studio/api/table_test.clj b/test/metabase/data_studio/api/table_test.cljindex 0f2096024cf..30d6c2037e7 100644--- a/test/metabase/data_studio/api/table_test.clj+++ b/test/metabase/data_studio/api/table_test.clj@@ -35,11 +35,14 @@:data_layer "hidden"})(is (= :hidden (t2/select-one-fn :data_layer :model/Table :id table-1-id)))(is (= :hidden (t2/select-one-fn :visibility_type :model/Table :id table-1-id))))- (testing "cannot update both visibility_type and data_layer at once"- (mt/user-http-request :crowberto :post 400 "data-studio/table/edit"- {:table_ids [table-1-id]- :visibility_type "hidden"- :data_layer "hidden"})))))+ (testing "visibility_type is not part of this endpoint, so it is dropped and data_layer alone applies"+ (mt/user-http-request :crowberto :post 200 "data-studio/table/edit"+ {:table_ids [table-1-id]+ :visibility_type "hidden"+ :data_layer "final"})+ ;; had visibility_type been honoured, the model would have refused to update both at once+ (is (= :final (t2/select-one-fn :data_layer :model/Table :id table-1-id)))+ (is (= nil (t2/select-one-fn :visibility_type :model/Table :id table-1-id)))))))(deftest bulk-edit-does-not-allow-changing-data-source-away-from-transform-test(testing "POST /api/data-studio/table/edit cannot change a transform-created table's data_source"diff --git a/test/metabase/lib/join_test.cljc b/test/metabase/lib/join_test.cljcindex da1db428b59..e2a5544f7a6 100644--- a/test/metabase/lib/join_test.cljc+++ b/test/metabase/lib/join_test.cljc@@ -1253,9 +1253,10 @@:name "account__id":table-id account-tab-id:base-type :type/Integer}]- :dataset-query {:lib/type :mbql.stage/mbql+ :dataset-query {:lib/type :mbql/query:database (:id meta/database)- :source-table account-tab-id}})+ :stages [{:lib/type :mbql.stage/mbql+ :source-table account-tab-id}]}})(lib.tu/as-model{:id contact-card-id:name "Contact Model"@@ -1267,9 +1268,10 @@:base-type :type/Integer:semantic-type :type/FK:fk-target-field-id organization-f-id}]- :dataset-query {:lib/type :mbql.stage/mbql+ :dataset-query {:lib/type :mbql/query:database (:id meta/database)- :source-table contact-tab-id}})]})+ :stages [{:lib/type :mbql.stage/mbql+ :source-table contact-tab-id}]}})]})account-card (lib.metadata/card metadata-provider account-card-id)contact-card (lib.metadata/card metadata-provider contact-card-id)query (lib/query metadata-provider account-card)]diff --git a/test/metabase/lib/schema/join_test.cljc b/test/metabase/lib/schema/join_test.cljcindex 8532b7c7b78..ab4fb62cb71 100644--- a/test/metabase/lib/schema/join_test.cljc+++ b/test/metabase/lib/schema/join_test.cljc@@ -16,10 +16,8 @@(deftest ^:parallel join-schema-test(is (=? {:stages ["should have at least 1 elements" ["end of input"]]}(mu.humanize/humanize (mr/explain ::lib.schema.join/join {:stages []}))))- ;; not sure why these errors are repeated.(is (=? {:lib/type "missing required key"- :stages [[{:joins [{:stages [[{:lib/type "missing required key"}- "Invalid stage :lib/type: expected :mbql.stage/native or :mbql.stage/mbql"]]+ :stages [[{:joins [{:stages ["Invalid stage :lib/type: expected :mbql.stage/native or :mbql.stage/mbql"]:conditions "should have at least 1 elements"}]}"Initial MBQL stage must have either :source-table or :source-card (but not both)"]]}(mu.humanize/humanize (mr/explain ::lib.schema/query {:stages [{:lib/type :mbql.stage/mbqldiff --git a/test/metabase/measures/api_test.clj b/test/metabase/measures/api_test.cljindex 2b254db24fd..19f1d4fecbc 100644--- a/test/metabase/measures/api_test.clj+++ b/test/metabase/measures/api_test.clj@@ -109,7 +109,7 @@(is (=? {:errors {:revision_message "value must be a non-blank string."}}(mt/user-http-request :crowberto :put 400 "measure/1" {:name "abc":revision_message ""})))- (is (=? {:errors {:definition "nullable map"}}+ (is (=? {:errors {:definition "nullable Value must be a map."}}(mt/user-http-request :crowberto :put 400 "measure/1" {:name "abc":revision_message "123":definition "foobar"})))))diff --git a/test/metabase/notification/api/notification_test.clj b/test/metabase/notification/api/notification_test.cljindex d874e896531..08c7b600580 100644--- a/test/metabase/notification/api/notification_test.clj+++ b/test/metabase/notification/api/notification_test.clj@@ -269,7 +269,10 @@(is (=? template recreated-template))))))))(deftest api-rejects-handlebars-resource-templates-test- (let [resource-template {:name "test"+ (let [;; the request schema only admits the handlebars-text template type, so the API rejects a+ ;; handlebars-resource one before the endpoint gets a chance to look at it+ rejected {:errors {:handlers {:template {:details {:type "enum of :email/handlebars-text, email/handlebars-text"}}}}}+ resource-template {:name "test":channel_type "channel/email":details {:type "email/handlebars-resource":subject "test"@@ -277,7 +280,7 @@(testing "POST /api/notification rejects handlebars-resource templates"(mt/with-model-cleanup [:model/Notification](mt/with-temp [:model/Card {card-id :id} {}]- (is (=? "invalid template"+ (is (=? rejected(mt/user-http-request :crowberto :post 400 "notification"{:payload_type "notification/card":payload {:card_id card-id}@@ -287,7 +290,7 @@:user_id (mt/user->id :crowberto)}]}]}))))))(testing "POST /api/notification/send rejects handlebars-resource templates"(mt/with-temp [:model/Card {card-id :id} {}]- (is (=? "invalid template"+ (is (=? rejected(mt/user-http-request :crowberto :post 400 "notification/send"{:payload_type "notification/card":payload {:card_id card-id@@ -301,7 +304,7 @@[notification {:handlers [{:channel_type "channel/email":recipients [{:type :notification-recipient/user:user_id (mt/user->id :crowberto)}]}]}]- (is (=? "invalid template"+ (is (=? rejected(mt/user-http-request :crowberto :put 400 (format "notification/%d" (:id notification))(update notification :handlers(fn [[handler]]diff --git a/test/metabase/pulse/api/pulse_test.clj b/test/metabase/pulse/api/pulse_test.cljindex 827b0ff426e..64cb2554b16 100644--- a/test/metabase/pulse/api/pulse_test.clj+++ b/test/metabase/pulse/api/pulse_test.clj@@ -128,24 +128,24 @@{:name "abc":cards ["abc"]}{:errors {:cards "value must be a map with the keys `include_csv`, `include_xls`, and `dashboard_card_id`.",- :channels "one or more map"}}+ :channels #(str/starts-with? % "one or more map")}}{:name "abc":cards [{:id 100, :include_csv false, :include_xls false, :dashboard_card_id nil}{:id 200, :include_csv false, :include_xls false, :dashboard_card_id nil}]}- {:errors {:channels "one or more map"}}+ {:errors {:channels #(str/starts-with? % "one or more map")}}{:name "abc":cards [{:id 100, :include_csv false, :include_xls false, :dashboard_card_id nil}{:id 200, :include_csv false, :include_xls false, :dashboard_card_id nil}]:channels "foobar"}- {:errors {:channels "one or more map"}}+ {:errors {:channels #(str/starts-with? % "one or more map")}}{:name "abc":cards [{:id 100, :include_csv false, :include_xls false, :dashboard_card_id nil}{:id 200, :include_csv false, :include_xls false, :dashboard_card_id nil}]:channels ["abc"]}- {:errors {:channels "one or more map"}}}]+ {:errors {:channels #(str/starts-with? % "one or more map")}}}](testing (pr-str input)(is (=? expected-error(mt/user-http-request :rasta :post 400 "pulse" input))))))@@ -464,13 +464,13 @@{:errors {:cards "value must be a map with the keys `include_csv`, `include_xls`, and `dashboard_card_id`."}}{:channels 123}- {:errors {:channels "nullable one or more map"}}+ {:errors {:channels #(str/starts-with? % "nullable one or more map")}}{:channels "foobar"}- {:errors {:channels "nullable one or more map"}}+ {:errors {:channels #(str/starts-with? % "nullable one or more map")}}{:channels ["abc"]}- {:errors {:channels "nullable one or more map"}}}]+ {:errors {:channels #(str/starts-with? % "nullable one or more map")}}}](testing (pr-str input)(is (=? expected-error(mt/user-http-request :rasta :put 400 "pulse/1" input)))))))@@ -481,7 +481,7 @@:model/PulseChannel pc {:pulse_id (u/the-id pulse)}:model/PulseChannelRecipient _ {:pulse_channel_id (u/the-id pc) :user_id (mt/user->id :rasta)}:model/Card card {}]- (let [filter-params [{:id "123abc", :name "species", :type "string"}]]+ (let [filter-params [{:id "123abc", :name "species", :type "string/="}]](with-pulses-in-writeable-collection! [pulse](api.card-test/with-cards-in-readable-collection! [card](is (= (mergediff --git a/test/metabase/segments/api_test.clj b/test/metabase/segments/api_test.cljindex 21690384cd8..728b7c98cb5 100644--- a/test/metabase/segments/api_test.clj+++ b/test/metabase/segments/api_test.clj@@ -137,7 +137,7 @@(is (=? {:errors {:revision_message "value must be a non-blank string."}}(mt/user-http-request :crowberto :put 400 "segment/1" {:name "abc":revision_message ""})))- (is (=? {:errors {:definition "nullable map"}}+ (is (=? {:errors {:definition "nullable Value must be a map."}}(mt/user-http-request :crowberto :put 400 "segment/1" {:name "abc":revision_message "123":definition "foobar"})))))diff --git a/test/metabase/users_rest/api_test.clj b/test/metabase/users_rest/api_test.cljindex 336ea2f95b8..3a0f3738fd5 100644--- a/test/metabase/users_rest/api_test.clj+++ b/test/metabase/users_rest/api_test.clj@@ -1,6 +1,7 @@(ns metabase.users-rest.api-test"Tests for /api/user endpoints."(:require+ [clojure.string :as str][clojure.test :refer :all][metabase.api.response :as api.response][metabase.collections.models.collection :as collection]@@ -1091,29 +1092,21 @@:last_name "User":email "[email protected]":is_superuser true}]- (is (= {:specific-errors {:login_attributes {(keyword "@foo") ["login attribute keys must not start with `@`, received: \"@foo\""]}},- :errors- {:login_attributes- {(keyword "@foo")- "nullable map from <login attribute keys must be a keyword or string, and login attribute keys must not start with `@`> to <anything>"}}}- (mt/user-http-request :crowberto :put 400 (str "user/" user-id)- {:email "[email protected]"- :login_attributes {"@foo" "foo"}}))))))+ (is (=? {:errors {:login_attributes #(str/includes? % "must not start with `@`")}}+ (mt/user-http-request :crowberto :put 400 (str "user/" user-id)+ {:email "[email protected]"+ :login_attributes {"@foo" "foo"}}))))))(testing "POST /api/user"(let [user-name (mt/random-name)email (mt/random-email)](mt/with-model-cleanup [:model/User](mt/with-fake-inbox- (is (= {:specific-errors {:login_attributes {(keyword "@foo") ["login attribute keys must not start with `@`, received: \"@foo\""]}},- :errors- {:login_attributes- {(keyword "@foo")- "nullable map from <login attribute keys must be a keyword or string, and login attribute keys must not start with `@`> to <anything>"}}}- (mt/user-http-request :crowberto :post 400 "user"- {:first_name user-name- :last_name user-name- :email email- :login_attributes {"@foo" "bar"}}))))))))+ (is (=? {:errors {:login_attributes #(str/includes? % "must not start with `@`")}}+ (mt/user-http-request :crowberto :post 400 "user"+ {:first_name user-name+ :last_name user-name+ :email email+ :login_attributes {"@foo" "bar"}}))))))))(deftest ^:parallel updated-user-name-test(testing "Test that `metabase.users-rest.api/updated-user-name` works as intended."diff --git a/test/metabase/util/malli/humanize_test.cljc b/test/metabase/util/malli/humanize_test.cljcindex ec3cdaa1b50..bf76a287d71 100644--- a/test/metabase/util/malli/humanize_test.cljc+++ b/test/metabase/util/malli/humanize_test.cljc@@ -174,12 +174,10 @@(f error));; not sure why these errors are repeated.me/humanize- {:stages [{:joins [{:stages [{:lib/type ["missing required key"]- :malli/error ["Invalid stage :lib/type: expected :mbql.stage/native or :mbql.stage/mbql"- "Invalid stage :lib/type: expected :mbql.stage/native or :mbql.stage/mbql"]}]+ {:stages [{:joins [{:stages [["Invalid stage :lib/type: expected :mbql.stage/native or :mbql.stage/mbql"+ "Invalid stage :lib/type: expected :mbql.stage/native or :mbql.stage/mbql"]]:alias ["missing required key"]}]}]}mu.humanize/humanize- {:stages [{:joins [{:stages- [[{:lib/type "missing required key"} "Invalid stage :lib/type: expected :mbql.stage/native or :mbql.stage/mbql"]],- :alias "missing required key"}]}]})))+ {:stages [{:joins [{:stages ["Invalid stage :lib/type: expected :mbql.stage/native or :mbql.stage/mbql"]+ :alias "missing required key"}]}]})))diff --git a/test/metabase/warehouses_rest/api_test.clj b/test/metabase/warehouses_rest/api_test.cljindex 6d72e565abd..c6ad98fbc20 100644--- a/test/metabase/warehouses_rest/api_test.clj+++ b/test/metabase/warehouses_rest/api_test.clj@@ -626,24 +626,23 @@(let [curr-db (t2/select-one [:model/Database :cache_ttl], :id db-id)](is (= nil (:cache_ttl curr-db))))))))))-(deftest reject-is-stub-in-create-test- (testing "POST /api/database rejects :is_stub in the request body (advanced-config only path)"+(deftest ignore-is-stub-in-create-test+ (testing "POST /api/database ignores :is_stub in the request body (advanced-config only path)"(mt/with-model-cleanup [:model/Database](with-redefs [driver/available? (constantly true)driver/can-connect? (constantly true)]- (is (re-find #"is_stub"- (mt/user-http-request :crowberto :post 400 "database"- {:name (mt/random-name)- :engine (u/qualified-name ::test-driver)- :details {:db "my_db"}- :is_stub true})))))))--(deftest reject-is-stub-in-update-test- (testing "PUT /api/database/:id rejects :is_stub=true in the request body"+ (let [{:keys [id]} (mt/user-http-request :crowberto :post 200 "database"+ {:name (mt/random-name)+ :engine (u/qualified-name ::test-driver)+ :details {:db "my_db"}+ :is_stub true})]+ (is (false? (t2/select-one-fn :is_stub :model/Database :id id))))))))++(deftest ignore-is-stub-in-update-test+ (testing "PUT /api/database/:id ignores :is_stub=true in the request body"(mt/with-temp [:model/Database {db-id :id} {:engine ::test-driver}]- (is (re-find #"is_stub"- (mt/user-http-request :crowberto :put 400 (format "database/%d" db-id)- {:is_stub true})))+ (mt/user-http-request :crowberto :put 200 (format "database/%d" db-id)+ {:is_stub true})(testing "the row is unchanged"(is (false? (t2/select-one-fn :is_stub :model/Database :id db-id))))))(testing "PUT /api/database/:id passes when :is_stub=false is in the body (no-op, matches default)"