Skip to content

Commit b1942fc

Browse files
committed
feat; passes document to the remaining parameter references methods
Signed-off-by: Vincent Biret <[email protected]>
1 parent 2758496 commit b1942fc

8 files changed

+58
-43
lines changed

src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiParameterGenerator.cs

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ public static OpenApiParameter CreateTop(this ODataContext context, IEdmVocabula
377377
/// </summary>
378378
/// <param name="context">The OData context.</param>
379379
/// <param name="targetPath">The string representation of the Edm target path.</param>
380-
/// <param name="document">The Open API document.</param>
380+
/// <param name="document">The Open API document to use to build references.</param>
381381
/// <returns></returns>
382382
public static OpenApiParameter CreateTop(this ODataContext context, string targetPath, OpenApiDocument document)
383383
{
@@ -397,16 +397,18 @@ public static OpenApiParameter CreateTop(this ODataContext context, string targe
397397
/// </summary>
398398
/// <param name="context">The OData context.</param>
399399
/// <param name="target">The Edm annotation target.</param>
400+
/// <param name="document">The Open API document to use to build references.</param>
400401
/// <returns>The created <see cref="OpenApiParameter"/> or null.</returns>
401-
public static OpenApiParameter CreateSkip(this ODataContext context, IEdmVocabularyAnnotatable target)
402+
public static OpenApiParameter CreateSkip(this ODataContext context, IEdmVocabularyAnnotatable target, OpenApiDocument document)
402403
{
403404
Utils.CheckArgumentNull(context, nameof(context));
404405
Utils.CheckArgumentNull(target, nameof(target));
406+
Utils.CheckArgumentNull(document, nameof(document));
405407

406408
bool? skip = context.Model.GetBoolean(target, CapabilitiesConstants.SkipSupported);
407409
if (skip == null || skip.Value)
408410
{
409-
return new OpenApiParameterReference("skip", null);
411+
return new OpenApiParameterReference("skip", document);
410412
}
411413

412414
return null;
@@ -417,34 +419,38 @@ public static OpenApiParameter CreateSkip(this ODataContext context, IEdmVocabul
417419
/// </summary>
418420
/// <param name="context">The OData context.</param>
419421
/// <param name="targetPath">The string representation of the Edm target path.</param>
422+
/// <param name="document">The Open API document to use to build references.</param>
420423
/// <returns></returns>
421-
public static OpenApiParameter CreateSkip(this ODataContext context, string targetPath)
424+
public static OpenApiParameter CreateSkip(this ODataContext context, string targetPath, OpenApiDocument document)
422425
{
423426
Utils.CheckArgumentNull(context, nameof(context));
424427
Utils.CheckArgumentNull(targetPath, nameof(targetPath));
428+
Utils.CheckArgumentNull(document, nameof(document));
425429

426430
IEdmTargetPath target = context.Model.GetTargetPath(targetPath);
427431
if (target == null)
428432
return null;
429433

430-
return context.CreateSkip(target);
434+
return context.CreateSkip(target, document);
431435
}
432436

433437
/// <summary>
434438
/// Create the $search parameter.
435439
/// </summary>
436440
/// <param name="context">The OData context.</param>
437441
/// <param name="target">The Edm annotation target.</param>
442+
/// <param name="document">The Open API document to use to build references.</param>
438443
/// <returns>The created <see cref="OpenApiParameter"/> or null.</returns>
439-
public static OpenApiParameter CreateSearch(this ODataContext context, IEdmVocabularyAnnotatable target)
444+
public static OpenApiParameter CreateSearch(this ODataContext context, IEdmVocabularyAnnotatable target, OpenApiDocument document)
440445
{
441446
Utils.CheckArgumentNull(context, nameof(context));
442447
Utils.CheckArgumentNull(target, nameof(target));
448+
Utils.CheckArgumentNull(document, nameof(document));
443449

444450
SearchRestrictionsType search = context.Model.GetRecord<SearchRestrictionsType>(target, CapabilitiesConstants.SearchRestrictions);
445451
if (search == null || search.IsSearchable)
446452
{
447-
return new OpenApiParameterReference("search", null);
453+
return new OpenApiParameterReference("search", document);
448454
}
449455

450456
return null;
@@ -454,34 +460,38 @@ public static OpenApiParameter CreateSearch(this ODataContext context, IEdmVocab
454460
/// </summary>
455461
/// <param name="context">The OData context.</param>
456462
/// <param name="targetPath">The string representation of the Edm target path.</param>
463+
/// <param name="document">The Open API document to use to build references.</param>
457464
/// <returns></returns>
458-
public static OpenApiParameter CreateSearch(this ODataContext context, string targetPath)
465+
public static OpenApiParameter CreateSearch(this ODataContext context, string targetPath, OpenApiDocument document)
459466
{
460467
Utils.CheckArgumentNull(context, nameof(context));
461468
Utils.CheckArgumentNull(targetPath, nameof(targetPath));
469+
Utils.CheckArgumentNull(document, nameof(document));
462470

463471
IEdmTargetPath target = context.Model.GetTargetPath(targetPath);
464472
if (target == null)
465473
return null;
466474

467-
return context.CreateSearch(target);
475+
return context.CreateSearch(target, document);
468476
}
469477

470478
/// <summary>
471479
/// Create the $count parameter.
472480
/// </summary>
473481
/// <param name="context">The OData context.</param>
474482
/// <param name="target">The Edm annotation target.</param>
483+
/// <param name="document">The Open API document to use to build references.</param>
475484
/// <returns>The created <see cref="OpenApiParameter"/> or null.</returns>
476-
public static OpenApiParameter CreateCount(this ODataContext context, IEdmVocabularyAnnotatable target)
485+
public static OpenApiParameter CreateCount(this ODataContext context, IEdmVocabularyAnnotatable target, OpenApiDocument document)
477486
{
478487
Utils.CheckArgumentNull(context, nameof(context));
479488
Utils.CheckArgumentNull(target, nameof(target));
489+
Utils.CheckArgumentNull(document, nameof(document));
480490

481491
CountRestrictionsType count = context.Model.GetRecord<CountRestrictionsType>(target, CapabilitiesConstants.CountRestrictions);
482492
if (count == null || count.IsCountable)
483493
{
484-
return new OpenApiParameterReference("count", null);
494+
return new OpenApiParameterReference("count", document);
485495
}
486496

487497
return null;
@@ -492,34 +502,38 @@ public static OpenApiParameter CreateCount(this ODataContext context, IEdmVocabu
492502
/// </summary>
493503
/// <param name="context">The OData context.</param>
494504
/// <param name="targetPath">The string representation of the Edm target path.</param>
505+
/// <param name="document">The Open API document to use to build references.</param>
495506
/// <returns></returns>
496-
public static OpenApiParameter CreateCount(this ODataContext context, string targetPath)
507+
public static OpenApiParameter CreateCount(this ODataContext context, string targetPath, OpenApiDocument document)
497508
{
498509
Utils.CheckArgumentNull(context, nameof(context));
499510
Utils.CheckArgumentNull(targetPath, nameof(targetPath));
511+
Utils.CheckArgumentNull(document, nameof(document));
500512

501513
IEdmTargetPath target = context.Model.GetTargetPath(targetPath);
502514
if (target == null)
503515
return null;
504516

505-
return context.CreateCount(target);
517+
return context.CreateCount(target, document);
506518
}
507519

508520
/// <summary>
509521
/// Create the $filter parameter.
510522
/// </summary>
511523
/// <param name="context">The OData context.</param>
512524
/// <param name="target">The Edm annotation target.</param>
525+
/// <param name="document">The Open API document to use to build references.</param>
513526
/// <returns>The created <see cref="OpenApiParameter"/> or null.</returns>
514-
public static OpenApiParameter CreateFilter(this ODataContext context, IEdmVocabularyAnnotatable target)
527+
public static OpenApiParameter CreateFilter(this ODataContext context, IEdmVocabularyAnnotatable target, OpenApiDocument document)
515528
{
516529
Utils.CheckArgumentNull(context, nameof(context));
517530
Utils.CheckArgumentNull(target, nameof(target));
531+
Utils.CheckArgumentNull(document, nameof(document));
518532

519533
FilterRestrictionsType filter = context.Model.GetRecord<FilterRestrictionsType>(target, CapabilitiesConstants.FilterRestrictions);
520534
if (filter == null || filter.IsFilterable)
521535
{
522-
return new OpenApiParameterReference("filter", null);
536+
return new OpenApiParameterReference("filter", document);
523537
}
524538

525539
return null;
@@ -530,8 +544,9 @@ public static OpenApiParameter CreateFilter(this ODataContext context, IEdmVocab
530544
/// </summary>
531545
/// <param name="context">The OData context.</param>
532546
/// <param name="targetPath">The string representation of the Edm target path.</param>
547+
/// <param name="document">The Open API document to use to build references.</param>
533548
/// <returns></returns>
534-
public static OpenApiParameter CreateFilter(this ODataContext context, string targetPath)
549+
public static OpenApiParameter CreateFilter(this ODataContext context, string targetPath, OpenApiDocument document)
535550
{
536551
Utils.CheckArgumentNull(context, nameof(context));
537552
Utils.CheckArgumentNull(targetPath, nameof(targetPath));
@@ -540,7 +555,7 @@ public static OpenApiParameter CreateFilter(this ODataContext context, string ta
540555
if (target == null)
541556
return null;
542557

543-
return context.CreateFilter(target);
558+
return context.CreateFilter(target, document);
544559
}
545560

546561
public static OpenApiParameter CreateOrderBy(this ODataContext context, string targetPath, IEdmEntityType entityType)

src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyGetOperationHandler.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,28 +78,28 @@ protected override void SetParameters(OpenApiOperation operation)
7878
}
7979

8080
// $skip
81-
parameter = Context.CreateSkip(TargetPath) ?? Context.CreateSkip(ComplexPropertySegment.Property);
81+
parameter = Context.CreateSkip(TargetPath, _document) ?? Context.CreateSkip(ComplexPropertySegment.Property, _document);
8282
if (parameter != null)
8383
{
8484
operation.Parameters.Add(parameter);
8585
}
8686

8787
// $search
88-
parameter = Context.CreateSearch(TargetPath) ?? Context.CreateSearch(ComplexPropertySegment.Property);
88+
parameter = Context.CreateSearch(TargetPath, _document) ?? Context.CreateSearch(ComplexPropertySegment.Property, _document);
8989
if (parameter != null)
9090
{
9191
operation.Parameters.Add(parameter);
9292
}
9393

9494
// $filter
95-
parameter = Context.CreateFilter(TargetPath) ?? Context.CreateFilter(ComplexPropertySegment.Property);
95+
parameter = Context.CreateFilter(TargetPath, _document) ?? Context.CreateFilter(ComplexPropertySegment.Property, _document);
9696
if (parameter != null)
9797
{
9898
operation.Parameters.Add(parameter);
9999
}
100100

101101
// $count
102-
parameter = Context.CreateCount(TargetPath) ?? Context.CreateCount(ComplexPropertySegment.Property);
102+
parameter = Context.CreateCount(TargetPath, _document) ?? Context.CreateCount(ComplexPropertySegment.Property, _document);
103103
if (parameter != null)
104104
{
105105
operation.Parameters.Add(parameter);

src/Microsoft.OpenApi.OData.Reader/Operation/DollarCountGetOperationHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,13 @@ protected override void SetParameters(OpenApiOperation operation)
182182

183183
OpenApiParameter parameter;
184184

185-
parameter = Context.CreateSearch(TargetPath) ?? Context.CreateSearch(annotatable);
185+
parameter = Context.CreateSearch(TargetPath, _document) ?? Context.CreateSearch(annotatable, _document);
186186
if (parameter != null)
187187
{
188188
operation.Parameters.Add(parameter);
189189
}
190190

191-
parameter = Context.CreateFilter(TargetPath) ?? Context.CreateFilter(annotatable);
191+
parameter = Context.CreateFilter(TargetPath, _document) ?? Context.CreateFilter(annotatable, _document);
192192
if (parameter != null)
193193
{
194194
operation.Parameters.Add(parameter);

src/Microsoft.OpenApi.OData.Reader/Operation/EdmOperationOperationHandler.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,25 +248,25 @@ private void AppendSystemQueryOptions(IEdmFunction function, OpenApiOperation op
248248
}
249249

250250
// $skip
251-
if (Context.CreateSkip(function) is OpenApiParameter skipParameter)
251+
if (Context.CreateSkip(function, _document) is OpenApiParameter skipParameter)
252252
{
253253
operation.Parameters.AppendParameter(skipParameter);
254254
}
255255

256256
// $search
257-
if (Context.CreateSearch(function) is OpenApiParameter searchParameter)
257+
if (Context.CreateSearch(function, _document) is OpenApiParameter searchParameter)
258258
{
259259
operation.Parameters.AppendParameter(searchParameter);
260260
}
261261

262262
// $filter
263-
if (Context.CreateFilter(function) is OpenApiParameter filterParameter)
263+
if (Context.CreateFilter(function, _document) is OpenApiParameter filterParameter)
264264
{
265265
operation.Parameters.AppendParameter(filterParameter);
266266
}
267267

268268
// $count
269-
if (Context.CreateCount(function) is OpenApiParameter countParameter)
269+
if (Context.CreateCount(function, _document) is OpenApiParameter countParameter)
270270
{
271271
operation.Parameters.AppendParameter(countParameter);
272272
}

src/Microsoft.OpenApi.OData.Reader/Operation/EntitySetGetOperationHandler.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,28 +95,28 @@ protected override void SetParameters(OpenApiOperation operation)
9595
}
9696

9797
// $skip
98-
parameter = Context.CreateSkip(TargetPath) ?? Context.CreateSkip(EntitySet);
98+
parameter = Context.CreateSkip(TargetPath, _document) ?? Context.CreateSkip(EntitySet, _document);
9999
if (parameter != null)
100100
{
101101
operation.Parameters.Add(parameter);
102102
}
103103

104104
// $search
105-
parameter = Context.CreateSearch(TargetPath) ?? Context.CreateSearch(EntitySet);
105+
parameter = Context.CreateSearch(TargetPath, _document) ?? Context.CreateSearch(EntitySet, _document);
106106
if (parameter != null)
107107
{
108108
operation.Parameters.Add(parameter);
109109
}
110110

111111
// $filter
112-
parameter = Context.CreateFilter(TargetPath) ?? Context.CreateFilter(EntitySet);
112+
parameter = Context.CreateFilter(TargetPath, _document) ?? Context.CreateFilter(EntitySet, _document);
113113
if (parameter != null)
114114
{
115115
operation.Parameters.Add(parameter);
116116
}
117117

118118
// $count
119-
parameter = Context.CreateCount(TargetPath) ?? Context.CreateCount(EntitySet);
119+
parameter = Context.CreateCount(TargetPath, _document) ?? Context.CreateCount(EntitySet, _document);
120120
if (parameter != null)
121121
{
122122
operation.Parameters.Add(parameter);

src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyGetOperationHandler.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,25 +174,25 @@ protected override void SetParameters(OpenApiOperation operation)
174174
operation.Parameters.Add(parameter);
175175
}
176176

177-
parameter = Context.CreateSkip(TargetPath) ?? Context.CreateSkip(NavigationProperty);
177+
parameter = Context.CreateSkip(TargetPath, _document) ?? Context.CreateSkip(NavigationProperty, _document);
178178
if (parameter != null)
179179
{
180180
operation.Parameters.Add(parameter);
181181
}
182182

183-
parameter = Context.CreateSearch(TargetPath) ?? Context.CreateSearch(NavigationProperty);
183+
parameter = Context.CreateSearch(TargetPath, _document) ?? Context.CreateSearch(NavigationProperty, _document);
184184
if (parameter != null)
185185
{
186186
operation.Parameters.Add(parameter);
187187
}
188188

189-
parameter = Context.CreateFilter(TargetPath) ?? Context.CreateFilter(NavigationProperty);
189+
parameter = Context.CreateFilter(TargetPath, _document) ?? Context.CreateFilter(NavigationProperty, _document);
190190
if (parameter != null)
191191
{
192192
operation.Parameters.Add(parameter);
193193
}
194194

195-
parameter = Context.CreateCount(TargetPath) ?? Context.CreateCount(NavigationProperty);
195+
parameter = Context.CreateCount(TargetPath, _document) ?? Context.CreateCount(NavigationProperty, _document);
196196
if (parameter != null)
197197
{
198198
operation.Parameters.Add(parameter);

src/Microsoft.OpenApi.OData.Reader/Operation/ODataTypeCastGetOperationHandler.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,10 @@ private IEnumerable<OpenApiParameter> GetParametersForAnnotableOfMany(IEdmVocabu
346346
// So, how about for the navigation property.
347347
return [
348348
Context.CreateTop(annotable, _document),
349-
Context.CreateSkip(annotable),
350-
Context.CreateSearch(annotable),
351-
Context.CreateFilter(annotable),
352-
Context.CreateCount(annotable),
349+
Context.CreateSkip(annotable, _document),
350+
Context.CreateSearch(annotable, _document),
351+
Context.CreateFilter(annotable, _document),
352+
Context.CreateCount(annotable, _document),
353353
];
354354
}
355355

src/Microsoft.OpenApi.OData.Reader/Operation/RefGetOperationHandler.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,25 +155,25 @@ protected override void SetParameters(OpenApiOperation operation)
155155
operation.Parameters.Add(parameter);
156156
}
157157

158-
parameter = Context.CreateSkip(TargetPath) ?? Context.CreateSkip(NavigationProperty);
158+
parameter = Context.CreateSkip(TargetPath, _document) ?? Context.CreateSkip(NavigationProperty, _document);
159159
if (parameter != null)
160160
{
161161
operation.Parameters.Add(parameter);
162162
}
163163

164-
parameter = Context.CreateSearch(TargetPath) ?? Context.CreateSearch(NavigationProperty);
164+
parameter = Context.CreateSearch(TargetPath, _document) ?? Context.CreateSearch(NavigationProperty, _document);
165165
if (parameter != null)
166166
{
167167
operation.Parameters.Add(parameter);
168168
}
169169

170-
parameter = Context.CreateFilter(TargetPath) ?? Context.CreateFilter(NavigationProperty);
170+
parameter = Context.CreateFilter(TargetPath, _document) ?? Context.CreateFilter(NavigationProperty, _document);
171171
if (parameter != null)
172172
{
173173
operation.Parameters.Add(parameter);
174174
}
175175

176-
parameter = Context.CreateCount(TargetPath) ?? Context.CreateCount(NavigationProperty);
176+
parameter = Context.CreateCount(TargetPath, _document) ?? Context.CreateCount(NavigationProperty, _document);
177177
if (parameter != null)
178178
{
179179
operation.Parameters.Add(parameter);

0 commit comments

Comments
 (0)