fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #374 from hey-api/fix/invalid-typescript

fix: invalid typescript Record generated with circular dependencies

authored by

Jordan Shatford and committed by
GitHub
de22f5bc 5d500bf2

+356 -124
+5
.changeset/fast-olives-pump.md
··· 1 + --- 2 + "@hey-api/openapi-ts": patch 3 + --- 4 + 5 + fix: invalid typescript Record generated with circular dependencies
+12 -3
packages/openapi-ts/src/compiler/typedef.ts
··· 1 1 import ts from 'typescript'; 2 2 3 - import { addLeadingComment, type Comments } from './utils'; 3 + import { addLeadingComment, type Comments, tsNodeToString } from './utils'; 4 4 5 5 export const createTypeNode = (base: any | ts.TypeNode) => 6 6 ts.isTypeNode(base) ? base : ts.factory.createTypeReferenceNode(base); ··· 110 110 }; 111 111 112 112 /** 113 - * Create type record node. Example `Record<string, X | Y>` 113 + * Create type record node. Example `{ [key: string]: string }` 114 114 * @param keys - key types. 115 115 * @param values - value types. 116 116 * @param isNullable - if the whole type can be null ··· 123 123 ) => { 124 124 const keyNode = createTypeUnionNode(keys); 125 125 const valueNode = createTypeUnionNode(values); 126 - const node = ts.factory.createTypeReferenceNode('Record', [keyNode, valueNode]); 126 + // NOTE: We use the syntax `{ [key: string]: string }` because using a Record causes 127 + // invalid types with circular dependencies. This is functionally the same. 128 + // Ref: https://github.com/hey-api/openapi-ts/issues/370 129 + const node = createTypeInterfaceNode([ 130 + { 131 + isRequired: true, 132 + name: `[key: ${tsNodeToString(keyNode)}]`, 133 + type: valueNode, 134 + }, 135 + ]); 127 136 if (!isNullable) { 128 137 return node; 129 138 }
+30 -13
packages/openapi-ts/test/__snapshots__/test/generated/v2/models.ts.snap
··· 135 135 /** 136 136 * This is a string dictionary 137 137 */ 138 - export type DictionaryWithString = Record<string, string>; 138 + export type DictionaryWithString = { 139 + [key: string]: string; 140 + }; 139 141 140 142 /** 141 143 * This is a string reference 142 144 */ 143 - export type DictionaryWithReference = Record<string, ModelWithString>; 145 + export type DictionaryWithReference = { 146 + [key: string]: ModelWithString; 147 + }; 144 148 145 149 /** 146 150 * This is a complex dictionary 147 151 */ 148 - export type DictionaryWithArray = Record<string, Array<ModelWithString>>; 152 + export type DictionaryWithArray = { 153 + [key: string]: Array<ModelWithString>; 154 + }; 149 155 150 156 /** 151 157 * This is a string dictionary 152 158 */ 153 - export type DictionaryWithDictionary = Record<string, Record<string, string>>; 159 + export type DictionaryWithDictionary = { 160 + [key: string]: { 161 + [key: string]: string; 162 + }; 163 + }; 154 164 155 165 /** 156 166 * This is a complex dictionary 157 167 */ 158 - export type DictionaryWithProperties = Record< 159 - string, 160 - { 168 + export type DictionaryWithProperties = { 169 + [key: string]: { 161 170 foo?: string; 162 171 bar?: string; 163 - } 164 - >; 172 + }; 173 + }; 165 174 166 175 /** 167 176 * This is a type-only model that defines Date as a string ··· 244 253 * This is a model with nested enums 245 254 */ 246 255 export type ModelWithNestedEnums = { 247 - dictionaryWithEnum?: Record<string, 'Success' | 'Warning' | 'Error'>; 248 - dictionaryWithEnumFromDescription?: Record<string, number>; 256 + dictionaryWithEnum?: { 257 + [key: string]: 'Success' | 'Warning' | 'Error'; 258 + }; 259 + dictionaryWithEnumFromDescription?: { 260 + [key: string]: number; 261 + }; 249 262 arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; 250 263 arrayWithDescription?: Array<number>; 251 264 }; ··· 270 283 * This is a model with one property containing a dictionary 271 284 */ 272 285 export type ModelWithDictionary = { 273 - prop?: Record<string, string>; 286 + prop?: { 287 + [key: string]: string; 288 + }; 274 289 }; 275 290 276 291 /** ··· 675 690 /** 676 691 * This is a dictionary parameter 677 692 */ 678 - parameterDictionary: Record<string, string>; 693 + parameterDictionary: { 694 + [key: string]: string; 695 + }; 679 696 /** 680 697 * This is an enum parameter 681 698 */
+60 -21
packages/openapi-ts/test/__snapshots__/test/generated/v3/models.ts.snap
··· 169 169 /** 170 170 * This is a string dictionary 171 171 */ 172 - export type DictionaryWithString = Record<string, string>; 172 + export type DictionaryWithString = { 173 + [key: string]: string; 174 + }; 173 175 174 176 export type DictionaryWithPropertiesAndAdditionalProperties = { 175 177 foo?: string; ··· 179 181 /** 180 182 * This is a string reference 181 183 */ 182 - export type DictionaryWithReference = Record<string, ModelWithString>; 184 + export type DictionaryWithReference = { 185 + [key: string]: ModelWithString; 186 + }; 183 187 184 188 /** 185 189 * This is a complex dictionary 186 190 */ 187 - export type DictionaryWithArray = Record<string, Array<ModelWithString>>; 191 + export type DictionaryWithArray = { 192 + [key: string]: Array<ModelWithString>; 193 + }; 188 194 189 195 /** 190 196 * This is a string dictionary 191 197 */ 192 - export type DictionaryWithDictionary = Record<string, Record<string, string>>; 198 + export type DictionaryWithDictionary = { 199 + [key: string]: { 200 + [key: string]: string; 201 + }; 202 + }; 193 203 194 204 /** 195 205 * This is a complex dictionary 196 206 */ 197 - export type DictionaryWithProperties = Record< 198 - string, 199 - { 207 + export type DictionaryWithProperties = { 208 + [key: string]: { 200 209 foo?: string; 201 210 bar?: string; 202 - } 203 - >; 211 + }; 212 + }; 204 213 205 214 /** 206 215 * This is a model with one number property ··· 302 311 * This is a model with nested enums 303 312 */ 304 313 export type ModelWithNestedEnums = { 305 - dictionaryWithEnum?: Record<string, 'Success' | 'Warning' | 'Error'>; 306 - dictionaryWithEnumFromDescription?: Record<string, number>; 314 + dictionaryWithEnum?: { 315 + [key: string]: 'Success' | 'Warning' | 'Error'; 316 + }; 317 + dictionaryWithEnumFromDescription?: { 318 + [key: string]: number; 319 + }; 307 320 arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; 308 321 arrayWithDescription?: Array<number>; 309 322 /** ··· 341 354 * This is a model with one property containing a dictionary 342 355 */ 343 356 export type ModelWithDictionary = { 344 - prop?: Record<string, string>; 357 + prop?: { 358 + [key: string]: string; 359 + }; 345 360 }; 346 361 347 362 /** ··· 458 473 * This is a model that contains a simple dictionary within composition 459 474 */ 460 475 export type CompositionWithOneOfAndSimpleDictionary = { 461 - propA?: boolean | Record<string, number>; 476 + propA?: 477 + | boolean 478 + | { 479 + [key: string]: number; 480 + }; 462 481 }; 463 482 464 483 /** 465 484 * This is a model that contains a dictionary of simple arrays within composition 466 485 */ 467 486 export type CompositionWithOneOfAndSimpleArrayDictionary = { 468 - propA?: boolean | Record<string, Array<boolean>>; 487 + propA?: 488 + | boolean 489 + | { 490 + [key: string]: Array<boolean>; 491 + }; 469 492 }; 470 493 471 494 /** 472 495 * This is a model that contains a dictionary of complex arrays (composited) within composition 473 496 */ 474 497 export type CompositionWithOneOfAndComplexArrayDictionary = { 475 - propA?: boolean | Record<string, Array<number | string>>; 498 + propA?: 499 + | boolean 500 + | { 501 + [key: string]: Array<number | string>; 502 + }; 476 503 }; 477 504 478 505 /** ··· 626 653 /** 627 654 * This is a free-form object without additionalProperties. 628 655 */ 629 - export type FreeFormObjectWithoutAdditionalProperties = Record<string, unknown>; 656 + export type FreeFormObjectWithoutAdditionalProperties = { 657 + [key: string]: unknown; 658 + }; 630 659 631 660 /** 632 661 * This is a free-form object with additionalProperties: true. 633 662 */ 634 - export type FreeFormObjectWithAdditionalPropertiesEqTrue = Record<string, unknown>; 663 + export type FreeFormObjectWithAdditionalPropertiesEqTrue = { 664 + [key: string]: unknown; 665 + }; 635 666 636 667 /** 637 668 * This is a free-form object with additionalProperties: {}. 638 669 */ 639 - export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = Record<string, unknown>; 670 + export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = { 671 + [key: string]: unknown; 672 + }; 640 673 641 674 export type ModelWithConst = { 642 675 String?: 'String'; ··· 1162 1195 /** 1163 1196 * This is a dictionary parameter 1164 1197 */ 1165 - parameterDictionary: Record<string, unknown> | null; 1198 + parameterDictionary: { 1199 + [key: string]: unknown; 1200 + } | null; 1166 1201 /** 1167 1202 * This is an enum parameter 1168 1203 */ ··· 1174 1209 /** 1175 1210 * This is an object parameter 1176 1211 */ 1177 - parameterObject: Record<string, unknown> | null; 1212 + parameterObject: { 1213 + [key: string]: unknown; 1214 + } | null; 1178 1215 /** 1179 1216 * This is a string parameter 1180 1217 */ ··· 1196 1233 /** 1197 1234 * Response is a simple object 1198 1235 */ 1199 - 203: Record<string, unknown>; 1236 + 203: { 1237 + [key: string]: unknown; 1238 + }; 1200 1239 }; 1201 1240 }; 1202 1241 };
+60 -21
packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/models.ts.snap
··· 169 169 /** 170 170 * This is a string dictionary 171 171 */ 172 - export type DictionaryWithString = Record<string, string>; 172 + export type DictionaryWithString = { 173 + [key: string]: string; 174 + }; 173 175 174 176 export type DictionaryWithPropertiesAndAdditionalProperties = { 175 177 foo?: string; ··· 179 181 /** 180 182 * This is a string reference 181 183 */ 182 - export type DictionaryWithReference = Record<string, ModelWithString>; 184 + export type DictionaryWithReference = { 185 + [key: string]: ModelWithString; 186 + }; 183 187 184 188 /** 185 189 * This is a complex dictionary 186 190 */ 187 - export type DictionaryWithArray = Record<string, Array<ModelWithString>>; 191 + export type DictionaryWithArray = { 192 + [key: string]: Array<ModelWithString>; 193 + }; 188 194 189 195 /** 190 196 * This is a string dictionary 191 197 */ 192 - export type DictionaryWithDictionary = Record<string, Record<string, string>>; 198 + export type DictionaryWithDictionary = { 199 + [key: string]: { 200 + [key: string]: string; 201 + }; 202 + }; 193 203 194 204 /** 195 205 * This is a complex dictionary 196 206 */ 197 - export type DictionaryWithProperties = Record< 198 - string, 199 - { 207 + export type DictionaryWithProperties = { 208 + [key: string]: { 200 209 foo?: string; 201 210 bar?: string; 202 - } 203 - >; 211 + }; 212 + }; 204 213 205 214 /** 206 215 * This is a model with one number property ··· 302 311 * This is a model with nested enums 303 312 */ 304 313 export type ModelWithNestedEnums = { 305 - dictionaryWithEnum?: Record<string, 'Success' | 'Warning' | 'Error'>; 306 - dictionaryWithEnumFromDescription?: Record<string, number>; 314 + dictionaryWithEnum?: { 315 + [key: string]: 'Success' | 'Warning' | 'Error'; 316 + }; 317 + dictionaryWithEnumFromDescription?: { 318 + [key: string]: number; 319 + }; 307 320 arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; 308 321 arrayWithDescription?: Array<number>; 309 322 /** ··· 341 354 * This is a model with one property containing a dictionary 342 355 */ 343 356 export type ModelWithDictionary = { 344 - prop?: Record<string, string>; 357 + prop?: { 358 + [key: string]: string; 359 + }; 345 360 }; 346 361 347 362 /** ··· 458 473 * This is a model that contains a simple dictionary within composition 459 474 */ 460 475 export type CompositionWithOneOfAndSimpleDictionary = { 461 - propA?: boolean | Record<string, number>; 476 + propA?: 477 + | boolean 478 + | { 479 + [key: string]: number; 480 + }; 462 481 }; 463 482 464 483 /** 465 484 * This is a model that contains a dictionary of simple arrays within composition 466 485 */ 467 486 export type CompositionWithOneOfAndSimpleArrayDictionary = { 468 - propA?: boolean | Record<string, Array<boolean>>; 487 + propA?: 488 + | boolean 489 + | { 490 + [key: string]: Array<boolean>; 491 + }; 469 492 }; 470 493 471 494 /** 472 495 * This is a model that contains a dictionary of complex arrays (composited) within composition 473 496 */ 474 497 export type CompositionWithOneOfAndComplexArrayDictionary = { 475 - propA?: boolean | Record<string, Array<number | string>>; 498 + propA?: 499 + | boolean 500 + | { 501 + [key: string]: Array<number | string>; 502 + }; 476 503 }; 477 504 478 505 /** ··· 626 653 /** 627 654 * This is a free-form object without additionalProperties. 628 655 */ 629 - export type FreeFormObjectWithoutAdditionalProperties = Record<string, unknown>; 656 + export type FreeFormObjectWithoutAdditionalProperties = { 657 + [key: string]: unknown; 658 + }; 630 659 631 660 /** 632 661 * This is a free-form object with additionalProperties: true. 633 662 */ 634 - export type FreeFormObjectWithAdditionalPropertiesEqTrue = Record<string, unknown>; 663 + export type FreeFormObjectWithAdditionalPropertiesEqTrue = { 664 + [key: string]: unknown; 665 + }; 635 666 636 667 /** 637 668 * This is a free-form object with additionalProperties: {}. 638 669 */ 639 - export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = Record<string, unknown>; 670 + export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = { 671 + [key: string]: unknown; 672 + }; 640 673 641 674 export type ModelWithConst = { 642 675 String?: 'String'; ··· 1162 1195 /** 1163 1196 * This is a dictionary parameter 1164 1197 */ 1165 - parameterDictionary: Record<string, unknown> | null; 1198 + parameterDictionary: { 1199 + [key: string]: unknown; 1200 + } | null; 1166 1201 /** 1167 1202 * This is an enum parameter 1168 1203 */ ··· 1174 1209 /** 1175 1210 * This is an object parameter 1176 1211 */ 1177 - parameterObject: Record<string, unknown> | null; 1212 + parameterObject: { 1213 + [key: string]: unknown; 1214 + } | null; 1178 1215 /** 1179 1216 * This is a string parameter 1180 1217 */ ··· 1196 1233 /** 1197 1234 * Response is a simple object 1198 1235 */ 1199 - 203: Record<string, unknown>; 1236 + 203: { 1237 + [key: string]: unknown; 1238 + }; 1200 1239 }; 1201 1240 }; 1202 1241 };
+60 -21
packages/openapi-ts/test/__snapshots__/test/generated/v3_client/models.ts.snap
··· 169 169 /** 170 170 * This is a string dictionary 171 171 */ 172 - export type DictionaryWithString = Record<string, string>; 172 + export type DictionaryWithString = { 173 + [key: string]: string; 174 + }; 173 175 174 176 export type DictionaryWithPropertiesAndAdditionalProperties = { 175 177 foo?: string; ··· 179 181 /** 180 182 * This is a string reference 181 183 */ 182 - export type DictionaryWithReference = Record<string, ModelWithString>; 184 + export type DictionaryWithReference = { 185 + [key: string]: ModelWithString; 186 + }; 183 187 184 188 /** 185 189 * This is a complex dictionary 186 190 */ 187 - export type DictionaryWithArray = Record<string, Array<ModelWithString>>; 191 + export type DictionaryWithArray = { 192 + [key: string]: Array<ModelWithString>; 193 + }; 188 194 189 195 /** 190 196 * This is a string dictionary 191 197 */ 192 - export type DictionaryWithDictionary = Record<string, Record<string, string>>; 198 + export type DictionaryWithDictionary = { 199 + [key: string]: { 200 + [key: string]: string; 201 + }; 202 + }; 193 203 194 204 /** 195 205 * This is a complex dictionary 196 206 */ 197 - export type DictionaryWithProperties = Record< 198 - string, 199 - { 207 + export type DictionaryWithProperties = { 208 + [key: string]: { 200 209 foo?: string; 201 210 bar?: string; 202 - } 203 - >; 211 + }; 212 + }; 204 213 205 214 /** 206 215 * This is a model with one number property ··· 302 311 * This is a model with nested enums 303 312 */ 304 313 export type ModelWithNestedEnums = { 305 - dictionaryWithEnum?: Record<string, 'Success' | 'Warning' | 'Error'>; 306 - dictionaryWithEnumFromDescription?: Record<string, number>; 314 + dictionaryWithEnum?: { 315 + [key: string]: 'Success' | 'Warning' | 'Error'; 316 + }; 317 + dictionaryWithEnumFromDescription?: { 318 + [key: string]: number; 319 + }; 307 320 arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; 308 321 arrayWithDescription?: Array<number>; 309 322 /** ··· 341 354 * This is a model with one property containing a dictionary 342 355 */ 343 356 export type ModelWithDictionary = { 344 - prop?: Record<string, string>; 357 + prop?: { 358 + [key: string]: string; 359 + }; 345 360 }; 346 361 347 362 /** ··· 458 473 * This is a model that contains a simple dictionary within composition 459 474 */ 460 475 export type CompositionWithOneOfAndSimpleDictionary = { 461 - propA?: boolean | Record<string, number>; 476 + propA?: 477 + | boolean 478 + | { 479 + [key: string]: number; 480 + }; 462 481 }; 463 482 464 483 /** 465 484 * This is a model that contains a dictionary of simple arrays within composition 466 485 */ 467 486 export type CompositionWithOneOfAndSimpleArrayDictionary = { 468 - propA?: boolean | Record<string, Array<boolean>>; 487 + propA?: 488 + | boolean 489 + | { 490 + [key: string]: Array<boolean>; 491 + }; 469 492 }; 470 493 471 494 /** 472 495 * This is a model that contains a dictionary of complex arrays (composited) within composition 473 496 */ 474 497 export type CompositionWithOneOfAndComplexArrayDictionary = { 475 - propA?: boolean | Record<string, Array<number | string>>; 498 + propA?: 499 + | boolean 500 + | { 501 + [key: string]: Array<number | string>; 502 + }; 476 503 }; 477 504 478 505 /** ··· 626 653 /** 627 654 * This is a free-form object without additionalProperties. 628 655 */ 629 - export type FreeFormObjectWithoutAdditionalProperties = Record<string, unknown>; 656 + export type FreeFormObjectWithoutAdditionalProperties = { 657 + [key: string]: unknown; 658 + }; 630 659 631 660 /** 632 661 * This is a free-form object with additionalProperties: true. 633 662 */ 634 - export type FreeFormObjectWithAdditionalPropertiesEqTrue = Record<string, unknown>; 663 + export type FreeFormObjectWithAdditionalPropertiesEqTrue = { 664 + [key: string]: unknown; 665 + }; 635 666 636 667 /** 637 668 * This is a free-form object with additionalProperties: {}. 638 669 */ 639 - export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = Record<string, unknown>; 670 + export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = { 671 + [key: string]: unknown; 672 + }; 640 673 641 674 export type ModelWithConst = { 642 675 String?: 'String'; ··· 1162 1195 /** 1163 1196 * This is a dictionary parameter 1164 1197 */ 1165 - parameterDictionary: Record<string, unknown> | null; 1198 + parameterDictionary: { 1199 + [key: string]: unknown; 1200 + } | null; 1166 1201 /** 1167 1202 * This is an enum parameter 1168 1203 */ ··· 1174 1209 /** 1175 1210 * This is an object parameter 1176 1211 */ 1177 - parameterObject: Record<string, unknown> | null; 1212 + parameterObject: { 1213 + [key: string]: unknown; 1214 + } | null; 1178 1215 /** 1179 1216 * This is a string parameter 1180 1217 */ ··· 1196 1233 /** 1197 1234 * Response is a simple object 1198 1235 */ 1199 - 203: Record<string, unknown>; 1236 + 203: { 1237 + [key: string]: unknown; 1238 + }; 1200 1239 }; 1201 1240 }; 1202 1241 };
+9 -3
packages/openapi-ts/test/__snapshots__/test/generated/v3_date/models.ts.snap
··· 427 427 /** 428 428 * This is a dictionary parameter 429 429 */ 430 - parameterDictionary: Record<string, unknown> | null; 430 + parameterDictionary: { 431 + [key: string]: unknown; 432 + } | null; 431 433 /** 432 434 * This is an enum parameter 433 435 */ ··· 439 441 /** 440 442 * This is an object parameter 441 443 */ 442 - parameterObject: Record<string, unknown> | null; 444 + parameterObject: { 445 + [key: string]: unknown; 446 + } | null; 443 447 /** 444 448 * This is a string parameter 445 449 */ ··· 461 465 /** 462 466 * Response is a simple object 463 467 */ 464 - 203: Record<string, unknown>; 468 + 203: { 469 + [key: string]: unknown; 470 + }; 465 471 }; 466 472 }; 467 473 };
+60 -21
packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/models.ts.snap
··· 169 169 /** 170 170 * This is a string dictionary 171 171 */ 172 - export type DictionaryWithString = Record<string, string>; 172 + export type DictionaryWithString = { 173 + [key: string]: string; 174 + }; 173 175 174 176 export type DictionaryWithPropertiesAndAdditionalProperties = { 175 177 foo?: string; ··· 179 181 /** 180 182 * This is a string reference 181 183 */ 182 - export type DictionaryWithReference = Record<string, ModelWithString>; 184 + export type DictionaryWithReference = { 185 + [key: string]: ModelWithString; 186 + }; 183 187 184 188 /** 185 189 * This is a complex dictionary 186 190 */ 187 - export type DictionaryWithArray = Record<string, Array<ModelWithString>>; 191 + export type DictionaryWithArray = { 192 + [key: string]: Array<ModelWithString>; 193 + }; 188 194 189 195 /** 190 196 * This is a string dictionary 191 197 */ 192 - export type DictionaryWithDictionary = Record<string, Record<string, string>>; 198 + export type DictionaryWithDictionary = { 199 + [key: string]: { 200 + [key: string]: string; 201 + }; 202 + }; 193 203 194 204 /** 195 205 * This is a complex dictionary 196 206 */ 197 - export type DictionaryWithProperties = Record< 198 - string, 199 - { 207 + export type DictionaryWithProperties = { 208 + [key: string]: { 200 209 foo?: string; 201 210 bar?: string; 202 - } 203 - >; 211 + }; 212 + }; 204 213 205 214 /** 206 215 * This is a model with one number property ··· 302 311 * This is a model with nested enums 303 312 */ 304 313 export type ModelWithNestedEnums = { 305 - dictionaryWithEnum?: Record<string, 'Success' | 'Warning' | 'Error'>; 306 - dictionaryWithEnumFromDescription?: Record<string, number>; 314 + dictionaryWithEnum?: { 315 + [key: string]: 'Success' | 'Warning' | 'Error'; 316 + }; 317 + dictionaryWithEnumFromDescription?: { 318 + [key: string]: number; 319 + }; 307 320 arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; 308 321 arrayWithDescription?: Array<number>; 309 322 /** ··· 341 354 * This is a model with one property containing a dictionary 342 355 */ 343 356 export type ModelWithDictionary = { 344 - prop?: Record<string, string>; 357 + prop?: { 358 + [key: string]: string; 359 + }; 345 360 }; 346 361 347 362 /** ··· 458 473 * This is a model that contains a simple dictionary within composition 459 474 */ 460 475 export type CompositionWithOneOfAndSimpleDictionary = { 461 - propA?: boolean | Record<string, number>; 476 + propA?: 477 + | boolean 478 + | { 479 + [key: string]: number; 480 + }; 462 481 }; 463 482 464 483 /** 465 484 * This is a model that contains a dictionary of simple arrays within composition 466 485 */ 467 486 export type CompositionWithOneOfAndSimpleArrayDictionary = { 468 - propA?: boolean | Record<string, Array<boolean>>; 487 + propA?: 488 + | boolean 489 + | { 490 + [key: string]: Array<boolean>; 491 + }; 469 492 }; 470 493 471 494 /** 472 495 * This is a model that contains a dictionary of complex arrays (composited) within composition 473 496 */ 474 497 export type CompositionWithOneOfAndComplexArrayDictionary = { 475 - propA?: boolean | Record<string, Array<number | string>>; 498 + propA?: 499 + | boolean 500 + | { 501 + [key: string]: Array<number | string>; 502 + }; 476 503 }; 477 504 478 505 /** ··· 626 653 /** 627 654 * This is a free-form object without additionalProperties. 628 655 */ 629 - export type FreeFormObjectWithoutAdditionalProperties = Record<string, unknown>; 656 + export type FreeFormObjectWithoutAdditionalProperties = { 657 + [key: string]: unknown; 658 + }; 630 659 631 660 /** 632 661 * This is a free-form object with additionalProperties: true. 633 662 */ 634 - export type FreeFormObjectWithAdditionalPropertiesEqTrue = Record<string, unknown>; 663 + export type FreeFormObjectWithAdditionalPropertiesEqTrue = { 664 + [key: string]: unknown; 665 + }; 635 666 636 667 /** 637 668 * This is a free-form object with additionalProperties: {}. 638 669 */ 639 - export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = Record<string, unknown>; 670 + export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = { 671 + [key: string]: unknown; 672 + }; 640 673 641 674 export type ModelWithConst = { 642 675 String?: 'String'; ··· 1162 1195 /** 1163 1196 * This is a dictionary parameter 1164 1197 */ 1165 - parameterDictionary: Record<string, unknown> | null; 1198 + parameterDictionary: { 1199 + [key: string]: unknown; 1200 + } | null; 1166 1201 /** 1167 1202 * This is an enum parameter 1168 1203 */ ··· 1174 1209 /** 1175 1210 * This is an object parameter 1176 1211 */ 1177 - parameterObject: Record<string, unknown> | null; 1212 + parameterObject: { 1213 + [key: string]: unknown; 1214 + } | null; 1178 1215 /** 1179 1216 * This is a string parameter 1180 1217 */ ··· 1196 1233 /** 1197 1234 * Response is a simple object 1198 1235 */ 1199 - 203: Record<string, unknown>; 1236 + 203: { 1237 + [key: string]: unknown; 1238 + }; 1200 1239 }; 1201 1240 }; 1202 1241 };
+60 -21
packages/openapi-ts/test/__snapshots__/test/generated/v3_models/models.ts.snap
··· 169 169 /** 170 170 * This is a string dictionary 171 171 */ 172 - export type DictionaryWithString = Record<string, string>; 172 + export type DictionaryWithString = { 173 + [key: string]: string; 174 + }; 173 175 174 176 export type DictionaryWithPropertiesAndAdditionalProperties = { 175 177 foo?: string; ··· 179 181 /** 180 182 * This is a string reference 181 183 */ 182 - export type DictionaryWithReference = Record<string, ModelWithString>; 184 + export type DictionaryWithReference = { 185 + [key: string]: ModelWithString; 186 + }; 183 187 184 188 /** 185 189 * This is a complex dictionary 186 190 */ 187 - export type DictionaryWithArray = Record<string, Array<ModelWithString>>; 191 + export type DictionaryWithArray = { 192 + [key: string]: Array<ModelWithString>; 193 + }; 188 194 189 195 /** 190 196 * This is a string dictionary 191 197 */ 192 - export type DictionaryWithDictionary = Record<string, Record<string, string>>; 198 + export type DictionaryWithDictionary = { 199 + [key: string]: { 200 + [key: string]: string; 201 + }; 202 + }; 193 203 194 204 /** 195 205 * This is a complex dictionary 196 206 */ 197 - export type DictionaryWithProperties = Record< 198 - string, 199 - { 207 + export type DictionaryWithProperties = { 208 + [key: string]: { 200 209 foo?: string; 201 210 bar?: string; 202 - } 203 - >; 211 + }; 212 + }; 204 213 205 214 /** 206 215 * This is a model with one number property ··· 302 311 * This is a model with nested enums 303 312 */ 304 313 export type ModelWithNestedEnums = { 305 - dictionaryWithEnum?: Record<string, 'Success' | 'Warning' | 'Error'>; 306 - dictionaryWithEnumFromDescription?: Record<string, number>; 314 + dictionaryWithEnum?: { 315 + [key: string]: 'Success' | 'Warning' | 'Error'; 316 + }; 317 + dictionaryWithEnumFromDescription?: { 318 + [key: string]: number; 319 + }; 307 320 arrayWithEnum?: Array<'Success' | 'Warning' | 'Error'>; 308 321 arrayWithDescription?: Array<number>; 309 322 /** ··· 341 354 * This is a model with one property containing a dictionary 342 355 */ 343 356 export type ModelWithDictionary = { 344 - prop?: Record<string, string>; 357 + prop?: { 358 + [key: string]: string; 359 + }; 345 360 }; 346 361 347 362 /** ··· 458 473 * This is a model that contains a simple dictionary within composition 459 474 */ 460 475 export type CompositionWithOneOfAndSimpleDictionary = { 461 - propA?: boolean | Record<string, number>; 476 + propA?: 477 + | boolean 478 + | { 479 + [key: string]: number; 480 + }; 462 481 }; 463 482 464 483 /** 465 484 * This is a model that contains a dictionary of simple arrays within composition 466 485 */ 467 486 export type CompositionWithOneOfAndSimpleArrayDictionary = { 468 - propA?: boolean | Record<string, Array<boolean>>; 487 + propA?: 488 + | boolean 489 + | { 490 + [key: string]: Array<boolean>; 491 + }; 469 492 }; 470 493 471 494 /** 472 495 * This is a model that contains a dictionary of complex arrays (composited) within composition 473 496 */ 474 497 export type CompositionWithOneOfAndComplexArrayDictionary = { 475 - propA?: boolean | Record<string, Array<number | string>>; 498 + propA?: 499 + | boolean 500 + | { 501 + [key: string]: Array<number | string>; 502 + }; 476 503 }; 477 504 478 505 /** ··· 626 653 /** 627 654 * This is a free-form object without additionalProperties. 628 655 */ 629 - export type FreeFormObjectWithoutAdditionalProperties = Record<string, unknown>; 656 + export type FreeFormObjectWithoutAdditionalProperties = { 657 + [key: string]: unknown; 658 + }; 630 659 631 660 /** 632 661 * This is a free-form object with additionalProperties: true. 633 662 */ 634 - export type FreeFormObjectWithAdditionalPropertiesEqTrue = Record<string, unknown>; 663 + export type FreeFormObjectWithAdditionalPropertiesEqTrue = { 664 + [key: string]: unknown; 665 + }; 635 666 636 667 /** 637 668 * This is a free-form object with additionalProperties: {}. 638 669 */ 639 - export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = Record<string, unknown>; 670 + export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = { 671 + [key: string]: unknown; 672 + }; 640 673 641 674 export type ModelWithConst = { 642 675 String?: 'String'; ··· 1162 1195 /** 1163 1196 * This is a dictionary parameter 1164 1197 */ 1165 - parameterDictionary: Record<string, unknown> | null; 1198 + parameterDictionary: { 1199 + [key: string]: unknown; 1200 + } | null; 1166 1201 /** 1167 1202 * This is an enum parameter 1168 1203 */ ··· 1174 1209 /** 1175 1210 * This is an object parameter 1176 1211 */ 1177 - parameterObject: Record<string, unknown> | null; 1212 + parameterObject: { 1213 + [key: string]: unknown; 1214 + } | null; 1178 1215 /** 1179 1216 * This is a string parameter 1180 1217 */ ··· 1196 1233 /** 1197 1234 * Response is a simple object 1198 1235 */ 1199 - 203: Record<string, unknown>; 1236 + 203: { 1237 + [key: string]: unknown; 1238 + }; 1200 1239 }; 1201 1240 }; 1202 1241 };