Skip to content

Commit 35a9fc5

Browse files
committed
Merged master
2 parents 60869f6 + 553061a commit 35a9fc5

18 files changed

+158
-25
lines changed

build.cmd

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
Echo Building Microsoft.OpenApi
33

44
SET PROJ=%~dp0src\Microsoft.OpenApi\Microsoft.OpenApi.csproj
5-
dotnet build %PROJ% /t:restore /p:Configuration=Release
6-
dotnet build %PROJ% /t:build /p:Configuration=Release
7-
dotnet build %PROJ% /t:pack /p:Configuration=Release;PackageOutputPath=%~dp0artifacts
5+
dotnet msbuild %PROJ% /t:restore /p:Configuration=Release
6+
dotnet msbuild %PROJ% /t:build /p:Configuration=Release
7+
dotnet msbuild %PROJ% /t:pack /p:Configuration=Release;PackageOutputPath=%~dp0artifacts
88

99
Echo Building Microsoft.OpenApi.Readers
1010

1111
SET PROJ=%~dp0src\Microsoft.OpenApi.Readers\Microsoft.OpenApi.Readers.csproj
12-
dotnet build %PROJ% /t:restore /p:Configuration=Release
13-
dotnet build %PROJ% /t:build /p:Configuration=Release
14-
dotnet build %PROJ% /t:pack /p:Configuration=Release;PackageOutputPath=%~dp0artifacts
12+
dotnet msbuild %PROJ% /t:restore /p:Configuration=Release
13+
dotnet msbuild %PROJ% /t:build /p:Configuration=Release
14+
dotnet msbuild %PROJ% /t:pack /p:Configuration=Release;PackageOutputPath=%~dp0artifacts
1515

1616
goto :end
1717
:error

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<Company>Microsoft</Company>
1111
<Title>Microsoft.OpenApi.Readers</Title>
1212
<PackageId>Microsoft.OpenApi.Readers</PackageId>
13-
<Version>1.2.0-preview.3</Version>
13+
<Version>1.2.3</Version>
1414
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
1515
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
1616
<PackageTags>OpenAPI .NET</PackageTags>

src/Microsoft.OpenApi.Readers/OpenApiTextReaderReader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ public OpenApiDocument Read(TextReader input, out OpenApiDiagnostic diagnostic)
3737
{
3838
YamlDocument yamlDocument;
3939

40-
// Parse the YAML/JSON
40+
// Parse the YAML/JSON text in the TextReader into the YamlDocument
4141
try
4242
{
4343
yamlDocument = LoadYamlDocument(input);
4444
}
4545
catch (YamlException ex)
4646
{
4747
diagnostic = new OpenApiDiagnostic();
48-
diagnostic.Errors.Add(new OpenApiError($"#char={ex.Start.Line}", ex.Message));
48+
diagnostic.Errors.Add(new OpenApiError($"#line={ex.Start.Line}", ex.Message));
4949
return new OpenApiDocument();
5050
}
5151

src/Microsoft.OpenApi.Readers/V2/OpenApiOperationDeserializer.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Collections.Generic;
55
using System.Linq;
6+
using Microsoft.OpenApi.Any;
67
using Microsoft.OpenApi.Extensions;
78
using Microsoft.OpenApi.Models;
89
using Microsoft.OpenApi.Readers.ParseNodes;
@@ -164,6 +165,7 @@ private static OpenApiRequestBody CreateFormBody(ParsingContext context, List<Op
164165
{
165166
var schema = v.Schema;
166167
schema.Description = v.Description;
168+
schema.Extensions = v.Extensions;
167169
return schema;
168170
}),
169171
Required = new HashSet<string>(formParameters.Where(p => p.Required).Select(p => p.Name))
@@ -201,9 +203,11 @@ internal static OpenApiRequestBody CreateRequestBody(
201203
v => new OpenApiMediaType
202204
{
203205
Schema = bodyParameter.Schema
204-
})
206+
}),
207+
Extensions = bodyParameter.Extensions
205208
};
206209

210+
requestBody.Extensions[OpenApiConstants.BodyName] = new OpenApiString(bodyParameter.Name);
207211
return requestBody;
208212
}
209213

src/Microsoft.OpenApi/Any/OpenApiString.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,21 @@ public class OpenApiString : OpenApiPrimitive<string>
1010
{
1111
private bool isExplicit;
1212

13+
/// <summary>
14+
/// Initializes the <see cref="OpenApiString"/> class.
15+
/// </summary>
16+
/// <param name="value"></param>
17+
public OpenApiString(string value)
18+
: this(value, false)
19+
{
20+
}
21+
1322
/// <summary>
1423
/// Initializes the <see cref="OpenApiString"/> class.
1524
/// </summary>
1625
/// <param name="value"></param>
1726
/// <param name="isExplicit">Used to indicate if a string is quoted.</param>
18-
public OpenApiString(string value, bool isExplicit = false)
27+
public OpenApiString(string value, bool isExplicit)
1928
: base(value)
2029
{
2130
this.isExplicit = isExplicit;

src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs

100644100755
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,26 @@ public static void SerializeAsYaml<T>(this T element, Stream stream, OpenApiSpec
4141
element.Serialize(stream, specVersion, OpenApiFormat.Yaml);
4242
}
4343

44+
/// <summary>
45+
/// Serializes the <see cref="IOpenApiSerializable"/> to the Open API document using
46+
/// the given stream, specification version and the format.
47+
/// </summary>
48+
/// <typeparam name="T">the <see cref="IOpenApiSerializable"/></typeparam>
49+
/// <param name="element">The Open API element.</param>
50+
/// <param name="stream">The given stream.</param>
51+
/// <param name="specVersion">The Open API specification version.</param>
52+
/// <param name="format">The output format (JSON or YAML).</param>
53+
/// <param name="settings">Provide configuration settings for controlling writing output</param>
54+
public static void Serialize<T>(
55+
this T element,
56+
Stream stream,
57+
OpenApiSpecVersion specVersion,
58+
OpenApiFormat format)
59+
where T : IOpenApiSerializable
60+
{
61+
element.Serialize(stream, specVersion, format, null);
62+
}
63+
4464
/// <summary>
4565
/// Serializes the <see cref="IOpenApiSerializable"/> to the Open API document using
4666
/// the given stream, specification version and the format.
@@ -56,7 +76,7 @@ public static void Serialize<T>(
5676
Stream stream,
5777
OpenApiSpecVersion specVersion,
5878
OpenApiFormat format,
59-
OpenApiWriterSettings settings = null)
79+
OpenApiWriterSettings settings)
6080
where T : IOpenApiSerializable
6181
{
6282
if (stream == null)

src/Microsoft.OpenApi/Microsoft.OpenApi.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<Company>Microsoft</Company>
1111
<Title>Microsoft.OpenApi</Title>
1212
<PackageId>Microsoft.OpenApi</PackageId>
13-
<Version>1.2.0-preview.3</Version>
13+
<Version>1.2.3</Version>
1414
<Description>.NET models with JSON and YAML writers for OpenAPI specification</Description>
1515
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
1616
<PackageTags>OpenAPI .NET</PackageTags>

src/Microsoft.OpenApi/Models/OpenApiConstants.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,11 @@ public static class OpenApiConstants
560560
/// </summary>
561561
public const string DefaultDescription = "Default Description";
562562

563+
/// <summary>
564+
/// Field: BodyName extensions
565+
/// </summary>
566+
public const string BodyName = "x-bodyName";
567+
563568
/// <summary>
564569
/// Field: version3_0_0
565570
/// </summary>

src/Microsoft.OpenApi/Models/OpenApiOperation.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,29 +228,44 @@ public void SerializeAsV2(IOpenApiWriter writer)
228228
{
229229
foreach (var property in RequestBody.Content.First().Value.Schema.Properties)
230230
{
231+
var paramName = property.Key;
232+
var paramSchema = property.Value;
233+
if (paramSchema.Type == "string" && paramSchema.Format == "binary") {
234+
paramSchema.Type = "file";
235+
paramSchema.Format = null;
236+
}
231237
parameters.Add(
232238
new OpenApiFormDataParameter
233239
{
234240
Description = property.Value.Description,
235241
Name = property.Key,
236242
Schema = property.Value,
237243
Required = RequestBody.Content.First().Value.Schema.Required.Contains(property.Key)
244+
238245
});
239246
}
240247
}
241248
else
242249
{
243250
var content = RequestBody.Content.Values.FirstOrDefault();
251+
244252
var bodyParameter = new OpenApiBodyParameter
245253
{
246254
Description = RequestBody.Description,
247255
// V2 spec actually allows the body to have custom name.
248-
// Our library does not support this at the moment.
256+
// To allow round-tripping we use an extension to hold the name
249257
Name = "body",
250258
Schema = content?.Schema ?? new OpenApiSchema(),
251-
Required = RequestBody.Required
259+
Required = RequestBody.Required,
260+
Extensions = RequestBody.Extensions.ToDictionary(k => k.Key, v => v.Value) // Clone extensions so we can remove the x-bodyName extensions from the output V2 model.
252261
};
253262

263+
if (bodyParameter.Extensions.ContainsKey(OpenApiConstants.BodyName))
264+
{
265+
bodyParameter.Name = (RequestBody.Extensions[OpenApiConstants.BodyName] as OpenApiString)?.Value ?? "body";
266+
bodyParameter.Extensions.Remove(OpenApiConstants.BodyName);
267+
}
268+
254269
parameters.Add(bodyParameter);
255270
}
256271
}

src/Microsoft.OpenApi/Services/OpenApiReferenceResolver.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public override void Visit(OpenApiComponents components)
5252
ResolveMap(components.Examples);
5353
ResolveMap(components.Schemas);
5454
ResolveMap(components.SecuritySchemes);
55+
ResolveMap(components.Headers);
5556
}
5657

5758
public override void Visit(IDictionary<string, OpenApiCallback> callbacks)
@@ -99,6 +100,15 @@ public override void Visit(OpenApiResponses responses)
99100
ResolveMap(responses);
100101
}
101102

103+
/// <summary>
104+
/// Resolve all references to headers
105+
/// </summary>
106+
/// <param name="headers"></param>
107+
public override void Visit(IDictionary<string, OpenApiHeader> headers)
108+
{
109+
ResolveMap(headers);
110+
}
111+
102112
/// <summary>
103113
/// Resolve all references to SecuritySchemes
104114
/// </summary>

0 commit comments

Comments
 (0)