Code generation tool that generates client libraries for accessing RESTful web services from OpenAPI specifications
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Configuration and settings management for AutoRest operations, primarily through the programmatic API and CLI interfaces.
AutoRest accepts configuration through multiple channels when using the programmatic API.
/**
* Main AutoRest interface - accepts configuration via AddConfiguration method
* Use create() function to get instances of this interface
*/
interface AutoRest {
/**
* Add configuration to the AutoRest instance
* Configuration is merged with existing settings
* @param config - Configuration object with AutoRest settings
*/
AddConfiguration(config: any): Promise<void>;
/**
* Process the configured specifications and generate code
* @returns Promise resolving to generation results
*/
Process(): Promise<GenerationResults>;
}Usage Examples:
import { create } from "autorest";
const autorest = await create(logger);
// Basic C# generation configuration
await autorest.AddConfiguration({
"input-file": "https://example.com/petstore.json",
"output-folder": "./generated/csharp",
"csharp": true,
"namespace": "PetStore.Client",
"client-name": "PetStoreClient"
});
// Additional configuration for authentication
await autorest.AddConfiguration({
"add-credentials": true,
"credential-default-policy-type": "BearerTokenCredentialPolicy"
});
// TypeScript generation configuration
await autorest.AddConfiguration({
"input-file": "./specs/api.yaml",
"output-folder": "./generated/typescript",
"typescript": true,
"generate-metadata": true,
"source-code-folder-path": "./src"
});
// Process with combined configuration
const results = await autorest.Process();AutoRest supports extensive configuration options for code generation.
/**
* Common AutoRest configuration properties
* These can be passed to AddConfiguration()
*/
interface AutoRestConfigurationOptions {
// Input and Output
"input-file"?: string | string[]; // OpenAPI specification file(s)
"output-folder"?: string; // Output directory for generated code
// Language Generators
"csharp"?: boolean; // Generate C# client
"java"?: boolean; // Generate Java client
"python"?: boolean; // Generate Python client
"typescript"?: boolean; // Generate TypeScript client
"go"?: boolean; // Generate Go client
"powershell"?: boolean; // Generate PowerShell cmdlets
// Generation Options
"namespace"?: string; // Generated code namespace
"client-name"?: string; // Generated client class name
"add-credentials"?: boolean; // Add authentication support
"sync-methods"?: "all" | "essential" | "none"; // Synchronous method generation
"generate-metadata"?: boolean; // Include metadata in output
// Debugging and Output
"debug"?: boolean; // Enable debug output
"verbose"?: boolean; // Enable verbose logging
"message-format"?: "regular" | "json"; // Output message format
// Advanced Options
"override-client-name"?: string; // Override default client naming
"use-datetimeoffset"?: boolean; // Use DateTimeOffset in .NET
"models-subnamespace"?: string; // Subnamespace for model classes
"operations-subnamespace"?: string; // Subnamespace for operation classes
// File and Path Options
"source-code-folder-path"?: string; // Source code output path
"clear-output-folder"?: boolean; // Clear output before generation
// Additional options can be specified as key-value pairs
[key: string]: any;
}AutoRest can load configuration from multiple sources with the following precedence:
AddConfiguration()autorest.md, readme.md, or .autorest folderConfiguration File Example:
Create an autorest.md file in your project:
# AutoRest Configuration
## Basic Settings
```yaml
input-file: ./specs/petstore.yaml
output-folder: ./generated
namespace: PetStore.SDK
client-name: PetStoreClient
```
## C# Configuration
```yaml
csharp:
add-credentials: true
sync-methods: essential
use-datetimeoffset: true
```
## TypeScript Configuration
```yaml
typescript:
generate-metadata: true
source-code-folder-path: ./src
```Usage with Configuration File:
import { create } from "autorest";
// AutoRest will automatically discover and load autorest.md
const autorest = await create(logger, undefined, "./project-folder");
// Additional configuration can still be added programmatically
await autorest.AddConfiguration({
"debug": true,
"verbose": true
});
const results = await autorest.Process();AutoRest validates configuration and provides detailed error messages for invalid settings.
Error Handling:
try {
const autorest = await create(logger);
await autorest.AddConfiguration({
"input-file": "invalid-spec.yaml",
"csharp": true,
"invalid-option": "not-supported"
});
const results = await autorest.Process();
} catch (error) {
// Handle configuration or generation errors
console.error("AutoRest configuration error:", error);
}Configuration can be influenced by environment variables:
autorest.md for team consistencyAddConfiguration() callsclear-output-folder option carefully to avoid data lossEach language generator supports specific configuration options:
namespace, client-name, add-credentialssync-methods, use-datetimeoffsetmodels-subnamespace, operations-subnamespacegenerate-metadata, source-code-folder-pathpackage-name, package-versionpackage-name, package-versionbasic-setup-py, override-client-namepackage-name, client-side-validationgenerate-client-as-impl, sync-methodsRefer to language-specific generator documentation for complete option lists.