Skip to content

Commit

Permalink
asyncapi#196 Fixed formatting etc + some PR remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Senn Geerts authored and Senn Geerts committed Jul 9, 2024
1 parent 90dcff1 commit a746e4d
Show file tree
Hide file tree
Showing 15 changed files with 160 additions and 189 deletions.
2 changes: 0 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ dotnet_naming_symbols.all_members.applicable_kinds = *

dotnet_naming_style.pascal_case_style.capitalization = pascal_case

file_header_template = Licensed to the .NET Foundation under one or more agreements.\nThe .NET Foundation licenses this file to you under the MIT license.\nSee the LICENSE file in the project root for more information.

# RS0016: Only enable if API files are present
dotnet_public_api_analyzer.require_api_files = true

Expand Down
6 changes: 1 addition & 5 deletions src/AsyncAPI.Saunter.Generator.Cli/Args.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

// ReSharper disable once CheckNamespace
// ReSharper disable once CheckNamespace
public static partial class Program
{
internal const string StartupAssemblyArgument = "startupassembly";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<LangVersion>12</LangVersion>
<RootNamespace>AsyncAPI.Saunter.Generator.Cli</RootNamespace>

<Description>AsyncAPI Command Line Tools</Description>
<Description>AsyncAPI Command Line Tools: Dotnet tool to generate AsyncAPI spec file from dotnet startup assembly.</Description>
<Authors>AsyncAPI Initiative</Authors>
<PackAsTool>true</PackAsTool>
<PackageId>AsyncAPI.Saunter.Generator.Cli</PackageId>
Expand All @@ -23,7 +23,10 @@
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Version>1.0.1</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard2.0' ">
Expand Down
6 changes: 1 addition & 5 deletions src/AsyncAPI.Saunter.Generator.Cli/Commands/Tofile.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Diagnostics;
using System.Diagnostics;
using System.Reflection;
using static Program;

Expand Down
30 changes: 12 additions & 18 deletions src/AsyncAPI.Saunter.Generator.Cli/Commands/TofileInternal.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using LEGO.AsyncAPI.Readers;
using Microsoft.Extensions.Options;
using Saunter.Serialization;
using Saunter;
using System.Reflection;
using System.Runtime.Loader;
using System.Reflection;
using AsyncApi.Saunter.Generator.Cli.SwashbuckleImport;
using LEGO.AsyncAPI;
using LEGO.AsyncAPI.Models;
using Microsoft.Extensions.DependencyInjection;
using AsyncApi.Saunter.Generator.Cli.SwashbuckleImport;
using Microsoft.AspNetCore.Hosting;
using LEGO.AsyncAPI.Readers;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Saunter.AsyncApiSchema.v2;
using Microsoft.Extensions.Options;
using Saunter;
using Saunter.Serialization;
using static Program;
using AsyncApiDocument = Saunter.AsyncApiSchema.v2.AsyncApiDocument;
using System.IO;

namespace AsyncApi.Saunter.Generator.Cli.Commands;

Expand All @@ -35,13 +29,13 @@ internal static int Run(IDictionary<string, string> namedArgs)
var envVars = (namedArgs.TryGetValue(EnvOption, out var x) && !string.IsNullOrWhiteSpace(x)) ? x.Split(',').Select(x => x.Trim()) : Array.Empty<string>();
foreach (var envVar in envVars.Select(x => x.Split('=').Select(x => x.Trim()).ToList()))
{
if (envVar.Count == 2)
if (envVar.Count is 1 or 2)
{
Environment.SetEnvironmentVariable(envVar[0], envVar[1], EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable(envVar[0], envVar.ElementAtOrDefault(1), EnvironmentVariableTarget.Process);
}
else
{
throw new ArgumentOutOfRangeException(EnvOption, namedArgs[EnvOption], "Environment variable should be in the format: env1=value1,env2=value2");
throw new ArgumentOutOfRangeException(EnvOption, namedArgs[EnvOption], "Environment variable should be in the format: env1=value1,env2=value2,env3");
}
}
var serviceProvider = GetServiceProvider(startupAssembly);
Expand All @@ -51,7 +45,7 @@ internal static int Run(IDictionary<string, string> namedArgs)
var asyncapiOptions = serviceProvider.GetService<IOptions<AsyncApiOptions>>().Value;
var documentSerializer = serviceProvider.GetRequiredService<IAsyncApiDocumentSerializer>();

var documentNames = (namedArgs.TryGetValue(DocOption, out var doc) && !string.IsNullOrWhiteSpace(doc)) ? [doc] : asyncapiOptions.NamedApis.Keys;
var documentNames = (namedArgs.TryGetValue(DocOption, out var doc) && !string.IsNullOrWhiteSpace(doc)) ? [doc] : asyncapiOptions.NamedApis.Keys;
var fileTemplate = (namedArgs.TryGetValue(FileNameOption, out var template) && !string.IsNullOrWhiteSpace(template)) ? template : "{document}_asyncapi.{extension}";
if (documentNames.Count == 0)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Reflection;
using System.Reflection;

namespace AsyncAPI.Saunter.Generator.Cli.Internal;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Diagnostics;
using System.Reflection;

namespace Microsoft.Extensions.Hosting;
Expand Down
6 changes: 3 additions & 3 deletions src/AsyncAPI.Saunter.Generator.Cli/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ A dotnet tool to generate AsyncAPI specification files based of a dotnet DLL (Th
```
dotnet asyncapi tofile --output [output-path] --format [json,yml,yaml] --doc [asyncapi-document-name] [startup-assembly]
```
startup-assembly: the file path to the entrypoint dotnet DLL that hosts AsyncAPI document(s).
- _startup-assembly_: the file path to the entrypoint dotnet DLL that hosts AsyncAPI document(s).

## Tool options
- _--doc_: The name of the AsyncAPI document as defined in the startup class by the ```.ConfigureNamedAsyncApi()```-method. If only ```.AddAsyncApiSchemaGeneration()``` is used, the document is unnamed and will always be exported. If not specified, all documents will be exported.
- _--output_: relative path where the AsyncAPI will be output [defaults to stdout]
- _--filename_: the template for the outputted file names. Default: "{document}_asyncapi.{extension}"
- _--format_: the output formats to generate, can be a combination of json, yml and/or yaml. File extension is appended to the output path.
- _--env_: define environment variable(s) for the application
- _--format_: the output formats to generate, can be a combination of json, yml and/or yaml.
- _--env_: define environment variable(s) for the application. Formatted as a comma separated list of _key=value_ pairs or just _key_ for flags, example: ```ASPNETCORE_ENVIRONMENT=AsyncAPI,CONNECT_TO_DATABASE=false,GENERATOR_FLAG```.

## Install the Generator.Cli dotnet Tool
```
Expand Down
14 changes: 7 additions & 7 deletions src/Saunter/AsyncApiOptions.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;

using System.Collections.Generic;

using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;


using NJsonSchema;
using NJsonSchema.NewtonsoftJson.Generation;


using Saunter.AsyncApiSchema.v2;
using Saunter.Generation.Filters;
using Saunter.Generation.SchemaGeneration;
Expand Down Expand Up @@ -90,10 +90,10 @@ public void AddOperationFilter<T>() where T : IOperationFilter

public class AsyncApiSchemaOptions : NewtonsoftJsonSchemaGeneratorSettings
{
public AsyncApiSchemaOptions()
public AsyncApiSchemaOptions()
{
SchemaType = SchemaType.JsonSchema; // AsyncAPI uses json-schema, see https://github.com/tehmantra/saunter/pull/103#issuecomment-893267360
TypeNameGenerator = new CamelCaseTypeNameGenerator();
TypeNameGenerator = new CamelCaseTypeNameGenerator();
SerializerSettings = new JsonSerializerSettings()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
Expand All @@ -120,4 +120,4 @@ public class AsyncApiMiddlewareOptions
/// </summary>
public string UiTitle { get; set; } = "AsyncAPI";
}
}
}
10 changes: 5 additions & 5 deletions src/Saunter/AsyncApiServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;

using System;

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

using Microsoft.Extensions.DependencyInjection.Extensions;

using Saunter.AsyncApiSchema.v2;
using Saunter.Generation;
using Saunter.Serialization;
Expand Down Expand Up @@ -57,4 +57,4 @@ public static IServiceCollection ConfigureNamedAsyncApi(this IServiceCollection
return services;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Diagnostics;
using System.Diagnostics;
using Shouldly;
using Xunit.Abstractions;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Diagnostics;
using System.Diagnostics;
using Shouldly;
using Xunit.Abstractions;

Expand Down
Loading

0 comments on commit a746e4d

Please sign in to comment.