Skip to content

Commit d23ad22

Browse files
Merge pull request #1037 from microsoft/vnext
Release 1.4.4-preview1
2 parents 5f8a702 + 76321be commit d23ad22

25 files changed

+179
-104
lines changed

.github/workflows/ci-cd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
GITHUB_RUN_NUMBER: ${{ github.run_number }}
1515
steps:
1616
- name: Setup .NET
17-
uses: actions/setup-dotnet@v2
17+
uses: actions/setup-dotnet@v3
1818
with:
1919
dotnet-version: 6.0.x
2020

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
uses: actions/checkout@v3
1818

1919
- name: Setup .NET
20-
uses: actions/setup-dotnet@v2
20+
uses: actions/setup-dotnet@v3
2121
with:
2222
dotnet-version: 6.0.x
2323

Microsoft.OpenApi.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.OpenApi.SmokeTest
2828
EndProject
2929
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.OpenApi.Hidi", "src\Microsoft.OpenApi.Hidi\Microsoft.OpenApi.Hidi.csproj", "{254841B5-7DAC-4D1D-A9C5-44FE5CE467BE}"
3030
EndProject
31-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.OpenApi.Hidi.Tests", "Microsoft.OpenApi.Hidi.Tests\Microsoft.OpenApi.Hidi.Tests.csproj", "{D8F799DD-04AC-4A13-B344-45A5B944450A}"
31+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.OpenApi.Hidi.Tests", "test\Microsoft.OpenApi.Hidi.Tests\Microsoft.OpenApi.Hidi.Tests.csproj", "{D8F799DD-04AC-4A13-B344-45A5B944450A}"
3232
EndProject
3333
Global
3434
GlobalSection(SolutionConfigurationPlatforms) = preSolution

src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<PackageId>Microsoft.OpenApi.Hidi</PackageId>
1616
<ToolCommandName>hidi</ToolCommandName>
1717
<PackageOutputPath>./../../artifacts</PackageOutputPath>
18-
<Version>1.1.0-preview1</Version>
18+
<Version>1.1.0-preview2</Version>
1919
<Description>OpenAPI.NET CLI tool for slicing OpenAPI documents</Description>
2020
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
2121
<PackageTags>OpenAPI .NET</PackageTags>
@@ -43,7 +43,7 @@
4343
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="6.0.0" />
4444
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
4545
<PackageReference Include="Microsoft.OData.Edm" Version="7.12.3" />
46-
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.1.0" />
46+
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.2.0-preview4" />
4747
</ItemGroup>
4848

4949
<ItemGroup>

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.4.1</Version>
13+
<Version>1.4.4-preview1</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/V2/OpenApiHeaderDeserializer.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

44
using System;
@@ -139,8 +139,12 @@ internal static partial class OpenApiV2Deserializer
139139
{
140140
OpenApiConstants.Default,
141141
new AnyFieldMapParameter<OpenApiHeader>(
142-
p => p.Schema.Default,
143-
(p, v) => p.Schema.Default = v,
142+
p => p.Schema?.Default,
143+
(p, v) =>
144+
{
145+
if(p.Schema == null) return;
146+
p.Schema.Default = v;
147+
},
144148
p => p.Schema)
145149
}
146150
};
@@ -151,8 +155,12 @@ internal static partial class OpenApiV2Deserializer
151155
{
152156
OpenApiConstants.Enum,
153157
new AnyListFieldMapParameter<OpenApiHeader>(
154-
p => p.Schema.Enum,
155-
(p, v) => p.Schema.Enum = v,
158+
p => p.Schema?.Enum,
159+
(p, v) =>
160+
{
161+
if(p.Schema == null) return;
162+
p.Schema.Enum = v;
163+
},
156164
p => p.Schema)
157165
},
158166
};

src/Microsoft.OpenApi/Microsoft.OpenApi.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<Company>Microsoft</Company>
1212
<Title>Microsoft.OpenApi</Title>
1313
<PackageId>Microsoft.OpenApi</PackageId>
14-
<Version>1.4.3</Version>
14+
<Version>1.4.4-preview1</Version>
1515
<Description>.NET models with JSON and YAML writers for OpenAPI specification</Description>
1616
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
1717
<PackageTags>OpenAPI .NET</PackageTags>

src/Microsoft.OpenApi/Models/OpenApiDocument.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public void SerializeAsV2(IOpenApiWriter writer)
160160
// paths
161161
writer.WriteRequiredObject(OpenApiConstants.Paths, Paths, (w, p) => p.SerializeAsV2(w));
162162

163-
// If references have been inlined we don't need the to render the components section
163+
// If references have been inlined we don't need to render the components section
164164
// however if they have cycles, then we will need a component rendered
165165
if (writer.GetSettings().InlineLocalReferences)
166166
{
@@ -208,9 +208,20 @@ public void SerializeAsV2(IOpenApiWriter writer)
208208
});
209209
}
210210
// parameters
211+
var parameters = Components?.Parameters != null
212+
? new Dictionary<string, OpenApiParameter>(Components.Parameters)
213+
: new Dictionary<string, OpenApiParameter>();
214+
215+
if (Components?.RequestBodies != null)
216+
{
217+
foreach (var requestBody in Components.RequestBodies.Where(b => !parameters.ContainsKey(b.Key)))
218+
{
219+
parameters.Add(requestBody.Key, requestBody.Value.ConvertToBodyParameter());
220+
}
221+
}
211222
writer.WriteOptionalMap(
212223
OpenApiConstants.Parameters,
213-
Components?.Parameters,
224+
parameters,
214225
(w, key, component) =>
215226
{
216227
if (component.Reference != null &&

src/Microsoft.OpenApi/Models/OpenApiOperation.cs

Lines changed: 38 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public void SerializeAsV2(IOpenApiWriter writer)
224224
// operationId
225225
writer.WriteProperty(OpenApiConstants.OperationId, OperationId);
226226

227-
IList<OpenApiParameter> parameters;
227+
List<OpenApiParameter> parameters;
228228
if (Parameters == null)
229229
{
230230
parameters = new List<OpenApiParameter>();
@@ -237,70 +237,58 @@ public void SerializeAsV2(IOpenApiWriter writer)
237237
if (RequestBody != null)
238238
{
239239
// consumes
240-
writer.WritePropertyName(OpenApiConstants.Consumes);
241-
writer.WriteStartArray();
242240
var consumes = RequestBody.Content.Keys.Distinct().ToList();
243-
foreach (var mediaType in consumes)
241+
if (consumes.Any())
244242
{
245-
writer.WriteValue(mediaType);
246-
}
247-
248-
writer.WriteEndArray();
249-
250-
// This is form data. We need to split the request body into multiple parameters.
251-
if (consumes.Contains("application/x-www-form-urlencoded") ||
252-
consumes.Contains("multipart/form-data"))
253-
{
254-
foreach (var property in RequestBody.Content.First().Value.Schema.Properties)
243+
// This is form data. We need to split the request body into multiple parameters.
244+
if (consumes.Contains("application/x-www-form-urlencoded") ||
245+
consumes.Contains("multipart/form-data"))
255246
{
256-
var paramSchema = property.Value;
257-
if ("string".Equals(paramSchema.Type, StringComparison.OrdinalIgnoreCase)
258-
&& ("binary".Equals(paramSchema.Format, StringComparison.OrdinalIgnoreCase)
259-
|| "base64".Equals(paramSchema.Format, StringComparison.OrdinalIgnoreCase)))
260-
{
261-
paramSchema.Type = "file";
262-
paramSchema.Format = null;
263-
}
264-
parameters.Add(
265-
new OpenApiFormDataParameter
266-
{
267-
Description = property.Value.Description,
268-
Name = property.Key,
269-
Schema = property.Value,
270-
Required = RequestBody.Content.First().Value.Schema.Required.Contains(property.Key)
271-
272-
});
247+
parameters.AddRange(RequestBody.ConvertToFormDataParameters());
248+
}
249+
else
250+
{
251+
parameters.Add(RequestBody.ConvertToBodyParameter());
273252
}
274253
}
275-
else
254+
else if (RequestBody.Reference != null)
276255
{
277-
var content = RequestBody.Content.Values.FirstOrDefault();
256+
parameters.Add(
257+
new OpenApiParameter
258+
{
259+
UnresolvedReference = true,
260+
Reference = RequestBody.Reference
261+
});
278262

279-
var bodyParameter = new OpenApiBodyParameter
263+
if (RequestBody.Reference.HostDocument != null)
280264
{
281-
Description = RequestBody.Description,
282-
// V2 spec actually allows the body to have custom name.
283-
// To allow round-tripping we use an extension to hold the name
284-
Name = "body",
285-
Schema = content?.Schema ?? new OpenApiSchema(),
286-
Required = RequestBody.Required,
287-
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.
288-
};
289-
290-
if (bodyParameter.Extensions.ContainsKey(OpenApiConstants.BodyName))
265+
var effectiveRequestBody = RequestBody.GetEffective(RequestBody.Reference.HostDocument);
266+
if (effectiveRequestBody != null)
267+
consumes = effectiveRequestBody.Content.Keys.Distinct().ToList();
268+
}
269+
}
270+
271+
if (consumes.Any())
272+
{
273+
writer.WritePropertyName(OpenApiConstants.Consumes);
274+
writer.WriteStartArray();
275+
foreach (var mediaType in consumes)
291276
{
292-
bodyParameter.Name = (RequestBody.Extensions[OpenApiConstants.BodyName] as OpenApiString)?.Value ?? "body";
293-
bodyParameter.Extensions.Remove(OpenApiConstants.BodyName);
277+
writer.WriteValue(mediaType);
294278
}
295-
296-
parameters.Add(bodyParameter);
279+
writer.WriteEndArray();
297280
}
298281
}
299282

300283
if (Responses != null)
301284
{
302-
var produces = Responses.Where(r => r.Value.Content != null)
303-
.SelectMany(r => r.Value.Content?.Keys)
285+
var produces = Responses
286+
.Where(static r => r.Value.Content != null)
287+
.SelectMany(static r => r.Value.Content?.Keys)
288+
.Concat(
289+
Responses
290+
.Where(static r => r.Value.Reference != null && r.Value.Reference.HostDocument != null)
291+
.SelectMany(static r => r.Value.GetEffective(r.Value.Reference.HostDocument)?.Content?.Keys))
304292
.Distinct()
305293
.ToList();
306294

src/Microsoft.OpenApi/Models/OpenApiReference.cs

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -214,31 +214,17 @@ private string GetExternalReferenceV2()
214214

215215
private string GetReferenceTypeNameAsV2(ReferenceType type)
216216
{
217-
switch (type)
217+
return type switch
218218
{
219-
case ReferenceType.Schema:
220-
return OpenApiConstants.Definitions;
221-
222-
case ReferenceType.Parameter:
223-
return OpenApiConstants.Parameters;
224-
225-
case ReferenceType.Response:
226-
return OpenApiConstants.Responses;
227-
228-
case ReferenceType.Header:
229-
return OpenApiConstants.Headers;
230-
231-
case ReferenceType.Tag:
232-
return OpenApiConstants.Tags;
233-
234-
case ReferenceType.SecurityScheme:
235-
return OpenApiConstants.SecurityDefinitions;
236-
237-
default:
238-
// If the reference type is not supported in V2, simply return null
239-
// to indicate that the reference is not pointing to any object.
240-
return null;
241-
}
219+
ReferenceType.Schema => OpenApiConstants.Definitions,
220+
ReferenceType.Parameter or ReferenceType.RequestBody => OpenApiConstants.Parameters,
221+
ReferenceType.Response => OpenApiConstants.Responses,
222+
ReferenceType.Header => OpenApiConstants.Headers,
223+
ReferenceType.Tag => OpenApiConstants.Tags,
224+
ReferenceType.SecurityScheme => OpenApiConstants.SecurityDefinitions,
225+
_ => null,// If the reference type is not supported in V2, simply return null
226+
// to indicate that the reference is not pointing to any object.
227+
};
242228
}
243229
}
244230
}

0 commit comments

Comments
 (0)