fork of hey-api/openapi-ts because I need some additional things
at feat/skip-token 32 lines 914 B view raw
1import type { AnalysisContext, Node } from '@hey-api/codegen-core'; 2 3import type { py } from '../../ts-python'; 4import type { DocFn, DocLines } from '../layout/doc'; 5import { DocPyDsl } from '../layout/doc'; 6import type { BaseCtor, MixinCtor } from './types'; 7 8export interface DocMethods extends Node { 9 $docs(): string | undefined; 10 doc(lines?: DocLines, fn?: DocFn): this; 11} 12 13export function DocMixin<T extends py.Node, TBase extends BaseCtor<T>>(Base: TBase) { 14 abstract class Doc extends Base { 15 private _doc?: DocPyDsl; 16 17 override analyze(ctx: AnalysisContext): void { 18 super.analyze(ctx); 19 } 20 21 protected doc(lines?: DocLines, fn?: DocFn): this { 22 this._doc = new DocPyDsl(lines, fn); 23 return this; 24 } 25 26 protected $docs(): string | undefined { 27 return this._doc ? this._doc.resolve() : undefined; 28 } 29 } 30 31 return Doc as unknown as MixinCtor<TBase, DocMethods>; 32}