fork of hey-api/openapi-ts because I need some additional things
at dfad1ca2457ff49e85a2d803733ba0b8b0403a80 603 lines 19 kB view raw
1/* eslint-disable @typescript-eslint/no-unused-vars, arrow-body-style */ 2// @ts-ignore 3import path from 'node:path'; 4 5// @ts-ignore 6import { customClientPlugin } from '@hey-api/custom-client/plugin'; 7// @ts-ignore 8import { defineConfig, reserved, utils } from '@hey-api/openapi-ts'; 9 10// @ts-ignore 11import { myClientPlugin } from '../packages/openapi-ts-tests/main/test/custom/client/plugin'; 12// @ts-ignore 13import { getSpecsPath } from '../packages/openapi-ts-tests/utils'; 14 15reserved.runtime.set((list) => [...list, 'Agent']); 16reserved.type.set((list) => [...list, 'Agent']); 17 18// @ts-ignore 19export default defineConfig(() => { 20 // ... 21 return [ 22 { 23 // experimentalParser: false, 24 input: [ 25 { 26 // fetch: { 27 // headers: { 28 // 'x-foo': 'bar', 29 // }, 30 // }, 31 // path: { 32 // components: {}, 33 // info: { 34 // version: '1.0.0', 35 // }, 36 // openapi: '3.1.0', 37 // paths: {}, 38 // }, 39 path: path.resolve( 40 getSpecsPath(), 41 '3.0.x', 42 // '3.1.x', 43 // 'circular.yaml', 44 // 'dutchie.json', 45 // 'enum-names-values.yaml', 46 // 'full.yaml', 47 // 'integer-formats.yaml', 48 // 'invalid', 49 // 'object-property-names.yaml', 50 // 'openai.yaml', 51 // 'opencode.yaml', 52 // 'pagination-ref.yaml', 53 // 'schema-const.yaml', 54 // 'sdk-instance.yaml', 55 'sdk-method-class-conflict.yaml', 56 // 'sdk-nested-classes.yaml', 57 // 'sdk-nested-conflict.yaml', 58 // 'string-with-format.yaml', 59 // 'transformers.json', 60 // 'transformers-recursive.json', 61 // 'type-format.yaml', 62 // 'validators.yaml', 63 // 'validators-circular-ref.json', 64 // 'validators-circular-ref-2.yaml', 65 // 'zoom-video-sdk.json', 66 ), 67 // path: 'https://get.heyapi.dev/hey-api/backend?branch=main&version=1.0.0', 68 // path: 'http://localhost:4000/', 69 // path: 'http://localhost:8000/openapi.json', 70 // path: 'https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/2caffd88277a4e27c95dcefc7e3b6a63a3b03297-v2-2023-11-15.json', 71 // path: 'https://raw.githubusercontent.com/swagger-api/swagger-petstore/master/src/main/resources/openapi.yaml', 72 // watch: { 73 // enabled: true, 74 // interval: 500, 75 // timeout: 30_000, 76 // }, 77 }, 78 // path.resolve(getSpecsPath(), '3.1.x', 'full.yaml'), 79 // { 80 // branch: 'main', 81 // organization: 'hey-api', 82 // path: 'hey-api/backend', 83 // project: 'backend', 84 // project: 'upload-openapi-spec', 85 // version: '1.0.0', 86 // }, 87 // 'hey-api/backend?branch=main&version=1.0.0', 88 // 'scalar:@scalar/access-service', 89 // 'readme:@developers/v2.0#nysezql0wwo236', 90 // 'readme:nysezql0wwo236', 91 // 'https://dash.readme.com/api/v1/api-registry/nysezql0wwo236', 92 // 'https://somefakedomain.com/openapi.yaml', 93 ], 94 logs: { 95 // level: 'debug', 96 path: './logs', 97 }, 98 // name: 'foo', 99 output: [ 100 { 101 // case: 'snake_case', 102 // clean: true, 103 // fileName: { 104 // // case: 'snake_case', 105 // // name: '{{name}}.renamed', 106 // suffix: '.meh', 107 // }, 108 // format: 'prettier', 109 // importFileExtension: '.js', 110 // indexFile: false, 111 // lint: 'eslint', 112 nameConflictResolver({ attempt, baseName }) { 113 // console.log('resolving conflict for:', { attempt, baseName }); 114 return attempt === 0 ? baseName : `${baseName}_N${attempt + 1}`; 115 }, 116 path: path.resolve(__dirname, '.gen'), 117 // preferExportAll: true, 118 resolveModuleName: (moduleName) => { 119 if (moduleName === 'valibot') { 120 return 'valibot'; 121 } 122 return; 123 }, 124 // tsConfigPath: path.resolve( 125 // __dirname, 126 // 'tsconfig', 127 // 'tsconfig.nodenext.json', 128 // ), 129 }, 130 // '.gen', 131 ], 132 parser: { 133 filters: { 134 // deprecated: false, 135 operations: { 136 include: [ 137 // 'GET /event', 138 // '/^[A-Z]+ /v1//', 139 ], 140 }, 141 // orphans: true, 142 // preserveOrder: true, 143 // schemas: { 144 // include: ['Foo'], 145 // }, 146 // tags: { 147 // exclude: ['bar'], 148 // }, 149 }, 150 hooks: { 151 events: { 152 // 'node:set:after': ({ node, plugin }) => { 153 // if (node) { 154 // console.log(`(${plugin.name}) set node:`, node.symbol); 155 // } 156 // }, 157 // 'node:set:before': ({ node, plugin }) => { 158 // console.log(`(${plugin.name}) setting node:`, node?.symbol?.id); 159 // }, 160 // 'plugin:handler:after': ({ plugin }) => { 161 // console.log(`(${plugin.name}): handler finished`); 162 // }, 163 // 'plugin:handler:before': ({ plugin }) => { 164 // console.log(`(${plugin.name}): handler starting`); 165 // }, 166 // 'symbol:register:after': ({ plugin, symbol }) => { 167 // console.log(`(global, ${plugin.name}) registered:`, symbol.id); 168 // }, 169 'symbol:register:before': ({ plugin, symbol }) => { 170 // if (!symbol.external && !symbol.meta?.resourceType) { 171 // console.log(`[${plugin.name}]:`, symbol.name); 172 // } 173 if (plugin && !symbol.external && !symbol.meta?.path) { 174 // console.log(`[${plugin.name}]:`, symbol.name, symbol.meta); 175 } 176 // if (symbol.meta?.tags && symbol.meta?.tags.size > 0) { 177 // console.log( 178 // `[${plugin.name}]:`, 179 // symbol.name, 180 // symbol.meta.path, 181 // symbol.meta.tags, 182 // ); 183 // } 184 }, 185 }, 186 operations: { 187 getKind() { 188 // noop 189 }, 190 isMutation() { 191 // noop 192 }, 193 isQuery: (op) => { 194 if (op.method === 'post' && op.path === '/search') { 195 return true; 196 } 197 return; 198 }, 199 }, 200 symbols: { 201 // getFilePath: (symbol) => { 202 // if (symbol.name) { 203 // return symbol.name[0]?.toLowerCase(); 204 // } 205 // return; 206 // }, 207 }, 208 }, 209 pagination: { 210 // keywords: ['aa'], 211 }, 212 patch: { 213 // operations: { 214 // 'GET /foo': (operation: any) => { 215 // operation.responses['200'].description = 'foo'; 216 // }, 217 // }, 218 // version: () => '3.1.1', 219 }, 220 transforms: { 221 // enums: { 222 // enabled: false, 223 // mode: 'root', 224 // // name: '{{name}}', 225 // }, 226 // propertiesRequiredByDefault: true, 227 // readWrite: { 228 // // enabled: false, 229 // requests: '{{name}}Writable', 230 // responses: '{{name}}', 231 // }, 232 }, 233 // validate_EXPERIMENTAL: true, 234 }, 235 plugins: [ 236 // customClientPlugin({ 237 // baseUrl: false, 238 // }), 239 // myClientPlugin(), 240 { 241 // baseUrl: false, 242 // exportFromIndex: true, 243 // name: '@hey-api/client-angular', 244 // runtimeConfigPath: path.resolve(__dirname, 'hey-api.ts'), 245 // runtimeConfigPath: './src/hey-api.ts', 246 // strictBaseUrl: true, 247 throwOnError: true, 248 }, 249 { 250 // case: 'snake_case', 251 // definitions: '你_snake_{{name}}', 252 enums: { 253 // case: 'PascalCase', 254 // constantsIgnoreNull: true, 255 // enabled: false, 256 // mode: 'typescript', 257 }, 258 // errors: { 259 // error: '他們_error_{{name}}', 260 // name: '你們_errors_{{name}}', 261 // }, 262 // exportFromIndex: false, 263 name: '@hey-api/typescript', 264 // requests: '我們_data_{{name}}', 265 // responses: { 266 // name: '我_responses_{{name}}', 267 // response: '他_response_{{name}}', 268 // }, 269 // topType: 'any', 270 // tree: true, 271 // webhooks: { 272 // name: 'Webby{{name}}Hook', 273 // payload: '{{name}}WebhookEvent', 274 // }, 275 }, 276 { 277 // asClass: true, 278 // auth: false, 279 // classNameBuilder: '{{name}}', 280 // classNameBuilder: '{{name}}Service', 281 // classStructure: 'off', 282 // client: false, 283 // getSignature: ({ fields, signature, operation }) => { 284 // // ... 285 // fields.unwrap('path') 286 // }, 287 // include... 288 instance: true, 289 name: '@hey-api/sdk', 290 // operationId: false, 291 // paramsStructure: 'flat', 292 // responseStyle: 'data', 293 // signature: 'auto', 294 // signature: 'client', 295 // signature: 'object', 296 // transformer: '@hey-api/transformers', 297 // transformer: true, 298 // validator: 'valibot', 299 // validator: { 300 // request: 'zod', 301 // response: 'zod', 302 // }, 303 '~hooks': { 304 symbols: { 305 // getFilePath: (symbol) => { 306 // if (symbol.name) { 307 // return utils.stringCase({ 308 // case: 'camelCase', 309 // value: symbol.name, 310 // }); 311 // } 312 // return; 313 // }, 314 }, 315 }, 316 }, 317 { 318 // bigInt: true, 319 dates: true, 320 // name: '@hey-api/transformers', 321 }, 322 { 323 // name: 'fastify', 324 }, 325 { 326 // name: 'swr', 327 }, 328 { 329 // case: 'SCREAMING_SNAKE_CASE', 330 // comments: false, 331 exportFromIndex: true, 332 infiniteQueryKeys: { 333 // name: '{{name}}IQK', 334 // name: 'options', 335 }, 336 infiniteQueryOptions: { 337 meta() { 338 return { 339 custom: 'value', 340 }; 341 }, 342 // name: '{{name}}IQO', 343 // name: 'options', 344 }, 345 mutationOptions: { 346 meta() { 347 return { 348 custom: 'value', 349 }; 350 }, 351 // name: '{{name}}MO', 352 // name: 'options', 353 }, 354 name: '@tanstack/react-query', 355 queryKeys: { 356 // name: '{{name}}QK', 357 // name: 'options', 358 tags: true, 359 }, 360 // queryOptions: false, 361 queryOptions: { 362 // meta() { 363 // return { 364 // custom: 'value', 365 // } 366 // }, 367 // name: '{{name}}QO', 368 // name: 'options', 369 }, 370 useQuery: true, 371 '~hooks': { 372 operations: { 373 getKind: (op) => { 374 if (op.method === 'post' && op.path === '/search') { 375 return ['query']; 376 } 377 return; 378 }, 379 isMutation() { 380 // noop 381 }, 382 isQuery: () => { 383 // noop 384 }, 385 }, 386 }, 387 }, 388 { 389 // name: 'arktype', 390 types: { 391 infer: true, 392 }, 393 }, 394 { 395 // case: 'SCREAMING_SNAKE_CASE', 396 // comments: false, 397 definitions: 'z{{name}}', 398 exportFromIndex: true, 399 // metadata: true, 400 // name: 'valibot', 401 // requests: { 402 // case: 'PascalCase', 403 // name: '{{name}}Data', 404 // }, 405 responses: { 406 // case: 'snake_case', 407 name: 'z{{name}}TestResponse', 408 }, 409 // webhooks: { 410 // name: 'q{{name}}CoolWebhook', 411 // }, 412 '~hooks': { 413 events: { 414 // 'symbol:register:after': ({ plugin, symbol }) => { 415 // console.log(`(${plugin.name}) registered:`, symbol.id); 416 // }, 417 // 'symbol:register:before': ({ plugin, symbol }) => { 418 // console.log(`(${plugin.name}):`, symbol.name); 419 // }, 420 }, 421 symbols: { 422 // getFilePath: (symbol) => { 423 // if (symbol.name) { 424 // return utils.stringCase({ 425 // case: 'camelCase', 426 // value: symbol.name, 427 // }); 428 // } 429 // return; 430 // }, 431 }, 432 }, 433 '~resolvers': { 434 object: { 435 // base({ $, additional, pipes, shape }) { 436 // if (additional === undefined) { 437 // return pipes.push($('v').attr('looseObject').call(shape)); 438 // } 439 // return; 440 // }, 441 }, 442 string: { 443 formats: { 444 // date: ({ $, pipes }) => pipes.push($('v').attr('isoDateTime').call()), 445 // 'date-time': ({ $, pipes }) => pipes.push($('v').attr('isoDateTime').call()), 446 }, 447 }, 448 // validator({ $, plugin, schema, v }) { 449 // const vShadow = plugin.symbol('v'); 450 // const test = plugin.symbol('test'); 451 // const e = plugin.symbol('err'); 452 // return [ 453 // $.const(vShadow).assign($.literal('hi')), 454 // $('console').attr('log').call(vShadow), 455 // $.try( 456 // $.const(test).assign($.literal('test')), 457 // $('console').attr('log').call($.literal('hi'), test), 458 // ).catchArg(e), 459 // $.const('parsed').assign( 460 // $(v).attr('safeParseAsync').call(schema, 'data').await(), 461 // ), 462 // $('parsed').return(), 463 // ]; 464 // }, 465 }, 466 }, 467 { 468 // case: 'snake_case', 469 // comments: false, 470 compatibilityVersion: 4, 471 dates: { 472 // local: true, 473 // offset: true, 474 }, 475 definitions: { 476 // name: 'z{{name}}Definition', 477 // types: { 478 // infer: 'D{{name}}ZodType', 479 // }, 480 }, 481 exportFromIndex: true, 482 metadata: true, 483 name: 'zod', 484 // requests: { 485 // // case: 'SCREAMING_SNAKE_CASE', 486 // // name: 'z{{name}}TestData', 487 // types: { 488 // infer: 'E{{name}}DataZodType', 489 // }, 490 // }, 491 responses: { 492 // case: 'snake_case', 493 // name: (name) => { 494 // if (name === 'complexTypes') { 495 // return 'z'; 496 // } 497 // return 'z{{name}}Response'; 498 // }, 499 // types: { 500 // infer: 'F{{name}}ResponseZodType', 501 // }, 502 }, 503 types: { 504 // infer: { 505 // case: 'snake_case', 506 // }, 507 }, 508 '~hooks': { 509 symbols: { 510 // getFilePath: (symbol) => { 511 // if (symbol.name === 'z') { 512 // return 'complexService'; 513 // } 514 // return; 515 // }, 516 }, 517 }, 518 '~resolvers': { 519 object: { 520 // base({ $, additional, shape }) { 521 // if (!additional) { 522 // // return $('z').attr('object').call(shape).attr('passthrough').call() 523 // return $('z').attr('object').call(shape).attr('strict').call(); 524 // } 525 // return; 526 // }, 527 }, 528 string: { 529 formats: { 530 // date: ({ $ }) => $('z').attr('date').call(), 531 // 'date-time': ({ $ }) => $('z').attr('date').call(), 532 // int64: ({ $ }) => $('z').attr('string').call().attr('refine').call( 533 // $.func().param('val').do( 534 // $.try( 535 // $('z').attr('int64').call().attr('parse').call($('BigInt').call('val')), 536 // $.return($.literal(true)) 537 // ).catch( 538 // $.return($.literal(false)) 539 // ), 540 // ), 541 // $.object().prop('message', $.literal('Must be a valid int64 string')) 542 // ), 543 }, 544 }, 545 // validator({ $, schema }) { 546 // return [ 547 // $.const('parsed').assign( 548 // $(schema).attr('safeParseAsync').call('data').await(), 549 // ), 550 // $('parsed').return(), 551 // ]; 552 // }, 553 }, 554 }, 555 { 556 exportFromIndex: true, 557 // name: '@hey-api/schemas', 558 // type: 'json', 559 }, 560 { 561 exportFromIndex: true, 562 httpRequests: { 563 asClass: true, 564 }, 565 httpResources: { 566 asClass: true, 567 }, 568 // name: '@angular/common', 569 }, 570 { 571 exportFromIndex: true, 572 // mutationOptions: '{{name}}Mutationssss', 573 name: '@pinia/colada', 574 // queryOptions: { 575 // name: '{{name}}Queryyyyy', 576 // }, 577 queryKeys: { 578 tags: true, 579 }, 580 '~hooks': { 581 operations: { 582 getKind: (op) => { 583 if (op.method === 'post' && op.path === '/search') { 584 return ['query']; 585 } 586 return; 587 }, 588 }, 589 }, 590 }, 591 ], 592 // watch: 3_000, 593 }, 594 // { 595 // input: 'scalar:@scalar/access-service', 596 // logs: { 597 // // level: 'debug', 598 // path: './logs', 599 // }, 600 // output: '.gen', 601 // }, 602 ]; 603});