Skip to content

Commit 097b7f3

Browse files
authored
Initialize collections (lists, dictionaries) in the models (#96)
- Initialize all collection properties - Remove default value from Info #85 - Ensure serializers to use Optional / Required writers correctly based on whether the property is marked as REQUIRED in the spec. - Remove all "AddXXX" extensions except AddExtension, which is still useful in detecting badly formed names for extensions (e.g. not starting with x-) - Fix unit tests - Up nuget to 1.0.0-beta004
1 parent 13c32b0 commit 097b7f3

File tree

58 files changed

+317
-486
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+317
-486
lines changed

src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Company>Microsoft</Company>
77
<Product>Microsoft.OpenApi.Readers</Product>
88
<PackageId>Microsoft.OpenApi.Readers</PackageId>
9-
<Version>1.0.0-beta003</Version>
9+
<Version>1.0.0-beta004</Version>
1010
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
1111
<AssemblyName>Microsoft.OpenApi.Readers</AssemblyName>
1212
<RootNamespace>Microsoft.OpenApi.Readers</RootNamespace>

src/Microsoft.OpenApi.Workbench/MainModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private string WriteContents(OpenApiDocument doc)
120120
{
121121
var outputstream = new MemoryStream();
122122
doc.Serialize(outputstream,
123-
IsV3 ? OpenApiSpecVersion.OpenApi3_0 : OpenApiSpecVersion.OpenApi2_0,
123+
IsV3 ? OpenApiSpecVersion.OpenApi3_0_0 : OpenApiSpecVersion.OpenApi2_0,
124124
this.format == "Yaml" ? OpenApiFormat.Yaml : OpenApiFormat.Json);
125125

126126
outputstream.Position = 0;

src/Microsoft.OpenApi/Extensions/OpenApiElementExtensions.cs

Lines changed: 0 additions & 252 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// ------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All rights reserved.
3+
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
4+
// ------------------------------------------------------------
5+
6+
using Microsoft.OpenApi.Any;
7+
using Microsoft.OpenApi.Exceptions;
8+
using Microsoft.OpenApi.Interfaces;
9+
using Microsoft.OpenApi.Models;
10+
using Microsoft.OpenApi.Properties;
11+
12+
namespace Microsoft.OpenApi.Extensions
13+
{
14+
/// <summary>
15+
/// Extension methods to verify validatity and add an extension to Extensions property.
16+
/// </summary>
17+
public static class OpenApiExtensibleExtensions
18+
{
19+
/// <summary>
20+
/// Add extension into the Extensions
21+
/// </summary>
22+
/// <typeparam name="T"><see cref="IOpenApiExtensible"/>.</typeparam>
23+
/// <param name="element">The extensible Open API element. </param>
24+
/// <param name="name">The extension name.</param>
25+
/// <param name="any">The extension value.</param>
26+
public static void AddExtension<T>(this T element, string name, IOpenApiAny any)
27+
where T : IOpenApiExtensible
28+
{
29+
if (element == null)
30+
{
31+
throw Error.ArgumentNull(nameof(element));
32+
}
33+
34+
if (string.IsNullOrWhiteSpace(name))
35+
{
36+
throw Error.ArgumentNullOrWhiteSpace(nameof(name));
37+
}
38+
39+
if (!name.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix))
40+
{
41+
throw new OpenApiException(string.Format(SRResource.ExtensionFieldNameMustBeginWithXDash, name));
42+
}
43+
44+
element.Extensions[name] = any ?? throw Error.ArgumentNull(nameof(any));
45+
}
46+
}
47+
}

src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public static void Serialize<T>(this T element, IOpenApiWriter writer, OpenApiSp
101101

102102
switch (specVersion)
103103
{
104-
case OpenApiSpecVersion.OpenApi3_0:
104+
case OpenApiSpecVersion.OpenApi3_0_0:
105105
element.SerializeAsV3(writer);
106106
break;
107107

src/Microsoft.OpenApi/Microsoft.OpenApi.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Company>Microsoft</Company>
77
<Product>Microsoft.OpenApi</Product>
88
<PackageId>Microsoft.OpenApi</PackageId>
9-
<Version>1.0.0-beta003</Version>
9+
<Version>1.0.0-beta004</Version>
1010
<Description>.NET models and JSON/YAML writers for OpenAPI specification</Description>
1111
<AssemblyName>Microsoft.OpenApi</AssemblyName>
1212
<RootNamespace>Microsoft.OpenApi</RootNamespace>

src/Microsoft.OpenApi/Models/OpenApiCallback.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public class OpenApiCallback : IOpenApiSerializable, IOpenApiReferenceable, IOpe
1919
/// <summary>
2020
/// A Path Item Object used to define a callback request and expected responses.
2121
/// </summary>
22-
public Dictionary<RuntimeExpression, OpenApiPathItem> PathItems { get; set; }
22+
public Dictionary<RuntimeExpression, OpenApiPathItem> PathItems { get; set; }
23+
= new Dictionary<RuntimeExpression, OpenApiPathItem>();
2324

2425
/// <summary>
2526
/// Reference pointer.
@@ -29,7 +30,7 @@ public class OpenApiCallback : IOpenApiSerializable, IOpenApiReferenceable, IOpe
2930
/// <summary>
3031
/// This object MAY be extended with Specification Extensions.
3132
/// </summary>
32-
public IDictionary<string, IOpenApiAny> Extensions { get; set; }
33+
public IDictionary<string, IOpenApiAny> Extensions { get; set; } = new Dictionary<string, IOpenApiAny>();
3334

3435
/// <summary>
3536
/// Add a <see cref="OpenApiPathItem"/> into the <see cref="PathItems"/>.

0 commit comments

Comments
 (0)