Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(devex): strip default:null from frontend zod codegen (#61256)

Julian Bez7b7bcbc28c7a
diff --git a/products/alerts/frontend/generated/api.zod.ts b/products/alerts/frontend/generated/api.zod.ts
index d92d15929544..d3581bd8f80d 100644
--- a/products/alerts/frontend/generated/api.zod.ts
+++ b/products/alerts/frontend/generated/api.zod.ts
@@ -24,6 +24,1049 @@ export const AlertsPartialUpdateBody = /* @__PURE__ */ zod
/**
* Simulate a detector on an insight's historical data. Read-only — no AlertCheck records are created.
*/
-export const AlertsSimulateCreateBody = /* @__PURE__ */ zod
- .record(zod.string(), zod.unknown())
- .describe('Deep\/recursive schema (opaque in Zod — use TypeScript types for full shape)')
+export const alertsSimulateCreateBodyDetectorConfigOneOneDetectorsItemOneTypeDefault = `zscore`
+export const alertsSimulateCreateBodyDetectorConfigOneOneDetectorsItemTwoTypeDefault = `mad`
+export const alertsSimulateCreateBodyDetectorConfigOneOneDetectorsItemThreeTypeDefault = `iqr`
+export const alertsSimulateCreateBodyDetectorConfigOneOneDetectorsItemFourTypeDefault = `threshold`
+export const alertsSimulateCreateBodyDetectorConfigOneOneDetectorsItemFiveTypeDefault = `ecod`
+export const alertsSimulateCreateBodyDetectorConfigOneOneDetectorsItemSixTypeDefault = `copod`
+export const alertsSimulateCreateBodyDetectorConfigOneOneDetectorsItemSevenTypeDefault = `isolation_forest`
+export const alertsSimulateCreateBodyDetectorConfigOneOneDetectorsItemEightTypeDefault = `knn`
+export const alertsSimulateCreateBodyDetectorConfigOneOneDetectorsItemNineTypeDefault = `hbos`
+export const alertsSimulateCreateBodyDetectorConfigOneOneDetectorsItemOnezeroTypeDefault = `lof`
+export const alertsSimulateCreateBodyDetectorConfigOneOneDetectorsItemOneoneTypeDefault = `ocsvm`
+export const alertsSimulateCreateBodyDetectorConfigOneOneDetectorsItemOnetwoTypeDefault = `pca`
+export const alertsSimulateCreateBodyDetectorConfigOneOneTypeDefault = `ensemble`
+export const alertsSimulateCreateBodyDetectorConfigOneTwoTypeDefault = `zscore`
+export const alertsSimulateCreateBodyDetectorConfigOneThreeTypeDefault = `mad`
+export const alertsSimulateCreateBodyDetectorConfigOneFourTypeDefault = `iqr`
+export const alertsSimulateCreateBodyDetectorConfigOneFiveTypeDefault = `threshold`
+export const alertsSimulateCreateBodyDetectorConfigOneSixTypeDefault = `ecod`
+export const alertsSimulateCreateBodyDetectorConfigOneSevenTypeDefault = `copod`
+export const alertsSimulateCreateBodyDetectorConfigOneEightTypeDefault = `isolation_forest`
+export const alertsSimulateCreateBodyDetectorConfigOneNineTypeDefault = `knn`
+export const alertsSimulateCreateBodyDetectorConfigOneOnezeroTypeDefault = `hbos`
+export const alertsSimulateCreateBodyDetectorConfigOneOneoneTypeDefault = `lof`
+export const alertsSimulateCreateBodyDetectorConfigOneOnetwoTypeDefault = `ocsvm`
+export const alertsSimulateCreateBodyDetectorConfigOneOnethreeTypeDefault = `pca`
+export const alertsSimulateCreateBodySeriesIndexDefault = 0
+
+export const AlertsSimulateCreateBody = /* @__PURE__ */ zod.object({
+ insight: zod.number().describe('Insight ID to simulate the detector on.'),
+ detector_config: zod
+ .union([
+ zod.object({
+ detectors: zod
+ .array(
+ zod.union([
+ zod.object({
+ preprocessing: zod
+ .union([
+ zod.object({
+ diffs_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Order of differencing. 0 = raw values, 1 = first-order diffs (default: 0)'
+ ),
+ lags_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Number of lag features. 0 = none, >0 = include n lagged values (default: 0)'
+ ),
+ smooth_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Moving average window size. 0 = no smoothing, >1 = smooth over n points (default: 0)'
+ ),
+ }),
+ zod.null(),
+ ])
+ .optional()
+ .describe('Preprocessing transforms applied before detection'),
+ threshold: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Anomaly probability threshold [0-1]. Points above this probability are flagged (default: 0.9)'
+ ),
+ type: zod
+ .literal('zscore')
+ .default(alertsSimulateCreateBodyDetectorConfigOneOneDetectorsItemOneTypeDefault),
+ window: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Rolling window size for calculating mean\/std (default: 30)'),
+ }),
+ zod.object({
+ preprocessing: zod
+ .union([
+ zod.object({
+ diffs_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Order of differencing. 0 = raw values, 1 = first-order diffs (default: 0)'
+ ),
+ lags_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Number of lag features. 0 = none, >0 = include n lagged values (default: 0)'
+ ),
+ smooth_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Moving average window size. 0 = no smoothing, >1 = smooth over n points (default: 0)'
+ ),
+ }),
+ zod.null(),
+ ])
+ .optional()
+ .describe('Preprocessing transforms applied before detection'),
+ threshold: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Anomaly probability threshold [0-1]. Points above this probability are flagged (default: 0.9)'
+ ),
+ type: zod
+ .literal('mad')
+ .default(alertsSimulateCreateBodyDetectorConfigOneOneDetectorsItemTwoTypeDefault),
+ window: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Rolling window size for calculating median\/MAD (default: 30)'),
+ }),
+ zod.object({
+ multiplier: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'IQR multiplier for fence calculation (default: 1.5, use 3.0 for far outliers)'
+ ),
+ preprocessing: zod
+ .union([
+ zod.object({
+ diffs_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Order of differencing. 0 = raw values, 1 = first-order diffs (default: 0)'
+ ),
+ lags_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Number of lag features. 0 = none, >0 = include n lagged values (default: 0)'
+ ),
+ smooth_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Moving average window size. 0 = no smoothing, >1 = smooth over n points (default: 0)'
+ ),
+ }),
+ zod.null(),
+ ])
+ .optional()
+ .describe('Preprocessing transforms applied before detection'),
+ type: zod
+ .literal('iqr')
+ .default(alertsSimulateCreateBodyDetectorConfigOneOneDetectorsItemThreeTypeDefault),
+ window: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Rolling window size for calculating quartiles (default: 30)'),
+ }),
+ zod.object({
+ lower_bound: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Lower bound - values below this are anomalies'),
+ preprocessing: zod
+ .union([
+ zod.object({
+ diffs_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Order of differencing. 0 = raw values, 1 = first-order diffs (default: 0)'
+ ),
+ lags_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Number of lag features. 0 = none, >0 = include n lagged values (default: 0)'
+ ),
+ smooth_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Moving average window size. 0 = no smoothing, >1 = smooth over n points (default: 0)'
+ ),
+ }),
+ zod.null(),
+ ])
+ .optional()
+ .describe('Preprocessing transforms applied before detection'),
+ type: zod
+ .literal('threshold')
+ .default(alertsSimulateCreateBodyDetectorConfigOneOneDetectorsItemFourTypeDefault),
+ upper_bound: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Upper bound - values above this are anomalies'),
+ }),
+ zod.object({
+ preprocessing: zod
+ .union([
+ zod.object({
+ diffs_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Order of differencing. 0 = raw values, 1 = first-order diffs (default: 0)'
+ ),
+ lags_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Number of lag features. 0 = none, >0 = include n lagged values (default: 0)'
+ ),
+ smooth_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Moving average window size. 0 = no smoothing, >1 = smooth over n points (default: 0)'
+ ),
+ }),
+ zod.null(),
+ ])
+ .optional()
+ .describe('Preprocessing transforms applied before detection'),
+ threshold: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Anomaly probability threshold (default: 0.9)'),
+ type: zod
+ .literal('ecod')
+ .default(alertsSimulateCreateBodyDetectorConfigOneOneDetectorsItemFiveTypeDefault),
+ window: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Rolling window size — how many historical data points to train on (default: based on calculation interval)'
+ ),
+ }),
+ zod.object({
+ preprocessing: zod
+ .union([
+ zod.object({
+ diffs_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Order of differencing. 0 = raw values, 1 = first-order diffs (default: 0)'
+ ),
+ lags_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Number of lag features. 0 = none, >0 = include n lagged values (default: 0)'
+ ),
+ smooth_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Moving average window size. 0 = no smoothing, >1 = smooth over n points (default: 0)'
+ ),
+ }),
+ zod.null(),
+ ])
+ .optional()
+ .describe('Preprocessing transforms applied before detection'),
+ threshold: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Anomaly probability threshold (default: 0.9)'),
+ type: zod
+ .literal('copod')
+ .default(alertsSimulateCreateBodyDetectorConfigOneOneDetectorsItemSixTypeDefault),
+ window: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Rolling window size — how many historical data points to train on (default: based on calculation interval)'
+ ),
+ }),
+ zod.object({
+ n_estimators: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Number of trees in the forest (default: 100)'),
+ preprocessing: zod
+ .union([
+ zod.object({
+ diffs_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Order of differencing. 0 = raw values, 1 = first-order diffs (default: 0)'
+ ),
+ lags_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Number of lag features. 0 = none, >0 = include n lagged values (default: 0)'
+ ),
+ smooth_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Moving average window size. 0 = no smoothing, >1 = smooth over n points (default: 0)'
+ ),
+ }),
+ zod.null(),
+ ])
+ .optional()
+ .describe('Preprocessing transforms applied before detection'),
+ threshold: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Anomaly probability threshold (default: 0.9)'),
+ type: zod
+ .literal('isolation_forest')
+ .default(alertsSimulateCreateBodyDetectorConfigOneOneDetectorsItemSevenTypeDefault),
+ window: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Rolling window size — how many historical data points to train on (default: based on calculation interval)'
+ ),
+ }),
+ zod.object({
+ method: zod
+ .union([zod.enum(['largest', 'mean', 'median']), zod.null()])
+ .optional()
+ .describe("Distance method: 'largest', 'mean', 'median' (default: 'largest')"),
+ n_neighbors: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Number of neighbors to consider (default: 5)'),
+ preprocessing: zod
+ .union([
+ zod.object({
+ diffs_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Order of differencing. 0 = raw values, 1 = first-order diffs (default: 0)'
+ ),
+ lags_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Number of lag features. 0 = none, >0 = include n lagged values (default: 0)'
+ ),
+ smooth_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Moving average window size. 0 = no smoothing, >1 = smooth over n points (default: 0)'
+ ),
+ }),
+ zod.null(),
+ ])
+ .optional()
+ .describe('Preprocessing transforms applied before detection'),
+ threshold: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Anomaly probability threshold (default: 0.9)'),
+ type: zod
+ .literal('knn')
+ .default(alertsSimulateCreateBodyDetectorConfigOneOneDetectorsItemEightTypeDefault),
+ window: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Rolling window size — how many historical data points to train on (default: based on calculation interval)'
+ ),
+ }),
+ zod.object({
+ n_bins: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Number of histogram bins (default: 10)'),
+ preprocessing: zod
+ .union([
+ zod.object({
+ diffs_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Order of differencing. 0 = raw values, 1 = first-order diffs (default: 0)'
+ ),
+ lags_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Number of lag features. 0 = none, >0 = include n lagged values (default: 0)'
+ ),
+ smooth_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Moving average window size. 0 = no smoothing, >1 = smooth over n points (default: 0)'
+ ),
+ }),
+ zod.null(),
+ ])
+ .optional()
+ .describe('Preprocessing transforms applied before detection'),
+ threshold: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Anomaly probability threshold (default: 0.9)'),
+ type: zod
+ .literal('hbos')
+ .default(alertsSimulateCreateBodyDetectorConfigOneOneDetectorsItemNineTypeDefault),
+ window: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Rolling window size — how many historical data points to train on (default: based on calculation interval)'
+ ),
+ }),
+ zod.object({
+ n_neighbors: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Number of neighbors for LOF (default: 20)'),
+ preprocessing: zod
+ .union([
+ zod.object({
+ diffs_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Order of differencing. 0 = raw values, 1 = first-order diffs (default: 0)'
+ ),
+ lags_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Number of lag features. 0 = none, >0 = include n lagged values (default: 0)'
+ ),
+ smooth_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Moving average window size. 0 = no smoothing, >1 = smooth over n points (default: 0)'
+ ),
+ }),
+ zod.null(),
+ ])
+ .optional()
+ .describe('Preprocessing transforms applied before detection'),
+ threshold: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Anomaly probability threshold (default: 0.9)'),
+ type: zod
+ .literal('lof')
+ .default(
+ alertsSimulateCreateBodyDetectorConfigOneOneDetectorsItemOnezeroTypeDefault
+ ),
+ window: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Rolling window size — how many historical data points to train on (default: based on calculation interval)'
+ ),
+ }),
+ zod.object({
+ kernel: zod
+ .union([zod.string(), zod.null()])
+ .optional()
+ .describe('SVM kernel type (default: \"rbf\")'),
+ nu: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Upper bound on training errors fraction (default: 0.1)'),
+ preprocessing: zod
+ .union([
+ zod.object({
+ diffs_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Order of differencing. 0 = raw values, 1 = first-order diffs (default: 0)'
+ ),
+ lags_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Number of lag features. 0 = none, >0 = include n lagged values (default: 0)'
+ ),
+ smooth_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Moving average window size. 0 = no smoothing, >1 = smooth over n points (default: 0)'
+ ),
+ }),
+ zod.null(),
+ ])
+ .optional()
+ .describe('Preprocessing transforms applied before detection'),
+ threshold: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Anomaly probability threshold (default: 0.9)'),
+ type: zod
+ .literal('ocsvm')
+ .default(
+ alertsSimulateCreateBodyDetectorConfigOneOneDetectorsItemOneoneTypeDefault
+ ),
+ window: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Rolling window size — how many historical data points to train on (default: based on calculation interval)'
+ ),
+ }),
+ zod.object({
+ preprocessing: zod
+ .union([
+ zod.object({
+ diffs_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Order of differencing. 0 = raw values, 1 = first-order diffs (default: 0)'
+ ),
+ lags_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Number of lag features. 0 = none, >0 = include n lagged values (default: 0)'
+ ),
+ smooth_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Moving average window size. 0 = no smoothing, >1 = smooth over n points (default: 0)'
+ ),
+ }),
+ zod.null(),
+ ])
+ .optional()
+ .describe('Preprocessing transforms applied before detection'),
+ threshold: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Anomaly probability threshold (default: 0.9)'),
+ type: zod
+ .literal('pca')
+ .default(
+ alertsSimulateCreateBodyDetectorConfigOneOneDetectorsItemOnetwoTypeDefault
+ ),
+ window: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Rolling window size — how many historical data points to train on (default: based on calculation interval)'
+ ),
+ }),
+ ])
+ )
+ .describe('Sub-detector configurations (minimum 2)'),
+ operator: zod.enum(['and', 'or']).describe('How to combine sub-detector results'),
+ type: zod.literal('ensemble').default(alertsSimulateCreateBodyDetectorConfigOneOneTypeDefault),
+ }),
+ zod.object({
+ preprocessing: zod
+ .union([
+ zod.object({
+ diffs_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Order of differencing. 0 = raw values, 1 = first-order diffs (default: 0)'),
+ lags_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Number of lag features. 0 = none, >0 = include n lagged values (default: 0)'
+ ),
+ smooth_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Moving average window size. 0 = no smoothing, >1 = smooth over n points (default: 0)'
+ ),
+ }),
+ zod.null(),
+ ])
+ .optional()
+ .describe('Preprocessing transforms applied before detection'),
+ threshold: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Anomaly probability threshold [0-1]. Points above this probability are flagged (default: 0.9)'
+ ),
+ type: zod.literal('zscore').default(alertsSimulateCreateBodyDetectorConfigOneTwoTypeDefault),
+ window: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Rolling window size for calculating mean\/std (default: 30)'),
+ }),
+ zod.object({
+ preprocessing: zod
+ .union([
+ zod.object({
+ diffs_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Order of differencing. 0 = raw values, 1 = first-order diffs (default: 0)'),
+ lags_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Number of lag features. 0 = none, >0 = include n lagged values (default: 0)'
+ ),
+ smooth_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Moving average window size. 0 = no smoothing, >1 = smooth over n points (default: 0)'
+ ),
+ }),
+ zod.null(),
+ ])
+ .optional()
+ .describe('Preprocessing transforms applied before detection'),
+ threshold: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Anomaly probability threshold [0-1]. Points above this probability are flagged (default: 0.9)'
+ ),
+ type: zod.literal('mad').default(alertsSimulateCreateBodyDetectorConfigOneThreeTypeDefault),
+ window: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Rolling window size for calculating median\/MAD (default: 30)'),
+ }),
+ zod.object({
+ multiplier: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('IQR multiplier for fence calculation (default: 1.5, use 3.0 for far outliers)'),
+ preprocessing: zod
+ .union([
+ zod.object({
+ diffs_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Order of differencing. 0 = raw values, 1 = first-order diffs (default: 0)'),
+ lags_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Number of lag features. 0 = none, >0 = include n lagged values (default: 0)'
+ ),
+ smooth_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Moving average window size. 0 = no smoothing, >1 = smooth over n points (default: 0)'
+ ),
+ }),
+ zod.null(),
+ ])
+ .optional()
+ .describe('Preprocessing transforms applied before detection'),
+ type: zod.literal('iqr').default(alertsSimulateCreateBodyDetectorConfigOneFourTypeDefault),
+ window: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Rolling window size for calculating quartiles (default: 30)'),
+ }),
+ zod.object({
+ lower_bound: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Lower bound - values below this are anomalies'),
+ preprocessing: zod
+ .union([
+ zod.object({
+ diffs_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Order of differencing. 0 = raw values, 1 = first-order diffs (default: 0)'),
+ lags_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Number of lag features. 0 = none, >0 = include n lagged values (default: 0)'
+ ),
+ smooth_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Moving average window size. 0 = no smoothing, >1 = smooth over n points (default: 0)'
+ ),
+ }),
+ zod.null(),
+ ])
+ .optional()
+ .describe('Preprocessing transforms applied before detection'),
+ type: zod.literal('threshold').default(alertsSimulateCreateBodyDetectorConfigOneFiveTypeDefault),
+ upper_bound: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Upper bound - values above this are anomalies'),
+ }),
+ zod.object({
+ preprocessing: zod
+ .union([
+ zod.object({
+ diffs_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Order of differencing. 0 = raw values, 1 = first-order diffs (default: 0)'),
+ lags_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Number of lag features. 0 = none, >0 = include n lagged values (default: 0)'
+ ),
+ smooth_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Moving average window size. 0 = no smoothing, >1 = smooth over n points (default: 0)'
+ ),
+ }),
+ zod.null(),
+ ])
+ .optional()
+ .describe('Preprocessing transforms applied before detection'),
+ threshold: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Anomaly probability threshold (default: 0.9)'),
+ type: zod.literal('ecod').default(alertsSimulateCreateBodyDetectorConfigOneSixTypeDefault),
+ window: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Rolling window size — how many historical data points to train on (default: based on calculation interval)'
+ ),
+ }),
+ zod.object({
+ preprocessing: zod
+ .union([
+ zod.object({
+ diffs_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Order of differencing. 0 = raw values, 1 = first-order diffs (default: 0)'),
+ lags_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Number of lag features. 0 = none, >0 = include n lagged values (default: 0)'
+ ),
+ smooth_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Moving average window size. 0 = no smoothing, >1 = smooth over n points (default: 0)'
+ ),
+ }),
+ zod.null(),
+ ])
+ .optional()
+ .describe('Preprocessing transforms applied before detection'),
+ threshold: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Anomaly probability threshold (default: 0.9)'),
+ type: zod.literal('copod').default(alertsSimulateCreateBodyDetectorConfigOneSevenTypeDefault),
+ window: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Rolling window size — how many historical data points to train on (default: based on calculation interval)'
+ ),
+ }),
+ zod.object({
+ n_estimators: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Number of trees in the forest (default: 100)'),
+ preprocessing: zod
+ .union([
+ zod.object({
+ diffs_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Order of differencing. 0 = raw values, 1 = first-order diffs (default: 0)'),
+ lags_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Number of lag features. 0 = none, >0 = include n lagged values (default: 0)'
+ ),
+ smooth_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Moving average window size. 0 = no smoothing, >1 = smooth over n points (default: 0)'
+ ),
+ }),
+ zod.null(),
+ ])
+ .optional()
+ .describe('Preprocessing transforms applied before detection'),
+ threshold: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Anomaly probability threshold (default: 0.9)'),
+ type: zod
+ .literal('isolation_forest')
+ .default(alertsSimulateCreateBodyDetectorConfigOneEightTypeDefault),
+ window: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Rolling window size — how many historical data points to train on (default: based on calculation interval)'
+ ),
+ }),
+ zod.object({
+ method: zod
+ .union([zod.enum(['largest', 'mean', 'median']), zod.null()])
+ .optional()
+ .describe("Distance method: 'largest', 'mean', 'median' (default: 'largest')"),
+ n_neighbors: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Number of neighbors to consider (default: 5)'),
+ preprocessing: zod
+ .union([
+ zod.object({
+ diffs_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Order of differencing. 0 = raw values, 1 = first-order diffs (default: 0)'),
+ lags_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Number of lag features. 0 = none, >0 = include n lagged values (default: 0)'
+ ),
+ smooth_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Moving average window size. 0 = no smoothing, >1 = smooth over n points (default: 0)'
+ ),
+ }),
+ zod.null(),
+ ])
+ .optional()
+ .describe('Preprocessing transforms applied before detection'),
+ threshold: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Anomaly probability threshold (default: 0.9)'),
+ type: zod.literal('knn').default(alertsSimulateCreateBodyDetectorConfigOneNineTypeDefault),
+ window: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Rolling window size — how many historical data points to train on (default: based on calculation interval)'
+ ),
+ }),
+ zod.object({
+ n_bins: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Number of histogram bins (default: 10)'),
+ preprocessing: zod
+ .union([
+ zod.object({
+ diffs_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Order of differencing. 0 = raw values, 1 = first-order diffs (default: 0)'),
+ lags_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Number of lag features. 0 = none, >0 = include n lagged values (default: 0)'
+ ),
+ smooth_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Moving average window size. 0 = no smoothing, >1 = smooth over n points (default: 0)'
+ ),
+ }),
+ zod.null(),
+ ])
+ .optional()
+ .describe('Preprocessing transforms applied before detection'),
+ threshold: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Anomaly probability threshold (default: 0.9)'),
+ type: zod.literal('hbos').default(alertsSimulateCreateBodyDetectorConfigOneOnezeroTypeDefault),
+ window: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Rolling window size — how many historical data points to train on (default: based on calculation interval)'
+ ),
+ }),
+ zod.object({
+ n_neighbors: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Number of neighbors for LOF (default: 20)'),
+ preprocessing: zod
+ .union([
+ zod.object({
+ diffs_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Order of differencing. 0 = raw values, 1 = first-order diffs (default: 0)'),
+ lags_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Number of lag features. 0 = none, >0 = include n lagged values (default: 0)'
+ ),
+ smooth_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Moving average window size. 0 = no smoothing, >1 = smooth over n points (default: 0)'
+ ),
+ }),
+ zod.null(),
+ ])
+ .optional()
+ .describe('Preprocessing transforms applied before detection'),
+ threshold: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Anomaly probability threshold (default: 0.9)'),
+ type: zod.literal('lof').default(alertsSimulateCreateBodyDetectorConfigOneOneoneTypeDefault),
+ window: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Rolling window size — how many historical data points to train on (default: based on calculation interval)'
+ ),
+ }),
+ zod.object({
+ kernel: zod.union([zod.string(), zod.null()]).optional().describe('SVM kernel type (default: \"rbf\")'),
+ nu: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Upper bound on training errors fraction (default: 0.1)'),
+ preprocessing: zod
+ .union([
+ zod.object({
+ diffs_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Order of differencing. 0 = raw values, 1 = first-order diffs (default: 0)'),
+ lags_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Number of lag features. 0 = none, >0 = include n lagged values (default: 0)'
+ ),
+ smooth_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Moving average window size. 0 = no smoothing, >1 = smooth over n points (default: 0)'
+ ),
+ }),
+ zod.null(),
+ ])
+ .optional()
+ .describe('Preprocessing transforms applied before detection'),
+ threshold: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Anomaly probability threshold (default: 0.9)'),
+ type: zod.literal('ocsvm').default(alertsSimulateCreateBodyDetectorConfigOneOnetwoTypeDefault),
+ window: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Rolling window size — how many historical data points to train on (default: based on calculation interval)'
+ ),
+ }),
+ zod.object({
+ preprocessing: zod
+ .union([
+ zod.object({
+ diffs_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Order of differencing. 0 = raw values, 1 = first-order diffs (default: 0)'),
+ lags_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Number of lag features. 0 = none, >0 = include n lagged values (default: 0)'
+ ),
+ smooth_n: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Moving average window size. 0 = no smoothing, >1 = smooth over n points (default: 0)'
+ ),
+ }),
+ zod.null(),
+ ])
+ .optional()
+ .describe('Preprocessing transforms applied before detection'),
+ threshold: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe('Anomaly probability threshold (default: 0.9)'),
+ type: zod.literal('pca').default(alertsSimulateCreateBodyDetectorConfigOneOnethreeTypeDefault),
+ window: zod
+ .union([zod.number(), zod.null()])
+ .optional()
+ .describe(
+ 'Rolling window size — how many historical data points to train on (default: based on calculation interval)'
+ ),
+ }),
+ ])
+ .describe('Detector configuration types')
+ .describe('Detector configuration to simulate.'),
+ series_index: zod
+ .number()
+ .default(alertsSimulateCreateBodySeriesIndexDefault)
+ .describe('Zero-based index of the series to analyze.'),
+ date_from: zod
+ .string()
+ .nullish()
+ .describe(
+ "Relative date string for how far back to simulate (e.g. '-24h', '-30d', '-4w'). If not provided, uses the detector's minimum required samples."
+ ),
+})
diff --git a/products/logs/frontend/generated/api.zod.ts b/products/logs/frontend/generated/api.zod.ts
index d5f4bfb8bc1f..83ac5b607bad 100644
--- a/products/logs/frontend/generated/api.zod.ts
+++ b/products/logs/frontend/generated/api.zod.ts
@@ -12,7 +12,6 @@ import * as zod from 'zod'
export const logsAlertsCreateBodyNameMax = 255
export const logsAlertsCreateBodyEnabledDefault = true
-
export const logsAlertsCreateBodyThresholdCountDefault = 100
export const logsAlertsCreateBodyThresholdCountMin = 0
@@ -53,16 +52,11 @@ export const LogsAlertsCreateBody = /* @__PURE__ */ zod.object({
}),
zod.null(),
])
- .nullish()
- .default(null),
- serviceNames: zod
- .union([zod.array(zod.string()), zod.null()])
- .nullish()
- .default(null),
+ .optional(),
+ serviceNames: zod.union([zod.array(zod.string()), zod.null()]).optional(),
severityLevels: zod
.union([zod.array(zod.enum(['trace', 'debug', 'info', 'warn', 'error', 'fatal'])), zod.null()])
- .nullish()
- .default(null),
+ .optional(),
})
.optional()
.describe(
@@ -112,7 +106,6 @@ export const LogsAlertsCreateBody = /* @__PURE__ */ zod.object({
export const logsAlertsUpdateBodyNameMax = 255
export const logsAlertsUpdateBodyEnabledDefault = true
-
export const logsAlertsUpdateBodyThresholdCountDefault = 100
export const logsAlertsUpdateBodyThresholdCountMin = 0
@@ -153,16 +146,11 @@ export const LogsAlertsUpdateBody = /* @__PURE__ */ zod.object({
}),
zod.null(),
])
- .nullish()
- .default(null),
- serviceNames: zod
- .union([zod.array(zod.string()), zod.null()])
- .nullish()
- .default(null),
+ .optional(),
+ serviceNames: zod.union([zod.array(zod.string()), zod.null()]).optional(),
severityLevels: zod
.union([zod.array(zod.enum(['trace', 'debug', 'info', 'warn', 'error', 'fatal'])), zod.null()])
- .nullish()
- .default(null),
+ .optional(),
})
.optional()
.describe(
@@ -212,7 +200,6 @@ export const LogsAlertsUpdateBody = /* @__PURE__ */ zod.object({
export const logsAlertsPartialUpdateBodyNameMax = 255
export const logsAlertsPartialUpdateBodyEnabledDefault = true
-
export const logsAlertsPartialUpdateBodyThresholdCountDefault = 100
export const logsAlertsPartialUpdateBodyThresholdCountMin = 0
@@ -253,16 +240,11 @@ export const LogsAlertsPartialUpdateBody = /* @__PURE__ */ zod.object({
}),
zod.null(),
])
- .nullish()
- .default(null),
- serviceNames: zod
- .union([zod.array(zod.string()), zod.null()])
- .nullish()
- .default(null),
+ .optional(),
+ serviceNames: zod.union([zod.array(zod.string()), zod.null()]).optional(),
severityLevels: zod
.union([zod.array(zod.enum(['trace', 'debug', 'info', 'warn', 'error', 'fatal'])), zod.null()])
- .nullish()
- .default(null),
+ .optional(),
})
.optional()
.describe(
@@ -340,7 +322,6 @@ export const LogsAlertsDestinationsDeleteCreateBody = /* @__PURE__ */ zod.object
/**
* Simulate a logs alert on historical data using the full state machine. Read-only — no alert check records are created.
*/
-
export const logsAlertsSimulateCreateBodyThresholdCountMin = 0
export const logsAlertsSimulateCreateBodyCheckIntervalMinutesDefault = 5
@@ -372,16 +353,11 @@ export const LogsAlertsSimulateCreateBody = /* @__PURE__ */ zod.object({
}),
zod.null(),
])
- .nullish()
- .default(null),
- serviceNames: zod
- .union([zod.array(zod.string()), zod.null()])
- .nullish()
- .default(null),
+ .optional(),
+ serviceNames: zod.union([zod.array(zod.string()), zod.null()]).optional(),
severityLevels: zod
.union([zod.array(zod.enum(['trace', 'debug', 'info', 'warn', 'error', 'fatal'])), zod.null()])
- .nullish()
- .default(null),
+ .optional(),
})
.describe('Filter criteria — same format as LogsAlertConfiguration.filters.'),
threshold_count: zod
diff --git a/services/mcp/scripts/generate-orval-schemas.mjs b/services/mcp/scripts/generate-orval-schemas.mjs
index ab8f57eb2d1a..51850b9dd786 100644
--- a/services/mcp/scripts/generate-orval-schemas.mjs
+++ b/services/mcp/scripts/generate-orval-schemas.mjs
@@ -73,61 +73,6 @@ function parseToolDefinition(filePath) {
// OpenAPI post-processing (MCP-specific)
// ------------------------------------------------------------------
-/**
- * Checks if the schema allows null in any of the following ways:
- * - `nullable: true` (OpenAPI 3.0)
- * - `type: 'null'` (OpenAPI 3.1 / JSON Schema)
- * - `type: ['string', 'null']` (OpenAPI 3.1 / JSON Schema)
- * - `anyOf: [{ type: 'string' }, { type: 'null' }]` (OpenAPI 3.1 / JSON Schema)
- * - `oneOf: [{ type: 'string' }, { type: 'null' }]` (OpenAPI 3.1 / JSON Schema)
- */
-function schemaAllowsNull(schema) {
- if (!schema || typeof schema !== 'object') {
- return false
- }
- if (schema.nullable === true || schema.type === 'null') {
- return true
- }
- if (Array.isArray(schema.type) && schema.type.includes('null')) {
- return true
- }
- for (const key of ['anyOf', 'oneOf']) {
- const variants = schema[key]
- if (Array.isArray(variants) && variants.some(schemaAllowsNull)) {
- return true
- }
- }
- return false
-}
-
-/**
- * Strip 'default: null' from nullable properties in OpenAPI schemas.
- *
- * Orval mirrors `default: null` into `.default(null)`, which makes Zod fill the
- * field with `null` whenever the caller omits it (`safeParse` applies defaults).
- * For request schemas that turns "field not sent" into "field sent as null",
- * which the backend then rejects (`extra="forbid"`) or silently overwrites.
- * Removing the null default lets Orval emit a plain `.nullable()` instead, so an
- * omitted field stays omitted while an explicit `null` still parses.
- */
-function stripNullDefaults(obj) {
- if (!obj || typeof obj !== 'object') {
- return obj
- }
- if (Array.isArray(obj)) {
- return obj.map(stripNullDefaults)
- }
- const result = {}
- for (const [key, value] of Object.entries(obj)) {
- // Skip injecting `default: null` if schema permits null
- if (key === 'default' && value === null && schemaAllowsNull(obj)) {
- continue
- }
- result[key] = stripNullDefaults(value)
- }
- return result
-}
-
/**
* Strip `default` values from Patched* (PATCH request body) schemas.
*
@@ -288,12 +233,11 @@ for (const def of definitions) {
}
totalEnabledOps += operationIds.size
- let filtered = filterSchemaByOperationIds(fullSchema, operationIds, { includeResponseSchemas: false })
+ const filtered = filterSchemaByOperationIds(fullSchema, operationIds, { includeResponseSchemas: false })
// Annotate title for easier debugging
filtered.info.title = `${fullSchema.info?.title ?? 'API'} - MCP ${operationIds.size} enabled ops`
- filtered = stripNullDefaults(filtered)
stripDefaultsFromPatchedSchemas(filtered)
stripUuidFormat(filtered)
stripReadOnlyFromRequired(filtered)
diff --git a/services/mcp/src/generated/cohorts/api.ts b/services/mcp/src/generated/cohorts/api.ts
index d73ed57c2779..0c0850e0ac94 100644
--- a/services/mcp/src/generated/cohorts/api.ts
+++ b/services/mcp/src/generated/cohorts/api.ts
@@ -40,9 +40,7 @@ export const cohortsCreateBodyNameMax = 400
export const cohortsCreateBodyDescriptionMax = 1000
export const cohortsCreateBodyFiltersOnePropertiesValuesItemOneNegationDefault = false
-export const cohortsCreateBodyFiltersOnePropertiesValuesItemOneEventFiltersOneItemTwoValueDefault = null
export const cohortsCreateBodyFiltersOnePropertiesValuesItemTwoNegationDefault = false
-export const cohortsCreateBodyFiltersOnePropertiesValuesItemThreeValueDefault = null
export const cohortsCreateBodyFiltersOnePropertiesValuesItemThreeNegationDefault = false
export const cohortsCreateBodyCreateStaticPersonIdsDefault = []
@@ -91,11 +89,7 @@ export const CohortsCreateBody = /* @__PURE__ */ zod.object({
zod.object({
type: zod.literal('hogql'),
key: zod.string(),
- value: zod
- .unknown()
- .default(
- cohortsCreateBodyFiltersOnePropertiesValuesItemOneEventFiltersOneItemTwoValueDefault
- ),
+ value: zod.unknown().optional(),
}),
])
),
@@ -123,9 +117,7 @@ export const CohortsCreateBody = /* @__PURE__ */ zod.object({
type: zod.literal('person'),
key: zod.string(),
operator: zod.union([zod.string(), zod.null()]).optional(),
- value: zod
- .unknown()
- .default(cohortsCreateBodyFiltersOnePropertiesValuesItemThreeValueDefault),
+ value: zod.unknown().optional(),
negation: zod
.boolean()
.default(cohortsCreateBodyFiltersOnePropertiesValuesItemThreeNegationDefault),
@@ -184,9 +176,7 @@ export const cohortsPartialUpdateBodyNameMax = 400
export const cohortsPartialUpdateBodyDescriptionMax = 1000
export const cohortsPartialUpdateBodyFiltersOnePropertiesValuesItemOneNegationDefault = false
-export const cohortsPartialUpdateBodyFiltersOnePropertiesValuesItemOneEventFiltersOneItemTwoValueDefault = null
export const cohortsPartialUpdateBodyFiltersOnePropertiesValuesItemTwoNegationDefault = false
-export const cohortsPartialUpdateBodyFiltersOnePropertiesValuesItemThreeValueDefault = null
export const cohortsPartialUpdateBodyFiltersOnePropertiesValuesItemThreeNegationDefault = false
export const CohortsPartialUpdateBody = /* @__PURE__ */ zod.object({
@@ -237,11 +227,7 @@ export const CohortsPartialUpdateBody = /* @__PURE__ */ zod.object({
zod.object({
type: zod.literal('hogql'),
key: zod.string(),
- value: zod
- .unknown()
- .default(
- cohortsPartialUpdateBodyFiltersOnePropertiesValuesItemOneEventFiltersOneItemTwoValueDefault
- ),
+ value: zod.unknown().optional(),
}),
])
),
@@ -271,11 +257,7 @@ export const CohortsPartialUpdateBody = /* @__PURE__ */ zod.object({
type: zod.literal('person'),
key: zod.string(),
operator: zod.union([zod.string(), zod.null()]).optional(),
- value: zod
- .unknown()
- .default(
- cohortsPartialUpdateBodyFiltersOnePropertiesValuesItemThreeValueDefault
- ),
+ value: zod.unknown().optional(),
negation: zod
.boolean()
.default(
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/cohorts-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/cohorts-create.json
index 0e5a6c358822..5fc423a5eb65 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/cohorts-create.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/cohorts-create.json
@@ -107,9 +107,7 @@
"const": "hogql",
"type": "string"
},
- "value": {
- "default": null
- }
+ "value": {}
},
"required": ["type", "key"],
"type": "object"
@@ -380,9 +378,7 @@
"const": "person",
"type": "string"
},
- "value": {
- "default": null
- }
+ "value": {}
},
"required": ["type", "key"],
"type": "object"
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/cohorts-partial-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/cohorts-partial-update.json
index c3325fda5e12..6a89812af492 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/cohorts-partial-update.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/cohorts-partial-update.json
@@ -110,9 +110,7 @@
"const": "hogql",
"type": "string"
},
- "value": {
- "default": null
- }
+ "value": {}
},
"required": ["type", "key"],
"type": "object"
@@ -383,9 +381,7 @@
"const": "person",
"type": "string"
},
- "value": {
- "default": null
- }
+ "value": {}
},
"required": ["type", "key"],
"type": "object"
diff --git a/tools/openapi-codegen/index.mjs b/tools/openapi-codegen/index.mjs
index 484c44dddb00..de611784d683 100644
--- a/tools/openapi-codegen/index.mjs
+++ b/tools/openapi-codegen/index.mjs
@@ -5,8 +5,10 @@ export {
INT32_MAX,
INT32_MIN,
preprocessSchema,
+ schemaAllowsNull,
SCHEMAS_TO_INLINE,
stripCollidingInlineEnums,
+ stripNullDefaults,
} from './src/preprocess.mjs'
export { formatJs, formatYaml } from './src/format.mjs'
export { runOrvalParallel } from './src/orval.mjs'
diff --git a/tools/openapi-codegen/src/preprocess.mjs b/tools/openapi-codegen/src/preprocess.mjs
index 32129345369f..4155fa9ca1bc 100644
--- a/tools/openapi-codegen/src/preprocess.mjs
+++ b/tools/openapi-codegen/src/preprocess.mjs
@@ -1,7 +1,7 @@
/**
* OpenAPI schema preprocessing to fix known Orval code generation issues.
*
- * Three patterns are handled before handing schemas to Orval:
+ * Four patterns are handled before handing schemas to Orval:
*
* 1. Named schemas that should be inlined (SCHEMAS_TO_INLINE)
* Each entry maps a component name to the inline schema that replaces every
@@ -29,6 +29,15 @@
* validator, which parses bounds as i64 — then reject the overflowed value.
* We clamp any integer schema's min/max/exclusiveMin/exclusiveMax to int32
* range, which is far more than enough for every PostHog identifier.
+ *
+ * 4. `default: null` on null-permitting schemas (stripNullDefaults)
+ * Pydantic emits `default: null` for every `Optional[...] = None` field.
+ * Orval mirrors that into `.default(null)`, which makes Zod fill the field
+ * with `null` whenever the caller omits it (`safeParse` applies defaults).
+ * For request schemas that turns "field not sent" into "field sent as null",
+ * which the backend then rejects (`extra="forbid"`) or silently overwrites.
+ * Removing the null default lets Orval emit a plain `.nullable()` instead,
+ * so an omitted field stays omitted while an explicit `null` still parses.
*/
export const INT32_MIN = -2147483648
@@ -123,6 +132,65 @@ export function clampIntegerBounds(obj) {
}
}
+/**
+ * Returns true when the schema accepts `null` — covers every shape Pydantic
+ * and drf-spectacular emit:
+ * - `nullable: true` (OpenAPI 3.0)
+ * - `type: 'null'` (OpenAPI 3.1 / JSON Schema)
+ * - `type: ['string', 'null']` (OpenAPI 3.1 type-array form)
+ * - `anyOf` / `oneOf` with a null variant (OpenAPI 3.1 union form)
+ * - Untyped `typing.Any` — Pydantic emits a bare `{}` (no type, no $ref, no
+ * variants, no enum, no properties) which accepts every value including null.
+ *
+ * A schema with `allOf` is treated as constrained (intersection of refs), so
+ * `{ allOf: [{ $ref: '...' }], default: null }` does NOT match — fall back to
+ * the explicit nullable keys above when the constituent permits null.
+ */
+export function schemaAllowsNull(schema) {
+ if (!schema || typeof schema !== 'object') {
+ return false
+ }
+ if (schema.nullable === true || schema.type === 'null') {
+ return true
+ }
+ if (Array.isArray(schema.type) && schema.type.includes('null')) {
+ return true
+ }
+ for (const key of ['anyOf', 'oneOf']) {
+ const variants = schema[key]
+ if (Array.isArray(variants) && variants.some(schemaAllowsNull)) {
+ return true
+ }
+ }
+ const constrained = ['type', 'allOf', 'anyOf', 'oneOf', '$ref', 'enum', 'const', 'properties']
+ if (constrained.every((key) => !(key in schema))) {
+ return true
+ }
+ return false
+}
+
+/**
+ * Strip `default: null` from any schema that already permits null. See the
+ * file-level doc for why this matters. Mutates in place.
+ */
+export function stripNullDefaults(obj) {
+ if (!obj || typeof obj !== 'object') {
+ return
+ }
+ if (Array.isArray(obj)) {
+ for (const item of obj) {
+ stripNullDefaults(item)
+ }
+ return
+ }
+ if ('default' in obj && obj.default === null && schemaAllowsNull(obj)) {
+ delete obj.default
+ }
+ for (const value of Object.values(obj)) {
+ stripNullDefaults(value)
+ }
+}
+
/**
* Run standard preprocessing on a full OpenAPI schema.
* Mutates the schema in place, also returns it for convenience.
@@ -134,5 +202,6 @@ export function preprocessSchema(schema) {
}
stripCollidingInlineEnums(schema)
clampIntegerBounds(schema)
+ stripNullDefaults(schema)
return schema
}
diff --git a/tools/openapi-codegen/tests/preprocess.test.mjs b/tools/openapi-codegen/tests/preprocess.test.mjs
index 4e429263d51b..e49bf3132690 100644
--- a/tools/openapi-codegen/tests/preprocess.test.mjs
+++ b/tools/openapi-codegen/tests/preprocess.test.mjs
@@ -1,6 +1,13 @@
import { describe, expect, it } from 'vitest'
-import { clampIntegerBounds, INT32_MAX, INT32_MIN, preprocessSchema } from '../src/preprocess.mjs'
+import {
+ clampIntegerBounds,
+ INT32_MAX,
+ INT32_MIN,
+ preprocessSchema,
+ schemaAllowsNull,
+ stripNullDefaults,
+} from '../src/preprocess.mjs'
describe('clampIntegerBounds', () => {
it('clamps i64 bounds to int32 range on a type: integer schema', () => {
@@ -93,6 +100,100 @@ describe('clampIntegerBounds', () => {
})
})
+describe('schemaAllowsNull', () => {
+ it.each([
+ ['nullable: true', { nullable: true }],
+ ['type: null', { type: 'null' }],
+ ['type array with null', { type: ['string', 'null'] }],
+ ['anyOf with null variant', { anyOf: [{ type: 'string' }, { type: 'null' }] }],
+ ['oneOf with null variant', { oneOf: [{ type: 'integer' }, { type: 'null' }] }],
+ ['nested anyOf with null', { anyOf: [{ anyOf: [{ type: 'null' }] }] }],
+ ['untyped Any (bare object)', {}],
+ ['untyped Any with title only', { title: 'Value' }],
+ ])('returns true for %s', (_label, schema) => {
+ expect(schemaAllowsNull(schema)).toBe(true)
+ })
+
+ it.each([
+ ['plain string', { type: 'string' }],
+ ['$ref', { $ref: '#/components/schemas/Foo' }],
+ ['enum without null', { enum: ['a', 'b'] }],
+ ['const', { const: 42 }],
+ ['object with properties', { properties: { id: { type: 'integer' } } }],
+ ['anyOf without null', { anyOf: [{ type: 'string' }, { type: 'integer' }] }],
+ ['allOf with $ref', { allOf: [{ $ref: '#/components/schemas/Foo' }] }],
+ ])('returns false for %s', (_label, schema) => {
+ expect(schemaAllowsNull(schema)).toBe(false)
+ })
+
+ it('returns false for non-objects', () => {
+ expect(schemaAllowsNull(null)).toBe(false)
+ expect(schemaAllowsNull(undefined)).toBe(false)
+ expect(schemaAllowsNull('string')).toBe(false)
+ expect(schemaAllowsNull(42)).toBe(false)
+ })
+})
+
+describe('stripNullDefaults', () => {
+ it('drops default:null from a 3.1 anyOf-null property', () => {
+ const schema = {
+ anyOf: [{ type: 'string' }, { type: 'null' }],
+ default: null,
+ title: 'Label',
+ }
+ stripNullDefaults(schema)
+ expect(schema).toEqual({
+ anyOf: [{ type: 'string' }, { type: 'null' }],
+ title: 'Label',
+ })
+ })
+
+ it('drops default:null from a 3.0 nullable property', () => {
+ const schema = { type: 'string', nullable: true, default: null }
+ stripNullDefaults(schema)
+ expect(schema).toEqual({ type: 'string', nullable: true })
+ })
+
+ it('drops default:null from an untyped Any property', () => {
+ const schema = { default: null, title: 'Value' }
+ stripNullDefaults(schema)
+ expect(schema).toEqual({ title: 'Value' })
+ })
+
+ it('leaves default:null on a non-nullable typed property alone', () => {
+ const schema = { type: 'string', default: null }
+ stripNullDefaults(schema)
+ expect(schema).toEqual({ type: 'string', default: null })
+ })
+
+ it('leaves non-null defaults alone', () => {
+ const schema = { type: 'string', default: 'hello' }
+ stripNullDefaults(schema)
+ expect(schema).toEqual({ type: 'string', default: 'hello' })
+ })
+
+ it('recurses into nested properties', () => {
+ const schema = {
+ type: 'object',
+ properties: {
+ label: { anyOf: [{ type: 'string' }, { type: 'null' }], default: null },
+ value: { default: null, title: 'Value' },
+ name: { type: 'string' },
+ },
+ }
+ stripNullDefaults(schema)
+ expect(schema.properties.label).toEqual({ anyOf: [{ type: 'string' }, { type: 'null' }] })
+ expect(schema.properties.value).toEqual({ title: 'Value' })
+ expect(schema.properties.name).toEqual({ type: 'string' })
+ })
+
+ it('is a no-op on null / undefined / primitives', () => {
+ expect(() => stripNullDefaults(null)).not.toThrow()
+ expect(() => stripNullDefaults(undefined)).not.toThrow()
+ expect(() => stripNullDefaults(42)).not.toThrow()
+ })
+})
+
describe('preprocessSchema', () => {
it('clamps integer bounds inside a full OpenAPI document', () => {
const spec = {