|
41 | 41 | let
|
42 | 42 | inner =
|
43 | 43 | {
|
44 |
| - type, |
| 44 | + type ? null, |
45 | 45 | enum ? null,
|
46 | 46 | minimum ? null,
|
47 | 47 | maximum ? null,
|
|
66 | 66 | t: mkRustAnalyzerOptionType nullable "${property_name}-sub" t
|
67 | 67 | ) possibleTypes;
|
68 | 68 | }
|
69 |
| - else if lib.isList type then |
| 69 | + else |
70 | 70 | (
|
71 |
| - if lib.head type == "null" then |
72 |
| - assert lib.assertMsg ( |
73 |
| - lib.length type == 2 |
74 |
| - ) "Lists starting with null are assumed to mean nullOr, so length 2"; |
75 |
| - let |
76 |
| - innerType = property // { |
77 |
| - type = lib.elemAt type 1; |
78 |
| - }; |
79 |
| - inner = mkRustAnalyzerOptionType nullable "${property_name}-inner" innerType; |
80 |
| - in |
81 |
| - assert lib.assertMsg nullable "nullOr types are not yet handled"; |
82 |
| - inner |
83 |
| - else |
84 |
| - let |
85 |
| - innerTypes = builtins.map ( |
86 |
| - t: mkRustAnalyzerOptionType nullable "${property_name}-inner" (property // { type = t; }) |
87 |
| - ) type; |
88 |
| - in |
| 71 | + assert lib.assertMsg (type != null) "property is neither anyOf nor enum, it must have a type"; |
| 72 | + if lib.isList type then |
| 73 | + ( |
| 74 | + if lib.head type == "null" then |
| 75 | + assert lib.assertMsg ( |
| 76 | + lib.length type == 2 |
| 77 | + ) "Lists starting with null are assumed to mean nullOr, so length 2"; |
| 78 | + let |
| 79 | + innerType = property // { |
| 80 | + type = lib.elemAt type 1; |
| 81 | + }; |
| 82 | + inner = mkRustAnalyzerOptionType nullable "${property_name}-inner" innerType; |
| 83 | + in |
| 84 | + assert lib.assertMsg nullable "nullOr types are not yet handled"; |
| 85 | + inner |
| 86 | + else |
| 87 | + let |
| 88 | + innerTypes = builtins.map ( |
| 89 | + t: mkRustAnalyzerOptionType nullable "${property_name}-inner" (property // { type = t; }) |
| 90 | + ) type; |
| 91 | + in |
| 92 | + { |
| 93 | + kind = "oneOf"; |
| 94 | + subTypes = innerTypes; |
| 95 | + } |
| 96 | + ) |
| 97 | + else if type == "array" then |
89 | 98 | {
|
90 |
| - kind = "oneOf"; |
91 |
| - subTypes = innerTypes; |
| 99 | + kind = "list"; |
| 100 | + item = mkRustAnalyzerOptionType false "${property_name}-item" items; |
92 | 101 | }
|
93 |
| - ) |
94 |
| - else if type == "array" then |
95 |
| - { |
96 |
| - kind = "list"; |
97 |
| - item = mkRustAnalyzerOptionType false "${property_name}-item" items; |
98 |
| - } |
99 |
| - else if type == "number" || type == "integer" then |
100 |
| - { |
101 |
| - kind = type; |
102 |
| - inherit minimum maximum; |
103 |
| - } |
104 |
| - else if type == "object" && properties != null then |
105 |
| - { |
106 |
| - kind = "submodule"; |
107 |
| - options = lib.mapAttrs ( |
108 |
| - name: value: mkRustAnalyzerOptionType false "${property_name}.${name}" value |
109 |
| - ) properties; |
110 |
| - } |
111 |
| - else if |
112 |
| - lib.elem type [ |
113 |
| - "object" |
114 |
| - "string" |
115 |
| - "boolean" |
116 |
| - ] |
117 |
| - then |
118 |
| - { kind = type; } |
119 |
| - else |
120 |
| - throw "Unhandled value in ${property_name}: ${lib.generators.toPretty { } property}"; |
| 102 | + else if type == "number" || type == "integer" then |
| 103 | + { |
| 104 | + kind = type; |
| 105 | + inherit minimum maximum; |
| 106 | + } |
| 107 | + else if type == "object" && properties != null then |
| 108 | + { |
| 109 | + kind = "submodule"; |
| 110 | + options = lib.mapAttrs ( |
| 111 | + name: value: mkRustAnalyzerOptionType false "${property_name}.${name}" value |
| 112 | + ) properties; |
| 113 | + } |
| 114 | + else if |
| 115 | + lib.elem type [ |
| 116 | + "object" |
| 117 | + "string" |
| 118 | + "boolean" |
| 119 | + ] |
| 120 | + then |
| 121 | + { kind = type; } |
| 122 | + else |
| 123 | + throw "Unhandled value in ${property_name}: ${lib.generators.toPretty { } property}" |
| 124 | + ); |
121 | 125 | in
|
122 | 126 | builtins.addErrorContext "While creating type for ${property_name}:\n${lib.generators.toPretty { } property}" (
|
123 | 127 | inner property
|
|
0 commit comments