( valueType: ts.Type, typeChecker: ts.TypeChecker, factory: ts.NodeFactory )
| 148 | } |
| 149 | |
| 150 | export function createAdditionalPropertiesValueSchema( |
| 151 | valueType: ts.Type, |
| 152 | typeChecker: ts.TypeChecker, |
| 153 | factory: ts.NodeFactory |
| 154 | ): ts.Expression { |
| 155 | const text = getText(valueType, typeChecker); |
| 156 | const objType = (t: string) => |
| 157 | factory.createObjectLiteralExpression( |
| 158 | [ |
| 159 | factory.createPropertyAssignment('type', factory.createStringLiteral(t)) |
| 160 | ], |
| 161 | false |
| 162 | ); |
| 163 | |
| 164 | if ( |
| 165 | isString(valueType) || |
| 166 | isStringLiteral(valueType) || |
| 167 | isStringMapping(valueType) |
| 168 | ) { |
| 169 | return objType('string'); |
| 170 | } |
| 171 | if (isNumber(valueType) || isBigInt(valueType)) { |
| 172 | return objType('number'); |
| 173 | } |
| 174 | if (isBoolean(valueType)) { |
| 175 | return objType('boolean'); |
| 176 | } |
| 177 | if (text === 'any' || text === 'unknown' || text === 'object') { |
| 178 | return factory.createTrue(); |
| 179 | } |
| 180 | |
| 181 | const nested = getRecordValueType(valueType, typeChecker); |
| 182 | if (nested) { |
| 183 | return factory.createObjectLiteralExpression( |
| 184 | [ |
| 185 | factory.createPropertyAssignment( |
| 186 | 'type', |
| 187 | factory.createStringLiteral('object') |
| 188 | ), |
| 189 | factory.createPropertyAssignment( |
| 190 | 'additionalProperties', |
| 191 | createAdditionalPropertiesValueSchema(nested, typeChecker, factory) |
| 192 | ) |
| 193 | ], |
| 194 | false |
| 195 | ); |
| 196 | } |
| 197 | if (isArray(valueType)) { |
| 198 | const elementType = getTypeArguments(valueType)[0]; |
| 199 | return factory.createObjectLiteralExpression( |
| 200 | [ |
| 201 | factory.createPropertyAssignment( |
| 202 | 'type', |
| 203 | factory.createStringLiteral('array') |
| 204 | ), |
| 205 | factory.createPropertyAssignment( |
| 206 | 'items', |
| 207 | createAdditionalPropertiesValueSchema( |
no test coverage detected
searching dependent graphs…