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
37 changes: 37 additions & 0 deletions src/Mindee/V2/Parsing/Search/ModelWebhook.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Text.Json.Serialization;

namespace Mindee.V2.Parsing.Search
{
/// <summary>
/// Information about a model's webhook.
/// </summary>
public class ModelWebhook
{
/// <summary>
/// ID of the webhook.
/// </summary>
[JsonPropertyName("id")]
public string Id { get; set; }

/// <summary>
/// Name of the webhook.
/// </summary>
[JsonPropertyName("name")]
public string Name { get; set; }

/// <summary>
/// URL of the webhook.
/// </summary>
[JsonPropertyName("url")]
public string Url { get; set; }

/// <summary>
/// String representation of the webhook.
/// </summary>
/// <returns></returns>
public override string ToString()
{
return $":Name: {Name}\n:ID: {Id}\n:URL: {Url}";
}
}
}
3 changes: 2 additions & 1 deletion src/Mindee/V2/Parsing/Search/PaginationMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
namespace Mindee.V2.Parsing.Search
{
/// <summary>
/// PaginationMetadata data associated with model search.
/// Pagination metadata associated with model search.
/// </summary>
public class PaginationMetadata
{

/// <summary>
/// Number of items per page.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions src/Mindee/V2/Parsing/Search/SearchModel.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Mindee.V2.Parsing.Search
Expand Down Expand Up @@ -25,6 +26,12 @@ public class SearchModel
[JsonPropertyName("model_type")]
public string ModelType { get; set; }

/// <summary>
/// List of webhooks associated with the model.
/// </summary>
[JsonPropertyName("webhooks")]
public List<ModelWebhook> Webhooks { get; set; }

/// <summary>
/// String representation of the model.
/// </summary>
Expand Down
20 changes: 16 additions & 4 deletions src/Mindee/V2/Parsing/Search/SearchResponse.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Text;
using System.Text.Json.Serialization;
using Mindee.Parsing;
Expand All @@ -8,7 +9,7 @@ namespace Mindee.V2.Parsing.Search
/// <summary>
/// Models search response.
/// </summary>
public class SearchResponse
public class SearchResponse : BaseResponse
{
/// <summary>
/// List of all models matching the search query.
Expand All @@ -18,10 +19,21 @@ public class SearchResponse
public SearchModels Models { get; set; }

/// <summary>
/// PaginationMetadata metadata.
/// Pagination metadata (Obsolete).
/// </summary>
[JsonIgnore]
[Obsolete("Use Pagination instead.")]
public PaginationMetadata PaginationMetadata
{
get => Pagination;
set => Pagination = value;
}

/// <summary>
/// Pagination metadata.
/// </summary>
[JsonPropertyName("pagination")]
public PaginationMetadata PaginationMetadata { get; set; }
public PaginationMetadata Pagination { get; set; }


/// <summary>
Expand All @@ -35,7 +47,7 @@ public override string ToString()
stringBuilder.Append('\n');
stringBuilder.Append("Pagination Metadata\n");
stringBuilder.Append("###################\n");
stringBuilder.Append(PaginationMetadata);
stringBuilder.Append(Pagination);
stringBuilder.Append('\n');

return SummaryHelper.Clean(stringBuilder.ToString());
Expand Down
39 changes: 39 additions & 0 deletions tests/Mindee.UnitTests/V2/Parsing/SearchTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Mindee.V2.Parsing;
using Mindee.V2.Parsing.Search;

namespace Mindee.UnitTests.V2.Parsing
{
[Trait("Category", "V2")]
[Trait("Category", "Search")]
public class SearchTest
{
[Fact]
public void SearchModels_LoadsLocally()
{
var localResponse = new LocalResponse(
new FileInfo(Constants.V2RootDir + "search/models.json"));
SearchResponse modelsResponse = localResponse.DeserializeResponse<SearchResponse>();

Assert.NotNull(modelsResponse);

Assert.Equal(5, modelsResponse.Models.Count);
Assert.Equal(5, modelsResponse.Pagination.TotalItems);
Assert.Equal(1, modelsResponse.Pagination.Page);
Assert.Equal(50, modelsResponse.Pagination.PerPage);
Assert.Equal(1, modelsResponse.Pagination.TotalPages);

var firstModel = modelsResponse.Models.First();
Assert.Equal("Extraction With Webhooks", firstModel.Name);
Assert.Equal("afde5151-aa11-aa11-9289-fa04e50ca3b9", firstModel.Id);
Assert.Equal("extraction", firstModel.ModelType);

Assert.Equal(2, firstModel.Webhooks.Count);
Assert.Equal("a2286ed9-aa11-aa11-bdc5-2f8496c5641a", firstModel.Webhooks[0].Id);
Assert.Equal("FAILURE", firstModel.Webhooks[0].Name);
Assert.Equal("https://failure.mindee.com", firstModel.Webhooks[0].Url);
var lastModel = modelsResponse.Models.Last();
Assert.Equal("Extraction Without Webhooks Key", lastModel.Name);
Assert.Equal("e14e0923-ee55-ee55-a335-8d2110917d7b", lastModel.Id);
}
}
}
Loading