Skip to content

Commit

Permalink
Task: regenerate with auth info (#5914)
Browse files Browse the repository at this point in the history
  • Loading branch information
thewahome authored Jan 7, 2025
1 parent 5750029 commit c4a25c6
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/kiota/Rpc/IServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal interface IServer
Task<ManifestResult> GetManifestDetailsAsync(string manifestPath, string apiIdentifier, bool clearCache, CancellationToken cancellationToken);
Task<List<LogEntry>> GenerateAsync(string openAPIFilePath, string outputPath, GenerationLanguage language, string[] includePatterns, string[] excludePatterns, string clientClassName, string clientNamespaceName, bool usesBackingStore, bool cleanOutput, bool clearCache, bool excludeBackwardCompatible, string[] disabledValidationRules, string[] serializers, string[] deserializers, string[] structuredMimeTypes, bool includeAdditionalData, ConsumerOperation operation, CancellationToken cancellationToken);
Task<LanguagesInformation> InfoForDescriptionAsync(string descriptionPath, bool clearCache, CancellationToken cancellationToken);
Task<List<LogEntry>> GeneratePluginAsync(string openAPIFilePath, string outputPath, PluginType[] pluginTypes, string[] includePatterns, string[] excludePatterns, string clientClassName, bool cleanOutput, bool clearCache, string[] disabledValidationRules, ConsumerOperation operation, CancellationToken cancellationToken);
Task<List<LogEntry>> GeneratePluginAsync(string openAPIFilePath, string outputPath, PluginType[] pluginTypes, string[] includePatterns, string[] excludePatterns, string clientClassName, bool cleanOutput, bool clearCache, string[] disabledValidationRules, PluginAuthType? pluginAuthType, string pluginAuthRefid, ConsumerOperation operation, CancellationToken cancellationToken);
Task<List<LogEntry>> MigrateFromLockFileAsync(string lockDirectoryPath, CancellationToken cancellationToken);
Task<List<LogEntry>> RemoveClientAsync(string clientName, bool cleanOutput, CancellationToken cancellationToken);
Task<List<LogEntry>> RemovePluginAsync(string pluginName, bool cleanOutput, CancellationToken cancellationToken);
Expand Down
11 changes: 10 additions & 1 deletion src/kiota/Rpc/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ public async Task<List<LogEntry>> GenerateAsync(string openAPIFilePath, string o
}
return logger.LogEntries;
}
public async Task<List<LogEntry>> GeneratePluginAsync(string openAPIFilePath, string outputPath, PluginType[] pluginTypes, string[] includePatterns, string[] excludePatterns, string clientClassName, bool cleanOutput, bool clearCache, string[] disabledValidationRules, ConsumerOperation operation, CancellationToken cancellationToken)
public async Task<List<LogEntry>> GeneratePluginAsync(string openAPIFilePath, string outputPath, PluginType[] pluginTypes, string[] includePatterns,
string[] excludePatterns, string clientClassName, bool cleanOutput, bool clearCache, string[] disabledValidationRules,
PluginAuthType? pluginAuthType, string? pluginAuthRefid, ConsumerOperation operation, CancellationToken cancellationToken)
{
var globalLogger = new ForwardedLogger<KiotaBuilder>();
var configuration = Configuration.Generation;
Expand All @@ -206,6 +208,13 @@ public async Task<List<LogEntry>> GeneratePluginAsync(string openAPIFilePath, st
configuration.ExcludePatterns = excludePatterns.Select(static x => x.TrimQuotes()).ToHashSet(StringComparer.OrdinalIgnoreCase);
configuration.OpenAPIFilePath = GetAbsolutePath(configuration.OpenAPIFilePath);
configuration.OutputPath = NormalizeSlashesInPath(GetAbsolutePath(configuration.OutputPath));
if (!string.IsNullOrEmpty(pluginAuthRefid) && pluginAuthType != null)
{
var pluginAuthConfig = new PluginAuthConfiguration(pluginAuthRefid);
pluginAuthConfig.AuthType = pluginAuthType.Value;
configuration.PluginAuthInformation = pluginAuthConfig;
}

try
{
using var fileLogger = new FileLogLogger<KiotaBuilder>(configuration.OutputPath, LogLevel.Warning);
Expand Down
2 changes: 1 addition & 1 deletion vscode/microsoft-kiota/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"publisher": "ms-graph",
"description": "Client generator for HTTP REST APIs described by OpenAPI which helps eliminate the need to take a dependency on a different API client for every API that you need to call, as well as limiting the generation to the exact API surface area you're interested in, thanks to a filtering capability.",
"version": "1.21.100000001",
"kiotaVersion": "1.21.0",
"kiotaVersion": "1.22.0",
"telemetryInstrumentationKey": "4c6357e0-daf9-42b5-bdfb-67878f8957b5",
"icon": "images/logo.png",
"engines": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ export class GenerateClientCommand extends Command {
settings.cleanOutput,
settings.disableValidationRules,
ConsumerOperation.Add,
undefined,
'',
config.workingDirectory
);
const duration = performance.now() - start;
Expand Down Expand Up @@ -245,6 +247,8 @@ export class GenerateClientCommand extends Command {
settings.cleanOutput,
settings.disableValidationRules,
ConsumerOperation.Add,
undefined,
'',
config.workingDirectory
);
const duration = performance.now() - start;
Expand Down
19 changes: 12 additions & 7 deletions vscode/microsoft-kiota/src/commands/generate/generatePlugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as vscode from "vscode";
import * as rpc from "vscode-jsonrpc/node";

import { connectToKiota, ConsumerOperation, GenerationConfiguration, KiotaLogEntry } from "../../kiotaInterop";
import { connectToKiota, ConsumerOperation, GenerationConfiguration, KiotaLogEntry, PluginAuthType } from "../../kiotaInterop";
import { KiotaPluginType } from "../../types/enums";
import { getWorkspaceJsonDirectory } from "../../util";

Expand All @@ -16,24 +16,29 @@ export function generatePlugin(context: vscode.ExtensionContext,
cleanOutput: boolean,
disableValidationRules: string[],
operation: ConsumerOperation,
workingDirectory: string = getWorkspaceJsonDirectory()): Promise<KiotaLogEntry[] | undefined> {
pluginAuthType?: PluginAuthType | null,
pluginAuthRefid?: string,
workingDirectory: string = getWorkspaceJsonDirectory(),
): Promise<KiotaLogEntry[] | undefined> {
return connectToKiota<KiotaLogEntry[]>(context, async (connection) => {
const request = new rpc.RequestType1<GenerationConfiguration, KiotaLogEntry[], void>(
"GeneratePlugin"
);
return await connection.sendRequest(
request,
{
pluginTypes: pluginTypes,
cleanOutput: cleanOutput,
clearCache: clearCache,
clientClassName: clientClassName,
pluginTypes,
cleanOutput,
clearCache,
clientClassName,
disabledValidationRules: disableValidationRules,
excludePatterns: excludeFilters,
includePatterns: includeFilters,
openAPIFilePath: descriptionPath,
outputPath: output,
operation: operation
pluginAuthType,
pluginAuthRefid,
operation,
} as GenerationConfiguration,
);
}, workingDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ export class RegenerateService {
settings.clearCache,
false,
settings.disableValidationRules,
ConsumerOperation.Edit
ConsumerOperation.Edit,
pluginObjectItem.authType ? pluginObjectItem.authType : null,
pluginObjectItem.authReferenceId ? pluginObjectItem.authReferenceId : '',
);
const duration = performance.now() - start;
const errorsCount = result ? getLogEntriesForLevel(result, LogLevel.critical, LogLevel.error).length : 0;
Expand Down
12 changes: 11 additions & 1 deletion vscode/microsoft-kiota/src/kiotaInterop/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export async function connectToKiota<T>(context: vscode.ExtensionContext, callba
try {
return await callback(connection);
} catch (error) {
console.warn(error);
const errorMessage = (error as { data?: { message: string } })?.data?.message
|| 'An unknown error occurred';
vscode.window.showErrorMessage(errorMessage);
Expand Down Expand Up @@ -248,6 +249,13 @@ export interface GenerationConfiguration {
usesBackingStore: boolean;
pluginTypes: KiotaPluginType[];
operation: ConsumerOperation;
pluginAuthRefid?: string;
pluginAuthType?: PluginAuthType | null;
}

export enum PluginAuthType {
oAuthPluginVault = "OAuthPluginVault",
apiKeyPluginVault = "ApiKeyPluginVault"
}

interface WorkspaceObjectProperties {
Expand All @@ -269,6 +277,8 @@ export interface ClientObjectProperties extends WorkspaceObjectProperties {

export interface PluginObjectProperties extends WorkspaceObjectProperties {
types: string[];
authType?: PluginAuthType,
authReferenceId?: string;
}

export type ClientOrPluginProperties = ClientObjectProperties | PluginObjectProperties;
export type ClientOrPluginProperties = ClientObjectProperties | PluginObjectProperties;

0 comments on commit c4a25c6

Please sign in to comment.