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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

## [0.5.5] - 2024-03-06

### Changed

- Fixed a bug where the api dependencies would be deduplicated if they had the same key with different casing.

## [0.5.4] - 2023-12-06

### Added
Expand Down
4 changes: 2 additions & 2 deletions src/lib/ApiManifestDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ internal void Validate()

public class ApiDependencies : Dictionary<string, ApiDependency>
{
public ApiDependencies(IDictionary<string, ApiDependency> dictionary) : base(dictionary, StringComparer.OrdinalIgnoreCase) { }
public ApiDependencies() : base(StringComparer.OrdinalIgnoreCase) { }
public ApiDependencies(IDictionary<string, ApiDependency> dictionary) : base(dictionary, StringComparer.Ordinal) { }
public ApiDependencies() : base(StringComparer.Ordinal) { }
}
4 changes: 2 additions & 2 deletions src/lib/apimanifest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>Microsoft.OpenApi.ApiManifest</PackageId>
<VersionPrefix>0.5.4</VersionPrefix>
<VersionPrefix>0.5.5</VersionPrefix>
<VersionSuffix>preview</VersionSuffix>
<PackageIconUrl>http://go.microsoft.com/fwlink/?LinkID=288890</PackageIconUrl>
<PackageProjectUrl>https://github.com/Microsoft/OpenApi.ApiManifest</PackageProjectUrl>
Expand Down Expand Up @@ -34,4 +34,4 @@
<PackageReference Include="System.Text.Json" Version="[6.0,9.0)" />
</ItemGroup>

</Project>
</Project>
58 changes: 50 additions & 8 deletions tests/ApiManifest.Tests/BasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ public void InitializeDocument()
[Fact]
public void SerializeDocument()
{
var stream = new MemoryStream();
var writer = new Utf8JsonWriter(stream);
using var stream = new MemoryStream();
using var writer = new Utf8JsonWriter(stream);
exampleApiManifest.Write(writer);
writer.Flush();
// Read string from stream
stream.Position = 0;
var reader = new StreamReader(stream);
using var reader = new StreamReader(stream);
var json = reader.ReadToEnd();
Debug.WriteLine(json);
var doc = JsonDocument.Parse(json);
using var doc = JsonDocument.Parse(json);
Assert.NotNull(doc);
Assert.Equal("application-name", doc.RootElement.GetProperty("applicationName").GetString());
Assert.Equal("Microsoft", doc.RootElement.GetProperty("publisher").GetProperty("name").GetString());
Expand All @@ -44,15 +44,15 @@ public void SerializeDocument()
[Fact]
public void DeserializeDocument()
{
var stream = new MemoryStream();
var writer = new Utf8JsonWriter(stream);
using var stream = new MemoryStream();
using var writer = new Utf8JsonWriter(stream);
exampleApiManifest.Write(writer);
writer.Flush();
// Read string from stream
stream.Position = 0;
var reader = new StreamReader(stream);
using var reader = new StreamReader(stream);
var json = reader.ReadToEnd();
var doc = JsonDocument.Parse(json);
using var doc = JsonDocument.Parse(json);
var apiManifest = ApiManifestDocument.Load(doc.RootElement);
Assert.Equivalent(exampleApiManifest.Publisher, apiManifest.Publisher);
Assert.Equivalent(exampleApiManifest.ApiDependencies["example"].Requests, apiManifest.ApiDependencies["example"].Requests);
Expand All @@ -68,6 +68,48 @@ public void DeserializeDocument()
Assert.Equal(exampleApiManifest.ApiDependencies["example"]?.Extensions?["example-API-dependency-extension"]?.ToString(), apiManifest.ApiDependencies["example"]?.Extensions?["example-api-dependency-extension"]?.ToString());
}

[Fact]
public void AcceptsMultipleDependenciesWithDifferentCasing()
{
var document = new ApiManifestDocument("foo");
document.ApiDependencies.Add("bar", new());
document.ApiDependencies.Add("BAR", new());
Assert.Equal(2, document.ApiDependencies.Count);
}
[Fact]
public void DeserializesMultipleDependenciesWithDifferentCasing()
{
using var stream = new MemoryStream();
using var writer = new Utf8JsonWriter(stream);
var document = new ApiManifestDocument("foo");
document.ApiDependencies.Add("bar", new()
{
Requests = [
new() {
UriTemplate = "/foo/bar",
Method = "GET"
}
]
});
document.ApiDependencies.Add("BAR", new()
{
Requests = [
new() {
UriTemplate = "/foo/bar",
Method = "GET"
}
]
});
document.Write(writer);
writer.Flush();
// Read string from stream
stream.Position = 0;
using var reader = new StreamReader(stream);
var json = reader.ReadToEnd();
using var doc = JsonDocument.Parse(json);
var apiManifest = ApiManifestDocument.Load(doc.RootElement);
Assert.Equal(2, apiManifest.ApiDependencies.Count);
}

// Create an empty document
[Fact]
Expand Down