-
Notifications
You must be signed in to change notification settings - Fork 2k
Working with AutoRest
AutoRest is the name of the tool we use to generate the communication layer that lies beneath the API we expose to our users. AutoRest saves us from having to write a lot of network communication code, and instead we can direct our focus towards building a great user experience on top of this generated code. Our goal should be to expose as little, and ideally none, of the generated code to the user.
- Fork and clone this GitHub repo.
git clone https://github.com/Azure/autorest.java.git
- Build the package using Maven
mvn clean package -Dlocal
- Run
npm install
. You need v10 version of Node.JS installed. - Run
npm install -g autorest
. - Run AutoRest commands like this:
To generate code from a local README file:
autorest --java --use=C:\work\autorest.java\ C:\swagger\updated\Blob\readme.md --output-folder=C:\work\azure-sdk-for-java\storage\client\ --namespace=com.azure.storage.blob --sync-methods=none --generate-client-interfaces=false --enable-xml --required-parameter-client-methods
To generate code from a json swagger spec accessed from a URL:
autorest --java --use:./ --input-file=https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/specification/search/data-plane/Azure.Search/preview/2019-05-06-preview/searchservice.json --namespace=com.azure.search.service --output-folder=generated-code --sync-methods=all --client-side-validations=true --add-context-parameter=true --context-client-method-parameter=true
- Include license header in generated code
Option name: license-header
Option values:
Option Value | Header |
---|---|
MICROSOFT_MIT | |
MICROSOFT_APACHE | |
MICROSOFT_MIT_NO_VERSION | |
MICROSOFT_APACHE_NO_VERSION | |
MICROSOFT_MIT_NO_CODEGEN | |
MICROSOFT_MIT_SMALL | |
MICROSOFT_MIT_SMALL_NO_CODEGEN | |
NONE |
-
Namespace
Option name:
namespace
Option value: Java base package name used for generating the code
-
Client side validation
Option name:
client-side-validations
Default value:
false
-
Client type prefix
Option name:
client-type-prefix
-
Generate client interfaces
Option name:
generate-client-interfaces
-
Generate client as implementation type
Option name:
generate-client-as-impl
-
Implementation subpackage name
Option name:
implementation-subpackage
-
Models subpackage name
Option name:
models-subpackage
-
Custom types
Option name:
custom-types
-
Custom types subpackage name
Option name:
custom-types-subpackage
-
Add context parameter to proxy methods
Option name:
add-context-parameter
-
Add context parameter to client methods
Option name:
context-client-method-parameter
-
Generate sync and async clients
Option name:
generate-sync-async-clients
-
Generate models with required fields as constructor arguments
Option name:
required-fields-as-ctor-args
-
Enable xml
Option name:
enable-xml
-
Generate fluent interface
Option name:
fluent
-
Output folder
Option name:
output-folder
-
Input file
Option name:
input-file
--use=<path to your autorest.java clone>
- If the input is a JSON spec, use
--input-file=<local path of URL of JSON file>
, if it's a README.md file, remove--input-file=
-
--enable-xml --required-parameter-client-methods
are not needed for services other than Storage -
autorest --reset
to remove all extensions; orautorest --version=<string>
to specify the autorest.core version
- Frequently Asked Questions
- Azure Identity Examples
- Configuration
- Performance Tuning
- Android Support
- Unit Testing
- Test Proxy Migration
- Azure Json Migration
- New Checkstyle and Spotbugs pattern migration
- Protocol Methods
- TypeSpec-Java Quickstart
- Getting Started Guidance
- Adding a Module
- Building
- Writing Performance Tests
- Working with AutoRest
- Deprecation
- BOM guidelines
- Release process
- Access helpers