@@ -5,7 +5,7 @@ import { fileURLToPath } from "node:url";
55import { camelCase , pascalCase , snakeCase , uppercaseFirstLetterOfEach } from "@root/api/writer-generator/utils" ;
66import { Writer , type WriterOptions } from "@root/api/writer-generator/writer.ts" ;
77import { groupByPackages , sortAsDeclarationSequence , type TypeSchemaIndex } from "@root/typeschema/utils" ;
8- import type { EnumDefinition , Field , Identifier , RegularTypeSchema } from "@typeschema/types.ts" ;
8+ import type { EnumDefinition , Field , Identifier , SpecializationTypeSchema } from "@typeschema/types.ts" ;
99
1010const PRIMITIVE_TYPE_MAP : Record < string , string > = {
1111 boolean : "bool" ,
@@ -148,8 +148,8 @@ const resolvePyAssets = (fn: string) => {
148148} ;
149149
150150type TypeSchemaPackageGroups = {
151- groupedResources : Record < string , RegularTypeSchema [ ] > ;
152- groupedComplexTypes : Record < string , RegularTypeSchema [ ] > ;
151+ groupedResources : Record < string , SpecializationTypeSchema [ ] > ;
152+ groupedComplexTypes : Record < string , SpecializationTypeSchema [ ] > ;
153153} ;
154154
155155export class Python extends Writer < PythonGeneratorOptions > {
@@ -191,7 +191,7 @@ export class Python extends Writer<PythonGeneratorOptions> {
191191 this . generateResourcePackages ( groups ) ;
192192 }
193193
194- private generateComplexTypesPackages ( groupedComplexTypes : Record < string , RegularTypeSchema [ ] > ) : void {
194+ private generateComplexTypesPackages ( groupedComplexTypes : Record < string , SpecializationTypeSchema [ ] > ) : void {
195195 for ( const [ packageName , packageComplexTypes ] of Object . entries ( groupedComplexTypes ) ) {
196196 this . cd ( `/${ snakeCase ( packageName ) } ` , ( ) => {
197197 this . generateBasePy ( packageComplexTypes ) ;
@@ -213,8 +213,8 @@ export class Python extends Writer<PythonGeneratorOptions> {
213213
214214 private generateResourcePackageContent (
215215 packageName : string ,
216- packageResources : RegularTypeSchema [ ] ,
217- packageComplexTypes : RegularTypeSchema [ ] ,
216+ packageResources : SpecializationTypeSchema [ ] ,
217+ packageComplexTypes : SpecializationTypeSchema [ ] ,
218218 ) : void {
219219 const pyPackageName = this . pyFhirPackageByName ( packageName ) ;
220220
@@ -255,7 +255,7 @@ export class Python extends Writer<PythonGeneratorOptions> {
255255 }
256256 }
257257
258- private generateBasePy ( packageComplexTypes : RegularTypeSchema [ ] ) : void {
258+ private generateBasePy ( packageComplexTypes : SpecializationTypeSchema [ ] ) : void {
259259 const hasGenericTypes = packageComplexTypes . some ( ( s ) => s . identifier . name in GENERIC_FIELD_REWRITES ) ;
260260 this . cat ( "base.py" , ( ) => {
261261 this . generateDisclaimer ( ) ;
@@ -270,7 +270,7 @@ export class Python extends Writer<PythonGeneratorOptions> {
270270 } ) ;
271271 }
272272
273- private generateComplexTypes ( complexTypes : RegularTypeSchema [ ] ) : void {
273+ private generateComplexTypes ( complexTypes : SpecializationTypeSchema [ ] ) : void {
274274 for ( const schema of sortAsDeclarationSequence ( complexTypes ) ) {
275275 this . generateNestedTypes ( schema ) ;
276276 this . line ( ) ;
@@ -280,8 +280,8 @@ export class Python extends Writer<PythonGeneratorOptions> {
280280
281281 private generateResourcePackageInit (
282282 fullPyPackageName : string ,
283- packageResources : RegularTypeSchema [ ] ,
284- packageComplexTypes ?: RegularTypeSchema [ ] ,
283+ packageResources : SpecializationTypeSchema [ ] ,
284+ packageComplexTypes ?: SpecializationTypeSchema [ ] ,
285285 ) : void {
286286 this . cat ( "__init__.py" , ( ) => {
287287 this . generateDisclaimer ( ) ;
@@ -292,7 +292,7 @@ export class Python extends Writer<PythonGeneratorOptions> {
292292 } ) ;
293293 }
294294
295- private importComplexTypes ( fullPyPackageName : string , packageComplexTypes ?: RegularTypeSchema [ ] ) : string [ ] {
295+ private importComplexTypes ( fullPyPackageName : string , packageComplexTypes ?: SpecializationTypeSchema [ ] ) : string [ ] {
296296 if ( ! packageComplexTypes || packageComplexTypes . length === 0 ) return [ ] ;
297297
298298 const baseTypes = packageComplexTypes . map ( ( t ) => t . identifier . name ) . sort ( ) ;
@@ -323,7 +323,7 @@ export class Python extends Writer<PythonGeneratorOptions> {
323323 private importResources (
324324 fullPyPackageName : string ,
325325 importEmptyResources : boolean ,
326- packageResources ?: RegularTypeSchema [ ] ,
326+ packageResources ?: SpecializationTypeSchema [ ] ,
327327 ) : string [ ] {
328328 if ( ! packageResources || packageResources . length === 0 ) return [ ] ;
329329 const allResourceNames : string [ ] = [ ] ;
@@ -337,7 +337,7 @@ export class Python extends Writer<PythonGeneratorOptions> {
337337 return allResourceNames ;
338338 }
339339
340- private importOneResource ( resource : RegularTypeSchema , fullPyPackageName : string ) : string [ ] {
340+ private importOneResource ( resource : SpecializationTypeSchema , fullPyPackageName : string ) : string [ ] {
341341 const moduleName = `${ fullPyPackageName } .${ snakeCase ( resource . identifier . name ) } ` ;
342342 const importNames = this . collectResourceImportNames ( resource ) ;
343343
@@ -353,7 +353,7 @@ export class Python extends Writer<PythonGeneratorOptions> {
353353 return names ;
354354 }
355355
356- private collectResourceImportNames ( resource : RegularTypeSchema ) : string [ ] {
356+ private collectResourceImportNames ( resource : SpecializationTypeSchema ) : string [ ] {
357357 const names = [ deriveResourceName ( resource . identifier ) ] ;
358358
359359 for ( const nested of resource . nested ?? [ ] ) {
@@ -364,12 +364,12 @@ export class Python extends Writer<PythonGeneratorOptions> {
364364 return names ;
365365 }
366366
367- private shouldImportResourceFamily ( resource : RegularTypeSchema ) : boolean {
367+ private shouldImportResourceFamily ( resource : SpecializationTypeSchema ) : boolean {
368368 return resource . identifier . kind === "resource" && ( resource . typeFamily ?. resources ?. length ?? 0 ) > 0 ;
369369 }
370370
371371 private generateExportsDeclaration (
372- packageComplexTypes : RegularTypeSchema [ ] | undefined ,
372+ packageComplexTypes : SpecializationTypeSchema [ ] | undefined ,
373373 allResourceNames : string [ ] ,
374374 ) : void {
375375 this . squareBlock ( [ "__all__" , "=" ] , ( ) => {
@@ -384,7 +384,7 @@ export class Python extends Writer<PythonGeneratorOptions> {
384384 } ) ;
385385 }
386386
387- private generateResourceModule ( schema : RegularTypeSchema ) : void {
387+ private generateResourceModule ( schema : SpecializationTypeSchema ) : void {
388388 this . cat ( `${ snakeCase ( schema . identifier . name ) } .py` , ( ) => {
389389 this . generateDisclaimer ( ) ;
390390 this . generateDefaultImports ( false ) ;
@@ -403,7 +403,7 @@ export class Python extends Writer<PythonGeneratorOptions> {
403403 this . pyImportFrom ( `${ this . opts . rootPackageName } .fhirpy_base_model` , "FhirpyBaseModel" ) ;
404404 }
405405
406- private generateType ( schema : RegularTypeSchema ) : void {
406+ private generateType ( schema : SpecializationTypeSchema ) : void {
407407 const className = deriveResourceName ( schema . identifier ) ;
408408 const superClasses = this . getSuperClasses ( schema ) ;
409409
@@ -414,15 +414,15 @@ export class Python extends Writer<PythonGeneratorOptions> {
414414 this . line ( ) ;
415415 }
416416
417- private getSuperClasses ( schema : RegularTypeSchema ) : string [ ] {
417+ private getSuperClasses ( schema : SpecializationTypeSchema ) : string [ ] {
418418 const bases : string [ ] = [ ] ;
419419 if ( schema . base ) bases . push ( schema . base . name ) ;
420420 bases . push ( ...this . injectSuperClasses ( schema . identifier . url ) ) ;
421421 if ( schema . identifier . name in GENERIC_FIELD_REWRITES ) bases . push ( "Generic[T]" ) ;
422422 return bases ;
423423 }
424424
425- private generateClassBody ( schema : RegularTypeSchema ) : void {
425+ private generateClassBody ( schema : SpecializationTypeSchema ) : void {
426426 this . generateModelConfig ( ) ;
427427
428428 if ( ! schema . fields ) {
@@ -446,7 +446,7 @@ export class Python extends Writer<PythonGeneratorOptions> {
446446 this . line ( `model_config = ConfigDict(validate_by_name=True, serialize_by_alias=True, extra="${ extraMode } ")` ) ;
447447 }
448448
449- private generateResourceTypeField ( schema : RegularTypeSchema ) : void {
449+ private generateResourceTypeField ( schema : SpecializationTypeSchema ) : void {
450450 const hasChildren = ( schema . typeFamily ?. resources ?. length ?? 0 ) > 0 ;
451451
452452 if ( hasChildren ) {
@@ -467,7 +467,7 @@ export class Python extends Writer<PythonGeneratorOptions> {
467467 this . line ( ")" ) ;
468468 }
469469
470- private generateFields ( schema : RegularTypeSchema , schemaName : string ) : void {
470+ private generateFields ( schema : SpecializationTypeSchema , schemaName : string ) : void {
471471 const sortedFields = Object . entries ( schema . fields ?? [ ] ) . sort ( ( [ a ] , [ b ] ) => a . localeCompare ( b ) ) ;
472472
473473 for ( const [ fieldName , field ] of sortedFields ) {
@@ -544,7 +544,7 @@ export class Python extends Writer<PythonGeneratorOptions> {
544544 return ` = Field(${ aliasSpec } )` ;
545545 }
546546
547- private generateResourceMethods ( schema : RegularTypeSchema ) : void {
547+ private generateResourceMethods ( schema : SpecializationTypeSchema ) : void {
548548 const className = schema . identifier . name . toString ( ) ;
549549
550550 this . line ( ) ;
@@ -556,7 +556,7 @@ export class Python extends Writer<PythonGeneratorOptions> {
556556 this . line ( " return cls.model_validate_json(json)" ) ;
557557 }
558558
559- private generateNestedTypes ( schema : RegularTypeSchema ) : void {
559+ private generateNestedTypes ( schema : SpecializationTypeSchema ) : void {
560560 if ( ! schema . nested ) return ;
561561
562562 this . line ( ) ;
@@ -578,7 +578,7 @@ export class Python extends Writer<PythonGeneratorOptions> {
578578 }
579579 }
580580
581- private generateDependenciesImports ( schema : RegularTypeSchema ) : void {
581+ private generateDependenciesImports ( schema : SpecializationTypeSchema ) : void {
582582 if ( ! schema . dependencies || schema . dependencies . length === 0 ) return ;
583583
584584 this . importComplexTypeDependencies ( schema . dependencies ) ;
@@ -650,7 +650,7 @@ export class Python extends Writer<PythonGeneratorOptions> {
650650 this . pyImportFrom ( this . pyPackage ( identifier ) , pascalCase ( identifier . name ) ) ;
651651 }
652652
653- private generateResourceFamilies ( packageResources : RegularTypeSchema [ ] ) : void {
653+ private generateResourceFamilies ( packageResources : SpecializationTypeSchema [ ] ) : void {
654654 assert ( this . tsIndex !== undefined ) ;
655655 const packages = //this.helper.getPackages(packageResources, this.opts.rootPackageName);
656656 Object . keys ( groupByPackages ( packageResources ) ) . map (
0 commit comments