Something went wrong. Try again.
fork of hey-api/openapi-ts because I need some additional things
Something went wrong. Try again.
1.7 kB · 58 lines
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859import { refs } from '@hey-api/codegen-core';import type { IR } from '@hey-api/shared';import { createSchemaProcessor, pathToJsonPointer } from '@hey-api/shared';
import { exportAst } from '../shared/export';import type { ProcessorContext, ProcessorResult } from '../shared/processor';import type { PluginState } from '../shared/types';import type { PydanticPlugin } from '../types';import { irSchemaToAst } from './plugin';
export function createProcessor(plugin: PydanticPlugin['Instance']): ProcessorResult { const processor = createSchemaProcessor();
const hooks = [plugin.config['~hooks']?.schemas, plugin.context.config.parser.hooks.schemas];
function extractor(ctx: ProcessorContext): IR.SchemaObject { if (processor.hasEmitted(ctx.path)) { return ctx.schema; }
for (const hook of hooks) { const result = hook?.shouldExtract?.(ctx); if (result) { process({ namingAnchor: processor.context.anchor, tags: processor.context.tags, ...ctx, }); return { $ref: pathToJsonPointer(ctx.path) }; } }
return ctx.schema; }
function process(ctx: ProcessorContext): void { if (!processor.markEmitted(ctx.path)) return;
processor.withContext({ anchor: ctx.namingAnchor, tags: ctx.tags }, () => { const state = refs<PluginState>({ hasLazyExpression: false, path: ctx.path, tags: ctx.tags, });
const ast = irSchemaToAst({ plugin, schema: ctx.schema, schemaExtractor: extractor, state, });
exportAst({ ...ctx, ast, plugin, state }); }); }
return { process };}