Skip to content

Commit e20fffb

Browse files
committed
Complete OpenApiXml and revert to initial the extension dictionary
1 parent 26d4768 commit e20fffb

File tree

6 files changed

+52
-40
lines changed

6 files changed

+52
-40
lines changed

src/Microsoft.OpenApi.Readers/YamlReaders/OpenApiV3Builder.cs

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,7 @@ public static OpenApiDocument LoadOpenApi(RootNode rootNode)
5656

5757
public static PatternFieldMap<OpenApiInfo> InfoPatternFields = new PatternFieldMap<OpenApiInfo>
5858
{
59-
{
60-
(s) => s.StartsWith("x-"),
61-
(o,k,n) =>
62-
{
63-
if (o.Extensions == null)
64-
{
65-
o.Extensions = new Dictionary<string, IOpenApiAny>();
66-
}
67-
68-
o.Extensions.Add(k, new OpenApiString(n.GetScalarValue()));
69-
}
70-
}
59+
{ (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) }
7160
};
7261

7362
public static OpenApiInfo LoadInfo(ParseNode node)
@@ -95,18 +84,7 @@ public static OpenApiInfo LoadInfo(ParseNode node)
9584

9685
public static PatternFieldMap<OpenApiContact> ContactPatternFields = new PatternFieldMap<OpenApiContact>
9786
{
98-
{
99-
(s)=> s.StartsWith("x-"),
100-
(o,k,n)=>
101-
{
102-
if (o.Extensions == null)
103-
{
104-
o.Extensions = new Dictionary<string, IOpenApiAny>();
105-
}
106-
107-
o.Extensions.Add(k, new OpenApiString(n.GetScalarValue()));
108-
}
109-
}
87+
{ (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) }
11088
};
11189

11290
public static OpenApiContact LoadContact(ParseNode node)
@@ -130,18 +108,7 @@ public static OpenApiContact LoadContact(ParseNode node)
130108

131109
public static PatternFieldMap<OpenApiLicense> LicensePatternFields = new PatternFieldMap<OpenApiLicense>
132110
{
133-
{
134-
(s) => s.StartsWith("x-"),
135-
(o,k,n) =>
136-
{
137-
if (o.Extensions == null)
138-
{
139-
o.Extensions = new Dictionary<string, IOpenApiAny>();
140-
}
141-
142-
o.Extensions.Add(k, new OpenApiString(n.GetScalarValue()));
143-
}
144-
}
111+
{ (s)=> s.StartsWith("x-"), (o,k,n)=> o.Extensions.Add(k, new OpenApiString(n.GetScalarValue())) }
145112
};
146113

147114
internal static OpenApiLicense LoadLicense(ParseNode node)

src/Microsoft.OpenApi/Models/OpenApiContact.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ public class OpenApiContact : IOpenApiExtension
3333
/// <summary>
3434
/// This object MAY be extended with Specification Extensions.
3535
/// </summary>
36-
public IDictionary<string, IOpenApiAny> Extensions { get; set; }
36+
public IDictionary<string, IOpenApiAny> Extensions { get; set; } = new Dictionary<string, IOpenApiAny>();
3737
}
3838
}

src/Microsoft.OpenApi/Models/OpenApiInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public string TermsOfService
6060
/// <summary>
6161
/// This object MAY be extended with Specification Extensions.
6262
/// </summary>
63-
public IDictionary<string, IOpenApiAny> Extensions { get; set; }
63+
public IDictionary<string, IOpenApiAny> Extensions { get; set; } = new Dictionary<string, IOpenApiAny>();
6464

6565
private static Regex versionRegex = new Regex(@"\d+\.\d+\.\d+");
6666
}

src/Microsoft.OpenApi/Models/OpenApiLicense.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ public class OpenApiLicense : IOpenApiExtension
2727
/// <summary>
2828
/// This object MAY be extended with Specification Extensions.
2929
/// </summary>
30-
public IDictionary<string, IOpenApiAny> Extensions { get; set; }
30+
public IDictionary<string, IOpenApiAny> Extensions { get; set; } = new Dictionary<string, IOpenApiAny>();
3131
}
3232
}

src/Microsoft.OpenApi/Models/OpenApiSchema.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ public class OpenApiSchema : IOpenApiReference, IOpenApiExtension
4949
public OpenApiExternalDocs ExternalDocs { get; set; }
5050
public bool Deprecated { get; set; }
5151

52+
/// <summary>
53+
/// Adds additional metadata to describe the XML representation of this property.
54+
/// </summary>
55+
public OpenApiXml Xml { get; set; }
56+
57+
/// <summary>
58+
/// Specification Extensions.
59+
/// </summary>
5260
public IDictionary<string, IOpenApiAny> Extensions { get; set; }
5361

5462
public OpenApiReference Pointer

src/Microsoft.OpenApi/Models/OpenApiXml.cs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,46 @@
44
// </copyright>
55
//---------------------------------------------------------------------
66

7+
using System;
8+
using System.Collections.Generic;
9+
710
namespace Microsoft.OpenApi
811
{
9-
public class OpenApiXml : IOpenApiElement
12+
/// <summary>
13+
/// XML Object.
14+
/// </summary>
15+
public class OpenApiXml : IOpenApiExtension
1016
{
17+
/// <summary>
18+
/// Replaces the name of the element/attribute used for the described schema property.
19+
/// </summary>
20+
public string Name { get; set; }
21+
22+
/// <summary>
23+
/// The URI of the namespace definition.
24+
/// </summary>
25+
public Uri Namespace { get; set; }
26+
27+
/// <summary>
28+
/// The prefix to be used for the name
29+
/// </summary>
30+
public string Prefix { get; set; }
31+
32+
/// <summary>
33+
/// Declares whether the property definition translates to an attribute instead of an element.
34+
/// Default value is false.
35+
/// </summary>
36+
public bool Attribute { get; set; }
37+
38+
/// <summary>
39+
/// Signifies whether the array is wrapped.
40+
/// Default value is false.
41+
/// </summary>
42+
public bool Wrapped { get; set; }
43+
44+
/// <summary>
45+
/// Specification Extensions.
46+
/// </summary>
47+
public IDictionary<string, IOpenApiAny> Extensions { get; set; }
1148
}
1249
}

0 commit comments

Comments
 (0)