Skip to content

AutoRest Clients

The AutoRest tool generates client libraries for accessing Virto Commerce API.

Installing the Autorest


Read the official AutoRest documentation: Installing AutoRest

  • Install Node.js
  • Install AutoRest using npm, at the moment using version 3.0.6274, because the Platform generate the api as OpenApi 3.0.x.
    npm install -g autorest
  • Then reset autorest cache:
    autorest --reset

Generating C# Clients with AutoRest

  • Have the platform run locally (10645 port by default)
  • Generate autorest client on the Storefront
  • Open Tools > NuGet Package Manager > Package Manager Console
  • Run the following commands to generate API clients:
    $modules = @('Platform', 'Cart', 'Catalog', 'Content', 'Core', 'Customer', 'Inventory', 'Marketing', 'Notifications', 'Orders', 'Payment', 'Pricing', 'Shipping', 'Sitemaps', 'Store', 'Subscription', 'Tax')
    $modules.ForEach( { autorest VirtoCommerce.Storefront\AutoRestClients\array-in-query-fix.yml --version=3.0.6274 --v3 --debug --input-file=http://localhost:10645/docs/VirtoCommerce.$_/swagger.json --output-folder=.\VirtoCommerce.Storefront\AutoRestClients --output-file=$_`ModuleApi.cs --namespace=VirtoCommerce.Storefront.AutoRestClients.$_`ModuleApi --override-client-name=$_`ModuleClient --add-credentials --csharp })
  • Add the api client to the ServiceColection:
    services.AddAutoRestClient((credentials, httpClient, disposeHttpClient, baseUri) => new TaxModuleApi(credentials, httpClient, disposeHttpClient) { BaseUri = baseUri });
    services.AddSingleton<ITaxModule>(sp => new TaxModule(sp.GetRequiredService<TaxModuleApi>()));

Know Issues

If code generation fails with errors like "The schema's '...' ancestors should have at lease one property", please make sure that the following platform configuration flags are explicitly set to false (either in appsettings.json or in Azure application service settings):

  • VirtoCommerce:UseAllOfToExtendReferenceSchemas
  • VirtoCommerce:IncludeOutputNullValues

Last update: May 8, 2023