Skip to content

Building Customized SDKs with Autorest.Swift

Travis Prescott edited this page Feb 28, 2022 · 7 revisions

This document is to be used by teams who want to create an SDK that uses Swagger-based generated code as a base layer in conjunction with a hand-written convenience layer. This document assumes all work is publicly available.

Step 1. Clone Repos

You will need to clone the following repos to your machine:

You will then need to switch to the appropriate branches for each repo:

  • autorest.swift: use the latest on the main branch
  • azure-sdk-for-ios: switch to the feature branch for your service (i.e.: feature/AzureStorageBlob). If a feature branch doesn't exist, contact the SDK team.
  • azure-rest-api-specs: if your Swagger is already merged to main, use that. Often, the Swagger is a work-in-progress on a feature branch, in which case you'll need to switch to that branch.

Step 2. Install AutoRest on your machine

Install autorest on your machine.

Step 3. Generate the Base SDK

In the autorest.swift repo root, run the following:

make build

README File

If you store some of your autorest configuration in a README file with Swift configuration, run the following, updating paths as needed:

autorest <PATH TO README>
--swift
--output-folder=~/<PATH TO azure-sdk-for-ios REPO>/sdk/<NAMESPACE>/<SDK NAME>
--use=~/<PATH to autorest.swift REPO>/

No README File

If you don't have a readme file, run the following command, updating paths as needed:

autorest
--input-file=~/<PATH TO azure-rest-api-specs REPO>/specification/<PATH TO YOUR SWAGGER FILE>
--output-folder=~/<PATH TO azure-sdk-for-ios REPO>/sdk/<NAMESPACE>/<SDK NAME>
--namespace=<SDK NAME>
--use=~/<PATH TO autorest.swift REPO>/

This will generate the SDK inside the azure-sdk-for-ios repo in the correct location.

Step 4. Write Convenience Layer

All generated code can be found under the Sources/Generated folder. Files and folders not found under this folder, such as any you create or the README.md and Package.swift files that are initially generated, will not be overwritten if you re-run the autorest command.

You MUST NOT modify any code under Sources/Generated. You may add or update any convenience code outside of this folder. If you feel you do need to modify something under Sources/Generated, reach out to the SDK team.