Permalink
Switch branches/tags
v2.0.4216 v2.0.4215 v1.2.2 v1.2.1 v1.2.1-20170717-2300-nightly v1.2.1-20170716-2300-nightly v1.2.1-20170715-2300-nightly v1.2.0 v1.2.0-20170714-2300-nightly v1.2.0-20170713-2300-nightly v1.1.0 v1.1.0-20170712-2300-nightly v1.1.0-20170711-2300-nightly v1.1.0-20170710-2300-nightly v1.1.0-20170709-2300-nightly v1.1.0-20170708-2300-nightly v1.1.0-20170707-2300-nightly v1.1.0-20170706-2300-nightly v1.1.0-20170705-2300-nightly v1.1.0-20170704-2300-nightly v1.1.0-20170703-2300-nightly v1.1.0-20170702-2300-nightly v1.1.0-20170701-2300-nightly v1.1.0-20170630-2300-nightly v1.1.0-20170629-2300-nightly v1.1.0-20170628-2300-nightly v1.1.0-20170627-2300-nightly v1.1.0-20170626-2300-nightly v1.1.0-20170625-2300-nightly v1.1.0-20170624-2300-nightly v1.1.0-20170623-2300-nightly v1.1.0-20170622-2300-nightly v1.1.0-20170621-2300-nightly v1.1.0-20170620-2300-nightly v1.1.0-20170619-2300-nightly v1.1.0-20170619-2207-preview v1.1.0-20170618-2300-nightly v1.1.0-20170617-2300-nightly v1.1.0-20170616-2300-nightly v1.1.0-20170615-2300-nightly v1.0.1 v1.0.1-20170614-2300-nightly v1.0.1-20170613-2300-nightly v1.0.1-20170612-2300-nightly v1.0.1-20170611-2300-nightly v1.0.1-20170610-2300-nightly v1.0.1-20170609-2300-nightly v1.0.1-20170608-2300-nightly v1.0.1-20170607-2300-nightly v1.0.1-20170606-2300-nightly v1.0.1-20170605-2300-nightly v1.0.1-20170604-2300-nightly v1.0.1-20170603-2300-nightly v1.0.1-20170602-2300-nightly v1.0.1-20170601-1255-preview v1.0.1-20170601-1221-preview v1.0.1-20170601-1157-preview v1.0.1-20170601-0934-preview v1.0.1-20170531-2300-nightly v1.0.1-20170530-2300-nightly v1.0.1-20170529-2300-nightly v1.0.1-20170528-2300-nightly v1.0.1-20170527-2300-nightly v1.0.1-20170526-2300-nightly v1.0.1-20170525-2300-nightly v1.0.1-20170524-2300-nightly v1.0.1-20170523-2300-nightly v1.0.1-20170523-1028-preview v1.0.1-20170522-2300-nightly v1.0.1-20170521-2300-nightly v1.0.1-20170520-2300-nightly v1.0.1-20170519-2300-nightly v1.0.1-20170518-2300-nightly v1.0.1-20170517-2300-nightly v1.0.1-20170516-2300-nightly v1.0.1-20170515-2300-nightly v1.0.1-20170514-2300-nightly v1.0.1-20170513-2300-nightly v1.0.1-20170512-2300-nightly v1.0.1-20170511-2300-nightly v1.0.1-20170510-2300-nightly v1.0.1-20170508-2300-nightly v1.0.1-20170507-2300-nightly v1.0.1-20170506-2300-nightly v1.0.1-20170505-2300-nightly v1.0.1-20170504-2300-nightly v1.0.1-20170503-2300-nightly v1.0.1-20170502-2300-nightly v1.0.1-20170501-2300-nightly v1.0.1-20170430-2300-nightly v1.0.1-20170429-2300-nightly v1.0.1-20170428-2300-nightly v1.0.1-20170427-2300-nightly v1.0.1-20170425-2300-nightly v1.0.1-20170424-2300-nightly v1.0.1-20170423-2300-nightly v1.0.1-20170422-2300-nightly v1.0.1-20170421-2300-nightly v1.0.1-20170420-2300-nightly v1.0.1-20170419-2300-nightly
Nothing to show
Find file Copy path
121 lines (88 sloc) 7.52 KB

AutoRest Command Line Interface Documentation

AutoRest

The AutoRest command line has been vastly simplified, with the preference to move things that were on the command line into a configuration file, with the ability to override the configuration file settings from the command line.

Command-line Usage

autorest [config-file.md] [additional options]

Configuration file

AutoRest will use a configuration file to control the code generation process. By default, AutoRest will look for a file called readme.md or it can be passed on the command line.

This is the preferred method, instead of passing all the information on the command line.

If you prefer to name your configuration file something else, you can supply the filename on the command line:

autorest my_config.md 

Passing additional options on the command line.

It is possible to override settings from the configuration file on the command line by prefacing the value with double dash (--) and setting the value with an equals sign (=). Ie:

autorest --input-file=myfile.json --output-folder=./generated/code/ --namespace=foo.bar

Common Command-line Options

Output Verbosity

Option Description
--verbose show verbose output information
--debug show internal debug information
--quiet suppress output

Managing the installed/used AutoRest version

Option                                Description
--list-installed show all installed versions of AutoRest tools
--list-available=nn lists the last nn releases available from github (defaults to 10)
--version=version uses version of AutoRest (installing if necessary.)
For version you can use a version label (see --list-available) or
  latest - get latest nightly build
  latest-release - get latest release version
--reset remove all installed versions of AutoRest tools and install the latest (override with --version)
--runtime-id=id overrides the platform detection for the dotnet runtime (special case). Refer to the Runtime Identifier (RID) catalog for more details.

Commonly used Settings

Option                                                                  Description
--input-file=FILENAME Adds the given file to the list of input files for generation process
--output-folder=DIRECTORY The location for generated files. If not specified, uses ./Generated as the default
--namespace=NAMESPACE sets the namespace to use for the generated code
--license-header|licence-header=HEADER Text to include as a header comment in generated files. Use NONE to suppress the default header.
--add-credentials If specified, the generated client includes a ServiceClientCredentials property and constructor parameter. Authentication behaviors are implemented by extending the ServiceClientCredentials type.
--package-name=PACKAGENAME Name of the package (Ruby, Python)
--package-version=VERSION Version of the package (Ruby, Python)
--sync-methods=all|essential|none Specifies mode for generating sync wrappers. Supported value are
  essential - generates only one sync returning body or header (default)
  all - generates one sync method for each async method
  none - does not generate any sync methods
--payload-flattening-threshold=NUMBER The maximum number of properties in the request body. If the number of properties in the request body is less than or equal to this value, these properties will be represented as method arguments
--override-client-name=NAME Name to use for the generated client type. By default, uses the value of the 'Title' field from the input files
--use-internal-constructors Indicates whether ctor needs to be generated with internal protection level.
--use-datetimeoffset Indicates whether to use DateTimeOffset instead of DateTime to model date-time types
--models-name=NAME Name to use for the generated client models namespace and folder name. By default, uses the value of 'Models'. This is not currently supported by all code generators.
--output-file=FILENAME If set, will cause generated code to be output to a single file. Not supported by all code generators.
--message-format=regular|json Specifies the format, messages will be printed as. JSON format is easier to process programmatically.

Authentication

AutoRest supports generating from private GitHub repositories. There are multiple options:

  1. Using the token query parameter: Pass the token query parameter you get when clicking "Raw" on a file of a private repo, i.e. https://github.com/<path-on-some-private-repo>/readme.md?token=<token>. When such a URI is passed to AutoRest, it will automatically reuse that token for subsequent requests (e.g. querying referenced OpenAPI definitions). This is a quick and easy solution if you manually want to run AutoRest against private bits from time to time.
  2. Using OAuth: GitHub allows generating OAuth tokens under Settings -> Personal access tokens. Create one with repo scope. It can be passed to AutoRest using --github-auth-token=<token> or by setting the environment variable GITHUB_AUTH_TOKEN. This is the way to go for all scripts and automation. Needless to say, do not put this token into scripts directly, use Azure KeyVault or similar.

Validation

Option                                                                  Description
--azure-validator If set, runs the Azure specific validator plugin.
--openapi-type=arm│default│data-plane Indicates the type of configuration file being passed to the azure-validator so that it can run the appropriate class of validation rules accordingly.
--model-validator (soon) If set, validates the provided OpenAPI definition(s) against provided examples.
--semantic-validator (soon) If set, semantically verifies the provided OpenAPI definition(s), e.g. checks that a parameter's specified default value matches the parameter's declared type.

Example: Run autorest --azure-validator --input-file=<path-to-spec> --message-format=json --openapi-type=arm to get the validation messages considering ARM guidelines in JSON format.

Also, see Samples/2a-validation for an example of validation using a configuration file.

Selecting the Language with which to generate code

Option                                Description
--csharp Runs the C# code generator
--nodejs Runs the nodejs javascript code generator
--python Runs the python code generator
--java Runs the java code generator
--ruby Runs the ruby code generator
--go Runs the go code generator
--typescript Runs the typescript code generator
--azureresourceschema Runs the AzureResourceSchema
 
--azure-arm Uses the Azure version of the specified code generator

You may generate one or more languages in a given invocation, ie:

autorest --csharp --python --ruby

To set a language-specific setting, prefix the setting with the language, ie:

autorest --csharp.namespace=Foo.Bar