-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathOpenApiDocumentGenerator.cs
More file actions
54 lines (45 loc) · 1.84 KB
/
OpenApiDocumentGenerator.cs
File metadata and controls
54 lines (45 loc) · 1.84 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
// ------------------------------------------------------------
// 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.Models;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Generator
{
/// <summary>
/// Extension methods to create <see cref="OpenApiDocument"/> by Edm model.
/// </summary>
internal static class OpenApiDocumentGenerator
{
/// <summary>
/// Create a <see cref="OpenApiDocument"/>, it's a single Open API Object.
/// </summary>
/// <param name="context">The OData to Open API context.</param>
/// <returns>The created <see cref="OpenApiDocument"/> object.</returns>
public static OpenApiDocument CreateDocument(this ODataContext context)
{
Utils.CheckArgumentNull(context, nameof(context));
// An OAS document consists of a single OpenAPI Object represented as OpenApiDocument object.
// {
// "openapi":"3.0.0",
// "info": …,
// "servers": …,
// "tags": …,
// "paths": …,
// "components": …
// }
OpenApiDocument doc = new()
{
Info = context.CreateInfo(),
Servers = context.CreateServers(),
Security = null,
ExternalDocs = null,
};
context.AddComponentsToDocument(doc);
context.AddPathsToDocument(doc);
doc.Tags = context.CreateTags(); // order matters so the operation generators have populated the tags
return doc;
}
}
}