@@ -132,11 +132,11 @@ public string Emit()
132132 if ( valueGroups . Count == 1 )
133133 {
134134 // All inline enums with this name have identical values → single enum
135- string resolvedName = baseName ;
135+ string resolvedName = NameHelper . ApplyTypePrefix ( baseName , _options . ModelPrefix ) ;
136136 if ( usedNames . Contains ( resolvedName ) )
137137 {
138138 // Conflict with a top-level type; differentiate
139- resolvedName = FindUniqueName ( baseName , usedNames ) ;
139+ resolvedName = FindUniqueName ( resolvedName , usedNames ) ;
140140 }
141141 usedNames . Add ( resolvedName ) ;
142142 foreach ( ( string SchemaName , string PropertyName , string EnumTypeName , List < string > Values , IOpenApiSchema Schema ) in valueGroups [ 0 ] )
@@ -314,7 +314,7 @@ private static bool ShouldEmitAsRecord(IOpenApiSchema schema)
314314
315315 private void EmitEnum ( string schemaName , IOpenApiSchema schema , string ? typeNameOverride = null )
316316 {
317- string typeName = typeNameOverride ?? NameHelper . ToTypeName ( schemaName ) ;
317+ string typeName = typeNameOverride ?? NameHelper . ToTypeName ( schemaName , _options . ModelPrefix ) ;
318318
319319 EmitDocComment ( schema . Description ) ;
320320
@@ -391,7 +391,7 @@ private void EmitEnum(string schemaName, IOpenApiSchema schema, string? typeName
391391
392392 private void EmitRecord ( string schemaName , IOpenApiSchema schema , string ? typeNameOverride = null )
393393 {
394- string typeName = typeNameOverride ?? NameHelper . ToTypeName ( schemaName ) ;
394+ string typeName = typeNameOverride ?? NameHelper . ToTypeName ( schemaName , _options . ModelPrefix ) ;
395395
396396 // Collect all properties (including from allOf)
397397 Dictionary < string , IOpenApiSchema > properties = CollectProperties ( schema ) ;
@@ -405,7 +405,7 @@ private void EmitRecord(string schemaName, IOpenApiSchema schema, string? typeNa
405405 OpenApiSchemaReference ? refSchema = schema . AllOf . OfType < OpenApiSchemaReference > ( ) . FirstOrDefault ( ) ;
406406 if ( refSchema ? . Reference ? . Id != null )
407407 {
408- baseType = NameHelper . ToTypeName ( refSchema . Reference . Id ) ;
408+ baseType = NameHelper . ToTypeName ( refSchema . Reference . Id , _options . ModelPrefix ) ;
409409 basePropertyNames = CollectBasePropertyNames ( refSchema ) ;
410410 }
411411 }
@@ -463,7 +463,7 @@ private void EmitProperty(string propertyName, IOpenApiSchema propertySchema, bo
463463 string typeName ;
464464 if ( propertySchema is OpenApiSchemaReference propRef && propRef . Reference . Id is not null )
465465 {
466- string refTypeName = NameHelper . ToTypeName ( propRef . Reference . Id ) ;
466+ string refTypeName = NameHelper . ToTypeName ( propRef . Reference . Id , _options . ModelPrefix ) ;
467467 typeName = isRequired ? refTypeName : refTypeName + "?" ;
468468 }
469469 else if ( TypeResolver . IsEnum ( propertySchema ) && ! _allSchemas . Values . Contains ( propertySchema ) )
@@ -552,19 +552,19 @@ private void EmitProperty(string propertyName, IOpenApiSchema propertySchema, bo
552552 return $ "\" { strVal . Replace ( "\" " , "\\ \" " , StringComparison . Ordinal ) } \" ";
553553 }
554554
555- if ( schema . Format == "date-time" && DateTime . TryParse ( strVal , null , DateTimeStyles . AdjustToUniversal , out DateTime dt ) )
555+ if ( schema . Format == "date-time" && DateTimeOffset . TryParse ( strVal , CultureInfo . InvariantCulture , DateTimeStyles . RoundtripKind , out DateTimeOffset dto ) )
556556 {
557- return $ "DateTime .Parse(\" { dt . ToString ( "o " , CultureInfo . InvariantCulture ) } \" , null , DateTimeStyles.AdjustToUniversal )";
557+ return $ "DateTimeOffset .Parse(\" { dto . ToString ( "O " , CultureInfo . InvariantCulture ) } \" , CultureInfo.InvariantCulture , DateTimeStyles.RoundtripKind )";
558558 }
559559
560- if ( schema . Format == "date" && DateTime . TryParse ( strVal , null , DateTimeStyles . None , out DateTime d ) )
560+ if ( schema . Format == "date" && DateOnly . TryParse ( strVal , CultureInfo . InvariantCulture , DateTimeStyles . None , out DateOnly dateOnly ) )
561561 {
562- return $ "DateTime.Parse (\" { d : yyyy-MM-dd} \" )";
562+ return $ "DateOnly.ParseExact (\" { dateOnly : yyyy-MM-dd} \" , \" yyyy-MM-dd \" , CultureInfo.InvariantCulture )";
563563 }
564564
565- if ( schema . Format == "time" && TimeSpan . TryParse ( strVal , out TimeSpan ts ) )
565+ if ( schema . Format == "time" && TimeOnly . TryParse ( strVal , CultureInfo . InvariantCulture , DateTimeStyles . None , out TimeOnly timeOnly ) )
566566 {
567- return $ "TimeSpan .Parse(\" { ts : c } \" )";
567+ return $ "TimeOnly .Parse(\" { timeOnly . ToString ( "O" , CultureInfo . InvariantCulture ) } \" , CultureInfo.InvariantCulture )";
568568 }
569569
570570 if ( schema . Format == "uuid" && Guid . TryParse ( strVal , out Guid guid ) )
@@ -625,7 +625,7 @@ private bool IsEnumTypeName(string typeName)
625625 // Check top-level schemas for a matching enum
626626 foreach ( ( string ? name , IOpenApiSchema ? schema ) in _allSchemas )
627627 {
628- if ( NameHelper . ToTypeName ( name ) == typeName && TypeResolver . IsEnum ( schema ) )
628+ if ( NameHelper . ToTypeName ( name , _options . ModelPrefix ) == typeName && TypeResolver . IsEnum ( schema ) )
629629 {
630630 return true ;
631631 }
@@ -641,7 +641,7 @@ private bool IsEnumTypeName(string typeName)
641641
642642 private void EmitTypeAlias ( string schemaName , IOpenApiSchema schema , string ? typeNameOverride = null )
643643 {
644- string typeName = typeNameOverride ?? NameHelper . ToTypeName ( schemaName ) ;
644+ string typeName = typeNameOverride ?? NameHelper . ToTypeName ( schemaName , _options . ModelPrefix ) ;
645645 string resolvedType = _typeResolver . ResolveUnderlyingType ( schema ) ;
646646
647647 EmitDocComment ( schema . Description ) ;
@@ -662,7 +662,7 @@ private void EmitTypeAlias(string schemaName, IOpenApiSchema schema, string? typ
662662
663663 private void EmitUnionType ( string schemaName , IOpenApiSchema schema , string ? typeNameOverride = null )
664664 {
665- string typeName = typeNameOverride ?? NameHelper . ToTypeName ( schemaName ) ;
665+ string typeName = typeNameOverride ?? NameHelper . ToTypeName ( schemaName , _options . ModelPrefix ) ;
666666 IList < IOpenApiSchema > variants = schema . OneOf ?? schema . AnyOf ?? [ ] ;
667667
668668 EmitDocComment ( schema . Description ) ;
@@ -690,7 +690,7 @@ private void EmitDiscriminatedUnion(
690690 {
691691 foreach ( ( string ? key , OpenApiSchemaReference ? schemaRef ) in discriminator . Mapping )
692692 {
693- mapping [ key ] = NameHelper . ToTypeName ( schemaRef . Reference . Id ) ;
693+ mapping [ key ] = NameHelper . ToTypeName ( schemaRef . Reference . Id , _options . ModelPrefix ) ;
694694 }
695695 }
696696 else
@@ -707,7 +707,7 @@ private void EmitDiscriminatedUnion(
707707 continue ;
708708 }
709709
710- mapping [ name ] = NameHelper . ToTypeName ( name ) ;
710+ mapping [ name ] = NameHelper . ToTypeName ( name , _options . ModelPrefix ) ;
711711 }
712712 }
713713 }
@@ -728,7 +728,7 @@ private void EmitSimpleUnion(string typeName, IList<IOpenApiSchema> variants)
728728 // Collect the variant type names for documentation
729729 var variantNames = variants
730730 . OfType < OpenApiSchemaReference > ( )
731- . Select ( v => NameHelper . ToTypeName ( v . Reference . Id ) )
731+ . Select ( v => NameHelper . ToTypeName ( v . Reference . Id , _options . ModelPrefix ) )
732732 . ToList ( ) ;
733733
734734 if ( variantNames . Count > 0 )
@@ -743,7 +743,7 @@ private void EmitSimpleUnion(string typeName, IList<IOpenApiSchema> variants)
743743 {
744744 foreach ( OpenApiSchemaReference variant in variants . OfType < OpenApiSchemaReference > ( ) )
745745 {
746- string derivedName = NameHelper . ToTypeName ( variant . Reference . Id ) ;
746+ string derivedName = NameHelper . ToTypeName ( variant . Reference . Id , _options . ModelPrefix ) ;
747747 AppendLine ( $ "[JsonDerivedType(typeof({ derivedName } ), \" { variant . Reference . Id } \" )]") ;
748748 }
749749 }
@@ -761,14 +761,14 @@ private void EmitSimpleUnion(string typeName, IList<IOpenApiSchema> variants)
761761 /// In each collision group, the most "natural" schema name keeps the clean PascalCase
762762 /// type name, and others get meaningfully differentiated names.
763763 /// </summary>
764- private static Dictionary < string , string > ResolveTypeNameCollisions ( IEnumerable < string > schemaNames )
764+ private Dictionary < string , string > ResolveTypeNameCollisions ( IEnumerable < string > schemaNames )
765765 {
766766 var result = new Dictionary < string , string > ( ) ;
767767 var usedNames = new HashSet < string > ( StringComparer . Ordinal ) ;
768768
769769 // Group schema names by their PascalCase type name
770770 var groups = schemaNames
771- . Select ( name => ( Original : name , PascalName : NameHelper . ToTypeName ( name ) ) )
771+ . Select ( name => ( Original : name , PascalName : NameHelper . ToTypeName ( name , prefix : null ) ) )
772772 . GroupBy ( x => x . PascalName )
773773 . ToList ( ) ;
774774
@@ -779,7 +779,7 @@ private static Dictionary<string, string> ResolveTypeNameCollisions(IEnumerable<
779779
780780 if ( members . Count == 1 )
781781 {
782- result [ members [ 0 ] . Original ] = pascalName ;
782+ result [ members [ 0 ] . Original ] = NameHelper . ApplyTypePrefix ( pascalName , _options . ModelPrefix ) ;
783783 usedNames . Add ( pascalName ) ;
784784 continue ;
785785 }
@@ -788,14 +788,14 @@ private static Dictionary<string, string> ResolveTypeNameCollisions(IEnumerable<
788788 var sorted = members . OrderBy ( m => NameHelper . NaturalnessScore ( m . Original , pascalName ) ) . ToList ( ) ;
789789
790790 // Winner gets the clean name
791- result [ sorted [ 0 ] . Original ] = pascalName ;
791+ result [ sorted [ 0 ] . Original ] = NameHelper . ApplyTypePrefix ( pascalName , _options . ModelPrefix ) ;
792792 usedNames . Add ( pascalName ) ;
793793
794794 // Others get differentiated names
795795 for ( int i = 1 ; i < sorted . Count ; i ++ )
796796 {
797797 string differentiated = NameHelper . ToDifferentiatedName ( sorted [ i ] . Original , pascalName , usedNames ) ;
798- result [ sorted [ i ] . Original ] = differentiated ;
798+ result [ sorted [ i ] . Original ] = NameHelper . ApplyTypePrefix ( differentiated , _options . ModelPrefix ) ;
799799 usedNames . Add ( differentiated ) ;
800800 }
801801 }
0 commit comments