diff --git a/.changeset/whole-parts-tan.md b/.changeset/whole-parts-tan.md new file mode 100644 index 000000000..d5ae2dd94 --- /dev/null +++ b/.changeset/whole-parts-tan.md @@ -0,0 +1,5 @@ +--- +'@hey-api/openapi-ts': patch +--- + +fix: bundled context types diff --git a/dev/playground.ts b/dev/playground.ts index 3678c8a1e..cf0cd4e77 100644 --- a/dev/playground.ts +++ b/dev/playground.ts @@ -1,56 +1,14 @@ -import { Sdk } from './.gen/sdk.gen'; +import type { DefinePlugin, IR } from '@hey-api/openapi-ts'; -const opencode = new Sdk(); -opencode.session.create( - { - parentID: '', - title: '', - }, - { - headers: { - 'X-Custom-Header': 'value', - }, - }, -); -opencode.session.init({ - id: '', - messageID: '', - modelID: '', - providerID: '', -}); -opencode.session.chat({ - agent: '', - id: '', - messageID: '', - modelID: '', - parts: [ - { - name: '', - type: 'agent', - }, - ], - providerID: '', - system: '', - tools: {}, -}); -opencode.auth.set({ - auth: { - // access: '', - // expires: 1, - key: '', - // refresh: '', - // token: '', - type: 'api', - }, - id: '123', -}); -opencode.postSessionByIdPermissionsByPermissionId({ - id: 'session-id', - permissionID: 'permission-id', - response: 'always', -}); -opencode.tui.showToast({ - message: '', - title: '', - variant: 'error', -}); +type MyPluginConfig = { readonly name: 'myplugin' }; +type MyPlugin = DefinePlugin; + +export function f(schema: IR.SchemaObject, plugin: MyPlugin['Instance']) { + plugin.context.resolveIrRef(schema.$ref); +} + +export const handler: MyPlugin['Handler'] = ({ plugin }) => { + plugin.forEach('schema', 'operation', (event) => { + console.log(event); + }); +}; diff --git a/packages/openapi-ts/src/createClient.ts b/packages/openapi-ts/src/createClient.ts index aa04acf60..f555b2c10 100644 --- a/packages/openapi-ts/src/createClient.ts +++ b/packages/openapi-ts/src/createClient.ts @@ -6,7 +6,7 @@ import colors from 'ansi-colors'; import { generateLegacyOutput } from '~/generate/legacy/output'; import { generateOutput } from '~/generate/output'; import { getSpec } from '~/getSpec'; -import type { IR } from '~/ir/types'; +import type { Context } from '~/ir/context'; import { parseLegacy, parseOpenApiSpec } from '~/openApi'; import { buildGraph } from '~/openApi/shared/utils/graph'; import { patchOpenApiSpec } from '~/openApi/shared/utils/patch'; @@ -254,7 +254,7 @@ export const createClient = async ({ * Always undefined on the first run, defined on subsequent runs. */ watches?: ReadonlyArray; -}): Promise => { +}): Promise => { const watches: ReadonlyArray = _watches || Array.from({ length: config.input.length }, () => ({ @@ -296,7 +296,7 @@ export const createClient = async ({ ).filter((data) => data.arrayBuffer || data.resolvedInput); let client: Client | undefined; - let context: IR.Context | undefined; + let context: Context | undefined; if (specData.length) { const refParser = new $RefParser(); diff --git a/packages/openapi-ts/src/generate.ts b/packages/openapi-ts/src/generate.ts index 28d48bdc2..3c2c62e39 100644 --- a/packages/openapi-ts/src/generate.ts +++ b/packages/openapi-ts/src/generate.ts @@ -11,7 +11,7 @@ import { printCrashReport, shouldReportCrash, } from '~/error'; -import type { IR } from '~/ir/types'; +import type { Context } from '~/ir/context'; import type { Client } from '~/types/client'; import type { UserConfig } from '~/types/config'; import type { LazyOrAsync, MaybeArray } from '~/types/utils'; @@ -27,7 +27,7 @@ import { Logger } from '~/utils/logger'; export const createClient = async ( userConfig?: LazyOrAsync>, logger = new Logger(), -): Promise> => { +): Promise> => { const resolvedConfig = typeof userConfig === 'function' ? await userConfig() : userConfig; const userConfigs = resolvedConfig @@ -90,7 +90,7 @@ export const createClient = async ( }), ); const result = clients.filter((client) => Boolean(client)) as ReadonlyArray< - Client | IR.Context + Client | Context >; eventCreateClient.timeEnd(); diff --git a/packages/openapi-ts/src/generate/output.ts b/packages/openapi-ts/src/generate/output.ts index 658103c86..123978984 100644 --- a/packages/openapi-ts/src/generate/output.ts +++ b/packages/openapi-ts/src/generate/output.ts @@ -3,13 +3,13 @@ import path from 'node:path'; import type { ProjectRenderMeta } from '@hey-api/codegen-core'; -import type { IR } from '~/ir/types'; +import type { Context } from '~/ir/context'; import { getClientPlugin } from '~/plugins/@hey-api/client-core/utils'; import { generateClientBundle } from './client'; import { removeDirSync } from './utils'; -export const generateOutput = async ({ context }: { context: IR.Context }) => { +export const generateOutput = async ({ context }: { context: Context }) => { const outputPath = path.resolve(context.config.output.path); if (context.config.output.clean) { diff --git a/packages/openapi-ts/src/ir/__tests__/pagination.test.ts b/packages/openapi-ts/src/ir/__tests__/pagination.test.ts index c2b61d951..be3cbb457 100644 --- a/packages/openapi-ts/src/ir/__tests__/pagination.test.ts +++ b/packages/openapi-ts/src/ir/__tests__/pagination.test.ts @@ -3,6 +3,7 @@ import { describe, expect, it, vi } from 'vitest'; import { defaultPaginationKeywords } from '~/config/parser'; import type { Config } from '~/types/config'; +import type { Context } from '../context'; import { operationPagination } from '../operation'; import { getPaginationKeywordsRegExp } from '../pagination'; import type { IR } from '../types'; @@ -92,7 +93,7 @@ describe('operationPagination', () => { ...(pagination ? { pagination: true } : {}), }); - const emptyContext = {} as IR.Context; + const emptyContext = {} as Context; const baseOperationMeta = { method: 'post' as const, @@ -216,7 +217,7 @@ describe('operationPagination', () => { }); it('resolves $ref and uses the resolved pagination property', () => { - const context: IR.Context = { + const context: Context = { resolveIrRef: vi.fn().mockReturnValue({ properties: { pagination: { @@ -228,7 +229,7 @@ describe('operationPagination', () => { }, type: 'object', }), - } as unknown as IR.Context; + } as unknown as Context; const operation: IR.OperationObject = { ...baseOperationMeta, diff --git a/packages/openapi-ts/src/ir/operation.ts b/packages/openapi-ts/src/ir/operation.ts index f06331cad..2e7cda065 100644 --- a/packages/openapi-ts/src/ir/operation.ts +++ b/packages/openapi-ts/src/ir/operation.ts @@ -1,3 +1,4 @@ +import type { Context } from './context'; import type { Pagination } from './pagination'; import { hasParametersObjectRequired, @@ -33,7 +34,7 @@ export const operationPagination = ({ context, operation, }: { - context: IR.Context; + context: Context; operation: IR.OperationObject; }): Pagination | undefined => { const body = operation.body; diff --git a/packages/openapi-ts/src/ir/parameter.ts b/packages/openapi-ts/src/ir/parameter.ts index 4fe60ccce..c14faf7d2 100644 --- a/packages/openapi-ts/src/ir/parameter.ts +++ b/packages/openapi-ts/src/ir/parameter.ts @@ -1,3 +1,4 @@ +import type { Context } from './context'; import type { Pagination } from './pagination'; import type { IR } from './types'; @@ -5,7 +6,7 @@ const getPaginationSchema = ({ context, parameter, }: { - context: IR.Context; + context: Context; parameter: IR.ParameterObject; }): IR.SchemaObject | undefined => { if (!parameter.pagination) { @@ -66,7 +67,7 @@ export const parameterWithPagination = ({ context, parameters, }: { - context: IR.Context; + context: Context; parameters: IR.ParametersObject | undefined; }): Pagination | undefined => { if (!parameters) { diff --git a/packages/openapi-ts/src/ir/types.d.ts b/packages/openapi-ts/src/ir/types.d.ts index 2a4416d98..6c28cce86 100644 --- a/packages/openapi-ts/src/ir/types.d.ts +++ b/packages/openapi-ts/src/ir/types.d.ts @@ -4,7 +4,6 @@ import type { ServerObject, } from '~/openApi/3.1.x/types/spec'; -import type { Context as IRContext } from './context'; import type { IRMediaType } from './mediaType'; interface IRBodyObject { @@ -221,7 +220,6 @@ interface IRModel { export namespace IR { export type BodyObject = IRBodyObject; export type ComponentsObject = IRComponentsObject; - export type Context = any> = IRContext; export type Model = IRModel; export type OperationObject = IROperationObject; export type ParameterObject = IRParameterObject; diff --git a/packages/openapi-ts/src/openApi/2.0.x/parser/__tests__/operation.test.ts b/packages/openapi-ts/src/openApi/2.0.x/parser/__tests__/operation.test.ts index 7c550ea8a..43262b199 100644 --- a/packages/openapi-ts/src/openApi/2.0.x/parser/__tests__/operation.test.ts +++ b/packages/openapi-ts/src/openApi/2.0.x/parser/__tests__/operation.test.ts @@ -1,6 +1,7 @@ import { describe, expect, it } from 'vitest'; -import type { IR } from '../../../../ir/types'; +import type { Context } from '~/ir/context'; + import type { ParameterObject, SecuritySchemeObject } from '../../types/spec'; import { parsePathOperation } from '../operation'; @@ -27,7 +28,7 @@ const createContext = () => resolveRef: () => // Mock implementation undefined, - }) as unknown as IR.Context; + }) as unknown as Context; describe('operation', () => { const context = createContext(); diff --git a/packages/openapi-ts/src/openApi/2.0.x/parser/__tests__/server.test.ts b/packages/openapi-ts/src/openApi/2.0.x/parser/__tests__/server.test.ts index 993f21b18..d0878ebf2 100644 --- a/packages/openapi-ts/src/openApi/2.0.x/parser/__tests__/server.test.ts +++ b/packages/openapi-ts/src/openApi/2.0.x/parser/__tests__/server.test.ts @@ -1,13 +1,13 @@ import { describe, expect, it } from 'vitest'; +import type { Context } from '~/ir/context'; import type { OpenApi } from '~/openApi/types'; -import type { IR } from '../../../../ir/types'; import { parseServers } from '../server'; describe('parseServers', () => { it('host + basePath + schemes', () => { - const context: Partial>> = { + const context: Partial>> = { config: { input: [ // @ts-expect-error @@ -23,7 +23,7 @@ describe('parseServers', () => { schemes: ['http', 'https'], }, }; - parseServers({ context: context as IR.Context }); + parseServers({ context: context as Context }); expect(context.ir!.servers).toEqual([ { url: 'http://foo.com/v1', @@ -35,7 +35,7 @@ describe('parseServers', () => { }); it('schemes + host', () => { - const context: Partial>> = { + const context: Partial>> = { config: { input: [ // @ts-expect-error @@ -50,7 +50,7 @@ describe('parseServers', () => { schemes: ['ws'], }, }; - parseServers({ context: context as IR.Context }); + parseServers({ context: context as Context }); expect(context.ir!.servers).toEqual([ { url: 'ws://foo.com', @@ -59,7 +59,7 @@ describe('parseServers', () => { }); it('host + basePath', () => { - const context: Partial>> = { + const context: Partial>> = { config: { input: [ // @ts-expect-error @@ -74,7 +74,7 @@ describe('parseServers', () => { host: 'foo.com', }, }; - parseServers({ context: context as IR.Context }); + parseServers({ context: context as Context }); expect(context.ir!.servers).toEqual([ { url: 'foo.com/v1', @@ -83,7 +83,7 @@ describe('parseServers', () => { }); it('host', () => { - const context: Partial>> = { + const context: Partial>> = { config: { input: [ // @ts-expect-error @@ -97,7 +97,7 @@ describe('parseServers', () => { host: 'foo.com', }, }; - parseServers({ context: context as IR.Context }); + parseServers({ context: context as Context }); expect(context.ir!.servers).toEqual([ { url: 'foo.com', @@ -106,7 +106,7 @@ describe('parseServers', () => { }); it('basePath', () => { - const context: Partial>> = { + const context: Partial>> = { config: { input: [ // @ts-expect-error @@ -120,7 +120,7 @@ describe('parseServers', () => { basePath: '/v1', }, }; - parseServers({ context: context as IR.Context }); + parseServers({ context: context as Context }); expect(context.ir!.servers).toEqual([ { url: '/v1', diff --git a/packages/openapi-ts/src/openApi/2.0.x/parser/index.ts b/packages/openapi-ts/src/openApi/2.0.x/parser/index.ts index 6b2be37b3..85d06b71b 100644 --- a/packages/openapi-ts/src/openApi/2.0.x/parser/index.ts +++ b/packages/openapi-ts/src/openApi/2.0.x/parser/index.ts @@ -1,4 +1,4 @@ -import type { IR } from '~/ir/types'; +import type { Context } from '~/ir/context'; import { buildResourceMetadata } from '~/openApi/shared/graph/meta'; import { transformOpenApiSpec } from '~/openApi/shared/transforms'; import type { State } from '~/openApi/shared/types/state'; @@ -28,7 +28,7 @@ import { validateOpenApiSpec } from './validate'; type PathKeys = keyof T extends infer K ? (K extends `/${string}` ? K : never) : never; -export const parseV2_0_X = (context: IR.Context) => { +export const parseV2_0_X = (context: Context) => { if (context.config.parser.validate_EXPERIMENTAL) { const result = validateOpenApiSpec(context.spec, context.logger); handleValidatorResult({ context, result }); diff --git a/packages/openapi-ts/src/openApi/2.0.x/parser/operation.ts b/packages/openapi-ts/src/openApi/2.0.x/parser/operation.ts index e078fed7e..6c6d67e66 100644 --- a/packages/openapi-ts/src/openApi/2.0.x/parser/operation.ts +++ b/packages/openapi-ts/src/openApi/2.0.x/parser/operation.ts @@ -1,3 +1,4 @@ +import type { Context } from '~/ir/context'; import type { IR, IRBodyObject } from '~/ir/types'; import type { State } from '~/openApi/shared/types/state'; import { operationToId } from '~/openApi/shared/utils/operation'; @@ -51,7 +52,7 @@ const initIrOperation = ({ path, state, }: Pick & { - context: IR.Context; + context: Context; operation: Operation; state: State; }): IR.OperationObject => { @@ -87,7 +88,7 @@ const operationToIrOperation = ({ securitySchemesMap, state, }: Pick & { - context: IR.Context; + context: Context; operation: Operation; securitySchemesMap: Map; state: State; @@ -364,7 +365,7 @@ export const parsePathOperation = ({ securitySchemesMap, state, }: { - context: IR.Context; + context: Context; method: Extract< keyof PathItemObject, 'delete' | 'get' | 'head' | 'options' | 'patch' | 'post' | 'put' | 'trace' diff --git a/packages/openapi-ts/src/openApi/2.0.x/parser/pagination.ts b/packages/openapi-ts/src/openApi/2.0.x/parser/pagination.ts index f92b727cd..8a980a01a 100644 --- a/packages/openapi-ts/src/openApi/2.0.x/parser/pagination.ts +++ b/packages/openapi-ts/src/openApi/2.0.x/parser/pagination.ts @@ -1,5 +1,5 @@ +import type { Context } from '~/ir/context'; import { getPaginationKeywordsRegExp } from '~/ir/pagination'; -import type { IR } from '~/ir/types'; import type { SchemaType } from '~/openApi/shared/types/schema'; import type { ParameterObject, ReferenceObject } from '../types/spec'; @@ -20,7 +20,7 @@ export const paginationField = ({ name, schema, }: { - context: IR.Context; + context: Context; name: string; schema: | ParameterObject diff --git a/packages/openapi-ts/src/openApi/2.0.x/parser/parameter.ts b/packages/openapi-ts/src/openApi/2.0.x/parser/parameter.ts index 531f0c0d9..ea4d4d61c 100644 --- a/packages/openapi-ts/src/openApi/2.0.x/parser/parameter.ts +++ b/packages/openapi-ts/src/openApi/2.0.x/parser/parameter.ts @@ -1,3 +1,4 @@ +import type { Context } from '~/ir/context'; import type { IR } from '~/ir/types'; import type { @@ -50,7 +51,7 @@ export const parametersArrayToObject = ({ operation, parameters, }: { - context: IR.Context; + context: Context; operation: OperationObject; parameters?: ReadonlyArray; }): IR.ParametersObject | undefined => { @@ -101,7 +102,7 @@ const parameterToIrParameter = ({ parameter, }: { $ref: string; - context: IR.Context; + context: Context; parameter: Parameter; }): IR.ParameterObject => { const schema = parameter; diff --git a/packages/openapi-ts/src/openApi/2.0.x/parser/schema.ts b/packages/openapi-ts/src/openApi/2.0.x/parser/schema.ts index c48f84164..f45a9f935 100644 --- a/packages/openapi-ts/src/openApi/2.0.x/parser/schema.ts +++ b/packages/openapi-ts/src/openApi/2.0.x/parser/schema.ts @@ -1,3 +1,4 @@ +import type { Context } from '~/ir/context'; import type { IR } from '~/ir/types'; import { addItemsToSchema } from '~/ir/utils'; import type { @@ -109,7 +110,7 @@ const parseArray = ({ schema, state, }: { - context: IR.Context; + context: Context; irSchema?: IR.SchemaObject; schema: SchemaObject; state: SchemaState; @@ -164,7 +165,7 @@ const parseArray = ({ const parseBoolean = ({ irSchema = {}, }: { - context: IR.Context; + context: Context; irSchema?: IR.SchemaObject; schema: SchemaObject; state: SchemaState; @@ -178,7 +179,7 @@ const parseNumber = ({ irSchema = {}, schema, }: { - context: IR.Context; + context: Context; irSchema?: IR.SchemaObject; schema: SchemaWithRequired; state: SchemaState; @@ -194,7 +195,7 @@ const parseObject = ({ schema, state, }: { - context: IR.Context; + context: Context; irSchema?: IR.SchemaObject; schema: SchemaObject; state: SchemaState; @@ -259,7 +260,7 @@ const parseObject = ({ const parseString = ({ irSchema = {}, }: { - context: IR.Context; + context: Context; irSchema?: IR.SchemaObject; schema: SchemaObject; state: SchemaState; @@ -289,7 +290,7 @@ const parseAllOf = ({ schema, state, }: { - context: IR.Context; + context: Context; schema: SchemaWithRequired; state: SchemaState; }): IR.SchemaObject => { @@ -449,7 +450,7 @@ const parseEnum = ({ schema, state, }: { - context: IR.Context; + context: Context; schema: SchemaWithRequired; state: SchemaState; }): IR.SchemaObject => { @@ -527,7 +528,7 @@ const parseRef = ({ schema, state, }: { - context: IR.Context; + context: Context; schema: SchemaWithRequired; state: SchemaState; }): IR.SchemaObject => { @@ -582,7 +583,7 @@ const parseNullableType = ({ schema, state, }: { - context: IR.Context; + context: Context; irSchema?: IR.SchemaObject; schema: SchemaWithRequired; state: SchemaState; @@ -626,7 +627,7 @@ const parseType = ({ schema, state, }: { - context: IR.Context; + context: Context; schema: SchemaWithRequired; state: SchemaState; }): IR.SchemaObject => { @@ -669,7 +670,7 @@ const parseOneType = ({ schema, state, }: { - context: IR.Context; + context: Context; irSchema?: IR.SchemaObject; schema: SchemaWithRequired; state: SchemaState; @@ -731,7 +732,7 @@ const parseUnknown = ({ irSchema, schema, }: { - context: IR.Context; + context: Context; irSchema?: IR.SchemaObject; schema: SchemaObject; }): IR.SchemaObject => { @@ -751,7 +752,7 @@ export const schemaToIrSchema = ({ schema, state, }: { - context: IR.Context; + context: Context; schema: SchemaObject; state: SchemaState | undefined; }): IR.SchemaObject => { @@ -807,7 +808,7 @@ export const parseSchema = ({ schema, }: { $ref: string; - context: IR.Context; + context: Context; schema: SchemaObject; }) => { if (!context.ir.components) { diff --git a/packages/openapi-ts/src/openApi/2.0.x/parser/server.ts b/packages/openapi-ts/src/openApi/2.0.x/parser/server.ts index ee8241316..db4471ffb 100644 --- a/packages/openapi-ts/src/openApi/2.0.x/parser/server.ts +++ b/packages/openapi-ts/src/openApi/2.0.x/parser/server.ts @@ -1,7 +1,7 @@ -import type { IR } from '~/ir/types'; +import type { Context } from '~/ir/context'; import { parseUrl } from '~/utils/url'; -export const parseServers = ({ context }: { context: IR.Context }) => { +export const parseServers = ({ context }: { context: Context }) => { let schemes: ReadonlyArray = context.spec.schemes ?? []; let host = context.spec.host ?? ''; const path = context.spec.basePath ?? ''; diff --git a/packages/openapi-ts/src/openApi/3.0.x/parser/__tests__/operation.test.ts b/packages/openapi-ts/src/openApi/3.0.x/parser/__tests__/operation.test.ts index 33fc9effa..3d339cafb 100644 --- a/packages/openapi-ts/src/openApi/3.0.x/parser/__tests__/operation.test.ts +++ b/packages/openapi-ts/src/openApi/3.0.x/parser/__tests__/operation.test.ts @@ -1,6 +1,7 @@ import { describe, expect, it } from 'vitest'; -import type { IR } from '../../../../ir/types'; +import type { Context } from '~/ir/context'; + import type { SecuritySchemeObject } from '../../types/spec'; import { parsePathOperation } from '../operation'; @@ -15,7 +16,7 @@ describe('operation', () => { paths: {}, servers: [], }, - } as unknown as IR.Context; + } as unknown as Context; it('should parse operation correctly', () => { const method = 'get'; diff --git a/packages/openapi-ts/src/openApi/3.0.x/parser/index.ts b/packages/openapi-ts/src/openApi/3.0.x/parser/index.ts index f21729226..6e7b3a493 100644 --- a/packages/openapi-ts/src/openApi/3.0.x/parser/index.ts +++ b/packages/openapi-ts/src/openApi/3.0.x/parser/index.ts @@ -1,4 +1,4 @@ -import type { IR } from '~/ir/types'; +import type { Context } from '~/ir/context'; import { buildResourceMetadata } from '~/openApi/shared/graph/meta'; import { transformOpenApiSpec } from '~/openApi/shared/transforms'; import type { State } from '~/openApi/shared/types/state'; @@ -27,7 +27,7 @@ import { parseSchema } from './schema'; import { parseServers } from './server'; import { validateOpenApiSpec } from './validate'; -export const parseV3_0_X = (context: IR.Context) => { +export const parseV3_0_X = (context: Context) => { if (context.config.parser.validate_EXPERIMENTAL) { const result = validateOpenApiSpec(context.spec, context.logger); handleValidatorResult({ context, result }); diff --git a/packages/openapi-ts/src/openApi/3.0.x/parser/operation.ts b/packages/openapi-ts/src/openApi/3.0.x/parser/operation.ts index 6d187a97d..4612beab6 100644 --- a/packages/openapi-ts/src/openApi/3.0.x/parser/operation.ts +++ b/packages/openapi-ts/src/openApi/3.0.x/parser/operation.ts @@ -1,3 +1,4 @@ +import type { Context } from '~/ir/context'; import type { IR } from '~/ir/types'; import type { State } from '~/openApi/shared/types/state'; import { operationToId } from '~/openApi/shared/utils/operation'; @@ -48,7 +49,7 @@ const initIrOperation = ({ path, state, }: Pick & { - context: IR.Context; + context: Context; operation: Operation; state: State; }): IR.OperationObject => { @@ -84,7 +85,7 @@ const operationToIrOperation = ({ securitySchemesMap, state, }: Pick & { - context: IR.Context; + context: Context; operation: Operation; securitySchemesMap: Map; state: State; @@ -237,7 +238,7 @@ export const parsePathOperation = ({ securitySchemesMap, state, }: { - context: IR.Context; + context: Context; method: Extract< keyof PathItemObject, 'delete' | 'get' | 'head' | 'options' | 'patch' | 'post' | 'put' | 'trace' diff --git a/packages/openapi-ts/src/openApi/3.0.x/parser/pagination.ts b/packages/openapi-ts/src/openApi/3.0.x/parser/pagination.ts index 589ac9153..347ec78f3 100644 --- a/packages/openapi-ts/src/openApi/3.0.x/parser/pagination.ts +++ b/packages/openapi-ts/src/openApi/3.0.x/parser/pagination.ts @@ -1,5 +1,5 @@ +import type { Context } from '~/ir/context'; import { getPaginationKeywordsRegExp } from '~/ir/pagination'; -import type { IR } from '~/ir/types'; import type { SchemaType } from '~/openApi/shared/types/schema'; import type { @@ -25,7 +25,7 @@ export const paginationField = ({ name, schema, }: { - context: IR.Context; + context: Context; name: string; schema: SchemaObject | ReferenceObject; }): boolean | string => { diff --git a/packages/openapi-ts/src/openApi/3.0.x/parser/parameter.ts b/packages/openapi-ts/src/openApi/3.0.x/parser/parameter.ts index 78622865e..82b3ee383 100644 --- a/packages/openapi-ts/src/openApi/3.0.x/parser/parameter.ts +++ b/packages/openapi-ts/src/openApi/3.0.x/parser/parameter.ts @@ -1,3 +1,4 @@ +import type { Context } from '~/ir/context'; import type { IR } from '~/ir/types'; import { refToName } from '~/utils/ref'; @@ -60,7 +61,7 @@ export const parametersArrayToObject = ({ context, parameters, }: { - context: IR.Context; + context: Context; parameters?: ReadonlyArray; }): IR.ParametersObject | undefined => { if (!parameters || !Object.keys(parameters).length) { @@ -97,7 +98,7 @@ const parameterToIrParameter = ({ parameter, }: { $ref: string; - context: IR.Context; + context: Context; parameter: ParameterObject; }): IR.ParameterObject => { // TODO: parser - fix @@ -181,7 +182,7 @@ export const parseParameter = ({ parameter, }: { $ref: string; - context: IR.Context; + context: Context; parameter: ParameterObject; }) => { if (!context.ir.components) { diff --git a/packages/openapi-ts/src/openApi/3.0.x/parser/requestBody.ts b/packages/openapi-ts/src/openApi/3.0.x/parser/requestBody.ts index 593146fa9..2abd004a5 100644 --- a/packages/openapi-ts/src/openApi/3.0.x/parser/requestBody.ts +++ b/packages/openapi-ts/src/openApi/3.0.x/parser/requestBody.ts @@ -1,3 +1,4 @@ +import type { Context } from '~/ir/context'; import type { IR } from '~/ir/types'; import { refToName } from '~/utils/ref'; @@ -11,7 +12,7 @@ const requestBodyToIrRequestBody = ({ requestBody, }: { $ref: string; - context: IR.Context; + context: Context; requestBody: RequestBodyObject; }): IR.RequestBodyObject => { // TODO: parser - fix @@ -54,7 +55,7 @@ export const parseRequestBody = ({ requestBody, }: { $ref: string; - context: IR.Context; + context: Context; requestBody: RequestBodyObject; }) => { if (!context.ir.components) { diff --git a/packages/openapi-ts/src/openApi/3.0.x/parser/schema.ts b/packages/openapi-ts/src/openApi/3.0.x/parser/schema.ts index aba96eeac..adac23cc2 100644 --- a/packages/openapi-ts/src/openApi/3.0.x/parser/schema.ts +++ b/packages/openapi-ts/src/openApi/3.0.x/parser/schema.ts @@ -1,3 +1,4 @@ +import type { Context } from '~/ir/context'; import type { IR } from '~/ir/types'; import { addItemsToSchema } from '~/ir/utils'; import type { @@ -115,7 +116,7 @@ const parseArray = ({ schema, state, }: { - context: IR.Context; + context: Context; irSchema?: IR.SchemaObject; schema: SchemaObject; state: SchemaState; @@ -171,7 +172,7 @@ const parseArray = ({ const parseBoolean = ({ irSchema = {}, }: { - context: IR.Context; + context: Context; irSchema?: IR.SchemaObject; schema: SchemaObject; state: SchemaState; @@ -185,7 +186,7 @@ const parseNumber = ({ irSchema = {}, schema, }: { - context: IR.Context; + context: Context; irSchema?: IR.SchemaObject; schema: SchemaWithRequired; state: SchemaState; @@ -201,7 +202,7 @@ const parseObject = ({ schema, state, }: { - context: IR.Context; + context: Context; irSchema?: IR.SchemaObject; schema: SchemaObject; state: SchemaState; @@ -265,7 +266,7 @@ const parseObject = ({ const parseString = ({ irSchema = {}, }: { - context: IR.Context; + context: Context; irSchema?: IR.SchemaObject; schema: SchemaObject; state: SchemaState; @@ -295,7 +296,7 @@ const parseAllOf = ({ schema, state, }: { - context: IR.Context; + context: Context; schema: SchemaWithRequired; state: SchemaState; }): IR.SchemaObject => { @@ -468,7 +469,7 @@ const parseAnyOf = ({ schema, state, }: { - context: IR.Context; + context: Context; schema: SchemaWithRequired; state: SchemaState; }): IR.SchemaObject => { @@ -556,7 +557,7 @@ const parseEnum = ({ schema, state, }: { - context: IR.Context; + context: Context; schema: SchemaWithRequired; state: SchemaState; }): IR.SchemaObject => { @@ -634,7 +635,7 @@ const parseOneOf = ({ schema, state, }: { - context: IR.Context; + context: Context; schema: SchemaWithRequired; state: SchemaState; }): IR.SchemaObject => { @@ -734,7 +735,7 @@ const parseRef = ({ schema, state, }: { - context: IR.Context; + context: Context; schema: ReferenceObject; state: SchemaState; }): IR.SchemaObject => { @@ -783,7 +784,7 @@ const parseNullableType = ({ schema, state, }: { - context: IR.Context; + context: Context; irSchema?: IR.SchemaObject; schema: SchemaWithRequired; state: SchemaState; @@ -827,7 +828,7 @@ const parseType = ({ schema, state, }: { - context: IR.Context; + context: Context; schema: SchemaWithRequired; state: SchemaState; }): IR.SchemaObject => { @@ -870,7 +871,7 @@ const parseOneType = ({ schema, state, }: { - context: IR.Context; + context: Context; irSchema?: IR.SchemaObject; schema: SchemaWithRequired; state: SchemaState; @@ -932,7 +933,7 @@ const parseUnknown = ({ irSchema, schema, }: { - context: IR.Context; + context: Context; irSchema?: IR.SchemaObject; schema: SchemaObject; }): IR.SchemaObject => { @@ -952,7 +953,7 @@ export const schemaToIrSchema = ({ schema, state, }: { - context: IR.Context; + context: Context; schema: SchemaObject | ReferenceObject; state: SchemaState | undefined; }): IR.SchemaObject => { @@ -1024,7 +1025,7 @@ export const parseSchema = ({ schema, }: { $ref: string; - context: IR.Context; + context: Context; schema: SchemaObject | ReferenceObject; }) => { if (!context.ir.components) { diff --git a/packages/openapi-ts/src/openApi/3.0.x/parser/server.ts b/packages/openapi-ts/src/openApi/3.0.x/parser/server.ts index 9732ada5f..4ba8c1bf4 100644 --- a/packages/openapi-ts/src/openApi/3.0.x/parser/server.ts +++ b/packages/openapi-ts/src/openApi/3.0.x/parser/server.ts @@ -1,7 +1,7 @@ -import type { IR } from '~/ir/types'; +import type { Context } from '~/ir/context'; import { parseUrl } from '~/utils/url'; -export const parseServers = ({ context }: { context: IR.Context }) => { +export const parseServers = ({ context }: { context: Context }) => { if (context.spec.servers) { context.ir.servers = context.spec.servers; return; diff --git a/packages/openapi-ts/src/openApi/3.1.x/parser/__tests__/operation.test.ts b/packages/openapi-ts/src/openApi/3.1.x/parser/__tests__/operation.test.ts index 33fc9effa..3d339cafb 100644 --- a/packages/openapi-ts/src/openApi/3.1.x/parser/__tests__/operation.test.ts +++ b/packages/openapi-ts/src/openApi/3.1.x/parser/__tests__/operation.test.ts @@ -1,6 +1,7 @@ import { describe, expect, it } from 'vitest'; -import type { IR } from '../../../../ir/types'; +import type { Context } from '~/ir/context'; + import type { SecuritySchemeObject } from '../../types/spec'; import { parsePathOperation } from '../operation'; @@ -15,7 +16,7 @@ describe('operation', () => { paths: {}, servers: [], }, - } as unknown as IR.Context; + } as unknown as Context; it('should parse operation correctly', () => { const method = 'get'; diff --git a/packages/openapi-ts/src/openApi/3.1.x/parser/index.ts b/packages/openapi-ts/src/openApi/3.1.x/parser/index.ts index e5886ed36..3cb9654b0 100644 --- a/packages/openapi-ts/src/openApi/3.1.x/parser/index.ts +++ b/packages/openapi-ts/src/openApi/3.1.x/parser/index.ts @@ -1,4 +1,4 @@ -import type { IR } from '~/ir/types'; +import type { Context } from '~/ir/context'; import { buildResourceMetadata } from '~/openApi/shared/graph/meta'; import { transformOpenApiSpec } from '~/openApi/shared/transforms'; import type { State } from '~/openApi/shared/types/state'; @@ -28,7 +28,7 @@ import { parseServers } from './server'; import { validateOpenApiSpec } from './validate'; import { parseWebhooks } from './webhook'; -export const parseV3_1_X = (context: IR.Context) => { +export const parseV3_1_X = (context: Context) => { if (context.config.parser.validate_EXPERIMENTAL) { const result = validateOpenApiSpec(context.spec, context.logger); handleValidatorResult({ context, result }); diff --git a/packages/openapi-ts/src/openApi/3.1.x/parser/operation.ts b/packages/openapi-ts/src/openApi/3.1.x/parser/operation.ts index 31824cb37..5b8d7aa36 100644 --- a/packages/openapi-ts/src/openApi/3.1.x/parser/operation.ts +++ b/packages/openapi-ts/src/openApi/3.1.x/parser/operation.ts @@ -1,3 +1,4 @@ +import type { Context } from '~/ir/context'; import type { IR } from '~/ir/types'; import type { State } from '~/openApi/shared/types/state'; import type { httpMethods } from '~/openApi/shared/utils/operation'; @@ -48,7 +49,7 @@ const initIrOperation = ({ path, state, }: Pick & { - context: IR.Context; + context: Context; operation: Operation; state: State; }): IR.OperationObject => { @@ -84,7 +85,7 @@ const operationToIrOperation = ({ securitySchemesMap, state, }: Pick & { - context: IR.Context; + context: Context; operation: Operation; securitySchemesMap: Map; state: State; @@ -222,7 +223,7 @@ const parseOperationObject = ({ securitySchemesMap, state, }: { - context: IR.Context; + context: Context; method: (typeof httpMethods)[number]; operation: Operation; path: keyof IR.PathsObject; @@ -251,7 +252,7 @@ export const parsePathOperation = ({ path, ...options }: { - context: IR.Context; + context: Context; method: (typeof httpMethods)[number]; operation: Operation; path: keyof IR.PathsObject; @@ -282,7 +283,7 @@ export const parseWebhookOperation = ({ method, ...options }: { - context: IR.Context; + context: Context; key: string; method: (typeof httpMethods)[number]; operation: Operation; diff --git a/packages/openapi-ts/src/openApi/3.1.x/parser/pagination.ts b/packages/openapi-ts/src/openApi/3.1.x/parser/pagination.ts index 00ac2aa95..49fa0a563 100644 --- a/packages/openapi-ts/src/openApi/3.1.x/parser/pagination.ts +++ b/packages/openapi-ts/src/openApi/3.1.x/parser/pagination.ts @@ -1,5 +1,5 @@ +import type { Context } from '~/ir/context'; import { getPaginationKeywordsRegExp } from '~/ir/pagination'; -import type { IR } from '~/ir/types'; import type { SchemaType } from '~/openApi/shared/types/schema'; import type { ParameterObject, RequestBodyObject } from '../types/spec'; @@ -21,7 +21,7 @@ export const paginationField = ({ name, schema, }: { - context: IR.Context; + context: Context; name: string; schema: SchemaObject; }): boolean | string => { diff --git a/packages/openapi-ts/src/openApi/3.1.x/parser/parameter.ts b/packages/openapi-ts/src/openApi/3.1.x/parser/parameter.ts index 607d4db45..c10c7510f 100644 --- a/packages/openapi-ts/src/openApi/3.1.x/parser/parameter.ts +++ b/packages/openapi-ts/src/openApi/3.1.x/parser/parameter.ts @@ -1,3 +1,4 @@ +import type { Context } from '~/ir/context'; import type { IR } from '~/ir/types'; import { refToName } from '~/utils/ref'; @@ -60,7 +61,7 @@ export const parametersArrayToObject = ({ context, parameters, }: { - context: IR.Context; + context: Context; parameters?: ReadonlyArray; }): IR.ParametersObject | undefined => { if (!parameters || !Object.keys(parameters).length) { @@ -97,7 +98,7 @@ const parameterToIrParameter = ({ parameter, }: { $ref: string; - context: IR.Context; + context: Context; parameter: ParameterObject; }): IR.ParameterObject => { // TODO: parser - fix @@ -174,7 +175,7 @@ export const parseParameter = ({ parameter, }: { $ref: string; - context: IR.Context; + context: Context; parameter: ParameterObject; }) => { if (!context.ir.components) { diff --git a/packages/openapi-ts/src/openApi/3.1.x/parser/requestBody.ts b/packages/openapi-ts/src/openApi/3.1.x/parser/requestBody.ts index 593146fa9..2abd004a5 100644 --- a/packages/openapi-ts/src/openApi/3.1.x/parser/requestBody.ts +++ b/packages/openapi-ts/src/openApi/3.1.x/parser/requestBody.ts @@ -1,3 +1,4 @@ +import type { Context } from '~/ir/context'; import type { IR } from '~/ir/types'; import { refToName } from '~/utils/ref'; @@ -11,7 +12,7 @@ const requestBodyToIrRequestBody = ({ requestBody, }: { $ref: string; - context: IR.Context; + context: Context; requestBody: RequestBodyObject; }): IR.RequestBodyObject => { // TODO: parser - fix @@ -54,7 +55,7 @@ export const parseRequestBody = ({ requestBody, }: { $ref: string; - context: IR.Context; + context: Context; requestBody: RequestBodyObject; }) => { if (!context.ir.components) { diff --git a/packages/openapi-ts/src/openApi/3.1.x/parser/schema.ts b/packages/openapi-ts/src/openApi/3.1.x/parser/schema.ts index 8dea32e73..7a270dd39 100644 --- a/packages/openapi-ts/src/openApi/3.1.x/parser/schema.ts +++ b/packages/openapi-ts/src/openApi/3.1.x/parser/schema.ts @@ -1,3 +1,4 @@ +import type { Context } from '~/ir/context'; import type { IR } from '~/ir/types'; import { addItemsToSchema } from '~/ir/utils'; import type { @@ -143,7 +144,7 @@ const parseArray = ({ schema, state, }: { - context: IR.Context; + context: Context; irSchema?: IR.SchemaObject; schema: SchemaObject; state: SchemaState; @@ -212,7 +213,7 @@ const parseArray = ({ const parseBoolean = ({ irSchema = {}, }: { - context: IR.Context; + context: Context; irSchema?: IR.SchemaObject; schema: SchemaObject; }): IR.SchemaObject => { @@ -224,7 +225,7 @@ const parseBoolean = ({ const parseNull = ({ irSchema = {}, }: { - context: IR.Context; + context: Context; irSchema?: IR.SchemaObject; schema: SchemaObject; }) => { @@ -237,7 +238,7 @@ const parseNumber = ({ irSchema = {}, schema, }: { - context: IR.Context; + context: Context; irSchema?: IR.SchemaObject; schema: Omit & { type: SchemaType; @@ -254,7 +255,7 @@ const parseObject = ({ schema, state, }: { - context: IR.Context; + context: Context; irSchema?: IR.SchemaObject; schema: SchemaObject; state: SchemaState; @@ -347,7 +348,7 @@ const parseObject = ({ const parseString = ({ irSchema = {}, }: { - context: IR.Context; + context: Context; irSchema?: IR.SchemaObject; schema: SchemaObject; }): IR.SchemaObject => { @@ -376,7 +377,7 @@ const parseAllOf = ({ schema, state, }: { - context: IR.Context; + context: Context; schema: SchemaWithRequired; state: SchemaState; }): IR.SchemaObject => { @@ -537,7 +538,7 @@ const parseAnyOf = ({ schema, state, }: { - context: IR.Context; + context: Context; schema: SchemaWithRequired; state: SchemaState; }): IR.SchemaObject => { @@ -625,7 +626,7 @@ const parseEnum = ({ schema, state, }: { - context: IR.Context; + context: Context; schema: SchemaWithRequired; state: SchemaState; }): IR.SchemaObject => { @@ -693,7 +694,7 @@ const parseOneOf = ({ schema, state, }: { - context: IR.Context; + context: Context; schema: SchemaWithRequired; state: SchemaState; }): IR.SchemaObject => { @@ -793,7 +794,7 @@ const parseRef = ({ schema, state, }: { - context: IR.Context; + context: Context; schema: SchemaWithRequired; state: SchemaState; }): IR.SchemaObject => { @@ -859,7 +860,7 @@ const parseOneType = ({ schema, state, }: { - context: IR.Context; + context: Context; irSchema?: IR.SchemaObject; schema: Omit & { type: SchemaType; @@ -923,7 +924,7 @@ const parseManyTypes = ({ schema, state, }: { - context: IR.Context; + context: Context; irSchema?: IR.SchemaObject; schema: Omit & { type: ReadonlyArray>; @@ -977,7 +978,7 @@ const parseType = ({ schema, state, }: { - context: IR.Context; + context: Context; schema: SchemaWithRequired; state: SchemaState; }): IR.SchemaObject => { @@ -1014,7 +1015,7 @@ const parseUnknown = ({ irSchema, schema, }: { - context: IR.Context; + context: Context; irSchema?: IR.SchemaObject; schema: SchemaObject; }): IR.SchemaObject => { @@ -1034,7 +1035,7 @@ export const schemaToIrSchema = ({ schema, state, }: { - context: IR.Context; + context: Context; schema: SchemaObject; state: SchemaState | undefined; }): IR.SchemaObject => { @@ -1106,7 +1107,7 @@ export const parseSchema = ({ schema, }: { $ref: string; - context: IR.Context; + context: Context; schema: SchemaObject; }) => { if (!context.ir.components) { diff --git a/packages/openapi-ts/src/openApi/3.1.x/parser/server.ts b/packages/openapi-ts/src/openApi/3.1.x/parser/server.ts index 9732ada5f..4ba8c1bf4 100644 --- a/packages/openapi-ts/src/openApi/3.1.x/parser/server.ts +++ b/packages/openapi-ts/src/openApi/3.1.x/parser/server.ts @@ -1,7 +1,7 @@ -import type { IR } from '~/ir/types'; +import type { Context } from '~/ir/context'; import { parseUrl } from '~/utils/url'; -export const parseServers = ({ context }: { context: IR.Context }) => { +export const parseServers = ({ context }: { context: Context }) => { if (context.spec.servers) { context.ir.servers = context.spec.servers; return; diff --git a/packages/openapi-ts/src/openApi/3.1.x/parser/webhook.ts b/packages/openapi-ts/src/openApi/3.1.x/parser/webhook.ts index cbeaf4ac5..ffdf670da 100644 --- a/packages/openapi-ts/src/openApi/3.1.x/parser/webhook.ts +++ b/packages/openapi-ts/src/openApi/3.1.x/parser/webhook.ts @@ -1,4 +1,4 @@ -import type { IR } from '~/ir/types'; +import type { Context } from '~/ir/context'; import { mergeParametersObjects } from '~/openApi/shared/utils/parameter'; import type { OpenApiV3_1_X, PathItemObject } from '../types/spec'; @@ -9,7 +9,7 @@ export const parseWebhooks = ({ context, securitySchemesMap, }: Pick[0], 'securitySchemesMap'> & { - context: IR.Context; + context: Context; }) => { const state: Parameters[0]['state'] = { ids: new Map(), diff --git a/packages/openapi-ts/src/openApi/index.ts b/packages/openapi-ts/src/openApi/index.ts index 7b44ff793..500657745 100644 --- a/packages/openapi-ts/src/openApi/index.ts +++ b/packages/openapi-ts/src/openApi/index.ts @@ -1,6 +1,5 @@ import { satisfies } from '~/config/utils/package'; import { Context } from '~/ir/context'; -import type { IR } from '~/ir/types'; import { parseV2_0_X } from '~/openApi/2.0.x'; import { parseV3_0_X } from '~/openApi/3.0.x'; import { parseV3_1_X } from '~/openApi/3.1.x'; @@ -73,7 +72,7 @@ export const parseOpenApiSpec = ({ dependencies: Record; logger: Logger; spec: unknown; -}): IR.Context | undefined => { +}): Context | undefined => { const context = new Context({ config, dependencies, @@ -82,17 +81,17 @@ export const parseOpenApiSpec = ({ }); if ('swagger' in context.spec) { - parseV2_0_X(context as IR.Context); + parseV2_0_X(context as Context); return context; } if (satisfies(context.spec.openapi, '>=3.0.0 <3.1.0')) { - parseV3_0_X(context as IR.Context); + parseV3_0_X(context as Context); return context; } if (satisfies(context.spec.openapi, '>=3.1.0')) { - parseV3_1_X(context as IR.Context); + parseV3_1_X(context as Context); return context; } diff --git a/packages/openapi-ts/src/openApi/shared/transforms/index.ts b/packages/openapi-ts/src/openApi/shared/transforms/index.ts index 6f34465a8..6a0db639a 100644 --- a/packages/openapi-ts/src/openApi/shared/transforms/index.ts +++ b/packages/openapi-ts/src/openApi/shared/transforms/index.ts @@ -1,10 +1,10 @@ -import type { IR } from '~/ir/types'; +import type { Context } from '~/ir/context'; import { enumsTransform } from './enums'; import { propertiesRequiredByDefaultTransform } from './propertiesRequiredByDefault'; import { readWriteTransform } from './readWrite'; -export const transformOpenApiSpec = ({ context }: { context: IR.Context }) => { +export const transformOpenApiSpec = ({ context }: { context: Context }) => { const { logger } = context; const eventTransformOpenApiSpec = logger.timeEvent('transform-openapi-spec'); if (context.config.parser.transforms.enums.enabled) { diff --git a/packages/openapi-ts/src/openApi/shared/utils/__tests__/operation.test.ts b/packages/openapi-ts/src/openApi/shared/utils/__tests__/operation.test.ts index 707ca9d7e..f754fb002 100644 --- a/packages/openapi-ts/src/openApi/shared/utils/__tests__/operation.test.ts +++ b/packages/openapi-ts/src/openApi/shared/utils/__tests__/operation.test.ts @@ -1,6 +1,7 @@ import { describe, expect, it } from 'vitest'; -import type { IR } from '../../../../ir/types'; +import type { Context } from '~/ir/context'; + import { operationToId } from '../operation'; describe('operationToId', () => { @@ -36,7 +37,7 @@ describe('operationToId', () => { it.each(scenarios)( 'transforms $method $path ($id) -> $output', async ({ id, method, output, path }) => { - const context: Partial = { + const context: Partial = { config: { plugins: { // @ts-expect-error @@ -51,7 +52,7 @@ describe('operationToId', () => { }; expect( operationToId({ - context: context as IR.Context, + context: context as Context, id, method, path, diff --git a/packages/openapi-ts/src/openApi/shared/utils/operation.ts b/packages/openapi-ts/src/openApi/shared/utils/operation.ts index 119159459..ec11085f9 100644 --- a/packages/openapi-ts/src/openApi/shared/utils/operation.ts +++ b/packages/openapi-ts/src/openApi/shared/utils/operation.ts @@ -1,5 +1,5 @@ +import type { Context } from '~/ir/context'; import { createOperationKey } from '~/ir/operation'; -import type { IR } from '~/ir/types'; import { sanitizeNamespaceIdentifier } from '~/openApi/common/parser/sanitize'; import { stringCase } from '~/utils/stringCase'; @@ -29,7 +29,7 @@ export const operationToId = ({ path, state, }: { - context: IR.Context; + context: Context; count?: number; id: string | undefined; method: string; diff --git a/packages/openapi-ts/src/openApi/shared/utils/validator.ts b/packages/openapi-ts/src/openApi/shared/utils/validator.ts index db79c7740..c5c237602 100644 --- a/packages/openapi-ts/src/openApi/shared/utils/validator.ts +++ b/packages/openapi-ts/src/openApi/shared/utils/validator.ts @@ -1,6 +1,6 @@ import colors from 'ansi-colors'; -import type { IR } from '~/ir/types'; +import type { Context } from '~/ir/context'; export interface ValidatorIssue { /** @@ -72,7 +72,7 @@ const shouldPrint = ({ context, issue, }: { - context: IR.Context; + context: Context; issue: ValidatorIssue; }) => { if (context.config.logs.level === 'silent') { @@ -90,7 +90,7 @@ export const handleValidatorResult = ({ context, result, }: { - context: IR.Context; + context: Context; result: ValidatorResult; }) => { for (const issue of result.issues) { diff --git a/packages/openapi-ts/src/plugins/@hey-api/schemas/plugin.ts b/packages/openapi-ts/src/plugins/@hey-api/schemas/plugin.ts index 7ea0e4990..52760f31e 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/schemas/plugin.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/schemas/plugin.ts @@ -1,5 +1,5 @@ import { satisfies } from '~/config/utils/package'; -import type { IR } from '~/ir/types'; +import type { Context } from '~/ir/context'; import type { OpenApiV2_0_XTypes } from '~/openApi/2.0.x'; import type { OpenApiV3_0_XTypes } from '~/openApi/3.0.x'; import type { OpenApiV3_1_XTypes } from '~/openApi/3.1.x'; @@ -47,7 +47,7 @@ const schemaToJsonSchemaDraft_04 = ({ plugin, schema: _schema, }: { - context: IR.Context; + context: Context; plugin: HeyApiSchemasPlugin['Instance']; schema: OpenApiV2_0_XTypes['SchemaObject']; }): OpenApiV2_0_XTypes['SchemaObject'] => { @@ -123,7 +123,7 @@ const schemaToJsonSchemaDraft_05 = ({ plugin, schema: _schema, }: { - context: IR.Context; + context: Context; plugin: HeyApiSchemasPlugin['Instance']; schema: | OpenApiV3_0_XTypes['SchemaObject'] @@ -225,7 +225,7 @@ const schemaToJsonSchema2020_12 = ({ plugin, schema: _schema, }: { - context: IR.Context; + context: Context; plugin: HeyApiSchemasPlugin['Instance']; schema: OpenApiV3_1_XTypes['SchemaObject']; }): OpenApiV3_1_XTypes['SchemaObject'] => { @@ -359,7 +359,7 @@ const schemasV2_0_X = ({ context, plugin, }: { - context: IR.Context; + context: Context; plugin: HeyApiSchemasPlugin['Instance']; }) => { if (!context.spec.definitions) { @@ -397,7 +397,7 @@ const schemasV3_0_X = ({ context, plugin, }: { - context: IR.Context; + context: Context; plugin: HeyApiSchemasPlugin['Instance']; }) => { if (!context.spec.components) { @@ -435,7 +435,7 @@ const schemasV3_1_X = ({ context, plugin, }: { - context: IR.Context; + context: Context; plugin: HeyApiSchemasPlugin['Instance']; }) => { if (!context.spec.components) { @@ -472,7 +472,7 @@ const schemasV3_1_X = ({ export const handler: HeyApiSchemasPlugin['Handler'] = ({ plugin }) => { if ('swagger' in plugin.context.spec) { schemasV2_0_X({ - context: plugin.context as IR.Context, + context: plugin.context as Context, plugin, }); return; @@ -480,7 +480,7 @@ export const handler: HeyApiSchemasPlugin['Handler'] = ({ plugin }) => { if (satisfies(plugin.context.spec.openapi, '>=3.0.0 <3.1.0')) { schemasV3_0_X({ - context: plugin.context as IR.Context, + context: plugin.context as Context, plugin, }); return; @@ -488,7 +488,7 @@ export const handler: HeyApiSchemasPlugin['Handler'] = ({ plugin }) => { if (satisfies(plugin.context.spec.openapi, '>=3.1.0')) { schemasV3_1_X({ - context: plugin.context as IR.Context, + context: plugin.context as Context, plugin, }); return; diff --git a/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/auth.ts b/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/auth.ts index 4c7315c6b..36610a79a 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/auth.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/auth.ts @@ -1,3 +1,4 @@ +import type { Context } from '~/ir/context'; import type { IR } from '~/ir/types'; import type { Auth } from '../../client-core/bundle/auth'; @@ -73,7 +74,7 @@ export const operationAuth = ({ operation, plugin, }: { - context: IR.Context; + context: Context; operation: IR.OperationObject; plugin: HeyApiSdkPlugin['Instance']; }): Array => { diff --git a/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/operation.ts b/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/operation.ts index 42ed9c269..97f383e2a 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/operation.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/operation.ts @@ -1,6 +1,7 @@ import type { SymbolMeta } from '@hey-api/codegen-core'; import type ts from 'typescript'; +import type { Context } from '~/ir/context'; import { statusCodeToGroup } from '~/ir/operation'; import type { IR } from '~/ir/types'; import { sanitizeNamespaceIdentifier } from '~/openApi'; @@ -39,7 +40,7 @@ const operationClassName = ({ context, value, }: { - context: IR.Context; + context: Context; value: string; }) => { const name = stringCase({ @@ -84,7 +85,7 @@ export const operationClasses = ({ operation, plugin, }: { - context: IR.Context; + context: Context; operation: IR.OperationObject; plugin: { config: Pick< diff --git a/packages/openapi-ts/src/plugins/shared/utils/case.ts b/packages/openapi-ts/src/plugins/shared/utils/case.ts index d3253d28c..84fd23cba 100644 --- a/packages/openapi-ts/src/plugins/shared/utils/case.ts +++ b/packages/openapi-ts/src/plugins/shared/utils/case.ts @@ -1,6 +1,6 @@ import ts from 'typescript'; -import type { IR } from '~/ir/types'; +import type { Context } from '~/ir/context'; import { numberRegExp } from '~/utils/regexp'; import { stringCase } from '~/utils/stringCase'; @@ -12,7 +12,7 @@ export const fieldName = ({ context, name, }: { - context: IR.Context; + context: Context; name: string; }) => { numberRegExp.lastIndex = 0; diff --git a/packages/openapi-ts/src/plugins/shared/utils/instance.ts b/packages/openapi-ts/src/plugins/shared/utils/instance.ts index 3de70f2e6..e64f77fb9 100644 --- a/packages/openapi-ts/src/plugins/shared/utils/instance.ts +++ b/packages/openapi-ts/src/plugins/shared/utils/instance.ts @@ -11,6 +11,7 @@ import type { import { HeyApiError } from '~/error'; import type { MatchPointerToGroupFn, WalkOptions } from '~/graph'; import { walk } from '~/graph'; +import type { Context } from '~/ir/context'; import type { IrTopLevelKind } from '~/ir/graph'; import { getIrPointerPriority, @@ -68,7 +69,7 @@ type EventHooks = { export class PluginInstance { api: T['api']; config: Omit; - context: IR.Context; + context: Context; dependencies: Required>['dependencies'] = []; private eventHooks: EventHooks; gen: IProject; @@ -81,7 +82,7 @@ export class PluginInstance { * information such as name, version, and dependency resolution during * code generation. */ - package: IR.Context['package']; + package: Context['package']; constructor( props: Pick< @@ -89,7 +90,7 @@ export class PluginInstance { 'config' | 'dependencies' | 'handler' > & { api?: T['api']; - context: IR.Context; + context: Context; gen: IProject; name: string; output: string; diff --git a/packages/openapi-ts/src/plugins/shared/utils/operation.ts b/packages/openapi-ts/src/plugins/shared/utils/operation.ts index a31aa9fbd..e1675484e 100644 --- a/packages/openapi-ts/src/plugins/shared/utils/operation.ts +++ b/packages/openapi-ts/src/plugins/shared/utils/operation.ts @@ -1,3 +1,4 @@ +import type { Context } from '~/ir/context'; import { hasOperationDataRequired } from '~/ir/operation'; import type { IR } from '~/ir/types'; import { getClientPlugin } from '~/plugins/@hey-api/client-core/utils'; @@ -42,7 +43,7 @@ export const isOperationOptionsRequired = ({ context, operation, }: { - context: IR.Context; + context: Context; operation: IR.OperationObject; }): boolean => { const client = getClientPlugin(context.config);