fork of hey-api/openapi-ts because I need some additional things
at main 21 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 // number(ctx) { 435 // const { $, plugin, symbols } = ctx; 436 // const { v } = symbols; 437 // // ctx.nodes.base = () => { 438 // // // implement custom base number resolver 439 // // } 440 // const big = plugin.symbolOnce('Big', { 441 // external: 'big.js', 442 // importKind: 'default', 443 // }); 444 // return $(v).attr('instance').call(big); 445 // }, 446 object(ctx) { 447 const { $, symbols } = ctx; 448 const { v } = symbols; 449 const additional = ctx.nodes.additionalProperties(ctx); 450 if (additional === undefined) { 451 const shape = ctx.nodes.shape(ctx); 452 ctx.nodes.base = () => $(v).attr('looseObject').call(shape); 453 } 454 }, 455 // string(ctx) { 456 // const { $, schema, symbols } = ctx; 457 // const { v } = symbols; 458 // if (schema.format === 'date' || schema.format === 'date-time') { 459 // ctx.nodes.format = () => $(v).attr('isoDateTime').call(); 460 // } 461 // }, 462 // validator(ctx) { 463 // const { $, plugin, symbols } = ctx; 464 // const { schema, v } = symbols; 465 // const vShadow = plugin.symbol('v'); 466 // const test = plugin.symbol('test'); 467 // const e = plugin.symbol('err'); 468 // return [ 469 // $.const(vShadow).assign($.literal('hi')), 470 // $('console').attr('log').call(vShadow), 471 // $.try( 472 // $.const(test).assign($.literal('test')), 473 // $('console').attr('log').call($.literal('hi'), test), 474 // ).catchArg(e), 475 // $.const('parsed').assign( 476 // $(v).attr('safeParseAsync').call(schema, 'data').await(), 477 // ), 478 // $('parsed').return(), 479 // ]; 480 // }, 481 }, 482 }, 483 { 484 // case: 'snake_case', 485 // comments: false, 486 compatibilityVersion: 'mini', 487 dates: { 488 // local: true, 489 // offset: true, 490 }, 491 definitions: { 492 // name: 'z{{name}}Definition', 493 // types: { 494 // infer: 'D{{name}}ZodType', 495 // }, 496 }, 497 exportFromIndex: true, 498 metadata: true, 499 name: 'zod', 500 // requests: { 501 // // case: 'SCREAMING_SNAKE_CASE', 502 // // name: 'z{{name}}TestData', 503 // types: { 504 // infer: 'E{{name}}DataZodType', 505 // }, 506 // }, 507 responses: { 508 // case: 'snake_case', 509 // name: (name) => { 510 // if (name === 'complexTypes') { 511 // return 'z'; 512 // } 513 // return 'z{{name}}Response'; 514 // }, 515 // types: { 516 // infer: 'F{{name}}ResponseZodType', 517 // }, 518 }, 519 types: { 520 // infer: { 521 // case: 'snake_case', 522 // }, 523 }, 524 '~hooks': { 525 symbols: { 526 // getFilePath: (symbol) => { 527 // if (symbol.name === 'z') { 528 // return 'complexService'; 529 // } 530 // return; 531 // }, 532 }, 533 }, 534 '~resolvers': { 535 // number(ctx) { 536 // const { $, plugin, symbols } = ctx; 537 // const { z } = symbols; 538 // // ctx.nodes.base = () => { 539 // // // implement custom base number resolver 540 // // } 541 // const big = plugin.symbolOnce('Big', { 542 // external: 'big.js', 543 // importKind: 'default', 544 // }); 545 // return $(z).attr('instanceof').call(big); 546 // }, 547 // object(ctx) { 548 // const { $, symbols } = ctx; 549 // const { z } = symbols; 550 // const additional = ctx.nodes.additionalProperties(ctx); 551 // if (additional === undefined) { 552 // const shape = ctx.nodes.shape(ctx); 553 // // return $('z').attr('object').call(shape).attr('passthrough').call() 554 // ctx.nodes.base = () => 555 // $(z).attr('object').call(shape).attr('strict').call(); 556 // } 557 // }, 558 // string(ctx) { 559 // const { $, schema, symbols } = ctx; 560 // const { z } = symbols; 561 // if (schema.format === 'date' || schema.format === 'date-time') { 562 // ctx.nodes.format = () => $(z).attr('date').call(); 563 // } 564 // if (schema.format === 'int64') { 565 // ctx.nodes.format = () => 566 // $(z) 567 // .attr('string') 568 // .call() 569 // .attr('refine') 570 // .call( 571 // $.func() 572 // .param('val') 573 // .do( 574 // $.try( 575 // $(z) 576 // .attr('int64') 577 // .call() 578 // .attr('parse') 579 // .call($('BigInt').call('val')), 580 // $.return($.literal(true)), 581 // ).catch($.return($.literal(false))), 582 // ), 583 // $.object().prop( 584 // 'message', 585 // $.literal('Must be a valid int64 string'), 586 // ), 587 // ); 588 // } 589 // }, 590 // validator({ $, schema }) { 591 // return [ 592 // $.const('parsed').assign( 593 // $(schema).attr('safeParseAsync').call('data').await(), 594 // ), 595 // $('parsed').return(), 596 // ]; 597 // }, 598 }, 599 }, 600 { 601 exportFromIndex: true, 602 // name: '@hey-api/schemas', 603 // type: 'json', 604 }, 605 { 606 exportFromIndex: true, 607 httpRequests: { 608 asClass: true, 609 }, 610 httpResources: { 611 asClass: true, 612 }, 613 // name: '@angular/common', 614 }, 615 { 616 exportFromIndex: true, 617 // mutationOptions: '{{name}}Mutationssss', 618 name: '@pinia/colada', 619 // queryOptions: { 620 // name: '{{name}}Queryyyyy', 621 // }, 622 queryKeys: { 623 tags: true, 624 }, 625 '~hooks': { 626 operations: { 627 getKind: (op) => { 628 if (op.method === 'post' && op.path === '/search') { 629 return ['query']; 630 } 631 return; 632 }, 633 }, 634 }, 635 }, 636 ], 637 // watch: 3_000, 638 }, 639 // { 640 // input: 'scalar:@scalar/access-service', 641 // logs: { 642 // // level: 'debug', 643 // path: './logs', 644 // }, 645 // output: '.gen', 646 // }, 647 ]; 648});