@@ -16,7 +16,7 @@ internal class PowerShellFormatter : OpenApiVisitorBase
16
16
{
17
17
private const string DefaultPutPrefix = ".Update" ;
18
18
private const string PowerShellPutPrefix = ".Set" ;
19
- private readonly Stack < OpenApiSchema > _schemaLoop = new ( ) ;
19
+ private readonly Stack < IOpenApiSchema > _schemaLoop = new ( ) ;
20
20
private static readonly Regex s_oDataCastRegex = new ( "(.*(?<=[a-z]))\\ .(As(?=[A-Z]).*)" , RegexOptions . Compiled , TimeSpan . FromSeconds ( 5 ) ) ;
21
21
private static readonly Regex s_hashSuffixRegex = new ( @"^[^-]+" , RegexOptions . Compiled , TimeSpan . FromSeconds ( 5 ) ) ;
22
22
private static readonly Regex s_oDataRefRegex = new ( "(?<=[a-z])Ref(?=[A-Z])" , RegexOptions . Compiled , TimeSpan . FromSeconds ( 5 ) ) ;
@@ -42,7 +42,7 @@ static PowerShellFormatter()
42
42
// 5. Fix anyOf and oneOf schema.
43
43
// 6. Add AdditionalProperties to object schemas.
44
44
45
- public override void Visit ( OpenApiSchema schema )
45
+ public override void Visit ( IOpenApiSchema schema )
46
46
{
47
47
AddAdditionalPropertiesToSchema ( schema ) ;
48
48
ResolveAnyOfSchema ( schema ) ;
@@ -165,22 +165,22 @@ private static void ResolveFunctionParameters(IList<IOpenApiParameter> parameter
165
165
// Replace content with a schema object of type array
166
166
// for structured or collection-valued function parameters
167
167
parameter . Content = null ;
168
- parameter . Schema = new ( )
168
+ parameter . Schema = new OpenApiSchema ( )
169
169
{
170
170
Type = JsonSchemaType . Array ,
171
- Items = new ( )
171
+ Items = new OpenApiSchema ( )
172
172
{
173
173
Type = JsonSchemaType . String
174
174
}
175
175
} ;
176
176
}
177
177
}
178
178
179
- private void AddAdditionalPropertiesToSchema ( OpenApiSchema schema )
179
+ private void AddAdditionalPropertiesToSchema ( IOpenApiSchema schema )
180
180
{
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 ) )
182
182
{
183
- schema . AdditionalProperties = new ( ) { Type = JsonSchemaType . Object } ;
183
+ openApiSchema . AdditionalProperties = new OpenApiSchema ( ) { Type = JsonSchemaType . Object } ;
184
184
185
185
/* Because 'additionalProperties' are now being walked,
186
186
* we need a way to keep track of visited schemas to avoid
@@ -190,39 +190,29 @@ private void AddAdditionalPropertiesToSchema(OpenApiSchema schema)
190
190
}
191
191
}
192
192
193
- private static void ResolveOneOfSchema ( OpenApiSchema schema )
193
+ private static void ResolveOneOfSchema ( IOpenApiSchema schema )
194
194
{
195
- if ( schema . OneOf ? . FirstOrDefault ( ) is { } newSchema )
195
+ if ( schema is OpenApiSchema openApiSchema && schema . OneOf ? . FirstOrDefault ( ) is OpenApiSchema newSchema )
196
196
{
197
- schema . OneOf = null ;
198
- FlattenSchema ( schema , newSchema ) ;
197
+ openApiSchema . OneOf = null ;
198
+ FlattenSchema ( openApiSchema , newSchema ) ;
199
199
}
200
200
}
201
201
202
- private static void ResolveAnyOfSchema ( OpenApiSchema schema )
202
+ private static void ResolveAnyOfSchema ( IOpenApiSchema schema )
203
203
{
204
- if ( schema . AnyOf ? . FirstOrDefault ( ) is { } newSchema )
204
+ if ( schema is OpenApiSchema openApiSchema && schema . AnyOf ? . FirstOrDefault ( ) is OpenApiSchema newSchema )
205
205
{
206
- schema . AnyOf = null ;
207
- FlattenSchema ( schema , newSchema ) ;
206
+ openApiSchema . AnyOf = null ;
207
+ FlattenSchema ( openApiSchema , newSchema ) ;
208
208
}
209
209
}
210
210
211
211
private static void FlattenSchema ( OpenApiSchema schema , OpenApiSchema newSchema )
212
212
{
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 ) ;
226
216
}
227
217
228
218
private static void CopySchema ( OpenApiSchema schema , OpenApiSchema newSchema )
0 commit comments