-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathMetadataGetOperationHandler.cs
More file actions
85 lines (76 loc) · 2.93 KB
/
MetadataGetOperationHandler.cs
File metadata and controls
85 lines (76 loc) · 2.93 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
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using System.Collections.Generic;
using System.Net.Http;
using Microsoft.OpenApi.OData.Common;
namespace Microsoft.OpenApi.OData.Operation
{
/// <summary>
/// Retrieve a metadata document "get"
/// </summary>
internal class MetadataGetOperationHandler : OperationHandler
{
/// <summary>
/// Initializes a new instance of <see cref="MetadataGetOperationHandler"/> class.
/// </summary>
/// <param name="document">The document to use to lookup references.</param>
public MetadataGetOperationHandler(OpenApiDocument document):base(document)
{
}
/// <inheritdoc/>
public override HttpMethod OperationType => HttpMethod.Get;
/// <inheritdoc/>
protected override void SetBasicInfo(OpenApiOperation operation)
{
// Summary
operation.Summary = $"Get OData metadata (CSDL) document";
// OperationId
if (Context is {Settings.EnableOperationId: true})
{
string routePrefix = Context.Settings.PathPrefix ?? "";
if (Context.Settings.PathPrefix != null)
{
operation.OperationId = $"{routePrefix}.Get.Metadata";
}
else
{
operation.OperationId = "Get.Metadata";
}
}
base.SetBasicInfo(operation);
}
/// <inheritdoc/>
protected override void SetResponses(OpenApiOperation operation)
{
OpenApiSchema schema = new OpenApiSchema
{
Type = JsonSchemaType.String
};
operation.Responses = new OpenApiResponses
{
{
Context?.Settings.UseSuccessStatusCodeRange ?? false ? Constants.StatusCodeClass2XX : Constants.StatusCode200,
new OpenApiResponse
{
Description = "Retrieved metadata document",
Content = new Dictionary<string, IOpenApiMediaType>
{
{
Constants.ApplicationXmlMediaType,
new OpenApiMediaType
{
Schema = schema
}
}
}
}
}
};
if (Context is not null)
operation.AddErrorResponses(Context.Settings, _document, false);
base.SetResponses(operation);
}
}
}