-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathEntitySetOperationHandler.cs
More file actions
88 lines (75 loc) · 3.1 KB
/
EntitySetOperationHandler.cs
File metadata and controls
88 lines (75 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using Microsoft.OData.Edm;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Models.References;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
using Microsoft.OpenApi.OData.Vocabulary.Core;
using System.Collections.Generic;
namespace Microsoft.OpenApi.OData.Operation
{
/// <summary>
/// Base class for entity set operation.
/// </summary>
internal abstract class EntitySetOperationHandler : OperationHandler
{
/// <summary>
/// Initializes a new instance of <see cref="EntitySetOperationHandler"/> class.
/// </summary>
/// <param name="document">The document to use to lookup references.</param>
protected EntitySetOperationHandler(OpenApiDocument document) : base(document)
{
}
/// <summary>
/// Gets/sets the <see cref="IEdmEntitySet"/>.
/// </summary>
protected IEdmEntitySet EntitySet { get; private set; }
/// <inheritdoc/>
protected override void Initialize(ODataContext context, ODataPath path)
{
base.Initialize(context, path);
// get the entity set.
ODataNavigationSourceSegment navigationSourceSegment = path.FirstSegment as ODataNavigationSourceSegment;
EntitySet = navigationSourceSegment.NavigationSource as IEdmEntitySet;
}
/// <inheritdoc/>
protected override void SetTags(OpenApiOperation operation)
{
var tagName = EntitySet.Name + "." + EntitySet.EntityType.Name;
operation.Tags ??= new HashSet<OpenApiTagReference>();
operation.Tags.Add(new OpenApiTagReference(tagName, _document));
Context.AddExtensionToTag(tagName, Constants.xMsTocType, new OpenApiAny("page"), () => new OpenApiTag()
{
Name = tagName
});
base.SetTags(operation);
}
/// <inheritdoc/>
protected override void SetExtensions(OpenApiOperation operation)
{
operation.Extensions.Add(Constants.xMsDosOperationType, new OpenApiAny("operation"));
base.SetExtensions(operation);
}
/// <inheritdoc/>
protected override void SetExternalDocs(OpenApiOperation operation)
{
if (Context.Settings.ShowExternalDocs)
{
var externalDocs = Context.Model.GetLinkRecord(TargetPath, CustomLinkRel) ??
Context.Model.GetLinkRecord(EntitySet, CustomLinkRel);
if (externalDocs != null)
{
operation.ExternalDocs = new OpenApiExternalDocs()
{
Description = CoreConstants.ExternalDocsDescription,
Url = externalDocs.Href
};
}
}
}
}
}