From 314edb9a93468a5c115ce016798cf51a56bd5fcb Mon Sep 17 00:00:00 2001 From: Steve Konves Date: Thu, 17 Jul 2025 20:07:51 -0700 Subject: [PATCH 1/5] feat: define optional explicily instead of as a rule --- src/generated/types.ts | 12 ++---------- src/schema.json | 16 ++-------------- 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/src/generated/types.ts b/src/generated/types.ts index 527a362..4b2b6cc 100644 --- a/src/generated/types.ts +++ b/src/generated/types.ts @@ -216,6 +216,7 @@ export type ComplexValue = { /** The name of a type, enum, or union defined in this Service. */ typeName: StringLiteral; isArray?: TrueLiteral; + isOptional?: TrueLiteral; rules: ValidationRule[]; }; @@ -1023,6 +1024,7 @@ export type PrimitiveValue = { typeName: PrimitiveLiteral; isArray?: TrueLiteral; isNullable?: TrueLiteral; + isOptional?: TrueLiteral; constant?: PrimitiveValueConstant; default?: PrimitiveValueDefault; rules: ValidationRule[]; @@ -1054,11 +1056,6 @@ export type Protocols = { http?: HttpRoute[]; }; -export type RequiredRule = { - kind: 'ValidationRule'; - id: 'Required'; -}; - export type ReturnValue = { kind: 'ReturnValue'; @@ -1434,7 +1431,6 @@ export function isDiscriminatedUnion(obj: Union): obj is DiscriminatedUnion { /** A validation rule. */ export type ValidationRule = - | RequiredRule | ConstantRule | StringMaxLengthRule | StringMinLengthRule @@ -1450,10 +1446,6 @@ export type ValidationRule = | ArrayMinItemsRule | ArrayUniqueItemsRule; -export function isRequiredRule(obj: ValidationRule): obj is RequiredRule { - return obj.id === 'Required'; -} - export function isConstantRule(obj: ValidationRule): obj is ConstantRule { return obj.id === 'Constant'; } diff --git a/src/schema.json b/src/schema.json index 6fbd34e..06b1e5e 100644 --- a/src/schema.json +++ b/src/schema.json @@ -392,6 +392,7 @@ "typeName": { "$ref": "#/definitions/primitiveLiteral" }, "isArray": { "$ref": "#/definitions/true" }, "isNullable": { "$ref": "#/definitions/true" }, + "isOptional": { "$ref": "#/definitions/true" }, "constant": { "oneOf": [ { "$ref": "#/definitions/string" }, @@ -424,6 +425,7 @@ "$ref": "#/definitions/string" }, "isArray": { "$ref": "#/definitions/true" }, + "isOptional": { "$ref": "#/definitions/true" }, "rules": { "type": "array", "items": { "$ref": "#/definitions/validationRule" } @@ -952,7 +954,6 @@ }, "description": "A validation rule.", "oneOf": [ - { "$ref": "#/definitions/requiredRule" }, { "$ref": "#/definitions/constantRule" }, { "$ref": "#/definitions/stringMaxLengthRule" }, { "$ref": "#/definitions/stringMinLengthRule" }, @@ -969,19 +970,6 @@ { "$ref": "#/definitions/arrayUniqueItemsRule" } ] }, - "requiredRule": { - "title": "RequiredRule", - "type": "object", - "required": ["kind", "id"], - "properties": { - "kind": { "type": "string", "const": "ValidationRule" }, - "id": { - "type": "string", - "const": "Required" - } - }, - "additionalProperties": false - }, "constantRule": { "title": "ConstantRule", "type": "object", From 9304a22c0022f25a3aeaa9d455836def45a7c5ab Mon Sep 17 00:00:00 2001 From: Steve Konves Date: Thu, 17 Jul 2025 20:08:28 -0700 Subject: [PATCH 2/5] feat: remove constant rule --- src/generated/types.ts | 13 ------------- src/schema.json | 21 --------------------- 2 files changed, 34 deletions(-) diff --git a/src/generated/types.ts b/src/generated/types.ts index 4b2b6cc..7b30c9c 100644 --- a/src/generated/types.ts +++ b/src/generated/types.ts @@ -220,12 +220,6 @@ export type ComplexValue = { rules: ValidationRule[]; }; -export type ConstantRule = { - kind: 'ValidationRule'; - id: 'Constant'; - value: ConstantRuleValue; -}; - /** TODO: don't allow arrays, enums, or other unions in discriminated unions */ export type DiscriminatedUnion = { kind: 'DiscriminatedUnion'; @@ -1324,8 +1318,6 @@ export type UntypedLiteral = { loc?: string; }; -export type ConstantRuleValue = StringLiteral | NumberLiteral | BooleanLiteral; - export type MemberValue = PrimitiveValue | ComplexValue; export function isPrimitiveValue(obj: MemberValue): obj is PrimitiveValue { @@ -1431,7 +1423,6 @@ export function isDiscriminatedUnion(obj: Union): obj is DiscriminatedUnion { /** A validation rule. */ export type ValidationRule = - | ConstantRule | StringMaxLengthRule | StringMinLengthRule | StringPatternRule @@ -1446,10 +1437,6 @@ export type ValidationRule = | ArrayMinItemsRule | ArrayUniqueItemsRule; -export function isConstantRule(obj: ValidationRule): obj is ConstantRule { - return obj.id === 'Constant'; -} - export function isStringMaxLengthRule( obj: ValidationRule, ): obj is StringMaxLengthRule { diff --git a/src/schema.json b/src/schema.json index 06b1e5e..d935527 100644 --- a/src/schema.json +++ b/src/schema.json @@ -954,7 +954,6 @@ }, "description": "A validation rule.", "oneOf": [ - { "$ref": "#/definitions/constantRule" }, { "$ref": "#/definitions/stringMaxLengthRule" }, { "$ref": "#/definitions/stringMinLengthRule" }, { "$ref": "#/definitions/stringPatternRule" }, @@ -970,26 +969,6 @@ { "$ref": "#/definitions/arrayUniqueItemsRule" } ] }, - "constantRule": { - "title": "ConstantRule", - "type": "object", - "required": ["kind", "id", "value"], - "properties": { - "kind": { "type": "string", "const": "ValidationRule" }, - "id": { - "type": "string", - "const": "Constant" - }, - "value": { - "oneOf": [ - { "$ref": "#/definitions/string" }, - { "$ref": "#/definitions/number" }, - { "$ref": "#/definitions/boolean" } - ] - } - }, - "additionalProperties": false - }, "stringMaxLengthRule": { "title": "StringMaxLengthRule", "type": "object", From 5253131d130d9dfa60fcd055a7e5007b7c98ff4f Mon Sep 17 00:00:00 2001 From: Steve Konves Date: Thu, 17 Jul 2025 20:10:36 -0700 Subject: [PATCH 3/5] feat: remove stringEnum rule --- src/generated/types.ts | 23 ----------------------- src/schema.json | 20 -------------------- 2 files changed, 43 deletions(-) diff --git a/src/generated/types.ts b/src/generated/types.ts index 7b30c9c..f896740 100644 --- a/src/generated/types.ts +++ b/src/generated/types.ts @@ -1172,24 +1172,6 @@ export type SimpleUnion = { meta?: MetaValue[]; }; -export type StringEnumRule = { - kind: 'ValidationRule'; - id: 'StringEnum'; - values: StringLiteral[]; - - /** - * A range in the source document encoded as a string. This string is a - * semicolon-separated list of numbers and MUST be in one of the following formats: - * - Single point: `;;` (eg. `"4;12;88"`) - * - Single row: `;;;;` (eg. `"4;12;21;88;97"`) - * - Multi row: `;;;;;` (eg. - * `"4;12;6;3;88;164"`) - * - * Both the `row` and `column` values are 1-based. The `offset` values are 0-based. - */ - loc?: string; -}; - export type StringFormatRule = { kind: 'ValidationRule'; id: 'StringFormat'; @@ -1427,7 +1409,6 @@ export type ValidationRule = | StringMinLengthRule | StringPatternRule | StringFormatRule - | StringEnumRule | NumberMultipleOfRule | NumberGtRule | NumberGteRule @@ -1461,10 +1442,6 @@ export function isStringFormatRule( return obj.id === 'StringFormat'; } -export function isStringEnumRule(obj: ValidationRule): obj is StringEnumRule { - return obj.id === 'StringEnum'; -} - export function isNumberMultipleOfRule( obj: ValidationRule, ): obj is NumberMultipleOfRule { diff --git a/src/schema.json b/src/schema.json index d935527..92a8078 100644 --- a/src/schema.json +++ b/src/schema.json @@ -958,7 +958,6 @@ { "$ref": "#/definitions/stringMinLengthRule" }, { "$ref": "#/definitions/stringPatternRule" }, { "$ref": "#/definitions/stringFormatRule" }, - { "$ref": "#/definitions/stringEnumRule" }, { "$ref": "#/definitions/numberMultipleOfRule" }, { "$ref": "#/definitions/numberGtRule" }, { "$ref": "#/definitions/numberGteRule" }, @@ -1029,25 +1028,6 @@ }, "additionalProperties": false }, - "stringEnumRule": { - "title": "StringEnumRule", - "type": "object", - "required": ["kind", "id", "values"], - "properties": { - "kind": { "type": "string", "const": "ValidationRule" }, - "id": { - "type": "string", - "const": "StringEnum" - }, - "values": { - "type": "array", - "items": { "$ref": "#/definitions/string" }, - "minItems": 1 - }, - "loc": { "$ref": "#/definitions/range" } - }, - "additionalProperties": false - }, "numberMultipleOfRule": { "title": "NumberMultipleOfRule", "type": "object", From 2c5d2887a4e7a78d56bcc7feb4b7c5f1e0174b6d Mon Sep 17 00:00:00 2001 From: Steve Konves Date: Mon, 21 Jul 2025 17:10:51 -0600 Subject: [PATCH 4/5] test: update example IR --- src/example.json | 284 ++++++++++++++++++++--------------------------- 1 file changed, 119 insertions(+), 165 deletions(-) diff --git a/src/example.json b/src/example.json index 2832eb2..db8f5bb 100644 --- a/src/example.json +++ b/src/example.json @@ -84,6 +84,7 @@ "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, "default": { "kind": "StringLiteral", "value": "ASDF" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] }, "meta": [ @@ -138,6 +139,7 @@ "kind": "StringLiteral", "value": "getGizmosResponse" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } } @@ -219,6 +221,7 @@ "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, "isArray": { "kind": "TrueLiteral", "value": true }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [ { "kind": "ValidationRule", @@ -247,6 +250,7 @@ "value": { "kind": "ComplexValue", "typeName": { "kind": "StringLiteral", "value": "gizmo" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } } @@ -330,18 +334,8 @@ "kind": "StringLiteral", "value": "createGizmoSize" }, - "rules": [ - { - "kind": "ValidationRule", - "id": "StringEnum", - "values": [ - { "kind": "StringLiteral", "value": "small" }, - { "kind": "StringLiteral", "value": "medium" }, - { "kind": "StringLiteral", "value": "big" }, - { "kind": "StringLiteral", "value": "XL" } - ] - } - ] + "isOptional": { "kind": "TrueLiteral", "value": true }, + "rules": [] } } ], @@ -360,6 +354,7 @@ "value": { "kind": "ComplexValue", "typeName": { "kind": "StringLiteral", "value": "gizmo" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } } @@ -477,6 +472,7 @@ "value": { "kind": "ComplexValue", "typeName": { "kind": "StringLiteral", "value": "widget" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } } @@ -530,6 +526,7 @@ "kind": "StringLiteral", "value": "createWidgetString" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } } @@ -572,8 +569,8 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [ - { "kind": "ValidationRule", "id": "Required" }, { "kind": "ValidationRule", "id": "StringMaxLength", @@ -591,6 +588,7 @@ "value": { "kind": "ComplexValue", "typeName": { "kind": "StringLiteral", "value": "widget" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } } @@ -622,8 +620,8 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [ - { "kind": "ValidationRule", "id": "Required" }, { "kind": "ValidationRule", "id": "StringMaxLength", @@ -780,6 +778,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -789,6 +788,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "date" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [ { "kind": "ValidationRule", @@ -810,6 +810,7 @@ "kind": "PrimitiveLiteral", "value": "date-time" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [ { "kind": "ValidationRule", @@ -828,6 +829,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "integer" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -837,6 +839,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "integer" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -846,6 +849,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "long" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -855,6 +859,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "number" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -864,6 +869,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "float" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -873,6 +879,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "double" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } } @@ -905,6 +912,7 @@ "kind": "StringLiteral", "value": "exhaustiveParamsString" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -914,6 +922,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -926,17 +935,8 @@ "kind": "StringLiteral", "value": "exhaustiveParamsQueryEnum" }, - "rules": [ - { - "kind": "ValidationRule", - "id": "StringEnum", - "values": [ - { "kind": "StringLiteral", "value": "one" }, - { "kind": "StringLiteral", "value": "two" }, - { "kind": "StringLiteral", "value": "three" } - ] - } - ] + "isOptional": { "kind": "TrueLiteral", "value": true }, + "rules": [] } }, { @@ -945,6 +945,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "number" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -954,6 +955,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "integer" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -963,6 +965,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "boolean" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -976,6 +979,7 @@ "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, "isArray": { "kind": "TrueLiteral", "value": true }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -989,17 +993,8 @@ "value": "exhaustiveParamsQueryEnumArray" }, "isArray": { "kind": "TrueLiteral", "value": true }, - "rules": [ - { - "kind": "ValidationRule", - "id": "StringEnum", - "values": [ - { "kind": "StringLiteral", "value": "one" }, - { "kind": "StringLiteral", "value": "two" }, - { "kind": "StringLiteral", "value": "three" } - ] - } - ] + "isOptional": { "kind": "TrueLiteral", "value": true }, + "rules": [] } }, { @@ -1012,6 +1007,7 @@ "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "number" }, "isArray": { "kind": "TrueLiteral", "value": true }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -1025,6 +1021,7 @@ "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "integer" }, "isArray": { "kind": "TrueLiteral", "value": true }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -1038,6 +1035,7 @@ "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "boolean" }, "isArray": { "kind": "TrueLiteral", "value": true }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -1047,7 +1045,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, - "rules": [{ "kind": "ValidationRule", "id": "Required" }] + "rules": [] } }, { @@ -1059,18 +1057,8 @@ "kind": "StringLiteral", "value": "exhaustiveParamsPathEnum" }, - "rules": [ - { "kind": "ValidationRule", "id": "Required" }, - { - "kind": "ValidationRule", - "id": "StringEnum", - "values": [ - { "kind": "StringLiteral", "value": "one" }, - { "kind": "StringLiteral", "value": "two" }, - { "kind": "StringLiteral", "value": "three" } - ] - } - ] + "isOptional": { "kind": "TrueLiteral", "value": true }, + "rules": [] } }, { @@ -1079,7 +1067,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "number" }, - "rules": [{ "kind": "ValidationRule", "id": "Required" }] + "rules": [] } }, { @@ -1088,7 +1076,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "integer" }, - "rules": [{ "kind": "ValidationRule", "id": "Required" }] + "rules": [] } }, { @@ -1097,7 +1085,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "boolean" }, - "rules": [{ "kind": "ValidationRule", "id": "Required" }] + "rules": [] } }, { @@ -1107,7 +1095,7 @@ "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, "isArray": { "kind": "TrueLiteral", "value": true }, - "rules": [{ "kind": "ValidationRule", "id": "Required" }] + "rules": [] } }, { @@ -1120,18 +1108,8 @@ "value": "exhaustiveParamsPathEnumArray" }, "isArray": { "kind": "TrueLiteral", "value": true }, - "rules": [ - { "kind": "ValidationRule", "id": "Required" }, - { - "kind": "ValidationRule", - "id": "StringEnum", - "values": [ - { "kind": "StringLiteral", "value": "one" }, - { "kind": "StringLiteral", "value": "two" }, - { "kind": "StringLiteral", "value": "three" } - ] - } - ] + "isOptional": { "kind": "TrueLiteral", "value": true }, + "rules": [] } }, { @@ -1141,7 +1119,7 @@ "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "number" }, "isArray": { "kind": "TrueLiteral", "value": true }, - "rules": [{ "kind": "ValidationRule", "id": "Required" }] + "rules": [] } }, { @@ -1154,7 +1132,7 @@ "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "integer" }, "isArray": { "kind": "TrueLiteral", "value": true }, - "rules": [{ "kind": "ValidationRule", "id": "Required" }] + "rules": [] } }, { @@ -1167,7 +1145,7 @@ "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "boolean" }, "isArray": { "kind": "TrueLiteral", "value": true }, - "rules": [{ "kind": "ValidationRule", "id": "Required" }] + "rules": [] } }, { @@ -1176,6 +1154,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -1188,17 +1167,8 @@ "kind": "StringLiteral", "value": "exhaustiveParamsHeaderEnum" }, - "rules": [ - { - "kind": "ValidationRule", - "id": "StringEnum", - "values": [ - { "kind": "StringLiteral", "value": "one" }, - { "kind": "StringLiteral", "value": "two" }, - { "kind": "StringLiteral", "value": "three" } - ] - } - ] + "isOptional": { "kind": "TrueLiteral", "value": true }, + "rules": [] } }, { @@ -1207,6 +1177,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "number" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -1216,6 +1187,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "integer" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -1225,6 +1197,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "boolean" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -1238,6 +1211,7 @@ "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, "isArray": { "kind": "TrueLiteral", "value": true }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -1251,17 +1225,8 @@ "value": "exhaustiveParamsHeaderEnumArray" }, "isArray": { "kind": "TrueLiteral", "value": true }, - "rules": [ - { - "kind": "ValidationRule", - "id": "StringEnum", - "values": [ - { "kind": "StringLiteral", "value": "one" }, - { "kind": "StringLiteral", "value": "two" }, - { "kind": "StringLiteral", "value": "three" } - ] - } - ] + "isOptional": { "kind": "TrueLiteral", "value": true }, + "rules": [] } }, { @@ -1274,6 +1239,7 @@ "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "number" }, "isArray": { "kind": "TrueLiteral", "value": true }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -1287,6 +1253,7 @@ "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "integer" }, "isArray": { "kind": "TrueLiteral", "value": true }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -1300,6 +1267,7 @@ "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "boolean" }, "isArray": { "kind": "TrueLiteral", "value": true }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } } @@ -2128,6 +2096,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [ { "kind": "ValidationRule", @@ -2143,6 +2112,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -2152,17 +2122,8 @@ "value": { "kind": "ComplexValue", "typeName": { "kind": "StringLiteral", "value": "productSize" }, - "rules": [ - { - "kind": "ValidationRule", - "id": "StringEnum", - "values": [ - { "kind": "StringLiteral", "value": "small" }, - { "kind": "StringLiteral", "value": "medium" }, - { "kind": "StringLiteral", "value": "large" } - ] - } - ] + "isOptional": { "kind": "TrueLiteral", "value": true }, + "rules": [] } } ], @@ -2178,6 +2139,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [ { "kind": "ValidationRule", @@ -2193,6 +2155,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [ { "kind": "ValidationRule", @@ -2216,6 +2179,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "number" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [ { "kind": "ValidationRule", @@ -2231,6 +2195,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "number" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [ { "kind": "ValidationRule", @@ -2246,6 +2211,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "number" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [ { "kind": "ValidationRule", @@ -2261,6 +2227,7 @@ "value": { "kind": "ComplexValue", "typeName": { "kind": "StringLiteral", "value": "widgetFoo" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -2270,17 +2237,8 @@ "value": { "kind": "ComplexValue", "typeName": { "kind": "StringLiteral", "value": "productSize" }, - "rules": [ - { - "kind": "ValidationRule", - "id": "StringEnum", - "values": [ - { "kind": "StringLiteral", "value": "small" }, - { "kind": "StringLiteral", "value": "medium" }, - { "kind": "StringLiteral", "value": "large" } - ] - } - ] + "isOptional": { "kind": "TrueLiteral", "value": true }, + "rules": [] } } ], @@ -2296,6 +2254,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [ { "kind": "ValidationRule", @@ -2319,6 +2278,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "number" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [ { "kind": "ValidationRule", @@ -2334,6 +2294,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "number" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [ { "kind": "ValidationRule", @@ -2349,6 +2310,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "number" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [ { "kind": "ValidationRule", @@ -2364,6 +2326,7 @@ "value": { "kind": "ComplexValue", "typeName": { "kind": "StringLiteral", "value": "newWidgetFoo" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -2373,17 +2336,8 @@ "value": { "kind": "ComplexValue", "typeName": { "kind": "StringLiteral", "value": "productSize" }, - "rules": [ - { - "kind": "ValidationRule", - "id": "StringEnum", - "values": [ - { "kind": "StringLiteral", "value": "small" }, - { "kind": "StringLiteral", "value": "medium" }, - { "kind": "StringLiteral", "value": "large" } - ] - } - ] + "isOptional": { "kind": "TrueLiteral", "value": true }, + "rules": [] } } ], @@ -2399,6 +2353,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -2411,6 +2366,7 @@ "kind": "StringLiteral", "value": "someTypeNestedUnion" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } } @@ -2427,13 +2383,8 @@ "value": { "kind": "ComplexValue", "typeName": { "kind": "StringLiteral", "value": "singleValueEnum" }, - "rules": [ - { - "kind": "ValidationRule", - "id": "StringEnum", - "values": [{ "kind": "StringLiteral", "value": "the value" }] - } - ] + "isOptional": { "kind": "TrueLiteral", "value": true }, + "rules": [] } }, { @@ -2442,16 +2393,8 @@ "value": { "kind": "ComplexValue", "typeName": { "kind": "StringLiteral", "value": "multiValueEnum" }, - "rules": [ - { - "kind": "ValidationRule", - "id": "StringEnum", - "values": [ - { "kind": "StringLiteral", "value": "the value" }, - { "kind": "StringLiteral", "value": "another value" } - ] - } - ] + "isOptional": { "kind": "TrueLiteral", "value": true }, + "rules": [] } }, { @@ -2461,15 +2404,8 @@ "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, "constant": { "kind": "StringLiteral", "value": "the only value" }, - "rules": [ - { - "kind": "ValidationRule", - "id": "StringEnum", - "values": [ - { "kind": "StringLiteral", "value": "the only value" } - ] - } - ] + "isOptional": { "kind": "TrueLiteral", "value": true }, + "rules": [] } } ], @@ -2485,6 +2421,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -2494,6 +2431,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -2503,6 +2441,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -2512,6 +2451,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -2521,6 +2461,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -2530,6 +2471,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } } @@ -2546,6 +2488,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -2555,6 +2498,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -2564,6 +2508,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -2573,6 +2518,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } } @@ -2589,6 +2535,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -2598,6 +2545,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } } @@ -2615,13 +2563,8 @@ "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, "constant": { "kind": "StringLiteral", "value": "cat" }, - "rules": [ - { - "kind": "ValidationRule", - "id": "StringEnum", - "values": [{ "kind": "StringLiteral", "value": "cat" }] - } - ] + "isOptional": { "kind": "TrueLiteral", "value": true }, + "rules": [] } }, { @@ -2630,6 +2573,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "integer" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } } @@ -2647,13 +2591,8 @@ "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, "constant": { "kind": "StringLiteral", "value": "dog" }, - "rules": [ - { - "kind": "ValidationRule", - "id": "StringEnum", - "values": [{ "kind": "StringLiteral", "value": "dog" }] - } - ] + "isOptional": { "kind": "TrueLiteral", "value": true }, + "rules": [] } }, { @@ -2662,6 +2601,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "boolean" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } } @@ -2678,8 +2618,9 @@ "value": { "kind": "ComplexValue", "typeName": { "kind": "StringLiteral", "value": "gizmo" }, - "rules": [], - "isArray": { "kind": "TrueLiteral", "value": true } + "isArray": { "kind": "TrueLiteral", "value": true }, + "isOptional": { "kind": "TrueLiteral", "value": true }, + "rules": [] } } ], @@ -2695,6 +2636,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } } @@ -2711,6 +2653,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -2720,6 +2663,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "string" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } } @@ -2737,6 +2681,7 @@ "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "number" }, "constant": { "kind": "NumberLiteral", "value": 123456 }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -2746,6 +2691,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "number" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } } @@ -2763,6 +2709,7 @@ "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "number" }, "constant": { "kind": "NumberLiteral", "value": 123456 }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } }, @@ -2772,6 +2719,7 @@ "value": { "kind": "PrimitiveValue", "typeName": { "kind": "PrimitiveLiteral", "value": "number" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } } @@ -2973,11 +2921,13 @@ { "kind": "ComplexValue", "typeName": { "kind": "StringLiteral", "value": "partA" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] }, { "kind": "ComplexValue", "typeName": { "kind": "StringLiteral", "value": "partB" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } ], @@ -2993,11 +2943,13 @@ { "kind": "ComplexValue", "typeName": { "kind": "StringLiteral", "value": "partA" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] }, { "kind": "ComplexValue", "typeName": { "kind": "StringLiteral", "value": "partB" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } ], @@ -3014,11 +2966,13 @@ { "kind": "ComplexValue", "typeName": { "kind": "StringLiteral", "value": "cat" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] }, { "kind": "ComplexValue", "typeName": { "kind": "StringLiteral", "value": "dog" }, + "isOptional": { "kind": "TrueLiteral", "value": true }, "rules": [] } ] From f4d929be975262a3a9ab2b57d221c0e143056d10 Mon Sep 17 00:00:00 2001 From: Steve Konves Date: Mon, 21 Jul 2025 17:11:03 -0600 Subject: [PATCH 5/5] feat: make complex types nullable --- src/generated/types.ts | 1 + src/schema.json | 1 + 2 files changed, 2 insertions(+) diff --git a/src/generated/types.ts b/src/generated/types.ts index f896740..2514496 100644 --- a/src/generated/types.ts +++ b/src/generated/types.ts @@ -216,6 +216,7 @@ export type ComplexValue = { /** The name of a type, enum, or union defined in this Service. */ typeName: StringLiteral; isArray?: TrueLiteral; + isNullable?: TrueLiteral; isOptional?: TrueLiteral; rules: ValidationRule[]; }; diff --git a/src/schema.json b/src/schema.json index 92a8078..b419fd0 100644 --- a/src/schema.json +++ b/src/schema.json @@ -425,6 +425,7 @@ "$ref": "#/definitions/string" }, "isArray": { "$ref": "#/definitions/true" }, + "isNullable": { "$ref": "#/definitions/true" }, "isOptional": { "$ref": "#/definitions/true" }, "rules": { "type": "array",