diff --git a/.changeset/eight-dodos-find.md b/.changeset/eight-dodos-find.md new file mode 100644 index 0000000000..7056eeb9ee --- /dev/null +++ b/.changeset/eight-dodos-find.md @@ -0,0 +1,5 @@ +--- +"@hey-api/codegen-core": patch +--- + +**node**: add `~dsl` property diff --git a/.changeset/eighty-cats-kneel.md b/.changeset/eighty-cats-kneel.md new file mode 100644 index 0000000000..b0f4f657bf --- /dev/null +++ b/.changeset/eighty-cats-kneel.md @@ -0,0 +1,5 @@ +--- +"@hey-api/shared": patch +--- + +**plugin**: add generics support to `querySymbol()` and `querySymbols()` diff --git a/.changeset/eleven-bees-invite.md b/.changeset/eleven-bees-invite.md new file mode 100644 index 0000000000..7b03219560 --- /dev/null +++ b/.changeset/eleven-bees-invite.md @@ -0,0 +1,5 @@ +--- +"@hey-api/openapi-ts": patch +--- + +**cli**: simplify generate command messages diff --git a/.changeset/huge-pets-remain.md b/.changeset/huge-pets-remain.md new file mode 100644 index 0000000000..355bdfae0e --- /dev/null +++ b/.changeset/huge-pets-remain.md @@ -0,0 +1,5 @@ +--- +"@hey-api/openapi-ts": patch +--- + +**plugin(valibot)**: fix: revert referencing TypeScript enums diff --git a/.changeset/tired-suits-hunt.md b/.changeset/tired-suits-hunt.md new file mode 100644 index 0000000000..65cbf41bdf --- /dev/null +++ b/.changeset/tired-suits-hunt.md @@ -0,0 +1,5 @@ +--- +"@hey-api/openapi-ts": patch +--- + +**plugin(zod)**: fix: revert referencing TypeScript enums diff --git a/dev/inputs.ts b/dev/inputs.ts index 430f8d3b42..68c29018ff 100644 --- a/dev/inputs.ts +++ b/dev/inputs.ts @@ -7,10 +7,27 @@ export const inputs = { clerk: path.resolve(specsPath, '3.0.x', 'clerk-2025-11-10.yaml'), cloudflare: path.resolve(specsPath, '3.0.x', 'cloudflare-v4.json'), full: path.resolve(specsPath, '3.1.x', 'full.yaml'), + 'hey-api': 'hey-api/backend', local: 'http://localhost:8000/openapi.json', opencode: path.resolve(specsPath, '3.1.x', 'opencode.yaml'), petstore: 'https://raw.githubusercontent.com/swagger-api/swagger-petstore/master/src/main/resources/openapi.yaml', + raw: { + components: { + schemas: { + Foo: { + type: 'string', + }, + }, + }, + info: { + title: 'Raw Spec', + version: '1.0.0', + }, + openapi: '3.1.0', + } as const, + readme: 'readme:@developers/v2.0#nysezql0wwo236', + 'readme-uuid': 'readme:nysezql0wwo236', redfish: 'https://raw.githubusercontent.com/DMTF/Redfish-Publications/refs/heads/main/openapi/openapi.yaml', scalar: 'scalar:@scalar/access-service', diff --git a/packages/codegen-core/src/nodes/node.ts b/packages/codegen-core/src/nodes/node.ts index 38e3f7b64b..3be1ac591e 100644 --- a/packages/codegen-core/src/nodes/node.ts +++ b/packages/codegen-core/src/nodes/node.ts @@ -1,3 +1,5 @@ +import type { AnyString } from '@hey-api/types'; + import type { File } from '../files/file'; import type { Language } from '../languages/types'; import type { IAnalysisContext } from '../planner/types'; @@ -46,4 +48,6 @@ export interface INode { toAst(): T; /** Brand used for renderer dispatch. */ readonly '~brand': string; + /** Branding property to identify the DSL class at runtime. */ + readonly '~dsl'?: AnyString; } diff --git a/packages/openapi-python/src/createClient.ts b/packages/openapi-python/src/createClient.ts index 2a64f821c8..213a0cb385 100644 --- a/packages/openapi-python/src/createClient.ts +++ b/packages/openapi-python/src/createClient.ts @@ -49,8 +49,8 @@ export async function createClient({ const inputPaths = config.input.map((input) => compileInputPath(input)); // on first run, print the message as soon as possible - if (config.logs.level !== 'silent' && !_watches) { - logInputPaths(inputPaths, jobIndex); + if (!_watches) { + logInputPaths(inputPaths, jobIndex, config.logs.level); } const getSpecData = async (input: Input, index: number) => { @@ -116,9 +116,9 @@ export async function createClient({ // on subsequent runs in watch mode, print the message only if we know we're // generating the output - if (config.logs.level !== 'silent' && _watches) { + if (_watches) { console.clear(); - logInputPaths(inputPaths, jobIndex); + logInputPaths(inputPaths, jobIndex, config.logs.level); } const eventInputPatch = logger.timeEvent('input.patch'); @@ -183,7 +183,7 @@ export async function createClient({ ? `./${path.relative(process.env.INIT_CWD, config.output.path)}` : config.output.path; console.log( - `${jobPrefix}${colors.green('✅ Done!')} Your output is in ${colors.cyanBright(outputPath)} ${colors.gray(`(${fileCount} ${fileCount === 1 ? 'file' : 'files'} in ${ms(totalMs)})`)}`, + `${jobPrefix}${colors.green('✓')} ${colors.cyanBright(outputPath)} ${colors.gray(`· ${fileCount} ${fileCount === 1 ? 'file' : 'files'} · ${ms(totalMs)}`)}`, ); } } diff --git a/packages/openapi-ts-tests/main/test/3.1.x.test.ts b/packages/openapi-ts-tests/main/test/3.1.x.test.ts index ff68055402..4ce24fe22a 100644 --- a/packages/openapi-ts-tests/main/test/3.1.x.test.ts +++ b/packages/openapi-ts-tests/main/test/3.1.x.test.ts @@ -378,14 +378,14 @@ describe(`OpenAPI ${version}`, () => { }, { config: createConfig({ - input: 'enum-names-values.yaml', + input: 'enum-names-values.json', output: 'enum-names-values', }), description: 'handles various enum names and values', }, { config: createConfig({ - input: 'enum-names-values.yaml', + input: 'enum-names-values.json', output: 'enum-names-values-javascript-SCREAMING_SNAKE_CASE', plugins: [ { @@ -401,7 +401,7 @@ describe(`OpenAPI ${version}`, () => { }, { config: createConfig({ - input: 'enum-names-values.yaml', + input: 'enum-names-values.json', output: 'enum-names-values-javascript-PascalCase', plugins: [ { @@ -417,7 +417,7 @@ describe(`OpenAPI ${version}`, () => { }, { config: createConfig({ - input: 'enum-names-values.yaml', + input: 'enum-names-values.json', output: 'enum-names-values-javascript-camelCase', plugins: [ { @@ -433,7 +433,7 @@ describe(`OpenAPI ${version}`, () => { }, { config: createConfig({ - input: 'enum-names-values.yaml', + input: 'enum-names-values.json', output: 'enum-names-values-javascript-snake_case', plugins: [ { @@ -449,7 +449,7 @@ describe(`OpenAPI ${version}`, () => { }, { config: createConfig({ - input: 'enum-names-values.yaml', + input: 'enum-names-values.json', output: 'enum-names-values-javascript-preserve', plugins: [ { @@ -465,7 +465,7 @@ describe(`OpenAPI ${version}`, () => { }, { config: createConfig({ - input: 'enum-names-values.yaml', + input: 'enum-names-values.json', output: 'enum-names-values-javascript-ignore-null', plugins: [ { @@ -482,7 +482,7 @@ describe(`OpenAPI ${version}`, () => { }, { config: createConfig({ - input: 'enum-names-values.yaml', + input: 'enum-names-values.json', output: 'enum-names-values-typescript-SCREAMING_SNAKE_CASE', plugins: [ { @@ -498,7 +498,7 @@ describe(`OpenAPI ${version}`, () => { }, { config: createConfig({ - input: 'enum-names-values.yaml', + input: 'enum-names-values.json', output: 'enum-names-values-typescript-PascalCase', plugins: [ { @@ -514,7 +514,7 @@ describe(`OpenAPI ${version}`, () => { }, { config: createConfig({ - input: 'enum-names-values.yaml', + input: 'enum-names-values.json', output: 'enum-names-values-typescript-camelCase', plugins: [ { @@ -530,7 +530,7 @@ describe(`OpenAPI ${version}`, () => { }, { config: createConfig({ - input: 'enum-names-values.yaml', + input: 'enum-names-values.json', output: 'enum-names-values-typescript-snake_case', plugins: [ { @@ -546,7 +546,7 @@ describe(`OpenAPI ${version}`, () => { }, { config: createConfig({ - input: 'enum-names-values.yaml', + input: 'enum-names-values.json', output: 'enum-names-values-typescript-preserve', plugins: [ { @@ -562,7 +562,7 @@ describe(`OpenAPI ${version}`, () => { }, { config: createConfig({ - input: 'enum-names-values.yaml', + input: 'enum-names-values.json', output: 'enum-names-values-typescript-const', plugins: [ { diff --git a/packages/openapi-ts/src/createClient.ts b/packages/openapi-ts/src/createClient.ts index 3a96dc7e83..354f460b51 100644 --- a/packages/openapi-ts/src/createClient.ts +++ b/packages/openapi-ts/src/createClient.ts @@ -49,8 +49,8 @@ export async function createClient({ const inputPaths = config.input.map((input) => compileInputPath(input)); // on first run, print the message as soon as possible - if (config.logs.level !== 'silent' && !_watches) { - logInputPaths(inputPaths, jobIndex); + if (!_watches) { + logInputPaths(inputPaths, jobIndex, config.logs.level); } const getSpecData = async (input: Input, index: number) => { @@ -116,9 +116,9 @@ export async function createClient({ // on subsequent runs in watch mode, print the message only if we know we're // generating the output - if (config.logs.level !== 'silent' && _watches) { + if (_watches) { console.clear(); - logInputPaths(inputPaths, jobIndex); + logInputPaths(inputPaths, jobIndex, config.logs.level); } const eventInputPatch = logger.timeEvent('input.patch'); @@ -183,7 +183,7 @@ export async function createClient({ ? `./${path.relative(process.env.INIT_CWD, config.output.path)}` : config.output.path; console.log( - `${jobPrefix}${colors.green('✅ Done!')} Your output is in ${colors.cyanBright(outputPath)} ${colors.gray(`(${fileCount} ${fileCount === 1 ? 'file' : 'files'} in ${ms(totalMs)})`)}`, + `${jobPrefix}${colors.green('✓')} ${colors.cyanBright(outputPath)} ${colors.gray(`· ${fileCount} ${fileCount === 1 ? 'file' : 'files'} · ${ms(totalMs)}`)}`, ); } } diff --git a/packages/openapi-ts/src/plugins/valibot/v1/toAst/enum.ts b/packages/openapi-ts/src/plugins/valibot/v1/toAst/enum.ts index 854aea8fe7..53b8c1c5e7 100644 --- a/packages/openapi-ts/src/plugins/valibot/v1/toAst/enum.ts +++ b/packages/openapi-ts/src/plugins/valibot/v1/toAst/enum.ts @@ -1,5 +1,4 @@ -import { fromRef } from '@hey-api/codegen-core'; -import { pathToJsonPointer, type SchemaVisitorContext, type SchemaWithType } from '@hey-api/shared'; +import type { SchemaVisitorContext, SchemaWithType } from '@hey-api/shared'; import { $ } from '../../../../ts-dsl'; import type { EnumResolverContext } from '../../resolvers'; @@ -45,22 +44,21 @@ function baseNode(ctx: EnumResolverContext): PipeResult { const { v } = ctx.plugin.symbols; - const def = ctx.plugin - .querySymbols({ - resource: 'definition', // maybe we shouldn't hardcode definition - resourceId: pathToJsonPointer(fromRef(ctx.path)), - tool: 'typescript', - }) - // find const or enum, but not const enums, because Valibot doesn't support them - .filter( - (symbol) => - symbol.kind === 'var' || - (symbol.kind === 'enum' && - !(symbol.node as ReturnType).hasModifier('const')), - )[0]; - if (def) { - return $(v).attr(identifiers.schemas.enum).call(def); - } + // skip this feature for now, requires knowing whether the enum contains safe values only, which requires special handling that we don't currently support + // const def = ctx.plugin.querySymbol>( + // { + // resource: 'definition', // maybe we shouldn't hardcode definition + // resourceId: pathToJsonPointer(fromRef(ctx.path)), + // tool: 'typescript', + // }, + // ['EnumTsDsl', 'VarTsDsl'], + // // skip const enums, not supported by Valibot + // // skip enums with default values, requires special handling that we don't currently support + // (symbol) => symbol.node?.['~dsl'] !== 'EnumTsDsl' || (!symbol.node.hasModifier('const') && ctx.schema.default === undefined), + // ); + // if (def) { + // return $(v).attr(identifiers.schemas.enum).call(def); + // } if (picklistMembers.length > 0 && picklistMembers.length === literalSchemas.length) { return $(v) diff --git a/packages/openapi-ts/src/plugins/zod/mini/toAst/enum.ts b/packages/openapi-ts/src/plugins/zod/mini/toAst/enum.ts index d39224b0c1..53ab98b7ba 100644 --- a/packages/openapi-ts/src/plugins/zod/mini/toAst/enum.ts +++ b/packages/openapi-ts/src/plugins/zod/mini/toAst/enum.ts @@ -1,5 +1,4 @@ -import { fromRef } from '@hey-api/codegen-core'; -import { pathToJsonPointer, type SchemaVisitorContext, type SchemaWithType } from '@hey-api/shared'; +import type { SchemaVisitorContext, SchemaWithType } from '@hey-api/shared'; import { $ } from '../../../../ts-dsl'; import { identifiers } from '../../constants'; @@ -43,22 +42,21 @@ function baseNode(ctx: EnumResolverContext): Chain { const { z } = ctx.plugin.symbols; - const def = ctx.plugin - .querySymbols({ - resource: 'definition', // maybe we shouldn't hardcode definition - resourceId: pathToJsonPointer(fromRef(ctx.path)), - tool: 'typescript', - }) - // find const or enum, but not const enums, because Zod doesn't support them - .filter( - (symbol) => - symbol.kind === 'var' || - (symbol.kind === 'enum' && - !(symbol.node as ReturnType).hasModifier('const')), - )[0]; - if (def) { - return $(z).attr(identifiers.enum).call(def); - } + // skip this feature for now, requires knowing whether the enum contains safe values only, which requires special handling that we don't currently support + // const def = ctx.plugin.querySymbol>( + // { + // resource: 'definition', // maybe we shouldn't hardcode definition + // resourceId: pathToJsonPointer(fromRef(ctx.path)), + // tool: 'typescript', + // }, + // ['EnumTsDsl', 'VarTsDsl'], + // // skip const enums, not supported by Zod + // // skip enums with default values, requires special handling that we don't currently support + // (symbol) => symbol.node?.['~dsl'] !== 'EnumTsDsl' || (!symbol.node.hasModifier('const') && ctx.schema.default === undefined), + // ); + // if (def) { + // return $(z).attr(identifiers.enum).call(def); + // } if (enumMembers.length > 0 && enumMembers.length === literalSchemas.length) { return $(z) diff --git a/packages/openapi-ts/src/plugins/zod/v3/toAst/enum.ts b/packages/openapi-ts/src/plugins/zod/v3/toAst/enum.ts index 5f6108b3b4..479d18d4e7 100644 --- a/packages/openapi-ts/src/plugins/zod/v3/toAst/enum.ts +++ b/packages/openapi-ts/src/plugins/zod/v3/toAst/enum.ts @@ -1,5 +1,4 @@ -import { fromRef } from '@hey-api/codegen-core'; -import { pathToJsonPointer, type SchemaVisitorContext, type SchemaWithType } from '@hey-api/shared'; +import type { SchemaVisitorContext, SchemaWithType } from '@hey-api/shared'; import { $ } from '../../../../ts-dsl'; import { identifiers } from '../../constants'; @@ -43,22 +42,21 @@ function baseNode(ctx: EnumResolverContext): Chain { const { z } = ctx.plugin.symbols; - const def = ctx.plugin - .querySymbols({ - resource: 'definition', // maybe we shouldn't hardcode definition - resourceId: pathToJsonPointer(fromRef(ctx.path)), - tool: 'typescript', - }) - // find const or enum, but not const enums, because Zod doesn't support them - .filter( - (symbol) => - symbol.kind === 'var' || - (symbol.kind === 'enum' && - !(symbol.node as ReturnType).hasModifier('const')), - )[0]; - if (def) { - return $(z).attr(identifiers.nativeEnum).call(def); - } + // skip this feature for now, requires knowing whether the enum contains safe values only, which requires special handling that we don't currently support + // const def = ctx.plugin.querySymbol>( + // { + // resource: 'definition', // maybe we shouldn't hardcode definition + // resourceId: pathToJsonPointer(fromRef(ctx.path)), + // tool: 'typescript', + // }, + // ['EnumTsDsl', 'VarTsDsl'], + // // skip const enums, not supported by Zod + // // skip enums with default values, requires special handling that we don't currently support + // (symbol) => symbol.node?.['~dsl'] !== 'EnumTsDsl' || (!symbol.node.hasModifier('const') && ctx.schema.default === undefined), + // ); + // if (def) { + // return $(z).attr(identifiers.nativeEnum).call(def); + // } if (enumMembers.length > 0 && enumMembers.length === literalSchemas.length) { return $(z) diff --git a/packages/openapi-ts/src/plugins/zod/v4/toAst/enum.ts b/packages/openapi-ts/src/plugins/zod/v4/toAst/enum.ts index c626e555ce..53ab98b7ba 100644 --- a/packages/openapi-ts/src/plugins/zod/v4/toAst/enum.ts +++ b/packages/openapi-ts/src/plugins/zod/v4/toAst/enum.ts @@ -1,6 +1,4 @@ -import { fromRef } from '@hey-api/codegen-core'; import type { SchemaVisitorContext, SchemaWithType } from '@hey-api/shared'; -import { pathToJsonPointer } from '@hey-api/shared'; import { $ } from '../../../../ts-dsl'; import { identifiers } from '../../constants'; @@ -44,22 +42,21 @@ function baseNode(ctx: EnumResolverContext): Chain { const { z } = ctx.plugin.symbols; - const def = ctx.plugin - .querySymbols({ - resource: 'definition', // maybe we shouldn't hardcode definition - resourceId: pathToJsonPointer(fromRef(ctx.path)), - tool: 'typescript', - }) - // find const or enum, but not const enums, because Zod doesn't support them - .filter( - (symbol) => - symbol.kind === 'var' || - (symbol.kind === 'enum' && - !(symbol.node as ReturnType).hasModifier('const')), - )[0]; - if (def) { - return $(z).attr(identifiers.enum).call(def); - } + // skip this feature for now, requires knowing whether the enum contains safe values only, which requires special handling that we don't currently support + // const def = ctx.plugin.querySymbol>( + // { + // resource: 'definition', // maybe we shouldn't hardcode definition + // resourceId: pathToJsonPointer(fromRef(ctx.path)), + // tool: 'typescript', + // }, + // ['EnumTsDsl', 'VarTsDsl'], + // // skip const enums, not supported by Zod + // // skip enums with default values, requires special handling that we don't currently support + // (symbol) => symbol.node?.['~dsl'] !== 'EnumTsDsl' || (!symbol.node.hasModifier('const') && ctx.schema.default === undefined), + // ); + // if (def) { + // return $(z).attr(identifiers.enum).call(def); + // } if (enumMembers.length > 0 && enumMembers.length === literalSchemas.length) { return $(z) diff --git a/packages/shared/src/config/input/path.ts b/packages/shared/src/config/input/path.ts index 5fcbaa413e..628a35b59e 100644 --- a/packages/shared/src/config/input/path.ts +++ b/packages/shared/src/config/input/path.ts @@ -1,5 +1,6 @@ import colors from 'ansi-colors'; +import type { LogLevel } from '../../types/logs'; import type { Input } from './types'; export function compileInputPath(input: Omit) { @@ -12,6 +13,7 @@ export function compileInputPath(input: Omit) { | 'project' | 'registry' | 'tags' + | 'uuid' | 'version' > & Pick = { @@ -98,13 +100,15 @@ export function compileInputPath(input: Omit) { export function logInputPaths( inputPaths: ReadonlyArray>, jobIndex: number, + logLevel?: LogLevel, ): void { + if (logLevel === 'silent') return; + const lines: Array = []; const jobPrefix = colors.gray(`[Job ${jobIndex + 1}] `); - const count = inputPaths.length; - const baseString = colors.cyan(`Generating from ${count} ${count === 1 ? 'input' : 'inputs'}:`); - lines.push(`${jobPrefix}⏳ ${baseString}`); + const baseString = colors.cyan(`Generating...`); + lines.push(`${jobPrefix}${colors.gray('~')} ${baseString}`); inputPaths.forEach((inputPath, index) => { const itemPrefixStr = ` [${index + 1}] `; @@ -148,6 +152,11 @@ export function logInputPaths( )}`, ); } + if (logLevel === 'debug') { + lines.push( + `${jobPrefix}${detailIndent}${colors.gray('url:')} ${colors.green(inputPath.path)}`, + ); + } lines.push( `${jobPrefix}${detailIndent}${colors.gray('registry:')} ${colors.green('Hey API')}`, ); @@ -160,13 +169,14 @@ export function logInputPaths( } else { lines.push(`${jobPrefix}${itemPrefix}${baseInput}`); } - // @ts-expect-error if (inputPath.uuid) { lines.push( - `${jobPrefix}${detailIndent}${colors.gray('uuid:')} ${colors.green( - // @ts-expect-error - inputPath.uuid, - )}`, + `${jobPrefix}${detailIndent}${colors.gray('uuid:')} ${colors.green(inputPath.uuid)}`, + ); + } + if (logLevel === 'debug' && baseInput) { + lines.push( + `${jobPrefix}${detailIndent}${colors.gray('url:')} ${colors.green(inputPath.path)}`, ); } lines.push( @@ -177,6 +187,11 @@ export function logInputPaths( case 'scalar': { const baseInput = [inputPath.organization, inputPath.project].filter(Boolean).join('/'); lines.push(`${jobPrefix}${itemPrefix}${baseInput}`); + if (logLevel === 'debug') { + lines.push( + `${jobPrefix}${detailIndent}${colors.gray('url:')} ${colors.green(inputPath.path)}`, + ); + } lines.push( `${jobPrefix}${detailIndent}${colors.gray('registry:')} ${colors.green('Scalar')}`, ); diff --git a/packages/shared/src/config/input/types.ts b/packages/shared/src/config/input/types.ts index 6c6c946ec9..aca84156f7 100644 --- a/packages/shared/src/config/input/types.ts +++ b/packages/shared/src/config/input/types.ts @@ -155,6 +155,12 @@ export type Input = { * the first match will be returned. */ tags?: ReadonlyArray; + /** + * **Requires `registry` to be `readme`** + * + * The unique identifier for the ReadMe API registry entry. + */ + uuid?: string; /** * **Requires `path` to start with `https://get.heyapi.dev` or be undefined** * diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index d8fd66c694..bb39c3f183 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts @@ -130,7 +130,7 @@ export type { } from './plugins/validator'; export { requestValidatorLayers, resolveValidatorLayer } from './plugins/validator'; export { findPackageJson, findTsConfigPath, loadPackageJson } from './tsConfig'; -export type { Logs } from './types/logs'; +export type { LogLevel, Logs } from './types/logs'; export type { WatchValues } from './types/watch'; export { escapeComment } from './utils/escape'; export { utils } from './utils/exports'; diff --git a/packages/shared/src/plugins/shared/utils/instance.ts b/packages/shared/src/plugins/shared/utils/instance.ts index 09fe5a7381..002b724a74 100644 --- a/packages/shared/src/plugins/shared/utils/instance.ts +++ b/packages/shared/src/plugins/shared/utils/instance.ts @@ -360,12 +360,26 @@ export class PluginInstance { return result as T extends number ? void : number; } - querySymbol(filter: SymbolMeta): Symbol | undefined { - return this.querySymbols(filter)[0]; + querySymbol( + filter: SymbolMeta, + tags?: ReadonlyArray>, + predicate?: (symbol: Symbol) => boolean, + ): Symbol | undefined { + return this.querySymbols(filter, tags, predicate)[0]; } - querySymbols(filter: SymbolMeta): Array> { - return this.gen.symbols.query(filter) as Array>; + querySymbols( + filter: SymbolMeta, + tags?: ReadonlyArray>, + predicate?: (symbol: Symbol) => boolean, + ): Array> { + const results = this.gen.symbols.query(filter) as Array>; + if (!tags?.length && !predicate) return results; + const set = tags?.length ? new Set(tags) : null; + return results.filter((symbol) => { + if (set && !set.has(symbol.node?.['~dsl'] ?? '')) return false; + return predicate ? predicate(symbol) : true; + }); } referenceSymbol(meta: SymbolMeta): Symbol { diff --git a/packages/shared/src/types/logs.ts b/packages/shared/src/types/logs.ts index 752d885b99..bdb274b622 100644 --- a/packages/shared/src/types/logs.ts +++ b/packages/shared/src/types/logs.ts @@ -1,3 +1,5 @@ +export type LogLevel = 'debug' | 'error' | 'fatal' | 'info' | 'silent' | 'trace' | 'warn'; + export type Logs = { /** * Whether or not error logs should be written to a file or not @@ -22,7 +24,7 @@ export type Logs = { * * @default 'info' */ - level?: 'debug' | 'error' | 'fatal' | 'info' | 'silent' | 'trace' | 'warn'; + level?: LogLevel; /** * The relative location of the logs folder * diff --git a/specs/2.0.x/enum-names-values.json b/specs/2.0.x/enum-names-values.json index 8097b1fcac..21d4b1535c 100644 --- a/specs/2.0.x/enum-names-values.json +++ b/specs/2.0.x/enum-names-values.json @@ -6,6 +6,7 @@ }, "definitions": { "1-10": { + "default": "1-10", "enum": ["1-10", "11-20"], "type": "string" }, @@ -22,6 +23,7 @@ "type": "string" }, "Numbers": { + "default": 100, "enum": [100, 200, 300, -100, -200, -300], "type": "number" }, diff --git a/specs/3.0.x/enum-names-values.json b/specs/3.0.x/enum-names-values.json index e498cf7c5a..0d702457f9 100644 --- a/specs/3.0.x/enum-names-values.json +++ b/specs/3.0.x/enum-names-values.json @@ -7,6 +7,7 @@ "components": { "schemas": { "1-10": { + "default": "1-10", "enum": ["1-10", "11-20"], "type": "string" }, @@ -24,6 +25,7 @@ "type": "string" }, "Numbers": { + "default": 100, "enum": [100, 200, 300, -100, -200, -300], "type": "number" }, diff --git a/specs/3.1.x/enum-names-values.json b/specs/3.1.x/enum-names-values.json new file mode 100644 index 0000000000..9e311e4ba2 --- /dev/null +++ b/specs/3.1.x/enum-names-values.json @@ -0,0 +1,48 @@ +{ + "openapi": "3.1.1", + "info": { + "title": "OpenAPI 3.1.1 enum names values example", + "version": "1" + }, + "components": { + "schemas": { + "1-10": { + "default": "1-10", + "enum": ["1-10", "11-20"], + "type": "string" + }, + "myFoo": { + "enum": ["myFoo", "myBar"], + "type": "string" + }, + "MyFoo": { + "enum": ["MyFoo", "MyBar"], + "type": "string" + }, + "Foo": { + "enum": ["foo", "bar", null, "", true, false], + "type": ["string", "null"] + }, + "Numbers": { + "default": 100, + "enum": [100, 200, 300, -100, -200, -300], + "type": "number" + }, + "Arrays": { + "enum": [["foo"], ["bar"], ["baz"]], + "type": "array" + }, + "MyFooRef": { + "type": "object", + "properties": { + "foo": { + "type": "array", + "items": { + "$ref": "#/components/schemas/MyFoo" + } + } + } + } + } + } +} diff --git a/specs/3.1.x/enum-names-values.yaml b/specs/3.1.x/enum-names-values.yaml deleted file mode 100644 index 36ef57e853..0000000000 --- a/specs/3.1.x/enum-names-values.yaml +++ /dev/null @@ -1,54 +0,0 @@ -openapi: 3.1.1 -info: - title: OpenAPI 3.1.1 enum names values example - version: '1' -components: - schemas: - 1-10: - enum: - - 1-10 - - 11-20 - type: string - myFoo: - enum: - - myFoo - - myBar - type: string - MyFoo: - enum: - - MyFoo - - MyBar - type: string - Foo: - enum: - - foo - - bar - - null - - '' - - true - - false - type: - - string - - 'null' - Numbers: - enum: - - 100 - - 200 - - 300 - - -100 - - -200 - - -300 - type: number - Arrays: - enum: - - - foo - - - bar - - - baz - type: array - MyFooRef: - type: object - properties: - foo: - type: array - items: - $ref: '#/components/schemas/MyFoo'