Skip to content

Commit

Permalink
cli: Fix some init command mistakes.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Sep 23, 2024
1 parent b5b9408 commit 57510e7
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions src/libs/AutoSDK.CLI/Commands/InitializeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class InitializeCommand : Command
name: "solution-name",
getDefaultValue: () => string.Empty,
description: "Solution name");
var apiName = new Argument<string>(
name: "api-name",
var clientName = new Argument<string>(
name: "client-name",
getDefaultValue: () => string.Empty,
description: "API client name");
var openApiSpec = new Argument<string>(
Expand All @@ -36,7 +36,7 @@ public class InitializeCommand : Command
getDefaultValue: () => true,
description: "Adds integration tests to the solution");
AddArgument(solutionName);
AddArgument(apiName);
AddArgument(clientName);
AddArgument(openApiSpec);
AddArgument(company);
AddOption(output);
Expand All @@ -46,7 +46,7 @@ public class InitializeCommand : Command
this.SetHandler(
HandleAsync,
solutionName,
apiName,
clientName,
openApiSpec,
company,
output,
Expand All @@ -56,7 +56,7 @@ public class InitializeCommand : Command

private static async Task HandleAsync(
string solutionName,
string apiName,
string clientName,
string openApiSpec,
string company,
string outputPath,
Expand Down Expand Up @@ -172,7 +172,7 @@ string Replace(string content)

newContent = newContent
.Replace("$SolutionName$", solutionName, StringComparison.OrdinalIgnoreCase)
.Replace("$ApiName$", apiName, StringComparison.OrdinalIgnoreCase)
.Replace("$ClientName$", clientName, StringComparison.OrdinalIgnoreCase)
.Replace("$OpenApiSpec$", openApiSpec, StringComparison.OrdinalIgnoreCase)
.Replace("$CurrentYear$", DateTime.Now.Year.ToString(CultureInfo.InvariantCulture), StringComparison.OrdinalIgnoreCase)
.Replace("$CompanyName$", company, StringComparison.OrdinalIgnoreCase)
Expand Down
2 changes: 1 addition & 1 deletion src/libs/AutoSDK.CLI/Resources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
```csharp
using $SolutionName$;

using var api = new $ApiName$(apiKey);
using var client = new $ClientName$(apiKey);
```

## Support
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

text = text
.Replace("openapi: 3.1.0", "openapi: 3.0.1")
.Replace("\"openapi\":\"3.1.0\"", "\"openapi\":\"3.0.1\"")
;

var openApiDocument = new OpenApiStringReader().Read(text, out var diagnostics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

code = code
.Replace(
"using var api = GetAuthenticatedApi();",
"using var api = new $ApiName$(apiKey);")
"using var client = GetAuthenticatedClient();",
"using var client = new $ClientName$(apiKey);")
;

var newPath = Path.Combine(newDir, $"{Path.GetExtension(Path.GetFileNameWithoutExtension(path)).TrimStart('.')}.md");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<PropertyGroup Label="Nuget">
<Description>Generated C# SDK based on $SolutionName$ OpenAPI specification.</Description>
<Description>C# SDK based on $SolutionName$ OpenAPI specification.</Description>
<PackageTags>api;client;sdk;dotnet;swagger;openapi;specification;generated;nswag</PackageTags>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if [ $? -ne 0 ]; then
fi
autosdk generate openapi.yaml \
--namespace $SolutionName$ \
--clientClassName $ApiName$ \
--clientClassName $ClientName$ \
--targetFramework net8.0 \
--output Generated \
--exclude-deprecated-operations
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ public partial class Tests
[TestMethod]
public async Task Generate()
{
using var api = GetAuthenticatedApi();
using var client = GetAuthenticatedClient();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ namespace $SolutionName$.IntegrationTests;
[TestClass]
public partial class Tests
{
[TestMethod]
public $ApiName$ GetAuthenticatedApi()
private static $ClientName$ GetAuthenticatedClient()
{
var apiKey =
Environment.GetEnvironmentVariable("$SolutionNameUppercase$_API_KEY") ??
throw new AssertInconclusiveException("$SolutionNameUppercase$_API_KEY environment variable is not found.");

var api = new $ApiName$(apiKey);
var client = new $ClientName$(apiKey);

return api;
return client;
}
}

0 comments on commit 57510e7

Please sign in to comment.