Skip to content

Commit 6fd3122

Browse files
committed
Move classes out of Class1.cs :)
1 parent 4cc7c58 commit 6fd3122

File tree

6 files changed

+86
-48
lines changed

6 files changed

+86
-48
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using Elastic.Documentation.Configuration;
6+
using Elastic.Documentation.Site.FileProviders;
7+
using Elastic.Documentation.Site.Navigation;
8+
using Microsoft.OpenApi.Models;
9+
10+
namespace Elastic.ApiExplorer;
11+
12+
public record ApiRenderContext(
13+
BuildContext BuildContext,
14+
OpenApiDocument Model,
15+
StaticFileContentHashProvider StaticFileContentHashProvider
16+
)
17+
: RenderContext<OpenApiDocument>(BuildContext, Model)
18+
{
19+
public required string NavigationHtml { get; init; }
20+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using Elastic.Documentation.Site.FileProviders;
6+
7+
namespace Elastic.ApiExplorer;
8+
9+
public abstract class ApiViewModel
10+
{
11+
public required string NavigationHtml { get; init; }
12+
public required StaticFileContentHashProvider StaticFileContentHashProvider { get; init; }
13+
}

src/Elastic.ApiExplorer/Class1.cs renamed to src/Elastic.ApiExplorer/OpenApiGenerator.cs

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,57 +11,9 @@
1111
using Elastic.Documentation.Site.Navigation;
1212
using Microsoft.Extensions.Logging;
1313
using Microsoft.OpenApi.Models;
14-
using Microsoft.OpenApi.Reader;
1514

1615
namespace Elastic.ApiExplorer;
1716

18-
public static class OpenApiReader
19-
{
20-
public static async Task<OpenApiDocument?> Create(IFileInfo openApiSpecification)
21-
{
22-
if (!openApiSpecification.Exists)
23-
return null;
24-
25-
var settings = new OpenApiReaderSettings
26-
{
27-
LeaveStreamOpen = false
28-
};
29-
await using var fs = File.Open(openApiSpecification.FullName, FileMode.Open);
30-
var openApiDocument = await OpenApiDocument.LoadAsync(fs, settings: settings);
31-
return openApiDocument.Document;
32-
}
33-
}
34-
35-
public interface IPageRenderer<in T>
36-
{
37-
Task RenderAsync(FileSystemStream stream, T context, CancellationToken ctx = default);
38-
}
39-
40-
public interface IRenderContext<out T>
41-
{
42-
BuildContext BuildContext { get; }
43-
T Model { get; }
44-
}
45-
46-
public record RenderContext<T>(BuildContext BuildContext, T Model) : IRenderContext<T>;
47-
48-
public abstract class ApiViewModel
49-
{
50-
public required string NavigationHtml { get; init; }
51-
public required StaticFileContentHashProvider StaticFileContentHashProvider { get; init; }
52-
}
53-
54-
55-
public record ApiRenderContext(
56-
BuildContext BuildContext,
57-
OpenApiDocument Model,
58-
StaticFileContentHashProvider StaticFileContentHashProvider
59-
)
60-
: RenderContext<OpenApiDocument>(BuildContext, Model)
61-
{
62-
public required string NavigationHtml { get; init; }
63-
}
64-
6517
public class OpenApiGenerator(BuildContext context, ILoggerFactory logger)
6618
{
6719
private readonly ILogger _logger = logger.CreateLogger<OpenApiGenerator>();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using System.IO.Abstractions;
6+
using Microsoft.OpenApi.Models;
7+
using Microsoft.OpenApi.Reader;
8+
9+
namespace Elastic.ApiExplorer;
10+
11+
public static class OpenApiReader
12+
{
13+
public static async Task<OpenApiDocument?> Create(IFileInfo openApiSpecification)
14+
{
15+
if (!openApiSpecification.Exists)
16+
return null;
17+
18+
var settings = new OpenApiReaderSettings
19+
{
20+
LeaveStreamOpen = false
21+
};
22+
await using var fs = File.Open(openApiSpecification.FullName, FileMode.Open);
23+
var openApiDocument = await OpenApiDocument.LoadAsync(fs, settings: settings);
24+
return openApiDocument.Document;
25+
}
26+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using System.IO.Abstractions;
6+
7+
namespace Elastic.Documentation.Site.Navigation;
8+
9+
public interface IPageRenderer<in T>
10+
{
11+
Task RenderAsync(FileSystemStream stream, T context, CancellationToken ctx = default);
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using Elastic.Documentation.Configuration;
6+
7+
namespace Elastic.Documentation.Site.Navigation;
8+
9+
public interface IRenderContext<out T>
10+
{
11+
BuildContext BuildContext { get; }
12+
T Model { get; }
13+
}
14+
15+
public record RenderContext<T>(BuildContext BuildContext, T Model) : IRenderContext<T>;

0 commit comments

Comments
 (0)