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

file-system.mddocs/

File System Operations

AutoRest Core provides a pluggable file system abstraction that supports different environments and use cases. This includes real file system access, in-memory operations for testing, and enhanced GitHub integration with authentication.

Capabilities

File System Interface

Base interface that all file system implementations must provide.

/**
 * Interface for file system operations used by AutoRest
 */
interface IFileSystem {
  /**
   * Enumerates all file URIs in a given folder
   * @param folderUri - URI of the folder to enumerate
   * @returns Promise resolving to array of file URIs
   */
  EnumerateFileUris(folderUri: string): Promise<Array<string>>;

  /**
   * Reads the content of a file
   * @param uri - URI of the file to read
   * @returns Promise resolving to file content as string
   */
  ReadFile(uri: string): Promise<string>;
}

Real File System

Implementation for accessing the actual file system of the host machine.

/**
 * Real file system implementation for accessing actual files
 */
class RealFileSystem implements IFileSystem {
  /**
   * Creates a new RealFileSystem instance
   */
  constructor();

  /**
   * Enumerates file URIs in a folder, filtering for configuration files
   * @param folderUri - URI of the folder to enumerate
   * @returns Promise resolving to array of file URIs
   */
  EnumerateFileUris(folderUri: string): Promise<string[]>;

  /**
   * Reads content from a file URI
   * @param uri - URI of the file to read
   * @returns Promise resolving to file content
   */
  ReadFile(uri: string): Promise<string>;

  /**
   * Writes content to a file URI
   * @param uri - URI of the file to write
   * @param content - Content to write
   * @returns Promise that resolves when write completes
   */
  WriteFile(uri: string, content: string): Promise<void>;
}

Usage Examples:

import { RealFileSystem } from "@microsoft.azure/autorest-core/lib/file-system";

const fs = new RealFileSystem();

// Read a configuration file
const config = await fs.ReadFile("file:///path/to/autorest.json");
console.log("Config:", JSON.parse(config));

// List files in a directory
const files = await fs.EnumerateFileUris("file:///path/to/specs/");
console.log("Spec files:", files);

// Write generated output
await fs.WriteFile(
  "file:///output/generated-client.ts", 
  "// Generated client code here"
);

Memory File System

In-memory file system implementation useful for testing and scenarios where file operations should not touch the actual file system.

/**
 * In-memory file system implementation for testing and isolated operations
 */
class MemoryFileSystem implements IFileSystem {
  /** Default virtual root URI for memory file system */
  static readonly DefaultVirtualRootUri: string = "file:///";

  /**
   * Creates a new MemoryFileSystem with initial files
   * @param files - Map of relative paths to file contents
   */
  constructor(files: Map<string, string>);

  /**
   * Output files written during processing
   */
  readonly Outputs: Map<string, string>;

  /**
   * Reads content from a memory file
   * @param uri - URI of the file to read
   * @returns Promise resolving to file content
   * @throws Error if file doesn't exist
   */
  ReadFile(uri: string): Promise<string>;

  /**
   * Enumerates files in a virtual folder
   * @param folderUri - URI of the folder (defaults to root)
   * @returns Promise resolving to array of file URIs
   */
  EnumerateFileUris(folderUri?: string): Promise<Array<string>>;

  /**
   * Writes content to memory (stored in Outputs map)
   * @param uri - URI of the file to write
   * @param content - Content to write
   * @returns Promise that resolves when write completes
   */
  WriteFile(uri: string, content: string): Promise<void>;
}

Usage Examples:

import { MemoryFileSystem } from "@microsoft.azure/autorest-core/lib/file-system";

// Create with initial files
const initialFiles = new Map([
  ["swagger.json", JSON.stringify({ swagger: "2.0", info: { title: "Test API" } })],
  ["config.json", JSON.stringify({ "output-folder": "./generated" })]
]);

const memFs = new MemoryFileSystem(initialFiles);

// Read existing file
const swagger = await memFs.ReadFile("file:///swagger.json");
console.log("Swagger spec:", JSON.parse(swagger));

// List all files  
const files = await memFs.EnumerateFileUris();
console.log("Available files:", files);

// Write new file (goes to Outputs)
await memFs.WriteFile("file:///generated/client.ts", "export class ApiClient {}");

// Check outputs
console.log("Generated files:", Array.from(memFs.Outputs.keys()));
console.log("Client content:", memFs.Outputs.get("file:///generated/client.ts"));

Enhanced File System

Enhanced file system with GitHub integration and authentication support.

/**
 * Enhanced file system with GitHub URI adjustment and authentication
 */
class EnhancedFileSystem implements IFileSystem {
  /**
   * Creates enhanced file system with optional GitHub authentication
   * @param githubAuthToken - Optional GitHub OAuth token for private repos
   */
  constructor(githubAuthToken?: string);

  /**
   * Enumerates file URIs in a folder, filtering for configuration files
   * @param folderUri - URI of the folder to enumerate
   * @returns Promise resolving to array of file URIs
   */
  EnumerateFileUris(folderUri: string): Promise<string[]>;

  /**
   * Reads content from URI with GitHub authentication support
   * @param uri - URI of the file to read (automatically converts GitHub URLs to raw format)
   * @returns Promise resolving to file content
   */
  ReadFile(uri: string): Promise<string>;

  /**
   * Writes content to a file URI
   * @param uri - URI of the file to write
   * @param content - Content to write
   * @returns Promise that resolves when write completes
   */  
  WriteFile(uri: string, content: string): Promise<void>;
}

Usage Examples:

import { EnhancedFileSystem } from "@microsoft.azure/autorest-core/lib/file-system";

// Create with GitHub token for private repositories
const enhancedFs = new EnhancedFileSystem("ghp_your_github_token_here");

// Read from GitHub (automatically converts to raw URL and adds auth)
const spec = await enhancedFs.ReadFile(
  "https://github.com/myorg/private-specs/blob/main/api.json"
);

// Read from public GitHub repo (no auth needed)
const publicSpec = await enhancedFs.ReadFile(
  "https://github.com/Azure/azure-rest-api-specs/blob/main/specification/cognitiveservices/data-plane/TextAnalytics/preview/v3.1/TextAnalytics.json"
);

// Enumerate files in a local folder
const localFiles = await enhancedFs.EnumerateFileUris("file:///specs/");

File System Utilities

The file system implementations work with various URI formats and provide automatic conversion for GitHub URLs.

Supported URI Formats

  • File URIs: file:///absolute/path/to/file.json
  • HTTP/HTTPS: https://example.com/api.json
  • GitHub URLs: Automatically converted from blob URLs to raw URLs
  • Relative paths: Resolved against base URIs

GitHub Integration Features

  • Automatic URL conversion from GitHub blob URLs to raw content URLs
  • OAuth token authentication for private repositories
  • Standard GitHub API rate limiting support
  • Proper header handling for authenticated requests

docs

autorest-generator.md

configuration.md

document-processing.md

file-system.md

index.md

messaging.md

tile.json