fork of hey-api/openapi-ts because I need some additional things
at feat/skip-token 63 lines 2.0 kB view raw
1// import { fromRef, ref } from '@hey-api/codegen-core'; 2import type { SchemaWithType } from '@hey-api/shared'; 3 4import { $ } from '../../../../py-dsl'; 5import type { Ast, IrSchemaToAstOptions } from '../../shared/types'; 6// import { irSchemaToAst } from '../plugin'; 7 8export function objectToAst({ 9 plugin, 10 // schema, 11 // state, 12}: IrSchemaToAstOptions & { 13 schema: SchemaWithType<'object'>; 14}): Ast { 15 const symbolBaseModel = plugin.external('pydantic.BaseModel'); 16 // const fieldSymbol = plugin.external('pydantic.Field'); 17 const symbolTemp = plugin.symbol('temp'); 18 19 const classDef = $.class(symbolTemp).extends(symbolBaseModel); 20 console.log(classDef); 21 22 // if (schema.properties) { 23 // for (const name in schema.properties) { 24 // const property = schema.properties[name]!; 25 // const isOptional = !schema.required?.includes(name); 26 27 // const propertyAst = irSchemaToAst({ 28 // optional: isOptional, 29 // plugin, 30 // schema: property, 31 // state: { 32 // ...state, 33 // path: ref([...fromRef(state.path), 'properties', name]), 34 // }, 35 // }); 36 37 // let typeAnnotation = propertyAst.typeAnnotation; 38 39 // if (isOptional && !typeAnnotation.startsWith('Optional[')) { 40 // typeAnnotation = `Optional[${typeAnnotation}]`; 41 // } 42 43 // if (propertyAst.fieldConstraints && Object.keys(propertyAst.fieldConstraints).length > 0) { 44 // const constraints = Object.entries(propertyAst.fieldConstraints) 45 // .map(([key, value]) => `${key}=${JSON.stringify(value)}`) 46 // .join(', '); 47 // classDef.do($.expr(`${name}: ${typeAnnotation} = Field(${constraints})`)); 48 // } else { 49 // classDef.do($.expr(`${name}: ${typeAnnotation}`)); 50 // } 51 // } 52 // } 53 54 return { 55 // expression: classDef, 56 fieldConstraints: {}, 57 hasLazyExpression: false, 58 models: [], 59 // pipes: [], 60 typeAnnotation: 'DynamicModel', 61 typeName: 'DynamicModel', 62 }; 63}