Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
<PackageId>Microsoft.OpenApi.Hidi</PackageId>
<ToolCommandName>hidi</ToolCommandName>
<PackageOutputPath>./../../artifacts</PackageOutputPath>
<Version>0.5.0-preview4</Version>
<Version>0.6.0-preview1</Version>
<Description>OpenAPI.NET CLI tool for slicing OpenAPI documents</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>OpenAPI .NET</PackageTags>
<RepositoryUrl>https://github.com/Microsoft/OpenAPI.NET</RepositoryUrl>
<PackageReleaseNotes>
- Publish symbols.
- Upgrades Microsoft.OpenApi.OData to 1.0.10-preview1
</PackageReleaseNotes>
<AssemblyName>Microsoft.OpenApi.Hidi</AssemblyName>
<RootNamespace>Microsoft.OpenApi.Hidi</RootNamespace>
Expand All @@ -37,7 +37,7 @@
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="6.0.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta2.21617.1" />
<PackageReference Include="Microsoft.OData.Edm" Version="7.10.0" />
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.0.9" />
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.0.10-preview1" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 7 additions & 3 deletions src/Microsoft.OpenApi.Hidi/OpenApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ string filterbycollection
version ??= OpenApiSpecVersion.OpenApi3_0;

stream = await GetStream(csdl, logger);
document = ConvertCsdlToOpenApi(stream);
document = await ConvertCsdlToOpenApi(stream);
}
else
{
Expand Down Expand Up @@ -198,16 +198,20 @@ string filterbycollection
/// </summary>
/// <param name="csdl">The CSDL stream.</param>
/// <returns>An OpenAPI document.</returns>
public static OpenApiDocument ConvertCsdlToOpenApi(Stream csdl)
public static async Task<OpenApiDocument> ConvertCsdlToOpenApi(Stream csdl)
{
using var reader = new StreamReader(csdl);
var csdlText = reader.ReadToEndAsync().GetAwaiter().GetResult();
var csdlText = await reader.ReadToEndAsync();
var edmModel = CsdlReader.Parse(XElement.Parse(csdlText).CreateReader());

var settings = new OpenApiConvertSettings()
{
AddSingleQuotesForStringParameters = true,
AddEnumDescriptionExtension = true,
DeclarePathParametersOnPathItem = true,
EnableKeyAsSegment = true,
EnableOperationId = true,
ErrorResponsesAsDefault = false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these updated settings Kiota-specific or will they apply to all clients?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AddSingleQuotesForStringParameters is actually a bugfix, but Sam was worried it'd break some people, so we added a setting, IMHO this should be true by default
AddEnumDescriptionExtension just adds a x-ms-enum-description extension for enum members descriptions, it's more information (autorest uses the same extension)
DeclarePathParametersOnPathItem is optimization, to avoid duplicating parameters that are common to operations. I think the optimization will also be beneficial to other generators
ErrorResponsesAsDefault makes the description more specific, using 4XX and 5XX error code classes instead of default (which could be something else than an error)

PrefixEntityTypeNameBeforeKey = true,
TagDepth = 2,
EnablePagination = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ namespace Microsoft.OpenApi.Models
public const string AuthorizationUrl = "authorizationUrl";
public const string BasePath = "basePath";
public const string Basic = "basic";
public const string Bearer = "bearer";
public const string BearerFormat = "bearerFormat";
public const string BodyName = "x-bodyName";
public const string Callbacks = "callbacks";
Expand Down Expand Up @@ -400,6 +401,7 @@ namespace Microsoft.OpenApi.Models
public const string In = "in";
public const string Info = "info";
public const string Items = "items";
public const string Jwt = "JWT";
public const string License = "license";
public const string Links = "links";
public const string Mapping = "mapping";
Expand Down Expand Up @@ -1206,7 +1208,7 @@ namespace Microsoft.OpenApi.Validations.Rules
public static Microsoft.OpenApi.Validations.ValidationRule<Microsoft.OpenApi.Models.OpenApiResponses> ResponsesMustBeIdentifiedByDefaultOrStatusCode { get; }
public static Microsoft.OpenApi.Validations.ValidationRule<Microsoft.OpenApi.Models.OpenApiResponses> ResponsesMustContainAtLeastOneResponse { get; }
}
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.All, AllowMultiple=false, Inherited=false)]
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=false)]
public class OpenApiRuleAttribute : System.Attribute
{
public OpenApiRuleAttribute() { }
Expand Down
13 changes: 7 additions & 6 deletions test/Microsoft.OpenApi.Tests/Services/OpenApiServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.OpenApi.Hidi;
using Microsoft.OpenApi.Services;
using Xunit;
Expand All @@ -12,36 +13,36 @@ namespace Microsoft.OpenApi.Tests.Services
public class OpenApiServiceTests
{
[Fact]
public void ReturnConvertedCSDLFile()
public async Task ReturnConvertedCSDLFile()
{
// Arrange
var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "UtilityFiles\\Todo.xml");
var fileInput = new FileInfo(filePath);
var csdlStream = fileInput.OpenRead();

// Act
var openApiDoc = OpenApiService.ConvertCsdlToOpenApi(csdlStream);
var expectedPathCount = 5;
var openApiDoc = await OpenApiService.ConvertCsdlToOpenApi(csdlStream);
var expectedPathCount = 6;

// Assert
Assert.NotNull(openApiDoc);
Assert.NotEmpty(openApiDoc.Paths);
Assert.Equal(openApiDoc.Paths.Count, expectedPathCount);
Assert.Equal(expectedPathCount, openApiDoc.Paths.Count);
}

[Theory]
[InlineData("Todos.Todo.UpdateTodo",null, 1)]
[InlineData("Todos.Todo.ListTodo",null, 1)]
[InlineData(null, "Todos.Todo", 4)]
public void ReturnFilteredOpenApiDocBasedOnOperationIdsAndInputCsdlDocument(string operationIds, string tags, int expectedPathCount)
public async Task ReturnFilteredOpenApiDocBasedOnOperationIdsAndInputCsdlDocument(string operationIds, string tags, int expectedPathCount)
{
// Arrange
var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "UtilityFiles\\Todo.xml");
var fileInput = new FileInfo(filePath);
var csdlStream = fileInput.OpenRead();

// Act
var openApiDoc = OpenApiService.ConvertCsdlToOpenApi(csdlStream);
var openApiDoc = await OpenApiService.ConvertCsdlToOpenApi(csdlStream);
var predicate = OpenApiFilterService.CreatePredicate(operationIds, tags);
var subsetOpenApiDocument = OpenApiFilterService.CreateFilteredDocument(openApiDoc, predicate);

Expand Down