UNPKG

@codegena/oapi3ts

Version:

Codegeneration from OAS3 to TypeScript

119 lines (118 loc) 5.33 kB
import { HasResponses } from '@codegena/definitions/aspects'; import { Generic as SchemaGeneric, Schema } from '@codegena/definitions/json-schema'; import { Oas3Operation, Oas3Parameter, Oas3Response, Oas3Specification } from '@codegena/definitions/oas3'; import { ConvertorConfig } from './config'; import { ApiMetaInfo, DataTypeContainer, DataTypeDescriptor, DescriptorContext } from './index'; interface OperationMeta { operationJsonPath: string[]; apiMeta: ApiMetaInfo; } /** * Базовый класс загрузчика. */ export declare abstract class BaseConvertor { protected config: ConvertorConfig; protected _structure: Oas3Specification; protected _foreignSchemaFn: (resourcePath: string) => Schema; protected _operationsMeta: OperationMeta[]; constructor(config?: ConvertorConfig); loadOAPI3Structure(structure: Oas3Specification): void; setForeignSchemeFn(fn: (jsonPath: string) => Schema): void; getApiMeta(): OperationMeta[]; /** * Getting of "entry-points" from structure in {@link _structure} early * loaded by {@link loadOAPI3Structure}. * * Entrypoints are: * * - Parameters * - Requests * - Responses * * ### Why it needed? * * Entrypoints is needed to use [Convertor.renderRecursive]{@link Convertor.renderRecursive}. * It's like a pulling on thread where entrypoints are outstanding trheads. * * @param ApiMetaInfo metaInfo * Mutable object where meta-information accumulates during * API-info extracting. */ getOAPI3EntryPoints(context?: {}, metaInfo?: ApiMetaInfo[]): DataTypeContainer; /** * Получить дескриптор типа по JSON Path: * возвращает уже созданный ранее, или создает * новый при первом упоминании. * * @param path * @param context */ findTypeByPath(path: string, context: DescriptorContext): DataTypeContainer; /** * @deprecated will be renamed to `getSchemaByRef` * @param ref * @param pathWhereReferred * @return */ getSchemaByPath(ref: string, pathWhereReferred?: string[]): Schema; /** * Превращение JSON-схемы в описание типа данных. * Возвращает контейнер [дескрипторов типов]{@link DataTypeDescriptor}, * в котором перечисляются типы данных (возможна принадлежность * к более чем одному типу данных: `number[] | InterfaceName`). * * @param schema * Схема, для которой будет подобрано соответствущее * правило, по которому будет определен дескриптор * нового типа данных. * @param context * Контекст, в котором хранятся ранее просчитаные модели * в рамках одной цепочки обработки. * @param name * Собственное имя типа данных * @param suggestedName * Предлагаемое имя для типа данных: может * применяться, если тип данных анонимный, но * необходимо вынести его за пределы родительской * модели по-ситуации (например, в случае с Enum). * @param originalSchemaPath * Путь, по которому была взята схема * @param ancestors * Родительсткие модели * */ abstract convert(schema: Schema | SchemaGeneric, context: DescriptorContext, name?: string, suggestedName?: string, originalSchemaPath?: string, ancestors?: DataTypeDescriptor[]): DataTypeContainer; /** * Извлечени схем из параметров, ответов и тел запросов для API. * @param metaInfo * Place for storing meta-info of API-method. */ getMethodsSchemes(metaInfo: ApiMetaInfo[]): { [className: string]: Schema; }; /** * Get parameters from the `parameters` section * in method into {@link ApiMetaInfo}-object */ protected _pickApiMethodParameters(metaInfoItem: ApiMetaInfo, parameters: Oas3Parameter[], jsonPathToOperation: string[]): { [key: string]: Schema; }; protected _pickApiMethodResponses(metaInfoItem: ApiMetaInfo, responses: HasResponses<Oas3Response>, jsonPathToOperation: string[]): { [key: string]: Schema; }; protected _pickApiMethodRequest(apiOperation: Oas3Operation, metaInfoItem: ApiMetaInfo, jsonPathToOperation: string[]): { [modelName: string]: SchemaGeneric; } | null; /** * Получение нового дескриптора на основе JSON Path * из текущей структуры. * * @param path * @param context */ protected _processSchema(path: string, context: DescriptorContext): DataTypeContainer; protected _getForeignSchema(ref: string): Schema; private _getOperationBaseName; private _getOperationServers; } export {};