@@ -16,7 +16,7 @@ internal class PowerShellFormatter : OpenApiVisitorBase
1616 {
1717 private const string DefaultPutPrefix = ".Update" ;
1818 private const string PowerShellPutPrefix = ".Set" ;
19- private readonly Stack < OpenApiSchema > _schemaLoop = new ( ) ;
19+ private readonly Stack < IOpenApiSchema > _schemaLoop = new ( ) ;
2020 private static readonly Regex s_oDataCastRegex = new ( "(.*(?<=[a-z]))\\ .(As(?=[A-Z]).*)" , RegexOptions . Compiled , TimeSpan . FromSeconds ( 5 ) ) ;
2121 private static readonly Regex s_hashSuffixRegex = new ( @"^[^-]+" , RegexOptions . Compiled , TimeSpan . FromSeconds ( 5 ) ) ;
2222 private static readonly Regex s_oDataRefRegex = new ( "(?<=[a-z])Ref(?=[A-Z])" , RegexOptions . Compiled , TimeSpan . FromSeconds ( 5 ) ) ;
@@ -42,7 +42,7 @@ static PowerShellFormatter()
4242 // 5. Fix anyOf and oneOf schema.
4343 // 6. Add AdditionalProperties to object schemas.
4444
45- public override void Visit ( OpenApiSchema schema )
45+ public override void Visit ( IOpenApiSchema schema )
4646 {
4747 AddAdditionalPropertiesToSchema ( schema ) ;
4848 ResolveAnyOfSchema ( schema ) ;
@@ -165,22 +165,22 @@ private static void ResolveFunctionParameters(IList<IOpenApiParameter> parameter
165165 // Replace content with a schema object of type array
166166 // for structured or collection-valued function parameters
167167 parameter . Content = null ;
168- parameter . Schema = new ( )
168+ parameter . Schema = new OpenApiSchema ( )
169169 {
170170 Type = JsonSchemaType . Array ,
171- Items = new ( )
171+ Items = new OpenApiSchema ( )
172172 {
173173 Type = JsonSchemaType . String
174174 }
175175 } ;
176176 }
177177 }
178178
179- private void AddAdditionalPropertiesToSchema ( OpenApiSchema schema )
179+ private void AddAdditionalPropertiesToSchema ( IOpenApiSchema schema )
180180 {
181- if ( schema != null && ! _schemaLoop . Contains ( schema ) && schema . Type . Equals ( JsonSchemaType . Object ) )
181+ if ( schema is OpenApiSchema openApiSchema && ! _schemaLoop . Contains ( schema ) && schema . Type . Equals ( JsonSchemaType . Object ) )
182182 {
183- schema . AdditionalProperties = new ( ) { Type = JsonSchemaType . Object } ;
183+ openApiSchema . AdditionalProperties = new OpenApiSchema ( ) { Type = JsonSchemaType . Object } ;
184184
185185 /* Because 'additionalProperties' are now being walked,
186186 * we need a way to keep track of visited schemas to avoid
@@ -190,39 +190,29 @@ private void AddAdditionalPropertiesToSchema(OpenApiSchema schema)
190190 }
191191 }
192192
193- private static void ResolveOneOfSchema ( OpenApiSchema schema )
193+ private static void ResolveOneOfSchema ( IOpenApiSchema schema )
194194 {
195- if ( schema . OneOf ? . FirstOrDefault ( ) is { } newSchema )
195+ if ( schema is OpenApiSchema openApiSchema && schema . OneOf ? . FirstOrDefault ( ) is OpenApiSchema newSchema )
196196 {
197- schema . OneOf = null ;
198- FlattenSchema ( schema , newSchema ) ;
197+ openApiSchema . OneOf = null ;
198+ FlattenSchema ( openApiSchema , newSchema ) ;
199199 }
200200 }
201201
202- private static void ResolveAnyOfSchema ( OpenApiSchema schema )
202+ private static void ResolveAnyOfSchema ( IOpenApiSchema schema )
203203 {
204- if ( schema . AnyOf ? . FirstOrDefault ( ) is { } newSchema )
204+ if ( schema is OpenApiSchema openApiSchema && schema . AnyOf ? . FirstOrDefault ( ) is OpenApiSchema newSchema )
205205 {
206- schema . AnyOf = null ;
207- FlattenSchema ( schema , newSchema ) ;
206+ openApiSchema . AnyOf = null ;
207+ FlattenSchema ( openApiSchema , newSchema ) ;
208208 }
209209 }
210210
211211 private static void FlattenSchema ( OpenApiSchema schema , OpenApiSchema newSchema )
212212 {
213- if ( newSchema != null )
214- {
215- if ( newSchema . Reference != null )
216- {
217- schema . Reference = newSchema . Reference ;
218- schema . UnresolvedReference = true ;
219- }
220- else
221- {
222- // Copies schema properties based on https://github.com/microsoft/OpenAPI.NET.OData/pull/264.
223- CopySchema ( schema , newSchema ) ;
224- }
225- }
213+ if ( newSchema is null ) return ;
214+ // Copies schema properties based on https://github.com/microsoft/OpenAPI.NET.OData/pull/264.
215+ CopySchema ( schema , newSchema ) ;
226216 }
227217
228218 private static void CopySchema ( OpenApiSchema schema , OpenApiSchema newSchema )
0 commit comments