-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathComplexPropertyBaseOperationHandler.cs
More file actions
70 lines (61 loc) · 2.51 KB
/
ComplexPropertyBaseOperationHandler.cs
File metadata and controls
70 lines (61 loc) · 2.51 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
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
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;
internal abstract class ComplexPropertyBaseOperationHandler : OperationHandler
{
/// <summary>
/// Initializes a new instance of <see cref="ComplexPropertyBaseOperationHandler"/> class.
/// </summary>
/// <param name="document">The document to use to lookup references.</param>
protected ComplexPropertyBaseOperationHandler(OpenApiDocument document) : base(document)
{
}
protected ODataComplexPropertySegment ComplexPropertySegment;
/// <inheritdoc/>
protected override void Initialize(ODataContext context, ODataPath path)
{
base.Initialize(context, path);
ComplexPropertySegment = path.LastSegment as ODataComplexPropertySegment ?? throw Error.ArgumentNull(nameof(path));
}
/// <inheritdoc/>
protected override void SetTags(OpenApiOperation operation)
{
string tagName = EdmModelHelper.GenerateComplexPropertyPathTagName(Path, Context);
operation.Tags ??= new HashSet<OpenApiTagReference>();
if (!string.IsNullOrEmpty(tagName))
{
Context.AddExtensionToTag(tagName, Constants.xMsTocType, new OpenApiAny("page"), () => new OpenApiTag()
{
Name = tagName
});
operation.Tags.Add(new OpenApiTagReference(tagName, _document));
}
base.SetTags(operation);
}
/// <inheritdoc/>
protected override void SetExternalDocs(OpenApiOperation operation)
{
if (Context.Settings.ShowExternalDocs)
{
var externalDocs = Context.Model.GetLinkRecord(TargetPath, CustomLinkRel) ??
Context.Model.GetLinkRecord(ComplexPropertySegment.Property, CustomLinkRel);
if (externalDocs != null)
{
operation.ExternalDocs = new OpenApiExternalDocs()
{
Description = CoreConstants.ExternalDocsDescription,
Url = externalDocs.Href
};
}
}
}
}