CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-microsoft-azure--autorest-core

AutoRest core module that generates client libraries for accessing RESTful web services from OpenAPI specifications.

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

autorest-generator.mddocs/

AutoRest Generator

The AutoRest class is the main generator instance that orchestrates the entire code generation process. It provides event-driven architecture, configuration management, and coordinates with the processing pipeline to transform OpenAPI specifications into client libraries.

Capabilities

AutoRest Class

Main generator instance that manages the complete code generation workflow.

/**
 * An instance of the AutoRest generator that coordinates the entire code generation process
 */
class AutoRest {
  /**
   * Creates a new AutoRest instance
   * @param fileSystem - The implementation of the filesystem to load and save files (defaults to RealFileSystem)
   * @param configFileOrFolderUri - The URI of the configuration file or folder containing the configuration file
   */
  constructor(fileSystem?: IFileSystem, configFileOrFolderUri?: string);

  /**
   * Gets the current configuration view (creates one if none exists)
   */
  readonly view: Promise<ConfigurationView>;

  /**
   * Adds configuration to the current configuration stack
   * @param configuration - Configuration object to add
   */
  AddConfiguration(configuration: any): void;

  /**
   * Resets all configurations to empty state
   */
  ResetConfiguration(): Promise<void>;

  /**
   * Starts the processing of OpenAPI specifications
   * @returns Object with finish promise and cancel function
   */
  Process(): { finish: Promise<boolean | Error>, cancel: () => void };

  /**
   * Regenerates the configuration view
   * @param includeDefault - Whether to include default configuration
   */
  RegenerateView(includeDefault?: boolean): Promise<ConfigurationView>;

  /**
   * Invalidates the current configuration view
   */
  Invalidate(): void;
}

Usage Examples:

import { AutoRest, RealFileSystem } from "@microsoft.azure/autorest-core";

// Create with default file system
const autorest = new AutoRest();

// Create with custom file system and config
const autorest2 = new AutoRest(
  new RealFileSystem(), 
  "./my-config/autorest.json"
);

// Add configuration programmatically
autorest.AddConfiguration({
  "input-file": ["swagger.json", "swagger2.json"],
  "output-folder": "./generated",
  "client-name": "MyServiceClient",
  "namespace": "MyCompany.Services"
});

// Reset configuration
await autorest.ResetConfiguration();

// Get current configuration view
const view = await autorest.view;

Event System

AutoRest provides event-driven communication for monitoring and handling the generation process.

/**
 * Event: Signals when a Process() finishes
 */
Finished: IEvent<AutoRest, boolean | Error>;

/**
 * Event: Signals when a File is generated  
 */
GeneratedFile: IEvent<AutoRest, Artifact>;

/**
 * Event: Signals when a Folder is supposed to be cleared
 */
ClearFolder: IEvent<AutoRest, string>;

/**
 * Event: Signals when a message is generated
 */
Message: IEvent<AutoRest, Message>;

Usage Examples:

import { AutoRest, Channel } from "@microsoft.azure/autorest-core";

const autorest = new AutoRest();

// Listen for generated files
autorest.GeneratedFile.Subscribe((sender, artifact) => {
  console.log(`Generated file: ${artifact.uri}`);
  console.log(`File type: ${artifact.type}`);
  console.log(`Content length: ${artifact.content.length}`);
});

// Listen for messages
autorest.Message.Subscribe((sender, message) => {
  switch (message.Channel) {
    case Channel.Error:
      console.error(`Error: ${message.Text}`);
      break;
    case Channel.Warning:
      console.warn(`Warning: ${message.Text}`);
      break;
    case Channel.Information:
      console.log(`Info: ${message.Text}`);
      break;
  }
});

// Listen for folder clearing
autorest.ClearFolder.Subscribe((sender, folderPath) => {
  console.log(`Clearing folder: ${folderPath}`);
});

// Listen for completion
autorest.Finished.Subscribe((sender, result) => {
  if (result instanceof Error) {
    console.error("Generation failed:", result);
  } else {
    console.log("Generation completed successfully");
  }
});

Process Control

Control the generation process with cancellation support.

/**
 * Result of starting a generation process
 */
interface ProcessResult {
  /** Promise that resolves when processing completes */
  finish: Promise<boolean | Error>;
  /** Function to cancel the ongoing process */
  cancel: () => void;
}

Usage Examples:

const autorest = new AutoRest();

// Configure input
autorest.AddConfiguration({
  "input-file": "large-api.json",
  "output-folder": "./output"
});

// Start processing
const { finish, cancel } = autorest.Process();

// Set up timeout cancellation
const timeout = setTimeout(() => {
  console.log("Cancelling due to timeout");
  cancel();
}, 30000); // 30 second timeout

try {
  const result = await finish;
  clearTimeout(timeout);
  
  if (result instanceof Error) {
    console.error("Generation failed:", result.message);
  } else {
    console.log("Generation successful");
  }
} catch (error) {
  console.error("Process error:", error);
}

Types

interface IEvent<TSender, TArgs> {
  Subscribe(fn: (sender: TSender, args: TArgs) => void): void;
  Unsubscribe(fn: (sender: TSender, args: TArgs) => void): void;
  Dispatch(args: TArgs): void;
}

docs

autorest-generator.md

configuration.md

document-processing.md

file-system.md

index.md

messaging.md

tile.json