11using AutoSDK . Extensions ;
2+ using AutoSDK . Naming . Properties ;
23
34namespace AutoSDK . Models ;
45
@@ -37,7 +38,6 @@ public readonly record struct PropertyData(
3738 public static PropertyData FromSchemaContext ( SchemaContext context )
3839 {
3940 context = context ?? throw new ArgumentNullException ( nameof ( context ) ) ;
40- var propertyName = context . PropertyName ?? throw new InvalidOperationException ( "Property name or parameter name is required." ) ;
4141 var type = context . TypeData ;
4242
4343 // OpenAPI doesn't allow metadata for references so sometimes allOf with single item is used to add metadata.
@@ -50,21 +50,11 @@ public static PropertyData FromSchemaContext(SchemaContext context)
5050 } ;
5151 }
5252
53- var name = propertyName . ToPropertyName ( ) ;
54-
55- name = HandleWordSeparators ( name ) ;
56-
57- if ( context . Parent != null )
58- {
59- name = name . FixPropertyName ( context . Parent . Id ) ;
60- }
61-
62- name = SanitizeName ( name , context . Settings . ClsCompliantEnumPrefix , true ) ;
63-
6453 var requiredProperties = context . Parent != null
6554 ? new HashSet < string > ( context . Parent . Schema . Required )
6655 : [ ] ;
6756
57+ var propertyName = context . PropertyName ?? throw new InvalidOperationException ( "Property name or parameter name is required." ) ;
6858 var isRequired =
6959 requiredProperties . Contains ( propertyName ) &&
7060 context . Schema is { WriteOnly : false } ;
@@ -76,7 +66,7 @@ public static PropertyData FromSchemaContext(SchemaContext context)
7666
7767 return new PropertyData (
7868 Id : propertyName ,
79- Name : name ,
69+ Name : CSharpPropertyNameGenerator . ComputePropertyName ( context ) ,
8070 Type : type with
8171 {
8272 CSharpTypeNullability = type . CSharpTypeNullability || context . Schema is { WriteOnly : true } ,
@@ -99,70 +89,6 @@ public static PropertyData FromSchemaContext(SchemaContext context)
9989 DiscriminatorValue : string . Empty ) ;
10090 }
10191
102- internal static string SanitizeName ( string ? name , string clsCompliantEnumPrefix , bool skipHandlingWordSeparators = false )
103- {
104- static bool InvalidFirstChar ( char ch )
105- => ch is not ( '_' or >= 'A' and <= 'Z' or >= 'a' and <= 'z' ) ;
106-
107- static bool InvalidSubsequentChar ( char ch )
108- => ch is not (
109- '_'
110- or >= 'A' and <= 'Z'
111- or >= 'a' and <= 'z'
112- or >= '0' and <= '9'
113- ) ;
114-
115- if ( name is null || name . Length == 0 )
116- {
117- return "" ;
118- }
119-
120- if ( ! skipHandlingWordSeparators )
121- {
122- name = HandleWordSeparators ( name ) ;
123- }
124-
125- if ( name . Length == 0 )
126- {
127- return string . IsNullOrWhiteSpace ( clsCompliantEnumPrefix )
128- ? "_"
129- : clsCompliantEnumPrefix ;
130- }
131-
132- if ( InvalidFirstChar ( name [ 0 ] ) )
133- {
134- name = ( string . IsNullOrWhiteSpace ( clsCompliantEnumPrefix )
135- ? "_"
136- : clsCompliantEnumPrefix ) + name ;
137- }
138-
139- if ( ! name . Skip ( 1 ) . Any ( InvalidSubsequentChar ) )
140- {
141- return name ;
142- }
143-
144- Span < char > buf = stackalloc char [ name . Length ] ;
145- name . AsSpan ( ) . CopyTo ( buf ) ;
146-
147- for ( var i = 1 ; i < buf . Length ; i ++ )
148- {
149- if ( InvalidSubsequentChar ( buf [ i ] ) )
150- {
151- buf [ i ] = '_' ;
152- }
153- }
154-
155- // Span<char>.ToString implementation checks for char type, new string(&buf[0], buf.length)
156- return buf . ToString ( ) ;
157- }
158-
159- internal static string HandleWordSeparators ( string name )
160- {
161- return name
162- . ReplacePlusAndMinusOnStart ( )
163- . UseWordSeparator ( '_' , '+' , '-' , '.' , '/' , '(' , '[' , ']' , ')' ) ;
164- }
165-
16692 public string ParameterName => Name
16793 . Replace ( "." , string . Empty )
16894 . ToParameterName ( )
0 commit comments