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.

refactor: clean up symbolOnce interface

Lubos 497f219e 131085cb

+42 -32
+5 -7
dev/openapi-ts.config.ts
··· 432 432 }, 433 433 '~resolvers': { 434 434 number(ctx) { 435 - const { $, plugin } = ctx; 436 - const { v } = ctx.symbols; 435 + const { $, plugin, symbols } = ctx; 436 + const { v } = symbols; 437 + // ctx.nodes.base = () => { 438 + // // implement custom base number resolver 439 + // } 437 440 const big = plugin.symbolOnce('Big', { 438 441 external: 'big.js', 439 442 importKind: 'default', 440 - meta: { 441 - category: 'external', 442 - resource: 'big.js', 443 - }, 444 443 }); 445 444 return $(v).attr('instance').call(big); 446 445 }, ··· 458 457 // if (schema.format === 'date' || schema.format === 'date-time') { 459 458 // ctx.nodes.format = () => $('v').attr('isoDateTime').call(); 460 459 // } 461 - // return; 462 460 // }, 463 461 // validator({ $, plugin, schema, v }) { 464 462 // const vShadow = plugin.symbol('v');
+4
packages/codegen-core/src/symbols/types.d.ts
··· 44 44 getFilePath?: Symbol['getFilePath']; 45 45 /** 46 46 * Kind of import if this symbol represents an import. 47 + * 48 + * @default 'named' 47 49 */ 48 50 importKind?: BindingKind; 49 51 /** 50 52 * Kind of symbol. 53 + * 54 + * @default 'var' 51 55 */ 52 56 kind?: SymbolKind; 53 57 /**
+9 -2
packages/openapi-ts/src/plugins/shared/utils/instance.ts
··· 394 394 * metadata. This prevents duplicate symbols from being created in the project. 395 395 */ 396 396 symbolOnce(name: SymbolIn['name'], symbol?: Omit<SymbolIn, 'name'>): Symbol { 397 - const existing = symbol?.meta ? this.querySymbol(symbol.meta) : undefined; 397 + const meta = { 398 + ...symbol?.meta, 399 + }; 400 + if (symbol?.external) { 401 + meta.category = 'external'; 402 + meta.resource = symbol.external; 403 + } 404 + const existing = this.querySymbol(meta); 398 405 if (existing) return existing; 399 - return this.symbol(name, symbol); 406 + return this.symbol(name, { ...symbol, meta }); 400 407 } 401 408 402 409 private buildEventHooks(): EventHooks {
+2 -2
packages/openapi-ts/src/plugins/valibot/v1/api.ts
··· 8 8 const validatorResolver = ( 9 9 ctx: ValidatorResolverArgs, 10 10 ): ReturnType<typeof $.return> => { 11 - const { schema } = ctx; 12 - const { v } = ctx.symbols; 11 + const { schema, symbols } = ctx; 12 + const { v } = symbols; 13 13 return $(v) 14 14 .attr(identifiers.async.parseAsync) 15 15 .call(schema, 'data')
+8 -8
packages/openapi-ts/src/plugins/valibot/v1/toAst/number.ts
··· 13 13 import { identifiers } from '../constants'; 14 14 15 15 function baseNode(ctx: NumberResolverContext): PipeResult { 16 - const { schema } = ctx; 17 - const { v } = ctx.symbols; 16 + const { schema, symbols } = ctx; 17 + const { v } = symbols; 18 18 if (ctx.utils.shouldCoerceToBigInt(schema.format)) { 19 19 return [ 20 20 $(v) ··· 40 40 } 41 41 42 42 function constNode(ctx: NumberResolverContext): PipeResult | undefined { 43 - const { schema } = ctx; 44 - const { v } = ctx.symbols; 43 + const { schema, symbols } = ctx; 44 + const { v } = symbols; 45 45 if (schema.const === undefined) return; 46 46 return $(v) 47 47 .attr(identifiers.schemas.literal) ··· 49 49 } 50 50 51 51 function maxNode(ctx: NumberResolverContext): PipeResult | undefined { 52 - const { schema } = ctx; 53 - const { v } = ctx.symbols; 52 + const { schema, symbols } = ctx; 53 + const { v } = symbols; 54 54 if (schema.exclusiveMaximum !== undefined) { 55 55 return $(v) 56 56 .attr(identifiers.actions.ltValue) ··· 74 74 } 75 75 76 76 function minNode(ctx: NumberResolverContext): PipeResult | undefined { 77 - const { schema } = ctx; 78 - const { v } = ctx.symbols; 77 + const { schema, symbols } = ctx; 78 + const { v } = symbols; 79 79 if (schema.exclusiveMinimum !== undefined) { 80 80 return $(v) 81 81 .attr(identifiers.actions.gtValue)
+4 -3
packages/openapi-ts/src/plugins/valibot/v1/toAst/object.ts
··· 31 31 } 32 32 33 33 function baseNode(ctx: ObjectResolverContext): PipeResult { 34 - const { v } = ctx.symbols; 34 + const { nodes, symbols } = ctx; 35 + const { v } = symbols; 35 36 36 - const additional = ctx.nodes.additionalProperties(ctx); 37 - const shape = ctx.nodes.shape(ctx); 37 + const additional = nodes.additionalProperties(ctx); 38 + const shape = nodes.shape(ctx); 38 39 39 40 if (additional === null) { 40 41 return $(v).attr(identifiers.schemas.strictObject).call(shape);
+10 -10
packages/openapi-ts/src/plugins/valibot/v1/toAst/string.ts
··· 20 20 } 21 21 22 22 function formatNode(ctx: StringResolverContext): PipeResult | undefined { 23 - const { schema } = ctx; 24 - const { v } = ctx.symbols; 23 + const { schema, symbols } = ctx; 24 + const { v } = symbols; 25 25 switch (schema.format) { 26 26 case 'date': 27 27 return $(v).attr(identifiers.actions.isoDate).call(); ··· 44 44 } 45 45 46 46 function lengthNode(ctx: StringResolverContext): PipeResult | undefined { 47 - const { schema } = ctx; 48 - const { v } = ctx.symbols; 47 + const { schema, symbols } = ctx; 48 + const { v } = symbols; 49 49 if (schema.minLength === undefined || schema.minLength !== schema.maxLength) 50 50 return; 51 51 return $(v) ··· 54 54 } 55 55 56 56 function maxLengthNode(ctx: StringResolverContext): PipeResult | undefined { 57 - const { schema } = ctx; 58 - const { v } = ctx.symbols; 57 + const { schema, symbols } = ctx; 58 + const { v } = symbols; 59 59 if (schema.maxLength === undefined) return; 60 60 return $(v) 61 61 .attr(identifiers.actions.maxLength) ··· 63 63 } 64 64 65 65 function minLengthNode(ctx: StringResolverContext): PipeResult | undefined { 66 - const { schema } = ctx; 67 - const { v } = ctx.symbols; 66 + const { schema, symbols } = ctx; 67 + const { v } = symbols; 68 68 if (schema.minLength === undefined) return; 69 69 return $(v) 70 70 .attr(identifiers.actions.minLength) ··· 72 72 } 73 73 74 74 function patternNode(ctx: StringResolverContext): PipeResult | undefined { 75 - const { schema } = ctx; 76 - const { v } = ctx.symbols; 75 + const { schema, symbols } = ctx; 76 + const { v } = symbols; 77 77 if (!schema.pattern) return; 78 78 return $(v).attr(identifiers.actions.regex).call($.regexp(schema.pattern)); 79 79 }