Skip to content

Commit 8973a58

Browse files
Merge pull request #1543 from microsoft/vnext
Release Hidi and Libs
2 parents 79f59bf + d16d3bc commit 8973a58

File tree

61 files changed

+613
-92
lines changed

Some content is hidden

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

61 files changed

+613
-92
lines changed

.github/workflows/ci-cd.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name: CI/CD Pipeline
22

33
on: [push, pull_request, workflow_dispatch]
44

5+
permissions:
6+
contents: write
7+
58
jobs:
69
ci:
710
name: Continuous Integration

.github/workflows/sonarcloud.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ on:
99
types: [opened, synchronize, reopened]
1010
paths-ignore: ['.vscode/**']
1111

12+
13+
permissions:
14+
contents: read
15+
pull-requests: read
16+
1217
env:
1318
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
1419

@@ -46,14 +51,14 @@ jobs:
4651
with:
4752
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
4853
- name: Cache SonarCloud packages
49-
uses: actions/cache@v3
54+
uses: actions/cache@v4
5055
with:
5156
path: ~/.sonar/cache
5257
key: ${{ runner.os }}-sonar
5358
restore-keys: ${{ runner.os }}-sonar
5459
- name: Cache SonarCloud scanner
5560
id: cache-sonar-scanner
56-
uses: actions/cache@v3
61+
uses: actions/cache@v4
5762
with:
5863
path: ./.sonar/scanner
5964
key: ${{ runner.os }}-sonar-scanner

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
@@ -9,7 +9,7 @@
99
<Nullable>enable</Nullable>
1010
<ToolCommandName>hidi</ToolCommandName>
1111
<PackageOutputPath>./../../artifacts</PackageOutputPath>
12-
<Version>1.3.7</Version>
12+
<Version>1.3.8</Version>
1313
<Description>OpenAPI.NET CLI tool for slicing OpenAPI documents</Description>
1414
<SignAssembly>true</SignAssembly>
1515
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
@@ -35,7 +35,7 @@
3535
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
3636
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
3737
<PackageReference Include="Microsoft.OData.Edm" Version="7.20.0" />
38-
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.6.0-preview.2" />
38+
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.6.0-preview.4" />
3939
<PackageReference Include="Microsoft.OpenApi.ApiManifest" Version="0.5.0-preview" />
4040
<PackageReference Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22272.1" />
4141
</ItemGroup>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<TargetFramework>netstandard2.0</TargetFramework>
44
<LangVersion>latest</LangVersion>
55
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
6-
<Version>1.6.12</Version>
6+
<Version>1.6.13</Version>
77
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
88
<SignAssembly>true</SignAssembly>
99
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.Linq;
66
using System.Security.Cryptography.X509Certificates;
7+
using System.Xml.Linq;
78
using Microsoft.OpenApi.Any;
89
using Microsoft.OpenApi.Extensions;
910
using Microsoft.OpenApi.Models;
@@ -194,7 +195,8 @@ internal static OpenApiRequestBody CreateRequestBody(
194195
k => k,
195196
_ => new OpenApiMediaType
196197
{
197-
Schema = bodyParameter.Schema
198+
Schema = bodyParameter.Schema,
199+
Examples = bodyParameter.Examples
198200
}),
199201
Extensions = bodyParameter.Extensions
200202
};

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,17 @@ internal static partial class OpenApiV2Deserializer
9595
"schema",
9696
(o, n) => o.Schema = LoadSchema(n)
9797
},
98+
{
99+
"x-examples",
100+
LoadParameterExamplesExtension
101+
},
98102
};
99103

100104
private static readonly PatternFieldMap<OpenApiParameter> _parameterPatternFields =
101105
new()
102106
{
103-
{s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p, n))}
107+
{s => s.StartsWith("x-") && !s.Equals(OpenApiConstants.ExamplesExtension, StringComparison.OrdinalIgnoreCase),
108+
(o, p, n) => o.AddExtension(p, LoadExtension(p, n))}
104109
};
105110

106111
private static readonly AnyFieldMap<OpenApiParameter> _parameterAnyFields =
@@ -166,6 +171,12 @@ private static void LoadStyle(OpenApiParameter p, string v)
166171
}
167172
}
168173

174+
private static void LoadParameterExamplesExtension(OpenApiParameter parameter, ParseNode node)
175+
{
176+
var examples = LoadExamplesExtension(node);
177+
node.Context.SetTempStorage(TempStorageKeys.Examples, examples, parameter);
178+
}
179+
169180
private static OpenApiSchema GetOrCreateSchema(OpenApiParameter p)
170181
{
171182
if (p.Schema == null)
@@ -250,6 +261,14 @@ public static OpenApiParameter LoadParameter(ParseNode node, bool loadRequestBod
250261
node.Context.SetTempStorage("schema", null);
251262
}
252263

264+
// load examples from storage and add them to the parameter
265+
var examples = node.Context.GetFromTempStorage<Dictionary<string, OpenApiExample>>(TempStorageKeys.Examples, parameter);
266+
if (examples != null)
267+
{
268+
parameter.Examples = examples;
269+
node.Context.SetTempStorage("examples", null);
270+
}
271+
253272
var isBodyOrFormData = (bool)node.Context.GetFromTempStorage<object>(TempStorageKeys.ParameterIsBodyOrFormData);
254273
if (isBodyOrFormData && !loadRequestBody)
255274
{

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

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

4+
using System;
45
using System.Collections.Generic;
56
using Microsoft.OpenApi.Extensions;
67
using Microsoft.OpenApi.Models;
@@ -28,6 +29,10 @@ internal static partial class OpenApiV2Deserializer
2829
"examples",
2930
LoadExamples
3031
},
32+
{
33+
"x-examples",
34+
LoadResponseExamplesExtension
35+
},
3136
{
3237
"schema",
3338
(o, n) => n.Context.SetTempStorage(TempStorageKeys.ResponseSchema, LoadSchema(n), o)
@@ -37,7 +42,8 @@ internal static partial class OpenApiV2Deserializer
3742
private static readonly PatternFieldMap<OpenApiResponse> _responsePatternFields =
3843
new()
3944
{
40-
{s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p, n))}
45+
{s => s.StartsWith("x-") && !s.Equals(OpenApiConstants.ExamplesExtension, StringComparison.OrdinalIgnoreCase),
46+
(o, p, n) => o.AddExtension(p, LoadExtension(p, n))}
4147
};
4248

4349
private static readonly AnyFieldMap<OpenApiMediaType> _mediaTypeAnyFields =
@@ -69,6 +75,8 @@ private static void ProcessProduces(MapNode mapNode, OpenApiResponse response, P
6975
?? context.DefaultContentType ?? new List<string> { "application/octet-stream" };
7076

7177
var schema = context.GetFromTempStorage<OpenApiSchema>(TempStorageKeys.ResponseSchema, response);
78+
var examples = context.GetFromTempStorage<Dictionary<string, OpenApiExample>>(TempStorageKeys.Examples, response)
79+
?? new Dictionary<string, OpenApiExample>();
7280

7381
foreach (var produce in produces)
7482
{
@@ -84,20 +92,64 @@ private static void ProcessProduces(MapNode mapNode, OpenApiResponse response, P
8492
{
8593
var mediaType = new OpenApiMediaType
8694
{
87-
Schema = schema
95+
Schema = schema,
96+
Examples = examples
8897
};
8998

9099
response.Content.Add(produce, mediaType);
91100
}
92101
}
93102

94103
context.SetTempStorage(TempStorageKeys.ResponseSchema, null, response);
104+
context.SetTempStorage(TempStorageKeys.Examples, null, response);
95105
context.SetTempStorage(TempStorageKeys.ResponseProducesSet, true, response);
96106
}
97107

108+
private static void LoadResponseExamplesExtension(OpenApiResponse response, ParseNode node)
109+
{
110+
var examples = LoadExamplesExtension(node);
111+
node.Context.SetTempStorage(TempStorageKeys.Examples, examples, response);
112+
}
113+
114+
private static Dictionary<string, OpenApiExample> LoadExamplesExtension(ParseNode node)
115+
{
116+
var mapNode = node.CheckMapNode(OpenApiConstants.ExamplesExtension);
117+
var examples = new Dictionary<string, OpenApiExample>();
118+
119+
foreach (var examplesNode in mapNode)
120+
{
121+
// Load the media type node as an OpenApiExample object
122+
var example = new OpenApiExample();
123+
var exampleNode = examplesNode.Value.CheckMapNode(examplesNode.Name);
124+
foreach (var valueNode in exampleNode)
125+
{
126+
switch (valueNode.Name.ToLowerInvariant())
127+
{
128+
case "summary":
129+
example.Summary = valueNode.Value.GetScalarValue();
130+
break;
131+
case "description":
132+
example.Description = valueNode.Value.GetScalarValue();
133+
break;
134+
case "value":
135+
example.Value = OpenApiAnyConverter.GetSpecificOpenApiAny(valueNode.Value.CreateAny());
136+
break;
137+
case "externalValue":
138+
example.ExternalValue = valueNode.Value.GetScalarValue();
139+
break;
140+
}
141+
}
142+
143+
examples.Add(examplesNode.Name, example);
144+
}
145+
146+
return examples;
147+
}
148+
98149
private static void LoadExamples(OpenApiResponse response, ParseNode node)
99150
{
100151
var mapNode = node.CheckMapNode("examples");
152+
101153
foreach (var mediaTypeNode in mapNode)
102154
{
103155
LoadExample(response, mediaTypeNode.Name, mediaTypeNode.Value);
@@ -108,10 +160,7 @@ private static void LoadExample(OpenApiResponse response, string mediaType, Pars
108160
{
109161
var exampleNode = node.CreateAny();
110162

111-
if (response.Content == null)
112-
{
113-
response.Content = new Dictionary<string, OpenApiMediaType>();
114-
}
163+
response.Content ??= new Dictionary<string, OpenApiMediaType>();
115164

116165
OpenApiMediaType mediaTypeObject;
117166
if (response.Content.TryGetValue(mediaType, out var value))
@@ -141,6 +190,7 @@ public static OpenApiResponse LoadResponse(ParseNode node)
141190
}
142191

143192
var response = new OpenApiResponse();
193+
144194
foreach (var property in mapNode)
145195
{
146196
property.ParseField(response, _responseFixedFields, _responsePatternFields);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ internal static class TempStorageKeys
1717
public const string GlobalConsumes = "globalConsumes";
1818
public const string GlobalProduces = "globalProduces";
1919
public const string ParameterIsBodyOrFormData = "parameterIsBodyOrFormData";
20+
public const string Examples = "examples";
2021
}
2122
}

src/Microsoft.OpenApi/Microsoft.OpenApi.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<TargetFramework>netstandard2.0</TargetFramework>
44
<LangVersion>Latest</LangVersion>
55
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
6-
<Version>1.6.12</Version>
6+
<Version>1.6.13</Version>
77
<Description>.NET models with JSON and YAML writers for OpenAPI specification</Description>
88
<SignAssembly>true</SignAssembly>
99
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->

src/Microsoft.OpenApi/Models/OpenApiConstants.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,11 @@ public static class OpenApiConstants
565565
/// </summary>
566566
public const string BodyName = "x-bodyName";
567567

568+
/// <summary>
569+
/// Field: Examples Extension
570+
/// </summary>
571+
public const string ExamplesExtension = "x-examples";
572+
568573
/// <summary>
569574
/// Field: version3_0_0
570575
/// </summary>

0 commit comments

Comments
 (0)