Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b0bf2ae
Adds a copy constructor for all models and cleans up code
MaggieKimani1 May 11, 2022
c61e1cb
Update public Api interface
MaggieKimani1 May 11, 2022
0298364
Merge branch 'vnext' into mk/add-copy-constructors-for-models
MaggieKimani1 Jul 4, 2022
eae3641
Create new object instances for copying purposes
MaggieKimani1 Jul 4, 2022
d0dc9b3
Update public API interface
MaggieKimani1 Jul 4, 2022
dc300ab
Add XML comments
MaggieKimani1 Jul 4, 2022
17d4371
Implement ICloneable for type IOpenApiAny
MaggieKimani1 Jul 6, 2022
233da50
Initialize a new Uri instance during copying
MaggieKimani1 Jul 6, 2022
1dbab5d
Update documentation
MaggieKimani1 Jul 6, 2022
12fa16b
Update public API interface
MaggieKimani1 Jul 6, 2022
7cd6abc
Revert ICloneable changes and use reflection for deep copying
MaggieKimani1 Jul 6, 2022
85a0a1f
Clean up and add copy constructors
MaggieKimani1 Jul 6, 2022
e034d0c
Revert public API changes
MaggieKimani1 Jul 6, 2022
87180dd
Remove unnecessary using
MaggieKimani1 Jul 6, 2022
c0e09c7
remove duplicate SourceLink
SimonCropp Jul 9, 2022
e055dde
Merge pull request #940 from SimonCropp/remove-duplicate-SourceLink
baywet Jul 11, 2022
6a3e948
Merge pull request #853 from microsoft/mk/add-copy-constructors-for-m…
MaggieKimani1 Jul 12, 2022
b39303e
Retrieve missing path parameters during slicing
MaggieKimani1 Jul 14, 2022
ea2d73f
Adds test for retrieving path parameters
MaggieKimani1 Jul 14, 2022
51d5018
Code refactor and update public API interface
MaggieKimani1 Jul 15, 2022
69d0bdd
Revert API change
MaggieKimani1 Jul 15, 2022
9dc6ef1
Merge pull request #943 from microsoft/mk/fix-missing-path-params
MaggieKimani1 Jul 18, 2022
e8cd960
Bump Microsoft.OpenApi.OData from 1.0.11-preview5 to 1.0.11
dependabot[bot] Jul 18, 2022
dd71aec
Merge pull request #944 from microsoft/dependabot/nuget/Microsoft.Ope…
baywet Jul 18, 2022
29c9d0d
Bumps Hidi version
Jul 19, 2022
8184eb2
Merge pull request #946 from microsoft/release-hidi-version
andrueastman Jul 19, 2022
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
Expand Down Expand Up @@ -135,5 +135,22 @@ public void ThrowsInvalidOperationExceptionInCreatePredicateWhenInvalidArguments
var message2 = Assert.Throws<InvalidOperationException>(() => OpenApiFilterService.CreatePredicate("users.user.ListUser", "users.user")).Message;
Assert.Equal("Cannot specify both operationIds and tags at the same time.", message2);
}

[Theory]
[InlineData("reports.getTeamsUserActivityUserDetail-a3f1", null)]
[InlineData(null, "reports.Functions")]
public void ReturnsPathParametersOnSlicingBasedOnOperationIdsOrTags(string operationIds, string tags)
{
// Act
var predicate = OpenApiFilterService.CreatePredicate(operationIds, tags);
var subsetOpenApiDocument = OpenApiFilterService.CreateFilteredDocument(_openApiDocumentMock, predicate);

// Assert
foreach (var pathItem in subsetOpenApiDocument.Paths)
{
Assert.True(pathItem.Value.Parameters.Any());
Assert.Equal(1, pathItem.Value.Parameters.Count);
}
}
}
}
30 changes: 29 additions & 1 deletion Microsoft.OpenApi.Hidi.Tests/UtilityFiles/OpenApiDocumentMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ public static OpenApiDocument CreateOpenApiDocument()
}
}
}
},
Parameters = new List<OpenApiParameter>
{
{
new OpenApiParameter()
{
Name = "period",
In = ParameterLocation.Path,
Required = true,
Schema = new OpenApiSchema()
{
Type = "string"
}
}
}
}
},
["/reports/microsoft.graph.getTeamsUserActivityUserDetail(date={date})"] = new OpenApiPathItem()
Expand Down Expand Up @@ -175,7 +190,20 @@ public static OpenApiDocument CreateOpenApiDocument()
}
}
}
}
},
Parameters = new List<OpenApiParameter>
{
new OpenApiParameter
{
Name = "period",
In = ParameterLocation.Path,
Required = true,
Schema = new OpenApiSchema()
{
Type = "string"
}
}
}
},
["/users"] = new OpenApiPathItem()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1-*" PrivateAssets="All"/>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All"/>
</ItemGroup>
</Project>
8 changes: 2 additions & 6 deletions src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageId>Microsoft.OpenApi.Hidi</PackageId>
<ToolCommandName>hidi</ToolCommandName>
<PackageOutputPath>./../../artifacts</PackageOutputPath>
<Version>1.0.0-preview8</Version>
<Version>1.0.0-preview9</Version>
<Description>OpenAPI.NET CLI tool for slicing OpenAPI documents</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>OpenAPI .NET</PackageTags>
Expand Down Expand Up @@ -43,16 +43,12 @@
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="6.0.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta3.22114.1" />
<PackageReference Include="Microsoft.OData.Edm" Version="7.12.0" />
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.0.11-preview5" />
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.0.11" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.OpenApi.Readers\Microsoft.OpenApi.Readers.csproj" />
<ProjectReference Include="..\Microsoft.OpenApi\Microsoft.OpenApi.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.1.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="SharpYaml" Version="1.9.2" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.3.330701">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
36 changes: 36 additions & 0 deletions src/Microsoft.OpenApi/Any/OpenApiAnyCloneHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System.Reflection;

namespace Microsoft.OpenApi.Any
{
/// <summary>
/// Contains logic for cloning objects through copy constructors.
/// </summary>
public class OpenApiAnyCloneHelper
{
/// <summary>
/// Clones an instance of <see cref="IOpenApiAny"/> object from the copy constructor
/// </summary>
/// <param name="obj">The object instance.</param>
/// <returns>A clone copy or the object itself.</returns>
public static IOpenApiAny CloneFromCopyConstructor(IOpenApiAny obj)
{
if (obj != null)
{
var t = obj.GetType();
foreach (ConstructorInfo ci in t.GetConstructors())
{
ParameterInfo[] pi = ci.GetParameters();
if (pi.Length == 1 && pi[0].ParameterType == t)
{
return (IOpenApiAny)ci.Invoke(new object[] { obj });
}
}
}

return obj;
}
}
}
14 changes: 14 additions & 0 deletions src/Microsoft.OpenApi/Any/OpenApiArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.

using Microsoft.OpenApi.Writers;
using System;
using System.Collections.Generic;

namespace Microsoft.OpenApi.Any
Expand All @@ -16,6 +17,19 @@ public class OpenApiArray : List<IOpenApiAny>, IOpenApiAny
/// </summary>
public AnyType AnyType { get; } = AnyType.Array;

/// <summary>
/// Parameterless constructor
/// </summary>
public OpenApiArray() { }

/// <summary>
/// Initializes a copy of <see cref="OpenApiArray"/> object
/// </summary>
public OpenApiArray(OpenApiArray array)
{
AnyType = array.AnyType;
}

/// <summary>
/// Write out contents of OpenApiArray to passed writer
/// </summary>
Expand Down
13 changes: 13 additions & 0 deletions src/Microsoft.OpenApi/Any/OpenApiNull.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ public class OpenApiNull : IOpenApiAny
/// </summary>
public AnyType AnyType { get; } = AnyType.Null;

/// <summary>
/// Parameterless constructor
/// </summary>
public OpenApiNull() { }

/// <summary>
/// Initializes a copy of <see cref="OpenApiNull"/> object
/// </summary>
public OpenApiNull(OpenApiNull openApiNull)
{
AnyType = openApiNull.AnyType;
}

/// <summary>
/// Write out null representation
/// </summary>
Expand Down
13 changes: 13 additions & 0 deletions src/Microsoft.OpenApi/Any/OpenApiObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ public class OpenApiObject : Dictionary<string, IOpenApiAny>, IOpenApiAny
/// </summary>
public AnyType AnyType { get; } = AnyType.Object;

/// <summary>
/// Parameterless constructor
/// </summary>
public OpenApiObject() { }

/// <summary>
/// Initializes a copy of <see cref="OpenApiObject"/> object
/// </summary>
public OpenApiObject(OpenApiObject obj)
{
AnyType = obj.AnyType;
}

/// <summary>
/// Serialize OpenApiObject to writer
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions src/Microsoft.OpenApi/Any/OpenApiPrimitive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ public OpenApiPrimitive(T value)
Value = value;
}

/// <summary>
/// Initializes a copy of an <see cref="IOpenApiPrimitive"/> object
/// </summary>
/// <param name="openApiPrimitive"></param>
public OpenApiPrimitive(OpenApiPrimitive<T> openApiPrimitive)
{
Value = openApiPrimitive.Value;
}

/// <summary>
/// The kind of <see cref="IOpenApiAny"/>.
/// </summary>
Expand Down
4 changes: 0 additions & 4 deletions src/Microsoft.OpenApi/Microsoft.OpenApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\SRResource.Designer.cs">
<DesignTime>True</DesignTime>
Expand Down
16 changes: 16 additions & 0 deletions src/Microsoft.OpenApi/Models/OpenApiCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ public class OpenApiCallback : IOpenApiSerializable, IOpenApiReferenceable, IOpe
/// </summary>
public IDictionary<string, IOpenApiExtension> Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();

/// <summary>
/// Parameter-less constructor
/// </summary>
public OpenApiCallback() { }

/// <summary>
/// Initializes a copy of an <see cref="OpenApiCallback"/> object
/// </summary>
public OpenApiCallback(OpenApiCallback callback)
{
PathItems = new(callback.PathItems);
UnresolvedReference = callback.UnresolvedReference;
Reference = new(callback.Reference);
Extensions = new Dictionary<string, IOpenApiExtension>(callback.Extensions);
}

/// <summary>
/// Add a <see cref="OpenApiPathItem"/> into the <see cref="PathItems"/>.
/// </summary>
Expand Down
22 changes: 22 additions & 0 deletions src/Microsoft.OpenApi/Models/OpenApiComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,28 @@ public class OpenApiComponents : IOpenApiSerializable, IOpenApiExtensible
/// </summary>
public IDictionary<string, IOpenApiExtension> Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();

/// <summary>
/// Parameter-less constructor
/// </summary>
public OpenApiComponents() { }

/// <summary>
/// Initializes a copy of an <see cref="OpenApiComponents"/> object
/// </summary>
public OpenApiComponents(OpenApiComponents components)
{
Schemas = new Dictionary<string, OpenApiSchema>(components.Schemas);
Responses = new Dictionary<string, OpenApiResponse>(components.Responses);
Parameters = new Dictionary<string, OpenApiParameter>(components.Parameters);
Examples = new Dictionary<string, OpenApiExample>(components.Examples);
RequestBodies = new Dictionary<string, OpenApiRequestBody>(components.RequestBodies);
Headers = new Dictionary<string, OpenApiHeader>(components.Headers);
SecuritySchemes = new Dictionary<string, OpenApiSecurityScheme>(components.SecuritySchemes);
Links = new Dictionary<string, OpenApiLink>(components.Links);
Callbacks = new Dictionary<string, OpenApiCallback>(components.Callbacks);
Extensions = new Dictionary<string, IOpenApiExtension>(components.Extensions);
}

/// <summary>
/// Serialize <see cref="OpenApiComponents"/> to Open Api v3.0.
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions src/Microsoft.OpenApi/Models/OpenApiContact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ public class OpenApiContact : IOpenApiSerializable, IOpenApiExtensible
/// </summary>
public IDictionary<string, IOpenApiExtension> Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();

/// <summary>
/// Parameter-less constructor
/// </summary>
public OpenApiContact() { }

/// <summary>
/// Initializes a copy of an <see cref="OpenApiContact"/> instance
/// </summary>
public OpenApiContact(OpenApiContact contact)
{
Name = contact.Name;
Url = new Uri(contact.Url.OriginalString);
Email = contact.Email;
Extensions = new Dictionary<string, IOpenApiExtension>(contact.Extensions);
}

/// <summary>
/// Serialize <see cref="OpenApiContact"/> to Open Api v3.0
/// </summary>
Expand Down
14 changes: 14 additions & 0 deletions src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ public class OpenApiDiscriminator : IOpenApiSerializable
/// </summary>
public IDictionary<string, string> Mapping { get; set; } = new Dictionary<string, string>();

/// <summary>
/// Parameter-less constructor
/// </summary>
public OpenApiDiscriminator() { }

/// <summary>
/// Initializes a copy of an <see cref="OpenApiDiscriminator"/> instance
/// </summary>
public OpenApiDiscriminator(OpenApiDiscriminator discriminator)
{
PropertyName = discriminator.PropertyName;
Mapping = new Dictionary<string, string>(discriminator.Mapping);
}

/// <summary>
/// Serialize <see cref="OpenApiDiscriminator"/> to Open Api v3.0
/// </summary>
Expand Down
23 changes: 21 additions & 2 deletions src/Microsoft.OpenApi/Models/OpenApiDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Exceptions;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Services;
Expand Down Expand Up @@ -64,6 +62,27 @@ public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible
/// </summary>
public IDictionary<string, IOpenApiExtension> Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();

/// <summary>
/// Parameter-less constructor
/// </summary>
public OpenApiDocument() {}

/// <summary>
/// Initializes a copy of an an <see cref="OpenApiDocument"/> object
/// </summary>
public OpenApiDocument(OpenApiDocument document)
{
Workspace = new(document.Workspace);
Info = new(document.Info);
Servers = new List<OpenApiServer>(document.Servers);
Paths = new(document.Paths);
Components = new(document.Components);
SecurityRequirements = new List<OpenApiSecurityRequirement>(document.SecurityRequirements);
Tags = new List<OpenApiTag>(document.Tags);
ExternalDocs = new(document.ExternalDocs);
Extensions = new Dictionary<string, IOpenApiExtension>(document.Extensions);
}

/// <summary>
/// Serialize <see cref="OpenApiDocument"/> to the latest patch of OpenAPI object V3.0.
/// </summary>
Expand Down
Loading