Skip to content

Dataplane Codegen Quick Start with tools

Yuchao Yan edited this page Jun 3, 2024 · 29 revisions

The documentation describes how to generate Dataplane Codegen code with tools quickly.

Prerequisites

Setup your repo

Prepare Python Dev Environment(Windows)

assume work path is D:\

  • create virtual environment

    python -m venv venv-dev
    .\venv-dev\Scripts\Activate.ps1
    

Generate code(Windows)

If it is the first time for service to generate SDK, you need the script to help generate necessary files(setup.py, CHANGELOG.md, etc) which are necessary for a complete Python package, and go to Create;If you just want to update code, go to Update

Create

Before using the script, you need to run the following command:

pip install -r D:\azure-sdk-for-python\scripts\quickstart_tooling_dpg\dev_requirements.txt

Parameter Introduction

The scripts needs necessary parameters to generate SDK code:

  • --input-file: absolute path or url path of swagger input file. For example: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/webpubsub/data-plane/WebPubSub/stable/2021-10-01/webpubsub.json or D:\azure-rest-api-specs\specification\webpubsub\data-plane\WebPubSub\stable\2021-10-01\webpubsub.json. If there are multi files, the format is file1,file2,...,fileN and please make sure there is no space around ,
  • --output-folder: absolute path where generated SDK package will be put
  • --package-name: package name. For example: "azure-messaging-webpubsub"
  • --package-pprint-name: print name of the package. For example: "Azure Web PubSub Service"
  • --client-name: client name. For example: "WebPubSubServiceClient"
  • --security-scope/--security-header-name: If authentication is AADToken, security-scope is needed, like: https://webpubsub.azure.com/.default"; if authentication is api key, security-header-name is needed. See authentication

Here is the example, just try to run :

  • AADToken authentication
python D:\azure-sdk-for-python\scripts\quickstart_tooling_dpg\main.py --output-folder D:\azure-sdk-for-python\sdk\dpgexample\azure-messaging-webpubsubservic --input-file https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/webpubsub/data-plane/WebPubSub/stable/2021-10-01/webpubsub.json --security-scope https://webpubsub.azure.com/.default --package-name azure-messaging-webpubsubserviceexample --package-pprint-name "Azure WebPubSub Service" --client-name WebPubSubServiceClient

Or

  • Api key authentication

    python D:\azure-sdk-for-python\scripts\quickstart_tooling_dpg\main.py --output-folder D:\azure-sdk-for-python\sdk\dpgexample\azure-messaging-webpubsubservic --input-file https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/webpubsub/data-plane/WebPubSub/stable/2021-10-01/webpubsub.json --security-header-name ApiKeyHeader --package-name azure-messaging-webpubsubserviceexample --package-pprint-name "Azure WebPubSub Service" --client-name WebPubSubServiceClient
    

After running the scripts successfully, it creates necessary files and common test framework. But remember to edit README.md, test files under tests and sample files under samples since customers need more info to understand the package. You don't need it anymore after one-time successful run. Go to Update if you need to regenerate code.(webpubsub is a good example)

What to do after generating the SDK code

Please follow What-to-do-after-generating-the-SDK-code-with-codegen

Update

After Create, there will be READMD.md under swagger folder of output_folder. If need to update the code, step into swagger folder and run the following command:

autorest --version=3.10.2 --use=@autorest/python@6.13.18 --use=@autorest/modelerfour@4.27.0 README.md