import ts from "typescript" ; import type { OpenApi } from "../../../types" ; import { Factory } from "../../TsGenerator" ; import * as ConverterContext from "../ConverterContext" ; import * as Guard from "../Guard" ; import * as ToTypeNode from "../toTypeNode" ; import * as Reference from "./Reference" ; export const generateTypeNode = ( entryPoint , currentPoint , factory , name , header , context , converterContext ) : ts . TypeAliasDeclaration => { return factory . TypeAliasDeclaration . create ( { export : true , name : converterContext . escapeDeclarationText ( name ) , type : ToTypeNode . convert ( entryPoint , currentPoint , factory , header . schema || { type : "null" } , context , converterContext ) , } ) ; } ; export const generatePropertySignature = ( entryPoint , currentPoint , factory , name , header , context , converterContext ) : ts . PropertySignature => { if ( Guard . isReference ( header ) ) { const reference = Reference . generate < OpenApi . Header > ( entryPoint , currentPoint , header ) ; if ( reference . type === "local" ) { context . setReferenceHandler ( currentPoint , reference ) ; return factory . PropertySignature . create ( { name : converterContext . escapePropertySignatureName ( name ) , optional : false , type : factory . TypeReferenceNode . create ( { name : context . resolveReferencePath ( currentPoint , reference . path ) . name , } ) , } ) ; } return factory . PropertySignature . create ( { name : converterContext . escapePropertySignatureName ( name ) , optional : false , type : factory . TypeReferenceNode . create ( { name : context . resolveReferencePath ( currentPoint , reference . path ) . name , } ) , } ) ; } return factory . PropertySignature . create ( { name : converterContext . escapePropertySignatureName ( name ) , optional : false , type : ToTypeNode . convert ( entryPoint , currentPoint , factory , header . schema || { type : "null" } , context , converterContext ) , } ) ; } ; export const generatePropertySignatures = ( entryPoint , currentPoint , factory , headers , context , converterContext ) : ts . PropertySignature [ ] => { return Object . entries ( headers ) . map ( ( [ headerName , header ] ) => { return generatePropertySignature ( entryPoint , currentPoint , factory , headerName , header , context , converterContext ) ; } ) ; } ; export const generateInterface = ( entryPoint , currentPoint , factory , name , headers , context , converterContext ) : ts . InterfaceDeclaration => { return factory . InterfaceDeclaration . create ( { export : true , name : converterContext . escapeDeclarationText ( name ) , members : generatePropertySignatures ( entryPoint , currentPoint , factory , headers , context , converterContext ) , } ) ; } ;