or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

autorest-generator.mdconfiguration.mddocument-processing.mdfile-system.mdindex.mdmessaging.md

configuration.mddocs/

0

# Configuration Management

1

2

AutoRest Core provides a hierarchical configuration system that supports multiple configuration sources, view-based access patterns, and comprehensive options for customizing the code generation process. The system handles loading configurations from files, merging multiple sources, and provides a unified view for the generation pipeline.

3

4

## Capabilities

5

6

### Configuration View

7

8

The primary interface for accessing resolved configuration values from multiple sources.

9

10

```typescript { .api }

11

/**

12

* Configuration view providing access to resolved configuration values

13

*/

14

class ConfigurationView {

15

/**

16

* Message emitter for configuration-related events

17

*/

18

messageEmitter: MessageEmitter;

19

20

// Configuration access methods (implementation details vary)

21

// Provides unified access to all merged configuration sources

22

}

23

```

24

25

### Configuration Structure

26

27

Complete configuration interface defining all available AutoRest options.

28

29

```typescript { .api }

30

/**

31

* Complete AutoRest configuration structure

32

*/

33

interface AutoRestConfigurationImpl {

34

// Core input/output options

35

/** Input OpenAPI specification file(s) */

36

"input-file"?: string | string[];

37

/** Output folder for generated code */

38

"output-folder"?: string;

39

/** Base folder for resolving relative paths */

40

"base-folder"?: string;

41

42

// Processing control options

43

/** Enable debug mode with verbose logging */

44

"debug"?: boolean;

45

/** Enable verbose output */

46

"verbose"?: boolean;

47

/** Format for log messages */

48

"message-format"?: string;

49

/** Clear output folder before generation */

50

"clear-output-folder"?: boolean;

51

52

// Plugin and extension options

53

/** Extensions to use during generation */

54

"use-extension"?: string | string[];

55

/** Additional modules to require */

56

"require"?: string | string[];

57

/** Processing directives for customization */

58

"directive"?: any[];

59

60

// Language-specific options

61

/** Namespace for generated code */

62

"namespace"?: string;

63

/** Package name for generated code */

64

"package-name"?: string;

65

/** Client name for generated classes */

66

"client-name"?: string;

67

/** Client-side validation options */

68

"client-side-validation"?: boolean;

69

70

// Advanced processing options

71

/** Override information section */

72

"override-info"?: {

73

title?: string;

74

description?: string;

75

version?: string;

76

};

77

/** License header for generated files */

78

"license-header"?: string;

79

/** Add credentials to generated client */

80

"add-credentials"?: boolean;

81

/** Payload flattening threshold */

82

"payload-flattening-threshold"?: number;

83

84

// Pipeline customization

85

/** Custom pipeline stages */

86

"pipeline"?: { [stage: string]: any };

87

/** Pass additional properties to generators */

88

"pass-thru"?: { [key: string]: any };

89

}

90

```

91

92

**Usage Examples:**

93

94

```typescript

95

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

96

97

const autorest = new AutoRest();

98

99

// Basic configuration

100

autorest.AddConfiguration({

101

"input-file": "petstore.json",

102

"output-folder": "./generated",

103

"namespace": "PetStore",

104

"client-name": "PetStoreClient"

105

});

106

107

// Advanced configuration with multiple inputs

108

autorest.AddConfiguration({

109

"input-file": [

110

"swagger/pets.json",

111

"swagger/users.json",

112

"swagger/orders.json"

113

],

114

"output-folder": "./src/generated",

115

"base-folder": "./specs",

116

"clear-output-folder": true,

117

"debug": true,

118

"verbose": true,

119

"client-side-validation": true,

120

"payload-flattening-threshold": 2

121

});

122

123

// Language-specific configuration

124

autorest.AddConfiguration({

125

"package-name": "my-api-client",

126

"license-header": "Copyright (c) 2023 My Company. All rights reserved.",

127

"add-credentials": true,

128

"override-info": {

129

title: "My API Client",

130

description: "Generated client for My API",

131

version: "1.0.0"

132

}

133

});

134

```

135

136

### Configuration Merging

137

138

Utility function for merging multiple configuration objects.

139

140

```typescript { .api }

141

/**

142

* Merges multiple configuration objects into a single configuration

143

* @param configs - Configuration objects to merge (later configs override earlier ones)

144

* @returns Merged configuration object

145

*/

146

function MergeConfigurations(...configs: AutoRestConfigurationImpl[]): AutoRestConfigurationImpl;

147

```

148

149

**Usage Examples:**

150

151

```typescript

152

import { MergeConfigurations } from "@microsoft.azure/autorest-core";

153

154

// Base configuration

155

const baseConfig = {

156

"output-folder": "./generated",

157

"clear-output-folder": true,

158

"debug": false

159

};

160

161

// Environment-specific overrides

162

const devConfig = {

163

"debug": true,

164

"verbose": true,

165

"output-folder": "./dev-generated"

166

};

167

168

// Project-specific settings

169

const projectConfig = {

170

"namespace": "MyProject",

171

"client-name": "MyProjectClient"

172

};

173

174

// Merge configurations (later configs override earlier ones)

175

const finalConfig = MergeConfigurations(baseConfig, devConfig, projectConfig);

176

177

console.log(finalConfig);

178

// Result: {

179

// "output-folder": "./dev-generated", // overridden by devConfig

180

// "clear-output-folder": true, // from baseConfig

181

// "debug": true, // overridden by devConfig

182

// "verbose": true, // from devConfig

183

// "namespace": "MyProject", // from projectConfig

184

// "client-name": "MyProjectClient" // from projectConfig

185

// }

186

```

187

188

## Configuration Loading

189

190

AutoRest supports loading configuration from multiple sources with a well-defined precedence order:

191

192

### Configuration Sources (in precedence order, highest to lowest)

193

194

1. **Programmatic Configuration**: Added via `AddConfiguration()` method

195

2. **Command Line Arguments**: Specified via CLI flags

196

3. **Configuration Files**: Loaded from specified config file or folder

197

4. **Default Configuration**: Built-in default values

198

199

### Configuration File Formats

200

201

**JSON Configuration** (`.autorest.json`):

202

```json

203

{

204

"input-file": "swagger.json",

205

"output-folder": "./generated",

206

"namespace": "MyClient",

207

"debug": true

208

}

209

```

210

211

**YAML Configuration** (`.autorest.yaml`):

212

```yaml

213

input-file: swagger.json

214

output-folder: ./generated

215

namespace: MyClient

216

debug: true

217

```

218

219

**Literate Configuration** (`.autorest.md` or `README.md`):

220

````markdown

221

# AutoRest Configuration

222

223

> Input specification

224

input-file: swagger.json

225

226

> Output settings

227

output-folder: ./generated

228

namespace: MyClient

229

230

> Processing options

231

debug: true

232

verbose: false

233

````

234

235

### Configuration File Discovery

236

237

AutoRest automatically discovers configuration files using this search order:

238

239

1. **Explicit File**: If `configFileOrFolderUri` parameter specifies a file

240

2. **Folder Search**: If parameter specifies a folder, search for:

241

- `.autorest.json`

242

- `.autorest.yaml`

243

- `.autorest.md`

244

- `README.md` (with AutoRest configuration)

245

3. **Parent Directory Search**: Recursively search parent directories

246

4. **Home Directory**: Check user home directory for global configuration

247

248

### Advanced Configuration Features

249

250

**Environment Variable Expansion**:

251

```json

252

{

253

"output-folder": "${OUTPUT_DIR}/generated",

254

"namespace": "${PROJECT_NAME}Client"

255

}

256

```

257

258

**Conditional Configuration**:

259

```json

260

{

261

"input-file": "swagger.json",

262

"output-folder": "./generated",

263

"directive": [

264

{

265

"where": "$.paths[*][*]",

266

"transform": "$.operationId = $.operationId + 'Async'"

267

}

268

]

269

}

270

```

271

272

**Multi-Language Configuration**:

273

```json

274

{

275

"input-file": "swagger.json",

276

"csharp": {

277

"output-folder": "./generated/csharp",

278

"namespace": "MyCompany.Api"

279

},

280

"typescript": {

281

"output-folder": "./generated/typescript",

282

"package-name": "my-api-client"

283

}

284

}

285

```