From e94193562622ff2ea1a7357a2158f3bb14fe632b Mon Sep 17 00:00:00 2001 From: Alex McKinney Date: Tue, 7 May 2024 11:50:54 -0400 Subject: [PATCH] (fix, openapi): Recursively visit nested anyOf schemas (#3536) --- .../__snapshots__/hookdeck.test.ts.snap | 594 +-------- .../__snapshots__/hookdeck.test.ts.snap | 1157 +---------------- .../src/schema/convertSchemas.ts | 31 +- 3 files changed, 140 insertions(+), 1642 deletions(-) diff --git a/packages/cli/openapi-ir-to-fern/src/__test__/__snapshots__/hookdeck.test.ts.snap b/packages/cli/openapi-ir-to-fern/src/__test__/__snapshots__/hookdeck.test.ts.snap index 45a732a7d33..238116520c2 100644 --- a/packages/cli/openapi-ir-to-fern/src/__test__/__snapshots__/hookdeck.test.ts.snap +++ b/packages/cli/openapi-ir-to-fern/src/__test__/__snapshots__/hookdeck.test.ts.snap @@ -1921,34 +1921,13 @@ exports[`open api parser hookdeck docs 1`] = ` "id": "id", "name": "name", "paused_at": "2024-01-15T09:30:00Z", - "resolved_rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], - "rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], "ruleset": { "archived_at": "2024-01-15T09:30:00Z", "created_at": "2024-01-15T09:30:00Z", "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -2019,34 +1998,13 @@ exports[`open api parser hookdeck docs 1`] = ` "id": "id", "name": "name", "paused_at": "2024-01-15T09:30:00Z", - "resolved_rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], - "rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], "ruleset": { "archived_at": "2024-01-15T09:30:00Z", "created_at": "2024-01-15T09:30:00Z", "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -2154,34 +2112,13 @@ exports[`open api parser hookdeck docs 1`] = ` "id": "id", "name": "name", "paused_at": "2024-01-15T09:30:00Z", - "resolved_rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], - "rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], "ruleset": { "archived_at": "2024-01-15T09:30:00Z", "created_at": "2024-01-15T09:30:00Z", "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -2246,29 +2183,12 @@ exports[`open api parser hookdeck docs 1`] = ` "id": "id", "name": "name", "paused_at": "2024-01-15T09:30:00Z", - "resolved_rules": [ - { - "strategy": "linear", - "type": "retry", - }, - ], - "rules": [ - { - "strategy": "linear", - "type": "retry", - }, - ], "ruleset": { "created_at": "2024-01-15T09:30:00Z", "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -2352,34 +2272,13 @@ exports[`open api parser hookdeck docs 1`] = ` "id": "id", "name": "name", "paused_at": "2024-01-15T09:30:00Z", - "resolved_rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], - "rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], "ruleset": { "archived_at": "2024-01-15T09:30:00Z", "created_at": "2024-01-15T09:30:00Z", "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -2449,34 +2348,13 @@ exports[`open api parser hookdeck docs 1`] = ` "id": "id", "name": "name", "paused_at": "2024-01-15T09:30:00Z", - "resolved_rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], - "rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], "ruleset": { "archived_at": "2024-01-15T09:30:00Z", "created_at": "2024-01-15T09:30:00Z", "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -2546,34 +2424,13 @@ exports[`open api parser hookdeck docs 1`] = ` "id": "id", "name": "name", "paused_at": "2024-01-15T09:30:00Z", - "resolved_rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], - "rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], "ruleset": { "archived_at": "2024-01-15T09:30:00Z", "created_at": "2024-01-15T09:30:00Z", "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -2646,34 +2503,13 @@ exports[`open api parser hookdeck docs 1`] = ` "id": "id", "name": "name", "paused_at": "2024-01-15T09:30:00Z", - "resolved_rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], - "rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], "ruleset": { "archived_at": "2024-01-15T09:30:00Z", "created_at": "2024-01-15T09:30:00Z", "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -2769,34 +2605,13 @@ exports[`open api parser hookdeck docs 1`] = ` "id": "id", "name": "name", "paused_at": "2024-01-15T09:30:00Z", - "resolved_rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], - "rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], "ruleset": { "archived_at": "2024-01-15T09:30:00Z", "created_at": "2024-01-15T09:30:00Z", "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -5450,14 +5265,7 @@ exports[`open api parser hookdeck docs 1`] = ` "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -5494,14 +5302,7 @@ exports[`open api parser hookdeck docs 1`] = ` "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -5552,14 +5353,7 @@ exports[`open api parser hookdeck docs 1`] = ` "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -5596,12 +5390,7 @@ exports[`open api parser hookdeck docs 1`] = ` "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -5657,14 +5446,7 @@ exports[`open api parser hookdeck docs 1`] = ` "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -5703,14 +5485,7 @@ exports[`open api parser hookdeck docs 1`] = ` "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -5769,14 +5544,7 @@ exports[`open api parser hookdeck docs 1`] = ` "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -7600,10 +7368,6 @@ exports[`open api parser hookdeck docs 1`] = ` "docs": undefined, "properties": { "strategy": "AlertStrategy", - "type": { - "docs": "An alert rule must be of type \`alert\`", - "type": "literal<"alert">", - }, }, }, "AlertStrategy": { @@ -7941,10 +7705,6 @@ exports[`open api parser hookdeck docs 1`] = ` "docs": "Delay to introduce in MS", "type": "integer", }, - "type": { - "docs": "A delay rule must be of type \`delay\`", - "type": "literal<"delay">", - }, }, }, "DeletedBookmarkResponse": { @@ -8370,10 +8130,6 @@ exports[`open api parser hookdeck docs 1`] = ` "headers": "optional", "path": "optional", "query": "optional", - "type": { - "docs": "A filter rule must be of type \`filter\`", - "type": "literal<"filter">", - }, }, }, "FilteredMeta": { @@ -8911,10 +8667,6 @@ exports[`open api parser hookdeck docs 1`] = ` "type": "optional", }, "strategy": "RetryStrategy", - "type": { - "docs": "A retry rule must be of type \`retry\`", - "type": "literal<"retry">", - }, }, }, "RetryStrategy": { @@ -8925,15 +8677,16 @@ exports[`open api parser hookdeck docs 1`] = ` ], }, "Rule": { - "discriminated": false, + "base-properties": {}, + "discriminant": "type", "docs": undefined, - "union": [ - "RetryRule", - "AlertRule", - "FilterRule", - "TransformRule", - "DelayRule", - ], + "union": { + "alert": "AlertRule", + "delay": "DelayRule", + "filter": "FilterRule", + "retry": "RetryRule", + "transform": "TransformRule", + }, }, "Ruleset": { "docs": "Associated [Ruleset](#ruleset-object) object", @@ -11431,34 +11184,13 @@ exports[`open api parser hookdeck simple 1`] = ` "id": "id", "name": "name", "paused_at": "2024-01-15T09:30:00Z", - "resolved_rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], - "rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], "ruleset": { "archived_at": "2024-01-15T09:30:00Z", "created_at": "2024-01-15T09:30:00Z", "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -11529,34 +11261,13 @@ exports[`open api parser hookdeck simple 1`] = ` "id": "id", "name": "name", "paused_at": "2024-01-15T09:30:00Z", - "resolved_rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], - "rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], "ruleset": { "archived_at": "2024-01-15T09:30:00Z", "created_at": "2024-01-15T09:30:00Z", "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -11664,34 +11375,13 @@ exports[`open api parser hookdeck simple 1`] = ` "id": "id", "name": "name", "paused_at": "2024-01-15T09:30:00Z", - "resolved_rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], - "rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], "ruleset": { "archived_at": "2024-01-15T09:30:00Z", "created_at": "2024-01-15T09:30:00Z", "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -11756,29 +11446,12 @@ exports[`open api parser hookdeck simple 1`] = ` "id": "id", "name": "name", "paused_at": "2024-01-15T09:30:00Z", - "resolved_rules": [ - { - "strategy": "linear", - "type": "retry", - }, - ], - "rules": [ - { - "strategy": "linear", - "type": "retry", - }, - ], "ruleset": { "created_at": "2024-01-15T09:30:00Z", "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -11862,34 +11535,13 @@ exports[`open api parser hookdeck simple 1`] = ` "id": "id", "name": "name", "paused_at": "2024-01-15T09:30:00Z", - "resolved_rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], - "rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], "ruleset": { "archived_at": "2024-01-15T09:30:00Z", "created_at": "2024-01-15T09:30:00Z", "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -11959,34 +11611,13 @@ exports[`open api parser hookdeck simple 1`] = ` "id": "id", "name": "name", "paused_at": "2024-01-15T09:30:00Z", - "resolved_rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], - "rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], "ruleset": { "archived_at": "2024-01-15T09:30:00Z", "created_at": "2024-01-15T09:30:00Z", "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -12056,34 +11687,13 @@ exports[`open api parser hookdeck simple 1`] = ` "id": "id", "name": "name", "paused_at": "2024-01-15T09:30:00Z", - "resolved_rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], - "rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], "ruleset": { "archived_at": "2024-01-15T09:30:00Z", "created_at": "2024-01-15T09:30:00Z", "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -12156,34 +11766,13 @@ exports[`open api parser hookdeck simple 1`] = ` "id": "id", "name": "name", "paused_at": "2024-01-15T09:30:00Z", - "resolved_rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], - "rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], "ruleset": { "archived_at": "2024-01-15T09:30:00Z", "created_at": "2024-01-15T09:30:00Z", "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -12279,34 +11868,13 @@ exports[`open api parser hookdeck simple 1`] = ` "id": "id", "name": "name", "paused_at": "2024-01-15T09:30:00Z", - "resolved_rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], - "rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], "ruleset": { "archived_at": "2024-01-15T09:30:00Z", "created_at": "2024-01-15T09:30:00Z", "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -14960,14 +14528,7 @@ exports[`open api parser hookdeck simple 1`] = ` "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -15004,14 +14565,7 @@ exports[`open api parser hookdeck simple 1`] = ` "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -15062,14 +14616,7 @@ exports[`open api parser hookdeck simple 1`] = ` "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -15106,12 +14653,7 @@ exports[`open api parser hookdeck simple 1`] = ` "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -15167,14 +14709,7 @@ exports[`open api parser hookdeck simple 1`] = ` "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -15213,14 +14748,7 @@ exports[`open api parser hookdeck simple 1`] = ` "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -15279,14 +14807,7 @@ exports[`open api parser hookdeck simple 1`] = ` "id": "id", "is_team_default": true, "name": "name", - "rules": [ - { - "count": 1, - "interval": 1, - "strategy": "linear", - "type": "retry", - }, - ], + "rules": [], "team_id": "team_id", "updated_at": "2024-01-15T09:30:00Z", }, @@ -16355,10 +15876,6 @@ exports[`open api parser hookdeck simple 1`] = ` "docs": undefined, "properties": { "strategy": "AlertStrategy", - "type": { - "docs": "An alert rule must be of type \`alert\`", - "type": "literal<"alert">", - }, }, }, "AlertStrategy": { @@ -16696,10 +16213,6 @@ exports[`open api parser hookdeck simple 1`] = ` "docs": "Delay to introduce in MS", "type": "integer", }, - "type": { - "docs": "A delay rule must be of type \`delay\`", - "type": "literal<"delay">", - }, }, }, "DeletedBookmarkResponse": { @@ -17125,10 +16638,6 @@ exports[`open api parser hookdeck simple 1`] = ` "headers": "optional", "path": "optional", "query": "optional", - "type": { - "docs": "A filter rule must be of type \`filter\`", - "type": "literal<"filter">", - }, }, }, "FilteredMeta": { @@ -17666,10 +17175,6 @@ exports[`open api parser hookdeck simple 1`] = ` "type": "optional", }, "strategy": "RetryStrategy", - "type": { - "docs": "A retry rule must be of type \`retry\`", - "type": "literal<"retry">", - }, }, }, "RetryStrategy": { @@ -17680,15 +17185,16 @@ exports[`open api parser hookdeck simple 1`] = ` ], }, "Rule": { - "discriminated": false, + "base-properties": {}, + "discriminant": "type", "docs": undefined, - "union": [ - "RetryRule", - "AlertRule", - "FilterRule", - "TransformRule", - "DelayRule", - ], + "union": { + "alert": "AlertRule", + "delay": "DelayRule", + "filter": "FilterRule", + "retry": "RetryRule", + "transform": "TransformRule", + }, }, "Ruleset": { "docs": "Associated [Ruleset](#ruleset-object) object", diff --git a/packages/cli/openapi-parser/src/__test__/__snapshots__/hookdeck.test.ts.snap b/packages/cli/openapi-parser/src/__test__/__snapshots__/hookdeck.test.ts.snap index 3a00977757a..97289c13461 100644 --- a/packages/cli/openapi-parser/src/__test__/__snapshots__/hookdeck.test.ts.snap +++ b/packages/cli/openapi-parser/src/__test__/__snapshots__/hookdeck.test.ts.snap @@ -38779,24 +38779,7 @@ exports[`open api parser hookdeck parse open api 1`] = ` }, "rules": { "type": "array", - "value": [ - { - "properties": { - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], + "value": [], }, "team_id": { "type": "primitive", @@ -39942,38 +39925,7 @@ exports[`open api parser hookdeck parse open api 1`] = ` }, "rules": { "type": "array", - "value": [ - { - "properties": { - "count": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "interval": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], + "value": [], }, "team_id": { "type": "primitive", @@ -40206,38 +40158,7 @@ exports[`open api parser hookdeck parse open api 1`] = ` }, "rules": { "type": "array", - "value": [ - { - "properties": { - "count": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "interval": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], + "value": [], }, "team_id": { "type": "primitive", @@ -40456,38 +40377,7 @@ exports[`open api parser hookdeck parse open api 1`] = ` }, "rules": { "type": "array", - "value": [ - { - "properties": { - "count": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "interval": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], + "value": [], }, "team_id": { "type": "primitive", @@ -40668,38 +40558,7 @@ exports[`open api parser hookdeck parse open api 1`] = ` }, "rules": { "type": "array", - "value": [ - { - "properties": { - "count": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "interval": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], + "value": [], }, "team_id": { "type": "primitive", @@ -40974,38 +40833,7 @@ exports[`open api parser hookdeck parse open api 1`] = ` }, "rules": { "type": "array", - "value": [ - { - "properties": { - "count": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "interval": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], + "value": [], }, "team_id": { "type": "primitive", @@ -41155,38 +40983,7 @@ exports[`open api parser hookdeck parse open api 1`] = ` }, "rules": { "type": "array", - "value": [ - { - "properties": { - "count": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "interval": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], + "value": [], }, "team_id": { "type": "primitive", @@ -47180,48 +46977,6 @@ exports[`open api parser hookdeck parse open api 1`] = ` "value": "2024-01-15T09:30:00Z", }, }, - "resolved_rules": { - "type": "array", - "value": [ - { - "properties": { - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], - }, - "rules": { - "type": "array", - "value": [ - { - "properties": { - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], - }, "ruleset": { "properties": { "created_at": { @@ -47254,24 +47009,7 @@ exports[`open api parser hookdeck parse open api 1`] = ` }, "rules": { "type": "array", - "value": [ - { - "properties": { - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], + "value": [], }, "team_id": { "type": "primitive", @@ -48622,83 +48360,13 @@ exports[`open api parser hookdeck parse open api 1`] = ` "value": "2024-01-15T09:30:00Z", }, }, - "resolved_rules": { - "type": "array", - "value": [ - { - "properties": { - "count": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "interval": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], - }, - "rules": { - "type": "array", - "value": [ - { - "properties": { - "count": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "interval": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], - }, - "ruleset": { - "properties": { - "archived_at": { - "type": "primitive", - "value": { - "type": "datetime", - "value": "2024-01-15T09:30:00Z", + "ruleset": { + "properties": { + "archived_at": { + "type": "primitive", + "value": { + "type": "datetime", + "value": "2024-01-15T09:30:00Z", }, }, "created_at": { @@ -48731,24 +48399,7 @@ exports[`open api parser hookdeck parse open api 1`] = ` }, "rules": { "type": "array", - "value": [ - { - "properties": { - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], + "value": [], }, "team_id": { "type": "primitive", @@ -49608,76 +49259,6 @@ exports[`open api parser hookdeck parse open api 1`] = ` "value": "2024-01-15T09:30:00Z", }, }, - "resolved_rules": { - "type": "array", - "value": [ - { - "properties": { - "count": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "interval": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], - }, - "rules": { - "type": "array", - "value": [ - { - "properties": { - "count": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "interval": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], - }, "ruleset": { "properties": { "archived_at": { @@ -49717,24 +49298,7 @@ exports[`open api parser hookdeck parse open api 1`] = ` }, "rules": { "type": "array", - "value": [ - { - "properties": { - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], + "value": [], }, "team_id": { "type": "primitive", @@ -50580,76 +50144,6 @@ exports[`open api parser hookdeck parse open api 1`] = ` "value": "2024-01-15T09:30:00Z", }, }, - "resolved_rules": { - "type": "array", - "value": [ - { - "properties": { - "count": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "interval": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], - }, - "rules": { - "type": "array", - "value": [ - { - "properties": { - "count": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "interval": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], - }, "ruleset": { "properties": { "archived_at": { @@ -50689,24 +50183,7 @@ exports[`open api parser hookdeck parse open api 1`] = ` }, "rules": { "type": "array", - "value": [ - { - "properties": { - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], + "value": [], }, "team_id": { "type": "primitive", @@ -51074,76 +50551,6 @@ exports[`open api parser hookdeck parse open api 1`] = ` "value": "2024-01-15T09:30:00Z", }, }, - "resolved_rules": { - "type": "array", - "value": [ - { - "properties": { - "count": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "interval": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], - }, - "rules": { - "type": "array", - "value": [ - { - "properties": { - "count": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "interval": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], - }, "ruleset": { "properties": { "archived_at": { @@ -51183,24 +50590,7 @@ exports[`open api parser hookdeck parse open api 1`] = ` }, "rules": { "type": "array", - "value": [ - { - "properties": { - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], + "value": [], }, "team_id": { "type": "primitive", @@ -51737,76 +51127,6 @@ exports[`open api parser hookdeck parse open api 1`] = ` "value": "2024-01-15T09:30:00Z", }, }, - "resolved_rules": { - "type": "array", - "value": [ - { - "properties": { - "count": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "interval": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], - }, - "rules": { - "type": "array", - "value": [ - { - "properties": { - "count": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "interval": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], - }, "ruleset": { "properties": { "archived_at": { @@ -51846,24 +51166,7 @@ exports[`open api parser hookdeck parse open api 1`] = ` }, "rules": { "type": "array", - "value": [ - { - "properties": { - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], + "value": [], }, "team_id": { "type": "primitive", @@ -52179,96 +51482,26 @@ exports[`open api parser hookdeck parse open api 1`] = ` }, "type": "object", }, - "id": { - "type": "primitive", - "value": { - "type": "string", - "value": "id", - }, - }, - "name": { - "type": "primitive", - "value": { - "type": "string", - "value": "name", - }, - }, - "paused_at": { - "type": "primitive", - "value": { - "type": "datetime", - "value": "2024-01-15T09:30:00Z", - }, - }, - "resolved_rules": { - "type": "array", - "value": [ - { - "properties": { - "count": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "interval": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], - }, - "rules": { - "type": "array", - "value": [ - { - "properties": { - "count": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "interval": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], + "id": { + "type": "primitive", + "value": { + "type": "string", + "value": "id", + }, + }, + "name": { + "type": "primitive", + "value": { + "type": "string", + "value": "name", + }, + }, + "paused_at": { + "type": "primitive", + "value": { + "type": "datetime", + "value": "2024-01-15T09:30:00Z", + }, }, "ruleset": { "properties": { @@ -52309,24 +51542,7 @@ exports[`open api parser hookdeck parse open api 1`] = ` }, "rules": { "type": "array", - "value": [ - { - "properties": { - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], + "value": [], }, "team_id": { "type": "primitive", @@ -52663,76 +51879,6 @@ exports[`open api parser hookdeck parse open api 1`] = ` "value": "2024-01-15T09:30:00Z", }, }, - "resolved_rules": { - "type": "array", - "value": [ - { - "properties": { - "count": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "interval": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], - }, - "rules": { - "type": "array", - "value": [ - { - "properties": { - "count": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "interval": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], - }, "ruleset": { "properties": { "archived_at": { @@ -52772,24 +51918,7 @@ exports[`open api parser hookdeck parse open api 1`] = ` }, "rules": { "type": "array", - "value": [ - { - "properties": { - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], + "value": [], }, "team_id": { "type": "primitive", @@ -53126,76 +52255,6 @@ exports[`open api parser hookdeck parse open api 1`] = ` "value": "2024-01-15T09:30:00Z", }, }, - "resolved_rules": { - "type": "array", - "value": [ - { - "properties": { - "count": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "interval": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], - }, - "rules": { - "type": "array", - "value": [ - { - "properties": { - "count": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "interval": { - "type": "primitive", - "value": { - "type": "int", - "value": 1, - }, - }, - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], - }, "ruleset": { "properties": { "archived_at": { @@ -53235,24 +52294,7 @@ exports[`open api parser hookdeck parse open api 1`] = ` }, "rules": { "type": "array", - "value": [ - { - "properties": { - "strategy": { - "type": "enum", - "value": "linear", - }, - "type": { - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, - "type": "object", - }, - ], + "value": [], }, "team_id": { "type": "primitive", @@ -53530,11 +52572,6 @@ exports[`open api parser hookdeck parse open api 1`] = ` "ConnectionFilterProperty", "TransformReference", "TransformFull", - "RetryRule", - "AlertRule", - "FilterRule", - "TransformRule", - "DelayRule", ], "schemas": { "APIErrorResponse": { @@ -53691,24 +52728,6 @@ exports[`open api parser hookdeck parse open api 1`] = ` "groupName": null, "nameOverride": null, "properties": [ - { - "audiences": [], - "conflict": {}, - "generatedName": "alertRuleType", - "key": "type", - "nameOverride": null, - "schema": { - "description": "An alert rule must be of type \`alert\`", - "generatedName": "AlertRuleType", - "groupName": null, - "nameOverride": null, - "type": "literal", - "value": { - "type": "string", - "value": "alert", - }, - }, - }, { "audiences": [], "conflict": {}, @@ -55795,24 +54814,6 @@ exports[`open api parser hookdeck parse open api 1`] = ` "groupName": null, "nameOverride": null, "properties": [ - { - "audiences": [], - "conflict": {}, - "generatedName": "delayRuleType", - "key": "type", - "nameOverride": null, - "schema": { - "description": "A delay rule must be of type \`delay\`", - "generatedName": "DelayRuleType", - "groupName": null, - "nameOverride": null, - "type": "literal", - "value": { - "type": "string", - "value": "delay", - }, - }, - }, { "audiences": [], "conflict": {}, @@ -58771,24 +57772,6 @@ exports[`open api parser hookdeck parse open api 1`] = ` "groupName": null, "nameOverride": null, "properties": [ - { - "audiences": [], - "conflict": {}, - "generatedName": "filterRuleType", - "key": "type", - "nameOverride": null, - "schema": { - "description": "A filter rule must be of type \`filter\`", - "generatedName": "FilterRuleType", - "groupName": null, - "nameOverride": null, - "type": "literal", - "value": { - "type": "string", - "value": "filter", - }, - }, - }, { "audiences": [], "conflict": {}, @@ -62326,24 +61309,6 @@ exports[`open api parser hookdeck parse open api 1`] = ` "groupName": null, "nameOverride": null, "properties": [ - { - "audiences": [], - "conflict": {}, - "generatedName": "retryRuleType", - "key": "type", - "nameOverride": null, - "schema": { - "description": "A retry rule must be of type \`retry\`", - "generatedName": "RetryRuleType", - "groupName": null, - "nameOverride": null, - "type": "literal", - "value": { - "type": "string", - "value": "retry", - }, - }, - }, { "audiences": [], "conflict": {}, @@ -62460,53 +61425,55 @@ exports[`open api parser hookdeck parse open api 1`] = ` "Rule": { "type": "oneOf", "value": { + "commonProperties": [], "description": null, + "discriminantProperty": "type", "generatedName": "Rule", "groupName": null, "nameOverride": null, - "schemas": [ - { + "schemas": { + "alert": { "description": null, - "generatedName": "RuleZero", + "generatedName": "ComponentsSchemasAlertRule", "groupName": null, "nameOverride": null, - "schema": "RetryRule", + "schema": "AlertRule", "type": "reference", }, - { + "delay": { "description": null, - "generatedName": "RuleOne", + "generatedName": "ComponentsSchemasDelayRule", "groupName": null, "nameOverride": null, - "schema": "AlertRule", + "schema": "DelayRule", "type": "reference", }, - { + "filter": { "description": null, - "generatedName": "RuleTwo", + "generatedName": "ComponentsSchemasFilterRule", "groupName": null, "nameOverride": null, "schema": "FilterRule", "type": "reference", }, - { + "retry": { "description": null, - "generatedName": "RuleThree", + "generatedName": "ComponentsSchemasRetryRule", "groupName": null, "nameOverride": null, - "schema": "TransformRule", + "schema": "RetryRule", "type": "reference", }, - { + "transform": { "description": null, - "generatedName": "RuleFour", + "generatedName": "ComponentsSchemasTransformRule", "groupName": null, "nameOverride": null, - "schema": "DelayRule", + "schema": "TransformRule", "type": "reference", }, - ], - "type": "undisciminated", + }, + "type": "discriminated", }, }, "Ruleset": { diff --git a/packages/cli/openapi-parser/src/schema/convertSchemas.ts b/packages/cli/openapi-parser/src/schema/convertSchemas.ts index 6805a2dde73..94e12bbc4d5 100644 --- a/packages/cli/openapi-parser/src/schema/convertSchemas.ts +++ b/packages/cli/openapi-parser/src/schema/convertSchemas.ts @@ -522,7 +522,10 @@ export function convertSchemaObject( } } - const maybeDiscriminant = getDiscriminant({ schemas: schema.anyOf, context }); + const maybeDiscriminant = getDiscriminant({ + schemas: schema.anyOf, + context + }); if (maybeDiscriminant != null) { return convertDiscriminatedOneOfWithVariants({ nameOverride, @@ -850,8 +853,7 @@ function getDiscriminant({ Record > = {}; for (const schema of schemas) { - const resolvedSchema = isReferenceObject(schema) ? context.resolveSchemaReference(schema) : schema; - const possibleDiscriminants = getPossibleDiscriminants({ schema: resolvedSchema, context }); + const possibleDiscriminants = getPossibleDiscriminants({ schema, context }); for (const [property, value] of Object.entries(possibleDiscriminants)) { const variants = discriminantToVariants[property]; if (variants != null) { @@ -877,11 +879,34 @@ function getDiscriminant({ function getPossibleDiscriminants({ schema, context +}: { + schema: OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject; + context: SchemaParserContext; +}): Record { + const resolvedSchema = isReferenceObject(schema) ? context.resolveSchemaReference(schema) : schema; + return getPossibleDiscriminantsForSchemaObject({ schema: resolvedSchema, context }); +} + +function getPossibleDiscriminantsForSchemaObject({ + schema, + context }: { schema: OpenAPIV3.SchemaObject; context: SchemaParserContext; }): Record { const possibleDiscrimimants: Record = {}; + if (schema.anyOf != null) { + for (const elem of schema.anyOf) { + const possibleDiscriminantsForVariant = getPossibleDiscriminants({ + schema: elem, + context + }); + for (const [key, value] of Object.entries(possibleDiscriminantsForVariant ?? {})) { + possibleDiscrimimants[key] = value; + } + } + return possibleDiscrimimants; + } for (const [propertyName, propertySchema] of Object.entries(schema.properties ?? {})) { const resolvedPropertySchema = isReferenceObject(propertySchema) ? context.resolveSchemaReference(propertySchema)