...

Text file src/github.com/Azure/azure-sdk-for-go/documentation/code-generation.md

Documentation: github.com/Azure/azure-sdk-for-go/documentation

     1# Generate code
     2
     3## Generate SDK packages
     4
     5### Generate an Azure-SDK-for-Go service package
     6
     71. [Install AutoRest](https://github.com/Azure/autorest#installing-autorest).
     8
     91. Call autorest with the following arguments...
    10
    11``` cmd
    12autorest path/to/readme/file --go --go-sdk-folder=<your/gopath/src/github.com/Azure/azure-sdk-for-go> --package-version=<version> --user-agent=<Azure-SDK-For-Go/version services> [--tag=choose/a/tag/in/the/readme/file]
    13```
    14
    15For example...
    16
    17``` cmd
    18autorest C:/azure-rest-api-specs/specification/advisor/resource-manager/readme.md --go --go-sdk-folder=C:/goWorkspace/src/github.com/Azure/azure-sdk-for-go --tag=package-2016-07-preview --package-version=v11.2.0-beta --user-agent='Azure-SDK-For-Go/v11.2.0-beta services'
    19```
    20
    21- If you are looking to generate code based on a specific swagger file, you can replace `path/to/readme/file` with `--input-file=path/to/swagger/file`.
    22- If the readme file you want to use as input does not have golang tags yet, you can call autorest like this...
    23
    24``` cmd
    25autorest path/to/readme/file --go --license-header=<MICROSOFT_APACHE_NO_VERSION> --namespace=<packageName> --output-folder=<your/gopath/src/github.com/Azure/azure-sdk-for-go/services/serviceName/mgmt/APIversion/packageName> --package-version=<version> --user-agent=<Azure-SDK-For-Go/version services> --clear-output-folder --can-clear-output-folder --tag=<choose/a/tag/in/the/readme/file>
    26```
    27
    28For example...
    29
    30``` cmd
    31autorest --input-file=https://raw.githubusercontent.com/Azure/azure-rest-api-specs/current/specification/network/resource-manager/Microsoft.Network/2017-10-01/loadBalancer.json --go --license-header=MICROSOFT_APACHE_NO_VERSION --namespace=lb --output-folder=C:/goWorkspace/src/github.com/Azure/azure-sdk-for-go/services/network/mgmt/2017-09-01/network/lb --package-version=v11.2.0-beta --clear-output-folder --can-clear-output-folder
    32```
    33
    341. Run `go fmt` on the generated package folder.
    35
    361. To make sure the SDK has been generated correctly, also run `golint`, `go build` and `go vet`.
    37
    38### Generate Azure SDK for Go service packages in bulk
    39
    40All services, all API versions.
    41
    421. [Install AutoRest](https://github.com/Azure/autorest#installing-autorest).
    43
    44This repo contains a tool to generate the SDK, which depends on the golang tags from the readme files in the Azure REST API specs repo. The tool assumes you have an [Azure REST API specs](https://github.com/Azure/azure-rest-api-specs) clone, and [golint](https://github.com/golang/lint) is installed.
    45
    461. `cd eng/tools/generator`
    47
    481. `go install`
    49
    501. Add `GOPATH/bin` to your `PATH`, in case it was not already there.
    51
    521. Call the generator tool like this...
    53
    54``` cmd
    55generator –r [–v] [–l=logs/output/folder] –version=<version> path/to/your/swagger/repo/clone
    56```
    57
    58For example...
    59
    60``` cmd
    61generator –r –v –l=temp –version=v11.2.0-beta C:/azure-rest-api-specs
    62```
    63
    64The generator tool already runs `go fmt`, `golint`, `go build` and `go vet`; so running them is not necessary.
    65
    66#### Use the generator tool to generate a single package
    67
    681. Just call the generator tool specifying the service to be generated in the input folder.
    69
    70``` cmd
    71generator –r [–v] [–l=logs/output/folder] –version=<version> path/to/your/swagger/repo/clone/specification/service
    72```
    73
    74For example...
    75
    76``` cmd
    77generator –r –v –l=temp –version=v11.2.0-beta C:/azure-rest-api-specs/specification/network
    78```
    79
    80## Include a new package in the SDK
    81
    821. Submit a pull request to the Azure REST API specs repo adding the golang tags for the service and API versions in the service readme file, if the needed tags are not there yet.
    83
    841. Once the tags are available in the Azure REST API specs repo, generate the SDK.
    85
    861. In the changelog file, document the new generated SDK. Include the [autorest.go extension](https://github.com/Azure/autorest.go) version used, and the Azure REST API specs repo commit from where the SDK was generated.
    87
    881. Install [dep](https://github.com/golang/dep).
    89
    901. Run `dep ensure`.
    91
    921. Submit a pull request to this repo, and we will review it.
    93
    94## Generate Azure SDK for Go profiles
    95
    96Take a look into the [profile generator documentation](https://github.com/Azure/azure-sdk-for-go/tree/main/eng/tools/profileBuilder)

View as plain text