-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prototype of the cli utility for AOT/Trim applications #190
Draft
yurvon-screamo
wants to merge
3
commits into
main
Choose a base branch
from
feature/aot
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Saunter.AsyncApiSchema.v2; | ||
|
||
namespace Saunter.Cli; | ||
|
||
/// <summary> | ||
/// DTO to create specification prototype | ||
/// </summary> | ||
/// <param name="Id">Identifier of the application the AsyncAPI document is defining.</param> | ||
/// <param name="Info">Provides metadata about the API. The metadata can be used by the clients if needed.</param> | ||
/// <param name="Servers">Provides connection details of servers.</param> | ||
/// <param name="DefaultContentType">A string representing the default content type to use when encoding/decoding a message's payload.</param> | ||
/// <param name="ExternalDocs">Additional external documentation.</param> | ||
public record AsyncApiPrototype( | ||
string Id, | ||
Info? Info, | ||
Dictionary<string, Server>? Servers, | ||
string? DefaultContentType, | ||
ExternalDocumentation? ExternalDocs); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Saunter; | ||
using Saunter.Cli; | ||
|
||
ConsoleAppBuilder builder = ConsoleApp.CreateBuilder(args); | ||
|
||
builder.ConfigureServices(s => s.AddAsyncApiSchemaGeneration()); | ||
|
||
ConsoleApp app = builder.Build(); | ||
|
||
app.AddSubCommands<SpecificationGeneratorCommand>(); | ||
|
||
app.Run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Saunter.Cli | ||
|
||
A simple utility for generating async api specifications from a set of dlls. | ||
|
||
## Idea | ||
|
||
For aot and trim assemblies, it is inject at the post-build stage, сreates a json document that is included in the build and used by the running application. | ||
|
||
## Usage | ||
|
||
So far, just an example: | ||
|
||
```bash | ||
saunter-cli specification generate -p saunter/examples/StreetlightsAPI/bin/Release/net6.0/ --prototype '{ "id": "tester" }' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<InvariantGlobalization>true</InvariantGlobalization> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="ConsoleAppFramework" Version="4.2.4" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Saunter\Saunter.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
| ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.5.002.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Saunter.Cli", "Saunter.Cli.csproj", "{CD1C0B2D-99A8-4C86-B90B-ED20A654BCD3}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{CD1C0B2D-99A8-4C86-B90B-ED20A654BCD3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{CD1C0B2D-99A8-4C86-B90B-ED20A654BCD3}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{CD1C0B2D-99A8-4C86-B90B-ED20A654BCD3}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{CD1C0B2D-99A8-4C86-B90B-ED20A654BCD3}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {B4A02E6B-5357-475B-9CDA-233CFFE79CCB} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System.Reflection; | ||
using System.Runtime.Loader; | ||
|
||
using Saunter.AsyncApiSchema.v2; | ||
using Saunter.Serialization; | ||
|
||
namespace Saunter.Cli; | ||
|
||
/// <summary> | ||
/// Generate documentation from dll | ||
/// </summary> | ||
[Command("specification", "Generate documentation from dll")] | ||
public class SpecificationGeneratorCommand : ConsoleAppBase | ||
{ | ||
private readonly IAsyncApiDocumentProvider _provider; | ||
private readonly IAsyncApiDocumentSerializer _serializer; | ||
|
||
/// <summary> | ||
/// Documentation generator from dll | ||
/// </summary> | ||
public SpecificationGeneratorCommand(IAsyncApiDocumentProvider provider, IAsyncApiDocumentSerializer serializer) | ||
{ | ||
_provider = provider; | ||
_serializer = serializer; | ||
} | ||
|
||
/// <summary> | ||
/// Generate specification from dll directory | ||
/// </summary> | ||
/// <param name="dllDirectory"></param> | ||
/// <param name="prototype"></param> | ||
/// <returns></returns> | ||
[Command("generate", "Generate specification from dll directory")] | ||
public async Task Generate([Option("p", "The path containing the target application's dll")] string dllDirectory, AsyncApiPrototype prototype) | ||
{ | ||
AsyncApiDocument documentPrototype = new() | ||
{ | ||
Id = prototype.Id, | ||
}; | ||
|
||
if (!string.IsNullOrEmpty(prototype.DefaultContentType)) | ||
{ | ||
documentPrototype.DefaultContentType = prototype.DefaultContentType; | ||
} | ||
|
||
if (prototype.Info is not null) | ||
{ | ||
documentPrototype.Info = prototype.Info; | ||
} | ||
|
||
if (prototype.Servers is not null) | ||
{ | ||
documentPrototype.Servers = prototype.Servers; | ||
} | ||
|
||
if (prototype.ExternalDocs is not null) | ||
{ | ||
documentPrototype.ExternalDocs = prototype.ExternalDocs; | ||
} | ||
|
||
AsyncApiOptions options = new() | ||
{ | ||
AsyncApi = documentPrototype, | ||
}; | ||
|
||
string[] dllFiles = Directory.GetFiles(dllDirectory, "*.dll"); | ||
|
||
foreach (string dllFile in dllFiles) | ||
{ | ||
Assembly assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(dllFile); | ||
|
||
options.Assemblies.Add(assembly); | ||
} | ||
|
||
AsyncApiDocument document = _provider.GetDocument(options, options.AsyncApi); | ||
|
||
string jsonSpecification = _serializer.Serialize(document); | ||
|
||
await using StreamWriter writer = File.CreateText("asyncapi.json"); | ||
|
||
await writer.WriteAsync(jsonSpecification); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
test/Saunter.IntegrationTests.ReverseProxy/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"profiles": { | ||
"Saunter.IntegrationTests.ReverseProxy": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "https://localhost:65155;http://localhost:65158" | ||
} | ||
} | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be added to the .gitignore?