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
15 changes: 15 additions & 0 deletions tests/Elastic.ApiExplorer.Tests/TestSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Text.Json.Nodes;
using Elastic.ApiExplorer.Components.PropertyTree;
using Elastic.Documentation;
using Microsoft.AspNetCore.Html;
Expand Down Expand Up @@ -55,6 +57,19 @@ public static async Task<OpenApiDocument> LoadValidSpecAsync(string json)
return (generator, await LoadValidSpecAsync(json));
}

/// <summary>
/// A spec with no operations whose components hold the given schemas. The schemas stay raw JSON
/// because they are what the test is about; only the scaffold around them is supplied.
/// </summary>
public static string WithSchemas([StringSyntax(StringSyntaxAttribute.Json)] string schemasJson, string openApiVersion = "3.0.3") =>
new JsonObject
{
["openapi"] = openApiVersion,
["info"] = new JsonObject { ["title"] = "t", ["version"] = "1" },
["paths"] = new JsonObject(),
["components"] = new JsonObject { ["schemas"] = JsonNode.Parse(schemasJson) }
}.ToJsonString();

public static ApiPropertyTreeBuilder BuilderFor(OpenApiDocument document) =>
new(document, new PropertyDisplayOptions { RenderMarkdown = s => new HtmlString($"<p>{s}</p>"), ApiRootUrl = "/api/doc/fixture" });
}
Loading
Loading