Skip to content
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

- adds display url to the CLI experience #4655

Merged
merged 1 commit into from
May 14, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Added support for multipart form data request body in PHP. [#3029](https://github.com/microsoft/kiota/issues/3029)
- Added uri-form encoded serialization for PHP. [#2074](https://github.com/microsoft/kiota/issues/2074)
- Added information message with base URL in the CLI experience. [#4635](https://github.com/microsoft/kiota/issues/4635)

### Changed

Expand Down
3 changes: 3 additions & 0 deletions src/Kiota.Builder/KiotaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,10 @@
internal void SetApiRootUrl()
{
if (openApiDocument is not null && openApiDocument.GetAPIRootUrl(config.OpenAPIFilePath) is string candidateUrl)
{
config.ApiRootUrl = candidateUrl;
logger.LogInformation("Client root URL set to {ApiRootUrl}", candidateUrl);
}
else
logger.LogWarning("No server url found in the OpenAPI document. The base url will need to be set when using the client.");
}
Expand Down Expand Up @@ -656,7 +659,7 @@
methodToAdd.AddParameter(new CodeParameter
{
Name = "rawUrl",
Type = new CodeType { Name = "string", IsExternal = true },

Check warning on line 662 in src/Kiota.Builder/KiotaBuilder.cs

View workflow job for this annotation

GitHub Actions / Build

Define a constant instead of using this literal 'string' 19 times. (https://rules.sonarsource.com/csharp/RSPEC-1192)
Optional = false,
Documentation = new()
{
Expand Down Expand Up @@ -770,7 +773,7 @@
IsAsync = false,
IsStatic = false,
Documentation = new(new() {
{"TypeName", new CodeType {

Check warning on line 776 in src/Kiota.Builder/KiotaBuilder.cs

View workflow job for this annotation

GitHub Actions / Build

Define a constant instead of using this literal 'TypeName' 5 times. (https://rules.sonarsource.com/csharp/RSPEC-1192)
IsExternal = false,
TypeDefinition = currentClass,
}
Expand Down Expand Up @@ -1012,7 +1015,7 @@

if (!"string".Equals(parameter.Type.Name, StringComparison.OrdinalIgnoreCase) && config.IncludeBackwardCompatible)
{ // adding a second indexer for the string version of the parameter so we keep backward compatibility
//TODO remove for v2

Check warning on line 1018 in src/Kiota.Builder/KiotaBuilder.cs

View workflow job for this annotation

GitHub Actions / Build

Complete the task associated to this 'TODO' comment. (https://rules.sonarsource.com/csharp/RSPEC-1135)
var backCompatibleValue = (CodeIndexer)result[0].Clone();
backCompatibleValue.Name += "-string";
backCompatibleValue.IndexParameter.Type = DefaultIndexerParameterType;
Expand Down Expand Up @@ -1086,15 +1089,15 @@
var primitiveTypeName = (typeName?.ToLowerInvariant(), format?.ToLowerInvariant()) switch
{
("string", "base64url") => "base64url",
("file", _) => "binary",

Check warning on line 1092 in src/Kiota.Builder/KiotaBuilder.cs

View workflow job for this annotation

GitHub Actions / Build

Define a constant instead of using this literal 'binary' 6 times. (https://rules.sonarsource.com/csharp/RSPEC-1192)
("string", "duration") => "TimeSpan",
("string", "time") => "TimeOnly",
("string", "date") => "DateOnly",
("string", "date-time") => "DateTimeOffset",
("string", "uuid") => "Guid",
("string", _) => "string", // covers commonmark and html
("number", "double" or "float" or "decimal") => format.ToLowerInvariant(),

Check warning on line 1099 in src/Kiota.Builder/KiotaBuilder.cs

View workflow job for this annotation

GitHub Actions / Build

Define a constant instead of using this literal 'number' 6 times. (https://rules.sonarsource.com/csharp/RSPEC-1192)
("number" or "integer", "int8") => "sbyte",

Check warning on line 1100 in src/Kiota.Builder/KiotaBuilder.cs

View workflow job for this annotation

GitHub Actions / Build

Define a constant instead of using this literal 'integer' 6 times. (https://rules.sonarsource.com/csharp/RSPEC-1192)
("number" or "integer", "uint8") => "byte",
("number" or "integer", "int64") => "int64",
("number", "int32") => "integer",
Expand Down Expand Up @@ -1166,7 +1169,7 @@
var suffix = $"{operationType}Response";
var modelType = CreateModelDeclarations(currentNode, schema, operation, parentClass, suffix);
if (modelType is not null && config.IncludeBackwardCompatible && config.Language is GenerationLanguage.CSharp or GenerationLanguage.Go && modelType.Name.EndsWith(suffix, StringComparison.Ordinal))
{ //TODO remove for v2

Check warning on line 1172 in src/Kiota.Builder/KiotaBuilder.cs

View workflow job for this annotation

GitHub Actions / Build

Complete the task associated to this 'TODO' comment. (https://rules.sonarsource.com/csharp/RSPEC-1135)
var obsoleteTypeName = modelType.Name[..^suffix.Length] + "Response";
if (modelType is CodeType codeType &&
codeType.TypeDefinition is CodeClass codeClass)
Expand Down Expand Up @@ -1299,7 +1302,7 @@
executorMethod.AddParameter(cancellationParam);// Add cancellation token parameter

if (returnTypes.Item2 is not null && config.IncludeBackwardCompatible)
{ //TODO remove for v2

Check warning on line 1305 in src/Kiota.Builder/KiotaBuilder.cs

View workflow job for this annotation

GitHub Actions / Build

Complete the task associated to this 'TODO' comment. (https://rules.sonarsource.com/csharp/RSPEC-1135)
var additionalExecutorMethod = (CodeMethod)executorMethod.Clone();
additionalExecutorMethod.ReturnType = returnTypes.Item2;
additionalExecutorMethod.OriginalMethod = executorMethod;
Expand Down Expand Up @@ -2309,7 +2312,7 @@
if (!parameterClass.ContainsPropertyWithWireName(prop.WireName))
{
if (addBackwardCompatibleParameter && config.IncludeBackwardCompatible && config.Language is GenerationLanguage.CSharp or GenerationLanguage.Go)
{ //TODO remove for v2

Check warning on line 2315 in src/Kiota.Builder/KiotaBuilder.cs

View workflow job for this annotation

GitHub Actions / Build

Complete the task associated to this 'TODO' comment. (https://rules.sonarsource.com/csharp/RSPEC-1135)
var modernProp = (CodeProperty)prop.Clone();
modernProp.Name = $"{prop.Name}As{modernProp.Type.Name.ToFirstCharacterUpperCase()}";
modernProp.SerializationName = prop.WireName;
Expand Down
5 changes: 5 additions & 0 deletions src/kiota/Handlers/BaseKiotaCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ private static string GetSourceArg(string path, string manifest)
{
return string.IsNullOrEmpty(manifest) ? $"-d \"{path}\"" : $"-a \"{manifest}\"";
}
protected void DisplayUrlInformation(string? apiRootUrl, bool isPlugin = false)
{
if (!string.IsNullOrEmpty(apiRootUrl))
DisplayInfo($"{(isPlugin ? "Plugin" : "Client")} base url set to {apiRootUrl}");
}
protected void DisplayGenerateCommandHint()
{
DisplayHint("Hint: use the client generate command to generate the code.",
Expand Down
3 changes: 3 additions & 0 deletions src/kiota/Handlers/Client/AddHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ public override async Task<int> InvokeAsync(InvocationContext context)
var builder = new KiotaBuilder(logger, Configuration.Generation, httpClient, true);
var result = await builder.GenerateClientAsync(cancellationToken).ConfigureAwait(false);
if (result)
{
DisplaySuccess("Generation completed successfully");
DisplayUrlInformation(Configuration.Generation.ApiRootUrl);
}
else if (skipGeneration)
{
DisplaySuccess("Generation skipped as --skip-generation was passed");
Expand Down
3 changes: 3 additions & 0 deletions src/kiota/Handlers/Client/EditHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ public override async Task<int> InvokeAsync(InvocationContext context)
var builder = new KiotaBuilder(logger, Configuration.Generation, httpClient, true);
var result = await builder.GenerateClientAsync(cancellationToken).ConfigureAwait(false);
if (result)
{
DisplaySuccess("Generation completed successfully");
DisplayUrlInformation(Configuration.Generation.ApiRootUrl);
}
else if (skipGeneration)
{
DisplaySuccess("Generation skipped as --skip-generation was passed");
Expand Down
1 change: 1 addition & 0 deletions src/kiota/Handlers/Client/GenerateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public override async Task<int> InvokeAsync(InvocationContext context)
if (result)
{
DisplaySuccess($"Update of {clientEntry.Key} client completed");
DisplayUrlInformation(generationConfiguration.ApiRootUrl);
var manifestPath = $"{GetAbsolutePath(Path.Combine(WorkspaceConfigurationStorageService.KiotaDirectorySegment, WorkspaceConfigurationStorageService.ManifestFileName))}#{clientEntry.Key}";
DisplayInfoHint(generationConfiguration.Language, string.Empty, manifestPath);
}
Expand Down
3 changes: 3 additions & 0 deletions src/kiota/Handlers/KiotaGenerateCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ public override async Task<int> InvokeAsync(InvocationContext context)
var builder = new KiotaBuilder(logger, Configuration.Generation, httpClient);
var result = await builder.GenerateClientAsync(cancellationToken).ConfigureAwait(false);
if (result)
{
DisplaySuccess("Generation completed successfully");
DisplayUrlInformation(Configuration.Generation.ApiRootUrl);
}
else
{
DisplaySuccess("Generation skipped as no changes were detected");
Expand Down
3 changes: 3 additions & 0 deletions src/kiota/Handlers/KiotaUpdateCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ public override async Task<int> InvokeAsync(InvocationContext context)
var results = await Task.WhenAll(configurations
.Select(x => GenerateClientAsync(context, x, cancellationToken)));
foreach (var (lockInfo, lockDirectoryPath) in locks)
{
DisplaySuccess($"Update of {lockInfo?.ClientClassName} client for {lockInfo?.Language} at {lockDirectoryPath} completed");
DisplayUrlInformation(configurations.FirstOrDefault(x => lockDirectoryPath.Equals(x.OutputPath, StringComparison.OrdinalIgnoreCase))?.ApiRootUrl);
}
DisplaySuccess($"Update of {locks.Length} clients completed successfully");
foreach (var configuration in configurations)
DisplayInfoHint(configuration.Language, configuration.OpenAPIFilePath, string.Empty);
Expand Down
3 changes: 3 additions & 0 deletions src/kiota/Handlers/Plugin/AddHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ public override async Task<int> InvokeAsync(InvocationContext context)
var builder = new KiotaBuilder(logger, Configuration.Generation, httpClient, true);
var result = await builder.GeneratePluginAsync(cancellationToken).ConfigureAwait(false);
if (result)
{
DisplaySuccess("Generation completed successfully");
DisplayUrlInformation(Configuration.Generation.ApiRootUrl);
}
else if (skipGeneration)
{
DisplaySuccess("Generation skipped as --skip-generation was passed");
Expand Down
3 changes: 3 additions & 0 deletions src/kiota/Handlers/Plugin/EditHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ public override async Task<int> InvokeAsync(InvocationContext context)
var builder = new KiotaBuilder(logger, Configuration.Generation, httpClient, true);
var result = await builder.GeneratePluginAsync(cancellationToken).ConfigureAwait(false);
if (result)
{
DisplaySuccess("Generation completed successfully");
DisplayUrlInformation(Configuration.Generation.ApiRootUrl);
}
else if (skipGeneration)
{
DisplaySuccess("Generation skipped as --skip-generation was passed");
Expand Down
Loading