forked from microsoft/OpenAPI.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpenApiObject.cs
54 lines (47 loc) · 1.55 KB
/
OpenApiObject.cs
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.
using System.Collections.Generic;
using Microsoft.OpenApi.Writers;
namespace Microsoft.OpenApi.Any
{
/// <summary>
/// Open API object.
/// </summary>
public class OpenApiObject : Dictionary<string, IOpenApiAny>, IOpenApiAny
{
/// <summary>
/// Type of <see cref="IOpenApiAny"/>.
/// </summary>
public AnyType AnyType { get; } = AnyType.Object;
/// <summary>
/// Parameterless constructor
/// </summary>
public OpenApiObject() { }
/// <summary>
/// Initializes a copy of <see cref="OpenApiObject"/> object
/// </summary>
public OpenApiObject(OpenApiObject obj)
{
AnyType = obj.AnyType;
foreach (var key in obj.Keys)
{
this[key] = OpenApiAnyCloneHelper.CloneFromCopyConstructor(obj[key]);
}
}
/// <summary>
/// Serialize OpenApiObject to writer
/// </summary>
/// <param name="writer"></param>
/// <param name="specVersion">Version of the OpenAPI specification that that will be output.</param>
public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion)
{
writer.WriteStartObject();
foreach (var item in this)
{
writer.WritePropertyName(item.Key);
writer.WriteAny(item.Value);
}
writer.WriteEndObject();
}
}
}