Skip to content

Commit

Permalink
Merge branch 'main' into fix/go-cyclic-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
rkodev authored Oct 4, 2024
2 parents 5ae1a76 + a62abf6 commit c220c4e
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 71 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

### Changed

## [1.19.0] - 2024-10-03

### Added

- Control generated type access modifier for C# via `--type-access-modifier` flag. [#4788](https://github.com/microsoft/kiota/issues/4788)

### Changed
Expand Down Expand Up @@ -1463,3 +1469,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Initial GitHub release

4 changes: 2 additions & 2 deletions specs/schemas/workspace.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "<http://json-schema.org/draft-07/schema#>",
"$schema": "https://json-schema.org/2020-12/schema",
"type": "object",
"properties": {
"version": {
Expand Down Expand Up @@ -104,4 +104,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Kiota.Builder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<Title>Microsoft.OpenApi.Kiota.Builder</Title>
<PackageId>Microsoft.OpenApi.Kiota.Builder</PackageId>
<PackageOutputPath>./nupkg</PackageOutputPath>
<VersionPrefix>1.19.0</VersionPrefix>
<VersionPrefix>1.20.0</VersionPrefix>
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
<PackageReleaseNotes>
https://github.com/microsoft/kiota/releases
Expand Down
2 changes: 1 addition & 1 deletion src/kiota/kiota.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<Title>Microsoft.OpenApi.Kiota</Title>
<PackageId>Microsoft.OpenApi.Kiota</PackageId>
<PackageOutputPath>./nupkg</PackageOutputPath>
<VersionPrefix>1.19.0</VersionPrefix>
<VersionPrefix>1.20.0</VersionPrefix>
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
<PackageReleaseNotes>
https://github.com/microsoft/kiota/releases
Expand Down
3 changes: 3 additions & 0 deletions vscode/microsoft-kiota/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ All notable changes to this project will be documented in this file.

### Changed

## [1.19.100000001] - 2024-10-03

## [1.19.24092002] - 2024-09-20

### Changed
Expand All @@ -25,4 +27,5 @@ All notable changes to this project will be documented in this file.
- Bug fixes

### Changed

- Kiota extension logo [#5399](https://github.com/microsoft/kiota/issues/5399)
30 changes: 30 additions & 0 deletions vscode/microsoft-kiota/src/commands/editPathsCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { extensionId, treeViewId } from "../constants";
import { ClientOrPluginProperties } from "../kiotaInterop";
import { OpenApiTreeProvider } from "../openApiTreeProvider";
import { updateTreeViewIcons } from "../util";
import { openTreeViewWithProgress } from "../utilities/progress";
import { Command } from "./Command";

export class EditPathsCommand extends Command {

private _openApiTreeProvider: OpenApiTreeProvider;

public constructor(openApiTreeProvider: OpenApiTreeProvider) {
super();
this._openApiTreeProvider = openApiTreeProvider;
}

public getName(): string {
return `${extensionId}.editPaths`;
}

public async execute({ clientKey, clientObject }: { clientKey: string, clientObject: ClientOrPluginProperties }): Promise<void> {
await this.loadEditPaths(clientKey, clientObject);
this._openApiTreeProvider.resetInitialState();
await updateTreeViewIcons(treeViewId, false, true);
}

private async loadEditPaths(clientKey: string, clientObject: ClientOrPluginProperties) {
await openTreeViewWithProgress(() => this._openApiTreeProvider.loadEditPaths(clientKey, clientObject));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { connectToKiota, KiotaSearchResult, KiotaSearchResultItem } from "./kiotaInterop";
import * as rpc from "vscode-jsonrpc/node";
import * as vscode from "vscode";

import { KiotaSearchResultItem, connectToKiota, KiotaSearchResult } from "../../../kiotaInterop";

export function searchDescription(context: vscode.ExtensionContext, searchTerm: string, clearCache: boolean): Promise<Record<string, KiotaSearchResultItem> | undefined> {
return connectToKiota<Record<string, KiotaSearchResultItem>>(context, async (connection) => {
const request = new rpc.RequestType2<string, boolean, KiotaSearchResult, void>(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import TelemetryReporter from "@vscode/extension-telemetry";
import * as vscode from "vscode";

import { extensionId, treeViewId } from "../../../constants";
import { getExtensionSettings } from "../../../extensionSettings";
import { setDeepLinkParams } from "../../../handlers/deepLinkParamsHandler";
import { OpenApiTreeProvider } from "../../../openApiTreeProvider";
import { searchSteps } from "../../../steps";
import { IntegrationParams, validateDeepLinkQueryParams } from "../../../utilities/deep-linking";
import { Command } from "../../Command";
import { searchDescription } from "./searchDescription";
import { openTreeViewWithProgress } from "../../../utilities/progress";

export class SearchOrOpenApiDescriptionCommand extends Command {

private _openApiTreeProvider: OpenApiTreeProvider;
private _context: vscode.ExtensionContext;

constructor(openApiTreeProvider: OpenApiTreeProvider, context: vscode.ExtensionContext) {
super();
this._openApiTreeProvider = openApiTreeProvider;
this._context = context;
}

public getName(): string {
return `${treeViewId}.searchOrOpenApiDescription`;
}

public async execute(searchParams: Partial<IntegrationParams>): Promise<void> {
// set deeplink params if exists
if (Object.keys(searchParams).length > 0) {
let [params, errorsArray] = validateDeepLinkQueryParams(searchParams);
setDeepLinkParams(params);
const reporter = new TelemetryReporter(this._context.extension.packageJSON.telemetryInstrumentationKey);
reporter.sendTelemetryEvent("DeepLinked searchOrOpenApiDescription", {
"searchParameters": JSON.stringify(searchParams),
"validationErrors": errorsArray.join(", ")
});
}

// proceed to enable loading of openapi description
const yesAnswer = vscode.l10n.t("Yes, override it");
if (this._openApiTreeProvider.hasChanges()) {
const response = await vscode.window.showWarningMessage(
vscode.l10n.t(
"Before adding a new API description, consider that your changes and current selection will be lost."),
yesAnswer,
vscode.l10n.t("Cancel")
);
if (response !== yesAnswer) {
return;
}
}

const config = await searchSteps(x => vscode.window.withProgress({
location: vscode.ProgressLocation.Notification,
cancellable: false,
title: vscode.l10n.t("Searching...")
}, (progress, _) => {
const settings = getExtensionSettings(extensionId);
return searchDescription(this._context, x, settings.clearCache);
}));

if (config.descriptionPath) {
await openTreeViewWithProgress(() => this._openApiTreeProvider.setDescriptionUrl(config.descriptionPath!));
}
}
}
91 changes: 25 additions & 66 deletions vscode/microsoft-kiota/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import * as path from 'path';
import * as vscode from "vscode";

import { CodeLensProvider } from "./codelensProvider";
import { EditPathsCommand } from './commands/editPathsCommand';
import { MigrateFromLockFileCommand } from './commands/migrateFromLockFileCommand';
import { AddAllToSelectedEndpointsCommand } from './commands/open-api-tree-view/addAllToSelectedEndpointsCommand';
import { AddToSelectedEndpointsCommand } from './commands/open-api-tree-view/addToSelectedEndpointsCommand';
import { FilterDescriptionCommand } from './commands/open-api-tree-view/filterDescriptionCommand';
import { OpenDocumentationPageCommand } from './commands/open-api-tree-view/openDocumentationPageCommand';
import { RemoveAllFromSelectedEndpointsCommand } from './commands/open-api-tree-view/removeAllFromSelectedEndpointsCommand';
import { RemoveFromSelectedEndpointsCommand } from './commands/open-api-tree-view/removeFromSelectedEndpointsCommand';
import { SearchOrOpenApiDescriptionCommand } from './commands/open-api-tree-view/search-or-open-api-description/searchOrOpenApiDescriptionCommand';
import { KIOTA_WORKSPACE_FILE, dependenciesInfo, extensionId, statusBarCommandId, treeViewFocusCommand, treeViewId } from "./constants";
import { DependenciesViewProvider } from "./dependenciesViewProvider";
import { GenerationType, KiotaGenerationLanguage, KiotaPluginType } from "./enums";
Expand All @@ -21,6 +23,7 @@ import { generateClient } from "./generateClient";
import { generatePlugin } from "./generatePlugin";
import { getKiotaVersion } from "./getKiotaVersion";
import { getLanguageInformation, getLanguageInformationForDescription } from "./getLanguageInformation";
import { clearDeepLinkParams, getDeepLinkParams, setDeepLinkParams } from './handlers/deepLinkParamsHandler';
import {
ClientOrPluginProperties,
ConsumerOperation,
Expand All @@ -31,15 +34,15 @@ import {
} from "./kiotaInterop";
import { checkForLockFileAndPrompt } from "./migrateFromLockFile";
import { OpenApiTreeNode, OpenApiTreeProvider } from "./openApiTreeProvider";
import { searchDescription } from "./searchDescription";
import { GenerateState, generateSteps, searchSteps } from "./steps";
import { GenerateState, generateSteps } from "./steps";
import { updateClients } from "./updateClients";
import {
getSanitizedString, getWorkspaceJsonDirectory, getWorkspaceJsonPath,
isClientType, isPluginType, parseGenerationLanguage,
parseGenerationType, parsePluginType, updateTreeViewIcons
} from "./util";
import { IntegrationParams, isDeeplinkEnabled, transformToGenerationConfig, validateDeepLinkQueryParams } from './utilities/deep-linking';
import { openTreeViewWithProgress } from './utilities/progress';
import { confirmOverride } from './utilities/regeneration';
import { loadTreeView } from "./workspaceTreeProvider";

Expand Down Expand Up @@ -75,11 +78,12 @@ export async function activate(
const removeFromSelectedEndpointsCommand = new RemoveFromSelectedEndpointsCommand(openApiTreeProvider);
const filterDescriptionCommand = new FilterDescriptionCommand(openApiTreeProvider);
const openDocumentationPageCommand = new OpenDocumentationPageCommand();
const editPathsCommand = new EditPathsCommand(openApiTreeProvider);
const searchOrOpenApiDescriptionCommand = new SearchOrOpenApiDescriptionCommand(openApiTreeProvider, context);

await loadTreeView(context);
await checkForLockFileAndPrompt(context);
let codeLensProvider = new CodeLensProvider();
let deepLinkParams: Partial<IntegrationParams> = {};
context.subscriptions.push(
vscode.window.registerUriHandler({
handleUri: async (uri: vscode.Uri) => {
Expand All @@ -88,13 +92,14 @@ export async function activate(
}
const queryParameters = getQueryParameters(uri);
if (uri.path.toLowerCase() === "/opendescription") {
let errorsArray: string[];
[deepLinkParams, errorsArray] = validateDeepLinkQueryParams(queryParameters);
let [params, errorsArray] = validateDeepLinkQueryParams(queryParameters);
setDeepLinkParams(params);
reporter.sendTelemetryEvent("DeepLink.OpenDescription initialization status", {
"queryParameters": JSON.stringify(queryParameters),
"validationErrors": errorsArray.join(", ")
});

let deepLinkParams = getDeepLinkParams();
if (deepLinkParams.descriptionurl) {
await openTreeViewWithProgress(() => openApiTreeProvider.setDescriptionUrl(deepLinkParams.descriptionurl!));
return;
Expand Down Expand Up @@ -137,6 +142,7 @@ export async function activate(
registerCommandWithTelemetry(reporter,
`${treeViewId}.generateClient`,
async () => {
const deepLinkParams = getDeepLinkParams();
const selectedPaths = openApiTreeProvider.getSelectedPaths();
if (selectedPaths.length === 0) {
await vscode.window.showErrorMessage(
Expand Down Expand Up @@ -234,7 +240,7 @@ export async function activate(
}
}

deepLinkParams = {}; // Clear the state after the generation
clearDeepLinkParams(); // Clear the state after the generation
}
}
),
Expand All @@ -247,47 +253,8 @@ export async function activate(
void context.workspaceState.update('generatedOutput', undefined);
}
}),
registerCommandWithTelemetry(
reporter,
`${treeViewId}.searchOrOpenApiDescription`,
async (
searchParams: Partial<IntegrationParams> = {}
) => {
// set deeplink params if exists
if (Object.keys(searchParams).length > 0) {
let errorsArray: string[];
[deepLinkParams, errorsArray] = validateDeepLinkQueryParams(searchParams);
reporter.sendTelemetryEvent("DeepLinked searchOrOpenApiDescription", {
"searchParameters": JSON.stringify(searchParams),
"validationErrors": errorsArray.join(", ")
});
}

// proceed to enable loading of openapi description
const yesAnswer = vscode.l10n.t("Yes, override it");
if (!openApiTreeProvider.isEmpty() && openApiTreeProvider.hasChanges()) {
const response = await vscode.window.showWarningMessage(
vscode.l10n.t(
"Before adding a new API description, consider that your changes and current selection will be lost."),
yesAnswer,
vscode.l10n.t("Cancel")
);
if (response !== yesAnswer) {
return;
}
}
const config = await searchSteps(x => vscode.window.withProgress({
location: vscode.ProgressLocation.Notification,
cancellable: false,
title: vscode.l10n.t("Searching...")
}, (progress, _) => {
const settings = getExtensionSettings(extensionId);
return searchDescription(context, x, settings.clearCache);
}));
if (config.descriptionPath) {
await openTreeViewWithProgress(() => openApiTreeProvider.setDescriptionUrl(config.descriptionPath!));
}
}
registerCommandWithTelemetry(reporter, searchOrOpenApiDescriptionCommand.getName(),
async (searchParams: Partial<IntegrationParams> = {}) => await searchOrOpenApiDescriptionCommand.execute(searchParams)
),
registerCommandWithTelemetry(reporter, `${treeViewId}.closeDescription`, async () => {
const yesAnswer = vscode.l10n.t("Yes");
Expand All @@ -303,15 +270,13 @@ export async function activate(
}
),
registerCommandWithTelemetry(reporter, filterDescriptionCommand.getName(), async () => await filterDescriptionCommand.execute()),

registerCommandWithTelemetry(reporter, `${extensionId}.editPaths`, async (clientKey: string, clientObject: ClientOrPluginProperties, generationType: string) => {
registerCommandWithTelemetry(reporter, editPathsCommand.getName(), async (clientKey: string, clientObject: ClientOrPluginProperties, generationType: string) => {
clientOrPluginKey = clientKey;
clientOrPluginObject = clientObject;
workspaceGenerationType = generationType;
await loadEditPaths(clientOrPluginKey, clientObject, openApiTreeProvider);
openApiTreeProvider.resetInitialState();
await updateTreeViewIcons(treeViewId, false, true);
await editPathsCommand.execute({ clientKey, clientObject });
}),

registerCommandWithTelemetry(reporter, `${treeViewId}.regenerateButton`, async () => {
const regenerate = await confirmOverride();
if (!regenerate) {
Expand Down Expand Up @@ -449,6 +414,7 @@ export async function activate(
if (!isSuccess) {
await exportLogsAndShowErrors(result);
}
const deepLinkParams = getDeepLinkParams();
const isttkIntegration = deepLinkParams.source && deepLinkParams.source.toLowerCase() === 'ttk';
if (!isttkIntegration) {
void vscode.window.showInformationMessage(vscode.l10n.t('Plugin generated successfully.'));
Expand Down Expand Up @@ -675,17 +641,7 @@ export async function activate(

context.subscriptions.push(disposable);
}
function openTreeViewWithProgress<T>(callback: () => Promise<T>): Thenable<T> {
return vscode.window.withProgress({
location: vscode.ProgressLocation.Notification,
cancellable: false,
title: vscode.l10n.t("Loading...")
}, async (progress, _) => {
const result = await callback();
await vscode.commands.executeCommand(treeViewFocusCommand);
return result;
});
}

function registerCommandWithTelemetry(reporter: TelemetryReporter, command: string, callback: (...args: any[]) => any, thisArg?: any): vscode.Disposable {
return vscode.commands.registerCommand(command, (...args: any[]) => {
const splatCommand = command.split('/');
Expand All @@ -703,9 +659,12 @@ async function showUpgradeWarningMessage(clientPath: string, context: vscode.Ext
}
const workspaceFileData = await vscode.workspace.fs.readFile(vscode.Uri.file(workspaceFilePath));
const workspaceFile = JSON.parse(workspaceFileData.toString()) as { kiotaVersion: string };
const clientVersion = workspaceFile.kiotaVersion.toLocaleLowerCase();
if (clientVersion.toLocaleLowerCase() !== kiotaVersion) {
await vscode.window.showWarningMessage(vscode.l10n.t("Client will be upgraded from version {0} to {1}, upgrade your dependencies", clientVersion, kiotaVersion));
// don't fail if kiotaVersion isn't in the workspace config file
if (workspaceFile.kiotaVersion) {
const clientVersion = workspaceFile.kiotaVersion.toLocaleLowerCase();
if (clientVersion !== kiotaVersion) {
await vscode.window.showWarningMessage(vscode.l10n.t("Client will be upgraded from version {0} to {1}, upgrade your dependencies", clientVersion, kiotaVersion));
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions vscode/microsoft-kiota/src/handlers/deepLinkParamsHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { IntegrationParams } from "../utilities/deep-linking";

let deepLinkParams: Partial<IntegrationParams> = {};

export const getDeepLinkParams = () => deepLinkParams;
export const setDeepLinkParams = (params: Partial<IntegrationParams>) => {
deepLinkParams = { ...deepLinkParams, ...params };
};
export const clearDeepLinkParams = () => {
deepLinkParams = {};
};
Loading

0 comments on commit c220c4e

Please sign in to comment.