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.

Merge pull request #1464 from hey-api/fix/export-ir

fix: export IR types

authored by

Lubos and committed by
GitHub
24a0d09a cccc1605

+370 -363
+5
.changeset/tender-llamas-happen.md
··· 1 + --- 2 + '@hey-api/openapi-ts': patch 3 + --- 4 + 5 + fix: export IR types
+2 -2
packages/openapi-ts/src/generate/files.ts
··· 5 5 6 6 import { compiler } from '../compiler'; 7 7 import { type ImportExportItemObject, tsNodeToString } from '../compiler/utils'; 8 - import type { IRContext } from '../ir/context'; 8 + import type { IR } from '../ir/types'; 9 9 import { ensureValidIdentifier } from '../openApi/shared/utils/identifier'; 10 10 import type { StringCase } from '../types/config'; 11 11 import { stringCase } from '../utils/stringCase'; ··· 187 187 context, 188 188 id, 189 189 }: { 190 - context: IRContext; 190 + context: IR.Context; 191 191 id: string; 192 192 }): string { 193 193 const file = context.file({ id });
+2 -2
packages/openapi-ts/src/generate/output.ts
··· 1 1 import path from 'node:path'; 2 2 3 3 import { compiler } from '../compiler'; 4 - import type { IRContext } from '../ir/context'; 5 4 import { parseIR } from '../ir/parser'; 5 + import type { IR } from '../ir/types'; 6 6 import type { OpenApi } from '../openApi'; 7 7 import type { Client } from '../types/client'; 8 8 import type { Files } from '../types/utils'; ··· 106 106 }); 107 107 }; 108 108 109 - export const generateOutput = async ({ context }: { context: IRContext }) => { 109 + export const generateOutput = async ({ context }: { context: IR.Context }) => { 110 110 const outputPath = path.resolve(context.config.output.path); 111 111 112 112 if (context.config.output.clean) {
+4 -4
packages/openapi-ts/src/index.ts
··· 7 7 8 8 import { generateLegacyOutput, generateOutput } from './generate/output'; 9 9 import { ensureDirSync } from './generate/utils'; 10 - import type { IRContext } from './ir/context'; 10 + import type { IR } from './ir/types'; 11 11 import { parseExperimental, parseLegacy } from './openApi'; 12 12 import type { ClientPlugins, UserPlugins } from './plugins'; 13 13 import { defaultPluginConfigs } from './plugins'; ··· 444 444 Performance.end('spec'); 445 445 446 446 let client: Client | undefined; 447 - let context: IRContext | undefined; 447 + let context: IR.Context | undefined; 448 448 449 449 Performance.start('parser'); 450 450 if ( ··· 550 550 defineConfig, 551 551 }; 552 552 553 - export type { OpenApiV3_0_X } from './openApi/3.0.x'; 554 - export type { OpenApiV3_1_X } from './openApi/3.1.x'; 553 + export type { IR } from './ir/types'; 554 + export type { OpenApi } from './openApi/types'; 555 555 export type { Plugin } from './plugins/types'; 556 556 export type { UserConfig } from './types/config';
+7 -14
packages/openapi-ts/src/ir/context.ts
··· 4 4 import type { Config, StringCase } from '../types/config'; 5 5 import type { Files } from '../types/utils'; 6 6 import { resolveRef } from '../utils/ref'; 7 - import type { 8 - IR, 9 - IROperationObject, 10 - IRParameterObject, 11 - IRPathItemObject, 12 - IRRequestBodyObject, 13 - IRSchemaObject, 14 - } from './ir'; 7 + import type { IR } from './types'; 15 8 16 9 interface ContextFile { 17 10 /** ··· 44 37 */ 45 38 before: () => void; 46 39 operation: (args: { 47 - method: keyof IRPathItemObject; 48 - operation: IROperationObject; 40 + method: keyof IR.PathItemObject; 41 + operation: IR.OperationObject; 49 42 path: string; 50 43 }) => void; 51 44 parameter: (args: { 52 45 $ref: string; 53 46 name: string; 54 - parameter: IRParameterObject; 47 + parameter: IR.ParameterObject; 55 48 }) => void; 56 49 requestBody: (args: { 57 50 $ref: string; 58 51 name: string; 59 - requestBody: IRRequestBodyObject; 52 + requestBody: IR.RequestBodyObject; 60 53 }) => void; 61 54 schema: (args: { 62 55 $ref: string; 63 56 name: string; 64 - schema: IRSchemaObject; 57 + schema: IR.SchemaObject; 65 58 }) => void; 66 59 } 67 60 ··· 82 75 /** 83 76 * Intermediate representation model obtained from `spec`. 84 77 */ 85 - public ir: IR; 78 + public ir: IR.Model; 86 79 /** 87 80 * Resolved specification from `input`. 88 81 */
+31 -14
packages/openapi-ts/src/ir/ir.d.ts packages/openapi-ts/src/ir/types.d.ts
··· 1 1 import type { JsonSchemaDraft2020_12 } from '../openApi/3.1.x/types/json-schema-draft-2020-12'; 2 2 import type { SecuritySchemeObject } from '../openApi/3.1.x/types/spec'; 3 + import type { IRContext } from './context'; 3 4 import type { IRMediaType } from './mediaType'; 4 - 5 - export interface IR { 6 - components?: IRComponentsObject; 7 - paths?: IRPathsObject; 8 - } 9 5 10 6 interface IRComponentsObject { 11 7 parameters?: Record<string, IRParameterObject>; ··· 17 13 [path: `/${string}`]: IRPathItemObject; 18 14 } 19 15 20 - export interface IRPathItemObject { 16 + interface IRPathItemObject { 21 17 delete?: IROperationObject; 22 18 get?: IROperationObject; 23 19 head?: IROperationObject; ··· 28 24 trace?: IROperationObject; 29 25 } 30 26 31 - export interface IROperationObject { 27 + interface IROperationObject { 32 28 body?: IRBodyObject; 33 29 deprecated?: boolean; 34 30 description?: string; ··· 44 40 tags?: ReadonlyArray<string>; 45 41 } 46 42 47 - export interface IRBodyObject { 43 + interface IRBodyObject { 48 44 mediaType: string; 49 45 /** 50 46 * Does body control pagination? We handle only simple values ··· 56 52 type?: IRMediaType; 57 53 } 58 54 59 - export interface IRParametersObject { 55 + interface IRParametersObject { 60 56 cookie?: Record<string, IRParameterObject>; 61 57 header?: Record<string, IRParameterObject>; 62 58 path?: Record<string, IRParameterObject>; 63 59 query?: Record<string, IRParameterObject>; 64 60 } 65 61 66 - export interface IRParameterObject 62 + interface IRParameterObject 67 63 extends Pick<JsonSchemaDraft2020_12, 'deprecated' | 'description'> { 68 64 /** 69 65 * Determines whether the parameter value SHOULD allow reserved characters, as defined by RFC3986 `:/?#[]@!$&'()*+,;=` to be included without percent-encoding. The default value is `false`. This property SHALL be ignored if the request body media type is not `application/x-www-form-urlencoded` or `multipart/form-data`. If a value is explicitly defined, then the value of `contentType` (implicit or explicit) SHALL be ignored. ··· 98 94 | 'spaceDelimited'; 99 95 } 100 96 101 - export interface IRRequestBodyObject 97 + interface IRRequestBodyObject 102 98 extends Pick<JsonSchemaDraft2020_12, 'description'> { 103 99 required?: boolean; 104 100 schema: IRSchemaObject; 105 101 } 106 102 107 - export interface IRResponsesObject { 103 + interface IRResponsesObject { 108 104 /** 109 105 * Any {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#http-status-codes HTTP status code} can be used as the property name, but only one property per code, to describe the expected response for that HTTP status code. This field MUST be enclosed in quotation marks (for example, "200") for compatibility between JSON and YAML. To define a range of response codes, this field MAY contain the uppercase wildcard character `X`. For example, `2XX` represents all response codes between `[200-299]`. Only the following range definitions are allowed: `1XX`, `2XX`, `3XX`, `4XX`, and `5XX`. If a response is defined using an explicit code, the explicit code definition takes precedence over the range definition for that code. 110 106 */ ··· 115 111 default?: IRResponseObject; 116 112 } 117 113 118 - export interface IRResponseObject { 114 + interface IRResponseObject { 119 115 // TODO: parser - handle headers, links, and possibly other media types? 120 116 mediaType?: string; 121 117 schema: IRSchemaObject; 122 118 } 123 119 124 - export interface IRSchemaObject 120 + interface IRSchemaObject 125 121 extends Pick< 126 122 JsonSchemaDraft2020_12, 127 123 | '$ref' ··· 187 183 | 'unknown' 188 184 | 'void'; 189 185 } 186 + 187 + interface IRModel { 188 + components?: IRComponentsObject; 189 + paths?: IRPathsObject; 190 + } 191 + 192 + export namespace IR { 193 + export type BodyObject = IRBodyObject; 194 + export type ComponentsObject = IRComponentsObject; 195 + export type Context<Spec extends Record<string, any> = any> = IRContext<Spec>; 196 + export type Model = IRModel; 197 + export type OperationObject = IROperationObject; 198 + export type ParameterObject = IRParameterObject; 199 + export type ParametersObject = IRParametersObject; 200 + export type PathItemObject = IRPathItemObject; 201 + export type PathsObject = IRPathsObject; 202 + export type RequestBodyObject = IRRequestBodyObject; 203 + export type ResponseObject = IRResponseObject; 204 + export type ResponsesObject = IRResponsesObject; 205 + export type SchemaObject = IRSchemaObject; 206 + }
+15 -21
packages/openapi-ts/src/ir/operation.ts
··· 1 - import type { IRContext } from './context'; 2 - import type { IRRequestBodyObject } from './ir'; 3 - import { 4 - type IROperationObject, 5 - type IRResponseObject, 6 - type IRSchemaObject, 7 - } from './ir'; 8 1 import type { Pagination } from './pagination'; 9 2 import { 10 3 hasParametersObjectRequired, 11 4 parameterWithPagination, 12 5 } from './parameter'; 13 6 import { deduplicateSchema } from './schema'; 7 + import type { IR } from './types'; 14 8 import { addItemsToSchema } from './utils'; 15 9 16 10 export const hasOperationDataRequired = ( 17 - operation: IROperationObject, 11 + operation: IR.OperationObject, 18 12 ): boolean => { 19 13 if (hasParametersObjectRequired(operation.parameters)) { 20 14 return true; ··· 31 25 context, 32 26 operation, 33 27 }: { 34 - context: IRContext; 35 - operation: IROperationObject; 28 + context: IR.Context; 29 + operation: IR.OperationObject; 36 30 }): Pagination | undefined => { 37 31 if (operation.body?.pagination) { 38 32 if (typeof operation.body.pagination === 'boolean') { ··· 44 38 } 45 39 46 40 const schema = operation.body.schema.$ref 47 - ? context.resolveIrRef<IRRequestBodyObject | IRSchemaObject>( 41 + ? context.resolveIrRef<IR.RequestBodyObject | IR.SchemaObject>( 48 42 operation.body.schema.$ref, 49 43 ) 50 44 : operation.body.schema; ··· 88 82 /** 89 83 * A deduplicated union of all error types. Unknown types are omitted. 90 84 */ 91 - error?: IRSchemaObject; 85 + error?: IR.SchemaObject; 92 86 /** 93 87 * An object containing a map of status codes for each error type. 94 88 */ 95 - errors?: IRSchemaObject; 89 + errors?: IR.SchemaObject; 96 90 /** 97 91 * A deduplicated union of all response types. Unknown types are omitted. 98 92 */ 99 - response?: IRSchemaObject; 93 + response?: IR.SchemaObject; 100 94 /** 101 95 * An object containing a map of status codes for each response type. 102 96 */ 103 - responses?: IRSchemaObject; 97 + responses?: IR.SchemaObject; 104 98 } 105 99 106 100 export const operationResponsesMap = ( 107 - operation: IROperationObject, 101 + operation: IR.OperationObject, 108 102 ): OperationResponsesMap => { 109 103 const result: OperationResponsesMap = {}; 110 104 ··· 112 106 return result; 113 107 } 114 108 115 - const errors: Omit<IRSchemaObject, 'properties'> & 116 - Pick<Required<IRSchemaObject>, 'properties'> = { 109 + const errors: Omit<IR.SchemaObject, 'properties'> & 110 + Pick<Required<IR.SchemaObject>, 'properties'> = { 117 111 properties: {}, 118 112 type: 'object', 119 113 }; 120 114 121 - const responses: Omit<IRSchemaObject, 'properties'> & 122 - Pick<Required<IRSchemaObject>, 'properties'> = { 115 + const responses: Omit<IR.SchemaObject, 'properties'> & 116 + Pick<Required<IR.SchemaObject>, 'properties'> = { 123 117 properties: {}, 124 118 type: 'object', 125 119 }; 126 120 127 121 // store default response to be evaluated last 128 - let defaultResponse: IRResponseObject | undefined; 122 + let defaultResponse: IR.ResponseObject | undefined; 129 123 130 124 for (const name in operation.responses) { 131 125 const response = operation.responses[name]!;
+2 -2
packages/openapi-ts/src/ir/pagination.ts
··· 1 - import type { IRSchemaObject } from './ir'; 1 + import type { IR } from './types'; 2 2 3 3 export const paginationKeywordsRegExp = 4 4 /^(after|before|cursor|offset|page|start)$/; ··· 6 6 export interface Pagination { 7 7 in: string; 8 8 name: string; 9 - schema: IRSchemaObject; 9 + schema: IR.SchemaObject; 10 10 }
+4 -4
packages/openapi-ts/src/ir/parameter.ts
··· 1 - import type { IRParameterObject, IRParametersObject } from './ir'; 2 1 import type { Pagination } from './pagination'; 2 + import type { IR } from './types'; 3 3 4 4 export const hasParameterGroupObjectRequired = ( 5 - parameterGroup?: Record<string, IRParameterObject>, 5 + parameterGroup?: Record<string, IR.ParameterObject>, 6 6 ): boolean => { 7 7 for (const name in parameterGroup) { 8 8 if (parameterGroup[name].required) { ··· 14 14 }; 15 15 16 16 export const hasParametersObjectRequired = ( 17 - parameters: IRParametersObject | undefined, 17 + parameters: IR.ParametersObject | undefined, 18 18 ): boolean => { 19 19 if (!parameters) { 20 20 return false; ··· 40 40 }; 41 41 42 42 export const parameterWithPagination = ( 43 - parameters: IRParametersObject | undefined, 43 + parameters: IR.ParametersObject | undefined, 44 44 ): Pagination | undefined => { 45 45 if (!parameters) { 46 46 return;
+4 -5
packages/openapi-ts/src/ir/parser.ts
··· 1 - import type { IRContext } from './context'; 2 - import type { IRPathItemObject, IRPathsObject } from './ir'; 1 + import type { IR } from './types'; 3 2 4 3 /** 5 4 * Traverse the parsed intermediate representation model and broadcast 6 5 * various events to listeners. 7 6 */ 8 - export const parseIR = async ({ context }: { context: IRContext }) => { 7 + export const parseIR = async ({ context }: { context: IR.Context }) => { 9 8 await context.broadcast('before'); 10 9 11 10 if (context.ir.components) { ··· 29 28 } 30 29 31 30 for (const path in context.ir.paths) { 32 - const pathItem = context.ir.paths[path as keyof IRPathsObject]; 31 + const pathItem = context.ir.paths[path as keyof IR.PathsObject]; 33 32 34 33 for (const _method in pathItem) { 35 - const method = _method as keyof IRPathItemObject; 34 + const method = _method as keyof IR.PathItemObject; 36 35 const operation = pathItem[method]!; 37 36 await context.broadcast('operation', { method, operation, path }); 38 37 }
+3 -3
packages/openapi-ts/src/ir/schema.ts
··· 1 - import type { IRSchemaObject } from './ir'; 1 + import type { IR } from './types'; 2 2 3 3 /** 4 4 * Ensure we don't produce redundant types, e.g. string | string. 5 5 */ 6 - export const deduplicateSchema = <T extends IRSchemaObject>({ 6 + export const deduplicateSchema = <T extends IR.SchemaObject>({ 7 7 schema, 8 8 }: { 9 9 schema: T; ··· 12 12 return schema; 13 13 } 14 14 15 - const uniqueItems: Array<IRSchemaObject> = []; 15 + const uniqueItems: Array<IR.SchemaObject> = []; 16 16 const typeIds: Array<string> = []; 17 17 18 18 for (const item of schema.items) {
+4 -4
packages/openapi-ts/src/ir/utils.ts
··· 1 - import type { IRSchemaObject } from './ir'; 1 + import type { IR } from './types'; 2 2 3 3 /** 4 4 * Simply adds `items` to the schema. Also handles setting the logical operator ··· 10 10 mutateSchemaOneItem = false, 11 11 schema, 12 12 }: { 13 - items: Array<IRSchemaObject>; 14 - logicalOperator?: IRSchemaObject['logicalOperator']; 13 + items: Array<IR.SchemaObject>; 14 + logicalOperator?: IR.SchemaObject['logicalOperator']; 15 15 mutateSchemaOneItem?: boolean; 16 - schema: IRSchemaObject; 16 + schema: IR.SchemaObject; 17 17 }) => { 18 18 if (!items.length) { 19 19 return schema;
+2 -2
packages/openapi-ts/src/openApi/3.0.x/parser/index.ts
··· 1 - import type { IRContext } from '../../../ir/context'; 1 + import type { IR } from '../../../ir/types'; 2 2 import { canProcessRef } from '../../shared/utils/filter'; 3 3 import type { 4 4 OpenApiV3_0_X, ··· 17 17 import { parseRequestBody } from './requestBody'; 18 18 import { parseSchema } from './schema'; 19 19 20 - export const parseV3_0_X = (context: IRContext<OpenApiV3_0_X>) => { 20 + export const parseV3_0_X = (context: IR.Context<OpenApiV3_0_X>) => { 21 21 const operationIds = new Map<string, string>(); 22 22 const securitySchemesMap = new Map<string, SecuritySchemeObject>(); 23 23
+11 -12
packages/openapi-ts/src/openApi/3.0.x/parser/operation.ts
··· 1 - import type { IRContext } from '../../../ir/context'; 2 - import type { IROperationObject, IRPathsObject } from '../../../ir/ir'; 1 + import type { IR } from '../../../ir/types'; 3 2 import { operationToId } from '../../shared/utils/operation'; 4 3 import type { 5 4 OperationObject, ··· 14 13 15 14 interface Operation 16 15 extends Omit<OperationObject, 'parameters'>, 17 - Pick<IROperationObject, 'id' | 'parameters'> {} 16 + Pick<IR.OperationObject, 'id' | 'parameters'> {} 18 17 19 18 const parseOperationJsDoc = ({ 20 19 irOperation, 21 20 operation, 22 21 }: { 23 - irOperation: IROperationObject; 22 + irOperation: IR.OperationObject; 24 23 operation: Operation; 25 24 }) => { 26 25 if (operation.deprecated !== undefined) { ··· 44 43 method, 45 44 operation, 46 45 path, 47 - }: Pick<IROperationObject, 'method' | 'path'> & { 46 + }: Pick<IR.OperationObject, 'method' | 'path'> & { 48 47 operation: Operation; 49 - }): IROperationObject => { 50 - const irOperation: IROperationObject = { 48 + }): IR.OperationObject => { 49 + const irOperation: IR.OperationObject = { 51 50 id: operation.id, 52 51 method, 53 52 path, ··· 67 66 operation, 68 67 path, 69 68 securitySchemesMap, 70 - }: Pick<IROperationObject, 'method' | 'path'> & { 71 - context: IRContext; 69 + }: Pick<IR.OperationObject, 'method' | 'path'> & { 70 + context: IR.Context; 72 71 operation: Operation; 73 72 securitySchemesMap: Map<string, SecuritySchemeObject>; 74 - }): IROperationObject => { 73 + }): IR.OperationObject => { 75 74 const irOperation = initIrOperation({ method, operation, path }); 76 75 77 76 if (operation.parameters) { ··· 206 205 path, 207 206 securitySchemesMap, 208 207 }: { 209 - context: IRContext; 208 + context: IR.Context; 210 209 method: Extract< 211 210 keyof PathItemObject, 212 211 'delete' | 'get' | 'head' | 'options' | 'patch' | 'post' | 'put' | 'trace' 213 212 >; 214 213 operation: Operation; 215 214 operationIds: Map<string, string>; 216 - path: keyof IRPathsObject; 215 + path: keyof IR.PathsObject; 217 216 securitySchemesMap: Map<string, SecuritySchemeObject>; 218 217 }) => { 219 218 // TODO: parser - support throw on duplicate
+2 -2
packages/openapi-ts/src/openApi/3.0.x/parser/pagination.ts
··· 1 - import type { IRContext } from '../../../ir/context'; 2 1 import { paginationKeywordsRegExp } from '../../../ir/pagination'; 2 + import type { IR } from '../../../ir/types'; 3 3 import type { 4 4 ParameterObject, 5 5 ReferenceObject, ··· 15 15 name, 16 16 schema, 17 17 }: { 18 - context: IRContext; 18 + context: IR.Context; 19 19 name: string; 20 20 schema: SchemaObject | ReferenceObject; 21 21 }): boolean | string => {
+11 -12
packages/openapi-ts/src/openApi/3.0.x/parser/parameter.ts
··· 1 - import type { IRContext } from '../../../ir/context'; 2 - import type { IRParameterObject, IRParametersObject } from '../../../ir/ir'; 1 + import type { IR } from '../../../ir/types'; 3 2 import { refToName } from '../../../utils/ref'; 4 3 import type { 5 4 ParameterObject, ··· 60 59 context, 61 60 parameters, 62 61 }: { 63 - context: IRContext; 62 + context: IR.Context; 64 63 parameters?: ReadonlyArray<ParameterObject | ReferenceObject>; 65 - }): IRParametersObject | undefined => { 64 + }): IR.ParametersObject | undefined => { 66 65 if (!parameters || !Object.keys(parameters).length) { 67 66 return; 68 67 } 69 68 70 - const parametersObject: IRParametersObject = {}; 69 + const parametersObject: IR.ParametersObject = {}; 71 70 72 71 for (const parameterOrReference of parameters) { 73 72 const parameter = ··· 92 91 source, 93 92 target, 94 93 }: { 95 - source: IRParametersObject | undefined; 96 - target: IRParametersObject | undefined; 97 - }): IRParametersObject | undefined => { 94 + source: IR.ParametersObject | undefined; 95 + target: IR.ParametersObject | undefined; 96 + }): IR.ParametersObject | undefined => { 98 97 const result = { ...target }; 99 98 100 99 if (source) { ··· 154 153 context, 155 154 parameter, 156 155 }: { 157 - context: IRContext; 156 + context: IR.Context; 158 157 parameter: ParameterObject; 159 - }): IRParameterObject => { 158 + }): IR.ParameterObject => { 160 159 // TODO: parser - fix 161 160 let schema = parameter.schema; 162 161 ··· 196 195 ? parameter.allowReserved 197 196 : defaultAllowReserved(parameter.in); 198 197 199 - const irParameter: IRParameterObject = { 198 + const irParameter: IR.ParameterObject = { 200 199 allowReserved, 201 200 explode, 202 201 location: parameter.in, ··· 233 232 parameter, 234 233 }: { 235 234 $ref: string; 236 - context: IRContext; 235 + context: IR.Context; 237 236 parameter: ParameterObject; 238 237 }) => { 239 238 if (!context.ir.components) {
+5 -6
packages/openapi-ts/src/openApi/3.0.x/parser/requestBody.ts
··· 1 - import type { IRContext } from '../../../ir/context'; 2 - import type { IRRequestBodyObject } from '../../../ir/ir'; 1 + import type { IR } from '../../../ir/types'; 3 2 import { refToName } from '../../../utils/ref'; 4 3 import type { RequestBodyObject, SchemaObject } from '../types/spec'; 5 4 import { mediaTypeObject } from './mediaType'; ··· 9 8 context, 10 9 requestBody, 11 10 }: { 12 - context: IRContext; 11 + context: IR.Context; 13 12 requestBody: RequestBodyObject; 14 - }): IRRequestBodyObject => { 13 + }): IR.RequestBodyObject => { 15 14 // TODO: parser - fix 16 15 const content = mediaTypeObject({ 17 16 content: requestBody.content, ··· 23 22 ...schema, 24 23 }; 25 24 26 - const irRequestBody: IRRequestBodyObject = { 25 + const irRequestBody: IR.RequestBodyObject = { 27 26 schema: schemaToIrSchema({ 28 27 context, 29 28 schema: finalSchema, ··· 47 46 requestBody, 48 47 }: { 49 48 $ref: string; 50 - context: IRContext; 49 + context: IR.Context; 51 50 requestBody: RequestBodyObject; 52 51 }) => { 53 52 if (!context.ir.components) {
+46 -43
packages/openapi-ts/src/openApi/3.0.x/parser/schema.ts
··· 1 - import type { IRContext } from '../../../ir/context'; 2 - import type { IRSchemaObject } from '../../../ir/ir'; 1 + import type { IR } from '../../../ir/types'; 3 2 import { addItemsToSchema } from '../../../ir/utils'; 4 3 import { refToName } from '../../../utils/ref'; 5 4 import { discriminatorValue } from '../../shared/utils/discriminator'; ··· 11 10 * from the OpenAPI specification. 12 11 */ 13 12 $ref?: string; 14 - context: IRContext; 13 + context: IR.Context; 15 14 } 16 15 17 16 type SchemaWithRequired<K extends keyof Required<SchemaObject>> = Omit< ··· 41 40 irSchema, 42 41 schema, 43 42 }: { 44 - irSchema: IRSchemaObject; 43 + irSchema: IR.SchemaObject; 45 44 schema: SchemaObject; 46 45 }) => { 47 46 if (schema.deprecated !== undefined) { ··· 61 60 irSchema, 62 61 schema, 63 62 }: { 64 - irSchema: IRSchemaObject; 63 + irSchema: IR.SchemaObject; 65 64 schema: SchemaObject; 66 65 }) => { 67 66 if (schema.default !== undefined) { ··· 116 115 irSchema = {}, 117 116 schema, 118 117 }: SchemaContext & { 119 - irSchema?: IRSchemaObject; 118 + irSchema?: IR.SchemaObject; 120 119 schema: SchemaObject; 121 - }): IRSchemaObject => { 120 + }): IR.SchemaObject => { 122 121 if (schema.maxItems && schema.maxItems === schema.minItems) { 123 122 irSchema.type = 'tuple'; 124 123 } else { 125 124 irSchema.type = 'array'; 126 125 } 127 126 128 - let schemaItems: Array<IRSchemaObject> = []; 127 + let schemaItems: Array<IR.SchemaObject> = []; 129 128 130 129 if (schema.items) { 131 130 const irItemsSchema = schemaToIrSchema({ ··· 169 168 const parseBoolean = ({ 170 169 irSchema = {}, 171 170 }: SchemaContext & { 172 - irSchema?: IRSchemaObject; 171 + irSchema?: IR.SchemaObject; 173 172 schema: SchemaObject; 174 - }): IRSchemaObject => { 173 + }): IR.SchemaObject => { 175 174 irSchema.type = 'boolean'; 176 175 177 176 return irSchema; ··· 180 179 const parseNumber = ({ 181 180 irSchema = {}, 182 181 }: SchemaContext & { 183 - irSchema?: IRSchemaObject; 182 + irSchema?: IR.SchemaObject; 184 183 schema: SchemaObject; 185 - }): IRSchemaObject => { 184 + }): IR.SchemaObject => { 186 185 irSchema.type = 'number'; 187 186 188 187 return irSchema; ··· 193 192 irSchema = {}, 194 193 schema, 195 194 }: SchemaContext & { 196 - irSchema?: IRSchemaObject; 195 + irSchema?: IR.SchemaObject; 197 196 schema: SchemaObject; 198 - }): IRSchemaObject => { 197 + }): IR.SchemaObject => { 199 198 irSchema.type = 'object'; 200 199 201 - const schemaProperties: Record<string, IRSchemaObject> = {}; 200 + const schemaProperties: Record<string, IR.SchemaObject> = {}; 202 201 203 202 for (const name in schema.properties) { 204 203 const property = schema.properties[name]; ··· 250 249 const parseString = ({ 251 250 irSchema = {}, 252 251 }: SchemaContext & { 253 - irSchema?: IRSchemaObject; 252 + irSchema?: IR.SchemaObject; 254 253 schema: SchemaObject; 255 - }): IRSchemaObject => { 254 + }): IR.SchemaObject => { 256 255 irSchema.type = 'string'; 257 256 258 257 return irSchema; 259 258 }; 260 259 261 - const initIrSchema = ({ schema }: { schema: SchemaObject }): IRSchemaObject => { 262 - const irSchema: IRSchemaObject = {}; 260 + const initIrSchema = ({ 261 + schema, 262 + }: { 263 + schema: SchemaObject; 264 + }): IR.SchemaObject => { 265 + const irSchema: IR.SchemaObject = {}; 263 266 264 267 parseSchemaJsDoc({ 265 268 irSchema, ··· 275 278 schema, 276 279 }: SchemaContext & { 277 280 schema: SchemaWithRequired<'allOf'>; 278 - }): IRSchemaObject => { 281 + }): IR.SchemaObject => { 279 282 let irSchema = initIrSchema({ schema }); 280 283 281 - const schemaItems: Array<IRSchemaObject> = []; 284 + const schemaItems: Array<IR.SchemaObject> = []; 282 285 const schemaType = getSchemaType({ schema }); 283 286 284 287 const compositionSchemas = schema.allOf; ··· 306 309 const ref = context.resolveRef<SchemaObject>(compositionSchema.$ref); 307 310 // `$ref` should be passed from the root `parseSchema()` call 308 311 if (ref.discriminator && $ref) { 309 - const irDiscriminatorSchema: IRSchemaObject = { 312 + const irDiscriminatorSchema: IR.SchemaObject = { 310 313 properties: { 311 314 [ref.discriminator.propertyName]: { 312 315 const: discriminatorValue($ref, ref.discriminator.mapping), ··· 375 378 376 379 if (schema.nullable) { 377 380 // nest composition to avoid producing an intersection with null 378 - const nestedItems: Array<IRSchemaObject> = [ 381 + const nestedItems: Array<IR.SchemaObject> = [ 379 382 { 380 383 type: 'null', 381 384 }, ··· 411 414 schema, 412 415 }: SchemaContext & { 413 416 schema: SchemaWithRequired<'anyOf'>; 414 - }): IRSchemaObject => { 417 + }): IR.SchemaObject => { 415 418 let irSchema = initIrSchema({ schema }); 416 419 417 - const schemaItems: Array<IRSchemaObject> = []; 420 + const schemaItems: Array<IR.SchemaObject> = []; 418 421 const schemaType = getSchemaType({ schema }); 419 422 420 423 const compositionSchemas = schema.anyOf; ··· 427 430 428 431 // `$ref` should be defined with discriminators 429 432 if (schema.discriminator && '$ref' in compositionSchema) { 430 - const irDiscriminatorSchema: IRSchemaObject = { 433 + const irDiscriminatorSchema: IR.SchemaObject = { 431 434 properties: { 432 435 [schema.discriminator.propertyName]: { 433 436 const: discriminatorValue( ··· 484 487 schema, 485 488 }: SchemaContext & { 486 489 schema: SchemaWithRequired<'enum'>; 487 - }): IRSchemaObject => { 490 + }): IR.SchemaObject => { 488 491 let irSchema = initIrSchema({ schema }); 489 492 490 493 irSchema.type = 'enum'; 491 494 492 - const schemaItems: Array<IRSchemaObject> = []; 495 + const schemaItems: Array<IR.SchemaObject> = []; 493 496 494 497 for (const [index, enumValue] of schema.enum.entries()) { 495 498 const typeOfEnumValue = typeof enumValue; ··· 552 555 schema, 553 556 }: SchemaContext & { 554 557 schema: SchemaWithRequired<'oneOf'>; 555 - }): IRSchemaObject => { 558 + }): IR.SchemaObject => { 556 559 let irSchema = initIrSchema({ schema }); 557 560 558 - let schemaItems: Array<IRSchemaObject> = []; 561 + let schemaItems: Array<IR.SchemaObject> = []; 559 562 const schemaType = getSchemaType({ schema }); 560 563 561 564 const compositionSchemas = schema.oneOf; ··· 568 571 569 572 // `$ref` should be defined with discriminators 570 573 if (schema.discriminator && '$ref' in compositionSchema) { 571 - const irDiscriminatorSchema: IRSchemaObject = { 574 + const irDiscriminatorSchema: IR.SchemaObject = { 572 575 properties: { 573 576 [schema.discriminator.propertyName]: { 574 577 const: discriminatorValue( ··· 634 637 schema, 635 638 }: SchemaContext & { 636 639 schema: ReferenceObject; 637 - }): IRSchemaObject => { 638 - const irSchema: IRSchemaObject = {}; 640 + }): IR.SchemaObject => { 641 + const irSchema: IR.SchemaObject = {}; 639 642 640 643 // refs using unicode characters become encoded, didn't investigate why 641 644 // but the suspicion is this comes from `@apidevtools/json-schema-ref-parser` ··· 649 652 irSchema, 650 653 schema, 651 654 }: SchemaContext & { 652 - irSchema?: IRSchemaObject; 655 + irSchema?: IR.SchemaObject; 653 656 schema: SchemaWithRequired<'type'>; 654 - }): IRSchemaObject => { 657 + }): IR.SchemaObject => { 655 658 if (!irSchema) { 656 659 irSchema = initIrSchema({ schema }); 657 660 } 658 661 659 - const typeIrSchema: IRSchemaObject = {}; 662 + const typeIrSchema: IR.SchemaObject = {}; 660 663 661 664 parseSchemaMeta({ 662 665 irSchema: typeIrSchema, 663 666 schema, 664 667 }); 665 668 666 - const schemaItems: Array<IRSchemaObject> = [ 669 + const schemaItems: Array<IR.SchemaObject> = [ 667 670 parseOneType({ 668 671 context, 669 672 irSchema: typeIrSchema, ··· 687 690 schema, 688 691 }: SchemaContext & { 689 692 schema: SchemaWithRequired<'type'>; 690 - }): IRSchemaObject => { 693 + }): IR.SchemaObject => { 691 694 const irSchema = initIrSchema({ schema }); 692 695 693 696 parseSchemaMeta({ ··· 727 730 irSchema, 728 731 schema, 729 732 }: SchemaContext & { 730 - irSchema?: IRSchemaObject; 733 + irSchema?: IR.SchemaObject; 731 734 schema: SchemaWithRequired<'type'>; 732 - }): IRSchemaObject => { 735 + }): IR.SchemaObject => { 733 736 if (!irSchema) { 734 737 irSchema = initIrSchema({ schema }); 735 738 ··· 785 788 irSchema, 786 789 schema, 787 790 }: SchemaContext & { 788 - irSchema?: IRSchemaObject; 791 + irSchema?: IR.SchemaObject; 789 792 schema: SchemaObject; 790 - }): IRSchemaObject => { 793 + }): IR.SchemaObject => { 791 794 if (!irSchema) { 792 795 irSchema = initIrSchema({ schema }); 793 796 } ··· 808 811 schema, 809 812 }: SchemaContext & { 810 813 schema: SchemaObject | ReferenceObject; 811 - }): IRSchemaObject => { 814 + }): IR.SchemaObject => { 812 815 if ('$ref' in schema) { 813 816 return parseRef({ 814 817 $ref,
+2 -2
packages/openapi-ts/src/openApi/3.1.x/parser/index.ts
··· 1 - import type { IRContext } from '../../../ir/context'; 1 + import type { IR } from '../../../ir/types'; 2 2 import { canProcessRef } from '../../shared/utils/filter'; 3 3 import type { 4 4 OpenApiV3_1_X, ··· 17 17 import { parseRequestBody } from './requestBody'; 18 18 import { parseSchema } from './schema'; 19 19 20 - export const parseV3_1_X = (context: IRContext<OpenApiV3_1_X>) => { 20 + export const parseV3_1_X = (context: IR.Context<OpenApiV3_1_X>) => { 21 21 const operationIds = new Map<string, string>(); 22 22 const securitySchemesMap = new Map<string, SecuritySchemeObject>(); 23 23
+11 -12
packages/openapi-ts/src/openApi/3.1.x/parser/operation.ts
··· 1 - import type { IRContext } from '../../../ir/context'; 2 - import type { IROperationObject, IRPathsObject } from '../../../ir/ir'; 1 + import type { IR } from '../../../ir/types'; 3 2 import { operationToId } from '../../shared/utils/operation'; 4 3 import type { 5 4 OperationObject, ··· 14 13 15 14 interface Operation 16 15 extends Omit<OperationObject, 'parameters'>, 17 - Pick<IROperationObject, 'id' | 'parameters'> {} 16 + Pick<IR.OperationObject, 'id' | 'parameters'> {} 18 17 19 18 const parseOperationJsDoc = ({ 20 19 irOperation, 21 20 operation, 22 21 }: { 23 - irOperation: IROperationObject; 22 + irOperation: IR.OperationObject; 24 23 operation: Operation; 25 24 }) => { 26 25 if (operation.deprecated !== undefined) { ··· 44 43 method, 45 44 operation, 46 45 path, 47 - }: Pick<IROperationObject, 'method' | 'path'> & { 46 + }: Pick<IR.OperationObject, 'method' | 'path'> & { 48 47 operation: Operation; 49 - }): IROperationObject => { 50 - const irOperation: IROperationObject = { 48 + }): IR.OperationObject => { 49 + const irOperation: IR.OperationObject = { 51 50 id: operation.id, 52 51 method, 53 52 path, ··· 67 66 operation, 68 67 path, 69 68 securitySchemesMap, 70 - }: Pick<IROperationObject, 'method' | 'path'> & { 71 - context: IRContext; 69 + }: Pick<IR.OperationObject, 'method' | 'path'> & { 70 + context: IR.Context; 72 71 operation: Operation; 73 72 securitySchemesMap: Map<string, SecuritySchemeObject>; 74 - }): IROperationObject => { 73 + }): IR.OperationObject => { 75 74 const irOperation = initIrOperation({ method, operation, path }); 76 75 77 76 if (operation.parameters) { ··· 191 190 path, 192 191 securitySchemesMap, 193 192 }: { 194 - context: IRContext; 193 + context: IR.Context; 195 194 method: Extract< 196 195 keyof PathItemObject, 197 196 'delete' | 'get' | 'head' | 'options' | 'patch' | 'post' | 'put' | 'trace' 198 197 >; 199 198 operation: Operation; 200 199 operationIds: Map<string, string>; 201 - path: keyof IRPathsObject; 200 + path: keyof IR.PathsObject; 202 201 securitySchemesMap: Map<string, SecuritySchemeObject>; 203 202 }) => { 204 203 // TODO: parser - support throw on duplicate
+2 -2
packages/openapi-ts/src/openApi/3.1.x/parser/pagination.ts
··· 1 - import type { IRContext } from '../../../ir/context'; 2 1 import { paginationKeywordsRegExp } from '../../../ir/pagination'; 2 + import type { IR } from '../../../ir/types'; 3 3 import type { ParameterObject, RequestBodyObject } from '../types/spec'; 4 4 import { type SchemaObject } from '../types/spec'; 5 5 import { mediaTypeObject } from './mediaType'; ··· 11 11 name, 12 12 schema, 13 13 }: { 14 - context: IRContext; 14 + context: IR.Context; 15 15 name: string; 16 16 schema: SchemaObject; 17 17 }): boolean | string => {
+11 -12
packages/openapi-ts/src/openApi/3.1.x/parser/parameter.ts
··· 1 - import type { IRContext } from '../../../ir/context'; 2 - import type { IRParameterObject, IRParametersObject } from '../../../ir/ir'; 1 + import type { IR } from '../../../ir/types'; 3 2 import { refToName } from '../../../utils/ref'; 4 3 import type { 5 4 ParameterObject, ··· 60 59 context, 61 60 parameters, 62 61 }: { 63 - context: IRContext; 62 + context: IR.Context; 64 63 parameters?: ReadonlyArray<ParameterObject | ReferenceObject>; 65 - }): IRParametersObject | undefined => { 64 + }): IR.ParametersObject | undefined => { 66 65 if (!parameters || !Object.keys(parameters).length) { 67 66 return; 68 67 } 69 68 70 - const parametersObject: IRParametersObject = {}; 69 + const parametersObject: IR.ParametersObject = {}; 71 70 72 71 for (const parameterOrReference of parameters) { 73 72 const parameter = ··· 92 91 source, 93 92 target, 94 93 }: { 95 - source: IRParametersObject | undefined; 96 - target: IRParametersObject | undefined; 97 - }): IRParametersObject | undefined => { 94 + source: IR.ParametersObject | undefined; 95 + target: IR.ParametersObject | undefined; 96 + }): IR.ParametersObject | undefined => { 98 97 const result = { ...target }; 99 98 100 99 if (source) { ··· 154 153 context, 155 154 parameter, 156 155 }: { 157 - context: IRContext; 156 + context: IR.Context; 158 157 parameter: ParameterObject; 159 - }): IRParameterObject => { 158 + }): IR.ParameterObject => { 160 159 // TODO: parser - fix 161 160 let schema = parameter.schema; 162 161 ··· 189 188 ? parameter.allowReserved 190 189 : defaultAllowReserved(parameter.in); 191 190 192 - const irParameter: IRParameterObject = { 191 + const irParameter: IR.ParameterObject = { 193 192 allowReserved, 194 193 explode, 195 194 location: parameter.in, ··· 226 225 parameter, 227 226 }: { 228 227 $ref: string; 229 - context: IRContext; 228 + context: IR.Context; 230 229 parameter: ParameterObject; 231 230 }) => { 232 231 if (!context.ir.components) {
+5 -6
packages/openapi-ts/src/openApi/3.1.x/parser/requestBody.ts
··· 1 - import type { IRContext } from '../../../ir/context'; 2 - import type { IRRequestBodyObject } from '../../../ir/ir'; 1 + import type { IR } from '../../../ir/types'; 3 2 import { refToName } from '../../../utils/ref'; 4 3 import type { RequestBodyObject, SchemaObject } from '../types/spec'; 5 4 import { mediaTypeObject } from './mediaType'; ··· 9 8 context, 10 9 requestBody, 11 10 }: { 12 - context: IRContext; 11 + context: IR.Context; 13 12 requestBody: RequestBodyObject; 14 - }): IRRequestBodyObject => { 13 + }): IR.RequestBodyObject => { 15 14 // TODO: parser - fix 16 15 const content = mediaTypeObject({ 17 16 content: requestBody.content, ··· 23 22 ...schema, 24 23 }; 25 24 26 - const irRequestBody: IRRequestBodyObject = { 25 + const irRequestBody: IR.RequestBodyObject = { 27 26 schema: schemaToIrSchema({ 28 27 context, 29 28 schema: finalSchema, ··· 47 46 requestBody, 48 47 }: { 49 48 $ref: string; 50 - context: IRContext; 49 + context: IR.Context; 51 50 requestBody: RequestBodyObject; 52 51 }) => { 53 52 if (!context.ir.components) {
+46 -43
packages/openapi-ts/src/openApi/3.1.x/parser/schema.ts
··· 1 - import type { IRContext } from '../../../ir/context'; 2 - import type { IRSchemaObject } from '../../../ir/ir'; 1 + import type { IR } from '../../../ir/types'; 3 2 import { addItemsToSchema } from '../../../ir/utils'; 4 3 import { refToName } from '../../../utils/ref'; 5 4 import { discriminatorValue } from '../../shared/utils/discriminator'; ··· 11 10 * from the OpenAPI specification. 12 11 */ 13 12 $ref?: string; 14 - context: IRContext; 13 + context: IR.Context; 15 14 } 16 15 17 16 type SchemaWithRequired<K extends keyof Required<SchemaObject>> = Omit< ··· 47 46 irSchema, 48 47 schema, 49 48 }: { 50 - irSchema: IRSchemaObject; 49 + irSchema: IR.SchemaObject; 51 50 schema: SchemaObject; 52 51 }) => { 53 52 if (schema.deprecated !== undefined) { ··· 67 66 irSchema, 68 67 schema, 69 68 }: { 70 - irSchema: IRSchemaObject; 69 + irSchema: IR.SchemaObject; 71 70 schema: SchemaObject; 72 71 }) => { 73 72 if (schema.const !== undefined) { ··· 146 145 irSchema = {}, 147 146 schema, 148 147 }: SchemaContext & { 149 - irSchema?: IRSchemaObject; 148 + irSchema?: IR.SchemaObject; 150 149 schema: SchemaObject; 151 - }): IRSchemaObject => { 150 + }): IR.SchemaObject => { 152 151 if ( 153 152 (schema.prefixItems && schema.prefixItems.length) || 154 153 (schema.maxItems && schema.maxItems === schema.minItems) ··· 158 157 irSchema.type = 'array'; 159 158 } 160 159 161 - let schemaItems: Array<IRSchemaObject> = []; 160 + let schemaItems: Array<IR.SchemaObject> = []; 162 161 163 162 for (const item of schema.prefixItems ?? []) { 164 163 schemaItems.push( ··· 211 210 const parseBoolean = ({ 212 211 irSchema = {}, 213 212 }: SchemaContext & { 214 - irSchema?: IRSchemaObject; 213 + irSchema?: IR.SchemaObject; 215 214 schema: SchemaObject; 216 - }): IRSchemaObject => { 215 + }): IR.SchemaObject => { 217 216 irSchema.type = 'boolean'; 218 217 219 218 return irSchema; ··· 222 221 const parseNull = ({ 223 222 irSchema = {}, 224 223 }: SchemaContext & { 225 - irSchema?: IRSchemaObject; 224 + irSchema?: IR.SchemaObject; 226 225 schema: SchemaObject; 227 226 }) => { 228 227 irSchema.type = 'null'; ··· 233 232 const parseNumber = ({ 234 233 irSchema = {}, 235 234 }: SchemaContext & { 236 - irSchema?: IRSchemaObject; 235 + irSchema?: IR.SchemaObject; 237 236 schema: SchemaObject; 238 - }): IRSchemaObject => { 237 + }): IR.SchemaObject => { 239 238 irSchema.type = 'number'; 240 239 241 240 return irSchema; ··· 246 245 irSchema = {}, 247 246 schema, 248 247 }: SchemaContext & { 249 - irSchema?: IRSchemaObject; 248 + irSchema?: IR.SchemaObject; 250 249 schema: SchemaObject; 251 - }): IRSchemaObject => { 250 + }): IR.SchemaObject => { 252 251 irSchema.type = 'object'; 253 252 254 - const schemaProperties: Record<string, IRSchemaObject> = {}; 253 + const schemaProperties: Record<string, IR.SchemaObject> = {}; 255 254 256 255 for (const name in schema.properties) { 257 256 const property = schema.properties[name]; ··· 303 302 const parseString = ({ 304 303 irSchema = {}, 305 304 }: SchemaContext & { 306 - irSchema?: IRSchemaObject; 305 + irSchema?: IR.SchemaObject; 307 306 schema: SchemaObject; 308 - }): IRSchemaObject => { 307 + }): IR.SchemaObject => { 309 308 irSchema.type = 'string'; 310 309 311 310 return irSchema; 312 311 }; 313 312 314 - const initIrSchema = ({ schema }: { schema: SchemaObject }): IRSchemaObject => { 315 - const irSchema: IRSchemaObject = {}; 313 + const initIrSchema = ({ 314 + schema, 315 + }: { 316 + schema: SchemaObject; 317 + }): IR.SchemaObject => { 318 + const irSchema: IR.SchemaObject = {}; 316 319 317 320 parseSchemaJsDoc({ 318 321 irSchema, ··· 328 331 schema, 329 332 }: SchemaContext & { 330 333 schema: SchemaWithRequired<'allOf'>; 331 - }): IRSchemaObject => { 334 + }): IR.SchemaObject => { 332 335 let irSchema = initIrSchema({ schema }); 333 336 334 - const schemaItems: Array<IRSchemaObject> = []; 337 + const schemaItems: Array<IR.SchemaObject> = []; 335 338 const schemaTypes = getSchemaTypes({ schema }); 336 339 337 340 const compositionSchemas = schema.allOf; ··· 359 362 const ref = context.resolveRef<SchemaObject>(compositionSchema.$ref); 360 363 // `$ref` should be passed from the root `parseSchema()` call 361 364 if (ref.discriminator && $ref) { 362 - const irDiscriminatorSchema: IRSchemaObject = { 365 + const irDiscriminatorSchema: IR.SchemaObject = { 363 366 properties: { 364 367 [ref.discriminator.propertyName]: { 365 368 const: discriminatorValue($ref, ref.discriminator.mapping), ··· 429 432 430 433 if (schemaTypes.includes('null')) { 431 434 // nest composition to avoid producing an intersection with null 432 - const nestedItems: Array<IRSchemaObject> = [ 435 + const nestedItems: Array<IR.SchemaObject> = [ 433 436 { 434 437 type: 'null', 435 438 }, ··· 453 456 schema, 454 457 }: SchemaContext & { 455 458 schema: SchemaWithRequired<'anyOf'>; 456 - }): IRSchemaObject => { 459 + }): IR.SchemaObject => { 457 460 let irSchema = initIrSchema({ schema }); 458 461 459 - const schemaItems: Array<IRSchemaObject> = []; 462 + const schemaItems: Array<IR.SchemaObject> = []; 460 463 const schemaTypes = getSchemaTypes({ schema }); 461 464 462 465 const compositionSchemas = schema.anyOf; ··· 469 472 470 473 // `$ref` should be defined with discriminators 471 474 if (schema.discriminator && compositionSchema.$ref) { 472 - const irDiscriminatorSchema: IRSchemaObject = { 475 + const irDiscriminatorSchema: IR.SchemaObject = { 473 476 properties: { 474 477 [schema.discriminator.propertyName]: { 475 478 const: discriminatorValue( ··· 526 529 schema, 527 530 }: SchemaContext & { 528 531 schema: SchemaWithRequired<'enum'>; 529 - }): IRSchemaObject => { 532 + }): IR.SchemaObject => { 530 533 let irSchema = initIrSchema({ schema }); 531 534 532 535 irSchema.type = 'enum'; 533 536 534 - const schemaItems: Array<IRSchemaObject> = []; 537 + const schemaItems: Array<IR.SchemaObject> = []; 535 538 const schemaTypes = getSchemaTypes({ schema }); 536 539 537 540 for (const [index, enumValue] of schema.enum.entries()) { ··· 589 592 schema, 590 593 }: SchemaContext & { 591 594 schema: SchemaWithRequired<'oneOf'>; 592 - }): IRSchemaObject => { 595 + }): IR.SchemaObject => { 593 596 let irSchema = initIrSchema({ schema }); 594 597 595 - let schemaItems: Array<IRSchemaObject> = []; 598 + let schemaItems: Array<IR.SchemaObject> = []; 596 599 const schemaTypes = getSchemaTypes({ schema }); 597 600 598 601 const compositionSchemas = schema.oneOf; ··· 605 608 606 609 // `$ref` should be defined with discriminators 607 610 if (schema.discriminator && compositionSchema.$ref) { 608 - const irDiscriminatorSchema: IRSchemaObject = { 611 + const irDiscriminatorSchema: IR.SchemaObject = { 609 612 properties: { 610 613 [schema.discriminator.propertyName]: { 611 614 const: discriminatorValue( ··· 671 674 schema, 672 675 }: SchemaContext & { 673 676 schema: SchemaWithRequired<'$ref'>; 674 - }): IRSchemaObject => { 677 + }): IR.SchemaObject => { 675 678 const irSchema = initIrSchema({ schema }); 676 679 677 680 // refs using unicode characters become encoded, didn't investigate why ··· 686 689 irSchema, 687 690 schema, 688 691 }: SchemaContext & { 689 - irSchema?: IRSchemaObject; 692 + irSchema?: IR.SchemaObject; 690 693 schema: Omit<SchemaObject, 'type'> & { 691 694 type: SchemaType; 692 695 }; 693 - }): IRSchemaObject => { 696 + }): IR.SchemaObject => { 694 697 if (!irSchema) { 695 698 irSchema = initIrSchema({ schema }); 696 699 ··· 753 756 irSchema, 754 757 schema, 755 758 }: SchemaContext & { 756 - irSchema?: IRSchemaObject; 759 + irSchema?: IR.SchemaObject; 757 760 schema: Omit<SchemaObject, 'type'> & { 758 761 type: ReadonlyArray<SchemaType>; 759 762 }; 760 - }): IRSchemaObject => { 763 + }): IR.SchemaObject => { 761 764 if (!irSchema) { 762 765 irSchema = initIrSchema({ schema }); 763 766 } 764 767 765 - const typeIrSchema: IRSchemaObject = {}; 768 + const typeIrSchema: IR.SchemaObject = {}; 766 769 767 770 parseSchemaMeta({ 768 771 irSchema: typeIrSchema, 769 772 schema, 770 773 }); 771 774 772 - const schemaItems: Array<IRSchemaObject> = []; 775 + const schemaItems: Array<IR.SchemaObject> = []; 773 776 774 777 for (const type of schema.type) { 775 778 if (type === 'null') { ··· 801 804 schema, 802 805 }: SchemaContext & { 803 806 schema: SchemaWithRequired<'type'>; 804 - }): IRSchemaObject => { 807 + }): IR.SchemaObject => { 805 808 const irSchema = initIrSchema({ schema }); 806 809 807 810 parseSchemaMeta({ ··· 836 839 irSchema, 837 840 schema, 838 841 }: SchemaContext & { 839 - irSchema?: IRSchemaObject; 842 + irSchema?: IR.SchemaObject; 840 843 schema: SchemaObject; 841 - }): IRSchemaObject => { 844 + }): IR.SchemaObject => { 842 845 if (!irSchema) { 843 846 irSchema = initIrSchema({ schema }); 844 847 } ··· 859 862 schema, 860 863 }: SchemaContext & { 861 864 schema: SchemaObject; 862 - }): IRSchemaObject => { 865 + }): IR.SchemaObject => { 863 866 if (schema.$ref) { 864 867 return parseRef({ 865 868 $ref,
+10 -8
packages/openapi-ts/src/openApi/index.ts
··· 1 1 import { IRContext } from '../ir/context'; 2 + import type { IR } from '../ir/types'; 2 3 import type { Config } from '../types/config'; 3 - import { type OpenApiV3_0_X, parseV3_0_X } from './3.0.x'; 4 - import { type OpenApiV3_1_X, parseV3_1_X } from './3.1.x'; 4 + import { parseV3_0_X } from './3.0.x'; 5 + import { parseV3_1_X } from './3.1.x'; 5 6 import type { Client } from './common/interfaces/client'; 6 - import type { OpenApi } from './common/interfaces/OpenApi'; 7 + import type { OpenApi as LegacyOpenApi } from './common/interfaces/OpenApi'; 8 + import type { OpenApi } from './types'; 7 9 import { parse as parseV2 } from './v2'; 8 10 import { parse as parseV3 } from './v3'; 9 11 ··· 34 36 * @param openApi The OpenAPI spec that we have loaded from disk. 35 37 */ 36 38 export function parseLegacy({ openApi }: { openApi: unknown }): Client { 37 - const spec = openApi as OpenApi; 39 + const spec = openApi as LegacyOpenApi; 38 40 39 41 if ('openapi' in spec) { 40 42 return parseV3(spec); ··· 56 58 }: { 57 59 config: Config; 58 60 spec: unknown; 59 - }): IRContext | undefined => { 61 + }): IR.Context | undefined => { 60 62 const context = new IRContext({ 61 63 config, 62 64 spec: spec as Record<string, any>, ··· 64 66 65 67 // TODO: parser - handle Swagger 2.0 66 68 67 - const ctx = context as IRContext<OpenApiV3_0_X | OpenApiV3_1_X>; 69 + const ctx = context as IR.Context<OpenApi.V3_0_X | OpenApi.V3_1_X>; 68 70 switch (ctx.spec.openapi) { 69 71 case '3.0.0': 70 72 case '3.0.1': 71 73 case '3.0.2': 72 74 case '3.0.3': 73 75 case '3.0.4': 74 - parseV3_0_X(context as IRContext<OpenApiV3_0_X>); 76 + parseV3_0_X(context as IR.Context<OpenApi.V3_0_X>); 75 77 return context; 76 78 case '3.1.0': 77 79 case '3.1.1': 78 - parseV3_1_X(context as IRContext<OpenApiV3_1_X>); 80 + parseV3_1_X(context as IR.Context<OpenApi.V3_1_X>); 79 81 return context; 80 82 default: 81 83 // TODO: parser - uncomment after removing legacy parser.
+2 -2
packages/openapi-ts/src/openApi/shared/utils/operation.ts
··· 1 - import type { IRContext } from '../../../ir/context'; 1 + import type { IR } from '../../../ir/types'; 2 2 import { stringCase } from '../../../utils/stringCase'; 3 3 import { sanitizeNamespaceIdentifier } from '../../common/parser/sanitize'; 4 4 ··· 13 13 method, 14 14 path, 15 15 }: { 16 - context: IRContext; 16 + context: IR.Context; 17 17 id: string | undefined; 18 18 method: string; 19 19 path: string;
+8
packages/openapi-ts/src/openApi/types.d.ts
··· 1 + import type { OpenApiV3_0_X } from './3.0.x'; 2 + import type { OpenApiV3_1_X } from './3.1.x'; 3 + 4 + export namespace OpenApi { 5 + export type V3_0_X = OpenApiV3_0_X; 6 + 7 + export type V3_1_X = OpenApiV3_1_X; 8 + }
+9 -10
packages/openapi-ts/src/plugins/@hey-api/schemas/plugin.ts
··· 1 1 import { compiler } from '../../../compiler'; 2 - import type { IRContext } from '../../../ir/context'; 3 - import type { OpenApiV3_0_X } from '../../../openApi/3.0.x'; 2 + import type { IR } from '../../../ir/types'; 4 3 import type { 5 4 ReferenceObject as OpenApiV3_0_XReferenceObject, 6 5 SchemaObject as OpenApiV3_0_XSchemaObject, 7 6 } from '../../../openApi/3.0.x/types/spec'; 8 - import type { OpenApiV3_1_X } from '../../../openApi/3.1.x'; 9 7 import type { SchemaObject as OpenApiV3_1_XSchemaObject } from '../../../openApi/3.1.x/types/spec'; 10 8 import { ensureValidIdentifier } from '../../../openApi/shared/utils/identifier'; 9 + import type { OpenApi } from '../../../openApi/types'; 11 10 import type { Plugin } from '../../types'; 12 11 import type { Config } from './types'; 13 12 ··· 48 47 plugin, 49 48 schema: _schema, 50 49 }: { 51 - context: IRContext; 50 + context: IR.Context; 52 51 plugin: Plugin.Instance<Config>; 53 52 schema: OpenApiV3_0_XSchemaObject | OpenApiV3_0_XReferenceObject; 54 53 }): object => { ··· 144 143 plugin, 145 144 schema: _schema, 146 145 }: { 147 - context: IRContext; 146 + context: IR.Context; 148 147 plugin: Plugin.Instance<Config>; 149 148 schema: OpenApiV3_1_XSchemaObject; 150 149 }): object => { ··· 264 263 context, 265 264 plugin, 266 265 }: { 267 - context: IRContext<OpenApiV3_0_X>; 266 + context: IR.Context<OpenApi.V3_0_X>; 268 267 plugin: Plugin.Instance<Config>; 269 268 }) => { 270 269 if (!context.spec.components) { ··· 292 291 context, 293 292 plugin, 294 293 }: { 295 - context: IRContext<OpenApiV3_1_X>; 294 + context: IR.Context<OpenApi.V3_1_X>; 296 295 plugin: Plugin.Instance<Config>; 297 296 }) => { 298 297 if (!context.spec.components) { ··· 324 323 }); 325 324 326 325 if (context.spec.openapi) { 327 - const ctx = context as IRContext<OpenApiV3_0_X | OpenApiV3_1_X>; 326 + const ctx = context as IR.Context<OpenApi.V3_0_X | OpenApi.V3_1_X>; 328 327 switch (ctx.spec.openapi) { 329 328 // TODO: parser - handle Swagger 2.0 330 329 case '3.0.0': ··· 333 332 case '3.0.3': 334 333 case '3.0.4': 335 334 schemasV3_0_X({ 336 - context: context as IRContext<OpenApiV3_0_X>, 335 + context: context as IR.Context<OpenApi.V3_0_X>, 337 336 plugin, 338 337 }); 339 338 break; 340 339 case '3.1.0': 341 340 case '3.1.1': 342 341 schemasV3_1_X({ 343 - context: context as IRContext<OpenApiV3_1_X>, 342 + context: context as IR.Context<OpenApi.V3_1_X>, 344 343 plugin, 345 344 }); 346 345 break;
+2 -2
packages/openapi-ts/src/plugins/@hey-api/sdk/plugin-legacy.ts
··· 11 11 } from '../../../compiler/types'; 12 12 import { clientApi, clientModulePath } from '../../../generate/client'; 13 13 import { TypeScriptFile } from '../../../generate/files'; 14 - import type { IROperationObject } from '../../../ir/ir'; 14 + import type { IR } from '../../../ir/types'; 15 15 import { isOperationParameterRequired } from '../../../openApi'; 16 16 import type { 17 17 Client, ··· 491 491 config: Config; 492 492 handleIllegal?: boolean; 493 493 id: string; 494 - operation: IROperationObject | Operation; 494 + operation: IR.OperationObject | Operation; 495 495 }) => { 496 496 if (config.plugins['@hey-api/sdk']?.methodNameBuilder) { 497 497 return config.plugins['@hey-api/sdk'].methodNameBuilder(operation);
+5 -6
packages/openapi-ts/src/plugins/@hey-api/sdk/plugin.ts
··· 3 3 import { compiler } from '../../../compiler'; 4 4 import type { ObjectValue } from '../../../compiler/types'; 5 5 import { clientApi, clientModulePath } from '../../../generate/client'; 6 - import type { IRContext } from '../../../ir/context'; 7 - import type { IROperationObject } from '../../../ir/ir'; 8 6 import { 9 7 hasOperationDataRequired, 10 8 statusCodeToGroup, 11 9 } from '../../../ir/operation'; 10 + import type { IR } from '../../../ir/types'; 12 11 import { escapeComment } from '../../../utils/escape'; 13 12 import { getServiceName } from '../../../utils/postprocess'; 14 13 import { transformServiceName } from '../../../utils/transform'; ··· 94 93 operation, 95 94 plugin, 96 95 }: { 97 - context: IRContext; 98 - operation: IROperationObject; 96 + context: IR.Context; 97 + operation: IR.OperationObject; 99 98 plugin: Plugin.Instance<Config>; 100 99 }): Array<ts.Statement> => { 101 100 const file = context.file({ id: sdkId })!; ··· 383 382 context, 384 383 plugin, 385 384 }: { 386 - context: IRContext; 385 + context: IR.Context; 387 386 plugin: Plugin.Instance<Config>; 388 387 }) => { 389 388 const file = context.file({ id: sdkId })!; ··· 475 474 context, 476 475 plugin, 477 476 }: { 478 - context: IRContext; 477 + context: IR.Context; 479 478 plugin: Plugin.Instance<Config>; 480 479 }) => { 481 480 const file = context.file({ id: sdkId })!;
+3 -3
packages/openapi-ts/src/plugins/@hey-api/sdk/types.d.ts
··· 1 - import type { IROperationObject } from '../../../ir/ir'; 1 + import type { IR } from '../../../ir/types'; 2 2 import type { Operation } from '../../../types/client'; 3 3 import type { Plugin } from '../../types'; 4 4 ··· 44 44 */ 45 45 include?: string; 46 46 /** 47 - * Customise the name of methods within the service. By default, {@link IROperationObject.id} or {@link Operation.name} is used. 47 + * Customise the name of methods within the service. By default, {@link IR.OperationObject.id} or {@link Operation.name} is used. 48 48 */ 49 - methodNameBuilder?: (operation: IROperationObject | Operation) => string; 49 + methodNameBuilder?: (operation: IR.OperationObject | Operation) => string; 50 50 // TODO: parser - rename operationId option to something like inferId?: boolean 51 51 /** 52 52 * Use operation ID to generate operation names?
+6 -7
packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts
··· 1 1 import ts from 'typescript'; 2 2 3 3 import { compiler } from '../../../compiler'; 4 - import type { IRContext } from '../../../ir/context'; 5 - import type { IRSchemaObject } from '../../../ir/ir'; 6 4 import { operationResponsesMap } from '../../../ir/operation'; 5 + import type { IR } from '../../../ir/types'; 7 6 import { irRef } from '../../../utils/ref'; 8 7 import { stringCase } from '../../../utils/stringCase'; 9 8 import { operationIrRef } from '../../shared/utils/ref'; ··· 91 90 plugin, 92 91 schema, 93 92 }: { 94 - context: IRContext; 93 + context: IR.Context; 95 94 plugin: Plugin.Instance<Config>; 96 - schema: IRSchemaObject; 95 + schema: IR.SchemaObject; 97 96 }): Array<ts.Expression | ts.Statement> => { 98 97 const identifierData = compiler.identifier({ text: dataVariableName }); 99 98 const nodes = processSchemaType({ ··· 118 117 plugin, 119 118 schema, 120 119 }: { 121 - context: IRContext; 120 + context: IR.Context; 122 121 dataExpression?: ts.Expression | string; 123 122 plugin: Plugin.Instance<Config>; 124 - schema: IRSchemaObject; 123 + schema: IR.SchemaObject; 125 124 }): Array<ts.Expression | ts.Statement> => { 126 125 const file = context.file({ id: transformersId })!; 127 126 ··· 134 133 135 134 if (identifier.created && identifier.name) { 136 135 // create each schema response transformer only once 137 - const refSchema = context.resolveIrRef<IRSchemaObject>(schema.$ref); 136 + const refSchema = context.resolveIrRef<IR.SchemaObject>(schema.$ref); 138 137 const nodes = schemaResponseTransformerNodes({ 139 138 context, 140 139 plugin,
+31 -36
packages/openapi-ts/src/plugins/@hey-api/typescript/plugin.ts
··· 2 2 3 3 import type { Property } from '../../../compiler'; 4 4 import { compiler } from '../../../compiler'; 5 - import type { IRContext } from '../../../ir/context'; 6 - import type { 7 - IROperationObject, 8 - IRParameterObject, 9 - IRSchemaObject, 10 - } from '../../../ir/ir'; 11 5 import { operationResponsesMap } from '../../../ir/operation'; 12 6 import { deduplicateSchema } from '../../../ir/schema'; 7 + import type { IR } from '../../../ir/types'; 13 8 import { escapeComment } from '../../../utils/escape'; 14 9 import { irRef, isRefOpenApiComponent } from '../../../utils/ref'; 15 10 import { digitsRegExp } from '../../../utils/regexp'; ··· 19 14 import type { Plugin } from '../../types'; 20 15 import type { Config } from './types'; 21 16 22 - interface SchemaWithType<T extends Required<IRSchemaObject>['type']> 23 - extends Omit<IRSchemaObject, 'type'> { 24 - type: Extract<Required<IRSchemaObject>['type'], T>; 17 + interface SchemaWithType<T extends Required<IR.SchemaObject>['type']> 18 + extends Omit<IR.SchemaObject, 'type'> { 19 + type: Extract<Required<IR.SchemaObject>['type'], T>; 25 20 } 26 21 27 22 const typesId = 'types'; 28 23 29 - const parseSchemaJsDoc = ({ schema }: { schema: IRSchemaObject }) => { 24 + const parseSchemaJsDoc = ({ schema }: { schema: IR.SchemaObject }) => { 30 25 const comments = [ 31 26 schema.description && escapeComment(schema.description), 32 27 schema.deprecated && '@deprecated', ··· 46 41 schema, 47 42 }: { 48 43 $ref: string; 49 - context: IRContext; 44 + context: IR.Context; 50 45 plugin: Plugin.Instance<Config>; 51 46 schema: SchemaWithType<'enum'>; 52 47 }) => { ··· 87 82 schema, 88 83 }: { 89 84 plugin: Plugin.Instance<Config>; 90 - schema: IRSchemaObject; 85 + schema: IR.SchemaObject; 91 86 }) => { 92 87 const typeofItems: Array< 93 88 | 'bigint' ··· 154 149 schema, 155 150 }: { 156 151 $ref: string; 157 - context: IRContext; 152 + context: IR.Context; 158 153 plugin: Plugin.Instance<Config>; 159 154 schema: SchemaWithType<'enum'>; 160 155 }) => { ··· 201 196 schema, 202 197 }: { 203 198 $ref: string; 204 - context: IRContext; 199 + context: IR.Context; 205 200 plugin: Plugin.Instance<Config>; 206 201 schema: SchemaWithType<'enum'>; 207 202 }) => { ··· 252 247 plugin, 253 248 schema, 254 249 }: { 255 - context: IRContext; 250 + context: IR.Context; 256 251 namespace: Array<ts.Statement>; 257 252 plugin: Plugin.Instance<Config>; 258 253 schema: SchemaWithType<'array'>; ··· 293 288 const booleanTypeToIdentifier = ({ 294 289 schema, 295 290 }: { 296 - context: IRContext; 291 + context: IR.Context; 297 292 namespace: Array<ts.Statement>; 298 293 schema: SchemaWithType<'boolean'>; 299 294 }) => { ··· 316 311 schema, 317 312 }: { 318 313 $ref?: string; 319 - context: IRContext; 314 + context: IR.Context; 320 315 namespace: Array<ts.Statement>; 321 316 plugin: Plugin.Instance<Config>; 322 317 schema: SchemaWithType<'enum'>; ··· 406 401 const numberTypeToIdentifier = ({ 407 402 schema, 408 403 }: { 409 - context: IRContext; 404 + context: IR.Context; 410 405 namespace: Array<ts.Statement>; 411 406 schema: SchemaWithType<'number'>; 412 407 }) => { ··· 427 422 plugin, 428 423 schema, 429 424 }: { 430 - context: IRContext; 425 + context: IR.Context; 431 426 namespace: Array<ts.Statement>; 432 427 plugin: Plugin.Instance<Config>; 433 428 schema: SchemaWithType<'object'>; 434 429 }) => { 435 430 let indexProperty: Property | undefined; 436 431 const schemaProperties: Array<Property> = []; 437 - let indexPropertyItems: Array<IRSchemaObject> = []; 432 + let indexPropertyItems: Array<IR.SchemaObject> = []; 438 433 const required = schema.required ?? []; 439 434 let hasOptionalProperties = false; 440 435 ··· 506 501 context, 507 502 schema, 508 503 }: { 509 - context: IRContext; 504 + context: IR.Context; 510 505 namespace: Array<ts.Statement>; 511 506 schema: SchemaWithType<'string'>; 512 507 }) => { ··· 549 544 plugin, 550 545 schema, 551 546 }: { 552 - context: IRContext; 547 + context: IR.Context; 553 548 namespace: Array<ts.Statement>; 554 549 plugin: Plugin.Instance<Config>; 555 550 schema: SchemaWithType<'tuple'>; ··· 580 575 schema, 581 576 }: { 582 577 $ref?: string; 583 - context: IRContext; 578 + context: IR.Context; 584 579 namespace: Array<ts.Statement>; 585 580 plugin: Plugin.Instance<Config>; 586 - schema: IRSchemaObject; 581 + schema: IR.SchemaObject; 587 582 }): ts.TypeNode => { 588 - switch (schema.type as Required<IRSchemaObject>['type']) { 583 + switch (schema.type as Required<IR.SchemaObject>['type']) { 589 584 case 'array': 590 585 return arrayTypeToIdentifier({ 591 586 context, ··· 659 654 const irParametersToIrSchema = ({ 660 655 parameters, 661 656 }: { 662 - parameters: Record<string, IRParameterObject>; 663 - }): IRSchemaObject => { 664 - const irSchema: IRSchemaObject = { 657 + parameters: Record<string, IR.ParameterObject>; 658 + }): IR.SchemaObject => { 659 + const irSchema: IR.SchemaObject = { 665 660 type: 'object', 666 661 }; 667 662 668 663 if (parameters) { 669 - const properties: Record<string, IRSchemaObject> = {}; 664 + const properties: Record<string, IR.SchemaObject> = {}; 670 665 const required: Array<string> = []; 671 666 672 667 for (const name in parameters) { ··· 696 691 operation, 697 692 plugin, 698 693 }: { 699 - context: IRContext; 700 - operation: IROperationObject; 694 + context: IR.Context; 695 + operation: IR.OperationObject; 701 696 plugin: Plugin.Instance<Config>; 702 697 }) => { 703 698 const file = context.file({ id: typesId })!; 704 - const data: IRSchemaObject = { 699 + const data: IR.SchemaObject = { 705 700 type: 'object', 706 701 }; 707 702 const dataRequired: Array<string> = []; ··· 793 788 operation, 794 789 plugin, 795 790 }: { 796 - context: IRContext; 797 - operation: IROperationObject; 791 + context: IR.Context; 792 + operation: IR.OperationObject; 798 793 plugin: Plugin.Instance<Config>; 799 794 }) => { 800 795 operationToDataType({ ··· 909 904 schema, 910 905 }: { 911 906 $ref?: string; 912 - context: IRContext; 907 + context: IR.Context; 913 908 namespace?: Array<ts.Statement>; 914 909 plugin: Plugin.Instance<Config>; 915 - schema: IRSchemaObject; 910 + schema: IR.SchemaObject; 916 911 }): ts.TypeNode => { 917 912 const file = context.file({ id: typesId })!; 918 913
+3 -3
packages/openapi-ts/src/plugins/@tanstack/query-core/plugin-legacy.ts
··· 5 5 import type { ImportExportItemObject } from '../../../compiler/utils'; 6 6 import { clientApi, clientModulePath } from '../../../generate/client'; 7 7 import { relativeModulePath } from '../../../generate/utils'; 8 - import type { IROperationObject } from '../../../ir/ir'; 9 8 import { paginationKeywordsRegExp } from '../../../ir/pagination'; 9 + import type { IR } from '../../../ir/types'; 10 10 import { isOperationParameterRequired } from '../../../openApi'; 11 11 import { getOperationKey } from '../../../openApi/common/parser/operation'; 12 12 import type { ··· 56 56 }: { 57 57 config: Config; 58 58 id: string; 59 - operation: IROperationObject | Operation; 59 + operation: IR.OperationObject | Operation; 60 60 }) => 61 61 `${serviceFunctionIdentifier({ 62 62 config, ··· 73 73 config: Config; 74 74 id: string; 75 75 isInfinite?: boolean; 76 - operation: IROperationObject | Operation; 76 + operation: IR.OperationObject | Operation; 77 77 }) => 78 78 `${serviceFunctionIdentifier({ 79 79 config,
+21 -22
packages/openapi-ts/src/plugins/@tanstack/query-core/plugin.ts
··· 7 7 tsNodeToString, 8 8 } from '../../../compiler/utils'; 9 9 import { clientApi, clientModulePath } from '../../../generate/client'; 10 - import type { IRContext } from '../../../ir/context'; 11 - import type { IROperationObject } from '../../../ir/ir'; 12 10 import { 13 11 hasOperationDataRequired, 14 12 operationPagination, 15 13 } from '../../../ir/operation'; 14 + import type { IR } from '../../../ir/types'; 16 15 import { getConfig } from '../../../utils/config'; 17 16 import { getServiceName } from '../../../utils/postprocess'; 18 17 import { transformServiceName } from '../../../utils/transform'; ··· 39 38 context, 40 39 operation, 41 40 }: { 42 - context: IRContext; 43 - operation: IROperationObject; 41 + context: IR.Context; 42 + operation: IR.OperationObject; 44 43 }) => 45 44 `${serviceFunctionIdentifier({ 46 45 config: context.config, ··· 52 51 context, 53 52 operation, 54 53 }: { 55 - context: IRContext; 56 - operation: IROperationObject; 54 + context: IR.Context; 55 + operation: IR.OperationObject; 57 56 }) => 58 57 `${serviceFunctionIdentifier({ 59 58 config: context.config, ··· 65 64 context, 66 65 operation, 67 66 }: { 68 - context: IRContext; 69 - operation: IROperationObject; 67 + context: IR.Context; 68 + operation: IR.OperationObject; 70 69 }) => 71 70 `${serviceFunctionIdentifier({ 72 71 config: context.config, ··· 79 78 isInfinite, 80 79 operation, 81 80 }: { 82 - context: IRContext; 81 + context: IR.Context; 83 82 isInfinite?: boolean; 84 - operation: IROperationObject; 83 + operation: IR.OperationObject; 85 84 }) => 86 85 `${serviceFunctionIdentifier({ 87 86 config: context.config, ··· 106 105 context, 107 106 plugin, 108 107 }: { 109 - context: IRContext; 108 + context: IR.Context; 110 109 plugin: PluginInstance; 111 110 }) => { 112 111 const file = context.file({ id: plugin.name })!; ··· 295 294 context, 296 295 plugin, 297 296 }: { 298 - context: IRContext; 297 + context: IR.Context; 299 298 plugin: PluginInstance; 300 299 }) => { 301 300 const file = context.file({ id: plugin.name })!; ··· 491 490 context, 492 491 plugin, 493 492 }: { 494 - context: IRContext; 493 + context: IR.Context; 495 494 plugin: PluginInstance; 496 495 }) => { 497 496 const file = context.file({ id: plugin.name })!; ··· 549 548 isInfinite, 550 549 plugin, 551 550 }: { 552 - context: IRContext; 551 + context: IR.Context; 553 552 id: string; 554 553 isInfinite?: boolean; 555 554 plugin: PluginInstance; ··· 580 579 operation, 581 580 plugin, 582 581 }: { 583 - context: IRContext; 584 - operation: IROperationObject; 582 + context: IR.Context; 583 + operation: IR.OperationObject; 585 584 plugin: PluginInstance; 586 585 }) => { 587 586 const identifierData = context.file({ id: 'types' })!.identifier({ ··· 609 608 operation, 610 609 plugin, 611 610 }: { 612 - context: IRContext; 613 - operation: IROperationObject; 611 + context: IR.Context; 612 + operation: IR.OperationObject; 614 613 plugin: PluginInstance; 615 614 }) => { 616 615 const file = context.file({ id: plugin.name })!; ··· 657 656 operation, 658 657 plugin, 659 658 }: { 660 - context: IRContext; 661 - operation: IROperationObject; 659 + context: IR.Context; 660 + operation: IR.OperationObject; 662 661 plugin: PluginInstance; 663 662 }) => { 664 663 const identifierResponse = context.file({ id: 'types' })!.identifier({ ··· 686 685 plugin, 687 686 typeQueryKey, 688 687 }: { 689 - context: IRContext; 688 + context: IR.Context; 690 689 isInfinite: boolean; 691 - operation: IROperationObject; 690 + operation: IR.OperationObject; 692 691 plugin: PluginInstance; 693 692 typeQueryKey?: string; 694 693 }) => {
+3 -4
packages/openapi-ts/src/plugins/fastify/plugin.ts
··· 1 1 import type ts from 'typescript'; 2 2 3 3 import { compiler, type Property } from '../../compiler'; 4 - import type { IRContext } from '../../ir/context'; 5 - import type { IROperationObject } from '../../ir/ir'; 6 4 import { operationResponsesMap } from '../../ir/operation'; 7 5 import { hasParameterGroupObjectRequired } from '../../ir/parameter'; 6 + import type { IR } from '../../ir/types'; 8 7 import { operationIrRef } from '../shared/utils/ref'; 9 8 import type { Plugin } from '../types'; 10 9 import type { Config } from './types'; ··· 15 14 context, 16 15 operation, 17 16 }: { 18 - context: IRContext; 19 - operation: IROperationObject; 17 + context: IR.Context; 18 + operation: IR.OperationObject; 20 19 }): Property | undefined => { 21 20 const file = context.file({ id: fastifyId })!; 22 21 const fileTypes = context.file({ id: 'types' })!;
+2 -2
packages/openapi-ts/src/plugins/shared/utils/case.ts
··· 1 1 import ts from 'typescript'; 2 2 3 - import type { IRContext } from '../../../ir/context'; 3 + import type { IR } from '../../../ir/types'; 4 4 import { digitsRegExp } from '../../../utils/regexp'; 5 5 import { stringCase } from '../../../utils/stringCase'; 6 6 ··· 12 12 context, 13 13 name, 14 14 }: { 15 - context: IRContext; 15 + context: IR.Context; 16 16 name: string; 17 17 }) => { 18 18 digitsRegExp.lastIndex = 0;
+2 -2
packages/openapi-ts/src/plugins/types.d.ts
··· 1 - import type { IRContext } from '../ir/context'; 1 + import type { IR } from '../ir/types'; 2 2 import type { OpenApi } from '../openApi'; 3 3 import type { Client } from '../types/client'; 4 4 import type { Files } from '../types/utils'; ··· 99 99 * Plugin implementation for experimental parser. 100 100 */ 101 101 export type Handler<Config extends BaseConfig> = (args: { 102 - context: IRContext; 102 + context: IR.Context; 103 103 plugin: Plugin.Instance<Config>; 104 104 }) => void; 105 105
+24 -25
packages/openapi-ts/src/plugins/zod/plugin.ts
··· 1 1 import ts from 'typescript'; 2 2 3 3 import { compiler } from '../../compiler'; 4 - import type { IRContext } from '../../ir/context'; 5 - import type { IROperationObject, IRSchemaObject } from '../../ir/ir'; 6 4 import { operationResponsesMap } from '../../ir/operation'; 7 5 import { deduplicateSchema } from '../../ir/schema'; 6 + import type { IR } from '../../ir/types'; 8 7 import { digitsRegExp } from '../../utils/regexp'; 9 8 import { operationIrRef } from '../shared/utils/ref'; 10 9 import type { Plugin } from '../types'; 11 10 import type { Config } from './types'; 12 11 13 - interface SchemaWithType<T extends Required<IRSchemaObject>['type']> 14 - extends Omit<IRSchemaObject, 'type'> { 15 - type: Extract<Required<IRSchemaObject>['type'], T>; 12 + interface SchemaWithType<T extends Required<IR.SchemaObject>['type']> 13 + extends Omit<IR.SchemaObject, 'type'> { 14 + type: Extract<Required<IR.SchemaObject>['type'], T>; 16 15 } 17 16 18 17 interface Result { ··· 39 38 result, 40 39 schema, 41 40 }: { 42 - context: IRContext; 41 + context: IR.Context; 43 42 result: Result; 44 43 schema: SchemaWithType<'array'>; 45 44 }): ts.CallExpression => { ··· 140 139 const booleanTypeToZodSchema = ({ 141 140 schema, 142 141 }: { 143 - context: IRContext; 142 + context: IR.Context; 144 143 schema: SchemaWithType<'boolean'>; 145 144 }) => { 146 145 if (schema.const !== undefined) { ··· 163 162 context, 164 163 schema, 165 164 }: { 166 - context: IRContext; 165 + context: IR.Context; 167 166 schema: SchemaWithType<'enum'>; 168 167 }): ts.CallExpression => { 169 168 const enumMembers: Array<ts.LiteralExpression> = []; ··· 207 206 const neverTypeToZodSchema = ({ 208 207 schema, 209 208 }: { 210 - context: IRContext; 209 + context: IR.Context; 211 210 schema: SchemaWithType<'never'>; 212 211 }) => { 213 212 const expression = compiler.callExpression({ ··· 222 221 const nullTypeToZodSchema = ({ 223 222 schema, 224 223 }: { 225 - context: IRContext; 224 + context: IR.Context; 226 225 schema: SchemaWithType<'null'>; 227 226 }) => { 228 227 const expression = compiler.callExpression({ ··· 237 236 const numberTypeToZodSchema = ({ 238 237 schema, 239 238 }: { 240 - context: IRContext; 239 + context: IR.Context; 241 240 schema: SchemaWithType<'number'>; 242 241 }) => { 243 242 let numberExpression = compiler.callExpression({ ··· 302 301 result, 303 302 schema, 304 303 }: { 305 - context: IRContext; 304 + context: IR.Context; 306 305 result: Result; 307 306 schema: SchemaWithType<'object'>; 308 307 }) => { ··· 310 309 311 310 // let indexProperty: Property | undefined; 312 311 // const schemaProperties: Array<Property> = []; 313 - // let indexPropertyItems: Array<IRSchemaObject> = []; 312 + // let indexPropertyItems: Array<IR.SchemaObject> = []; 314 313 const required = schema.required ?? []; 315 314 // let hasOptionalProperties = false; 316 315 ··· 432 431 const stringTypeToZodSchema = ({ 433 432 schema, 434 433 }: { 435 - context: IRContext; 434 + context: IR.Context; 436 435 schema: SchemaWithType<'string'>; 437 436 }) => { 438 437 let stringExpression = compiler.callExpression({ ··· 526 525 const undefinedTypeToZodSchema = ({ 527 526 schema, 528 527 }: { 529 - context: IRContext; 528 + context: IR.Context; 530 529 schema: SchemaWithType<'undefined'>; 531 530 }) => { 532 531 const expression = compiler.callExpression({ ··· 541 540 const unknownTypeToZodSchema = ({ 542 541 schema, 543 542 }: { 544 - context: IRContext; 543 + context: IR.Context; 545 544 schema: SchemaWithType<'unknown'>; 546 545 }) => { 547 546 const expression = compiler.callExpression({ ··· 556 555 const voidTypeToZodSchema = ({ 557 556 schema, 558 557 }: { 559 - context: IRContext; 558 + context: IR.Context; 560 559 schema: SchemaWithType<'void'>; 561 560 }) => { 562 561 const expression = compiler.callExpression({ ··· 573 572 result, 574 573 schema, 575 574 }: { 576 - context: IRContext; 575 + context: IR.Context; 577 576 result: Result; 578 - schema: IRSchemaObject; 577 + schema: IR.SchemaObject; 579 578 }): ts.Expression => { 580 - switch (schema.type as Required<IRSchemaObject>['type']) { 579 + switch (schema.type as Required<IR.SchemaObject>['type']) { 581 580 case 'array': 582 581 return arrayTypeToZodSchema({ 583 582 context, ··· 656 655 operation, 657 656 result, 658 657 }: { 659 - context: IRContext; 660 - operation: IROperationObject; 658 + context: IR.Context; 659 + operation: IR.OperationObject; 661 660 result: Result; 662 661 }) => { 663 662 if (operation.responses) { ··· 688 687 * When $ref is supplied, a node will be emitted to the file. 689 688 */ 690 689 $ref?: string; 691 - context: IRContext; 690 + context: IR.Context; 692 691 result: Result; 693 - schema: IRSchemaObject; 692 + schema: IR.SchemaObject; 694 693 }): ts.Expression => { 695 694 const file = context.file({ id: zodId })!; 696 695 ··· 723 722 }); 724 723 725 724 if (!identifierRef.name) { 726 - const ref = context.resolveIrRef<IRSchemaObject>(schema.$ref); 725 + const ref = context.resolveIrRef<IR.SchemaObject>(schema.$ref); 727 726 expression = schemaToZodSchema({ 728 727 context, 729 728 result,
+2 -2
packages/openapi-ts/src/plugins/zod/types.d.ts
··· 1 - // import type { IROperationObject, IRSchemaObject } from '../../ir/ir'; 1 + // import type { IR } from '../../ir/types'; 2 2 import type { Plugin } from '../types'; 3 3 4 4 export interface Config extends Plugin.Name<'zod'> { ··· 6 6 * Customise the Zod schema name. By default, `z{{name}}` is used, 7 7 * where `name` is a definition name or an operation name. 8 8 */ 9 - // nameBuilder?: (model: IROperationObject | IRSchemaObject) => string; 9 + // nameBuilder?: (model: IR.OperationObject | IR.SchemaObject) => string; 10 10 /** 11 11 * Name of the generated file. 12 12 * @default 'zod'